762b30253bc7926cc96806ee3e2b32ad43d9912f
[dcaegen2/services.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : DataLake
4  * ================================================================================
5  * Copyright 2019 China Mobile
6  *=================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.datalake.feeder.util;
22
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.mockito.Mock;
27 import org.mockito.junit.MockitoJUnitRunner;
28 import org.springframework.http.HttpEntity;
29 import org.springframework.http.ResponseEntity;
30 import org.springframework.web.client.RestTemplate;
31
32 import static org.mockito.Mockito.when;
33
34 import static org.junit.Assert.*;
35
36 /**
37  * Test HtpClient
38  *
39  * @author guochunmeng
40  */
41 public class HttpClientUtilTest {
42
43     @Mock
44     private RestTemplate restTemplate;
45
46     @Mock
47     private HttpEntity httpEntity;
48
49     @Mock
50     private ResponseEntity responseEntity;
51
52 //    @Before
53 //    public void before() {
54 //        responseEntity = restTemplate.postForEntity("", httpEntity, String.class);
55 //    }
56
57     @Test
58     public void testSendPostKibana() {
59
60         String templateName = "unauthenticated.test";
61         String testUrl = "http://localhost:9200/_template/"+templateName;
62         String testJson = "{\n" +
63                 "\t\"template\":\"unauthenticated.test\",\n" +
64                 "\t\"order\":1,\n" +
65                 "\t\"mappings\":{\n" +
66                 "\t\t\"_default_\":{\n" +
67                 "\t\t\t\"properties\":{\n" +
68                 "\t\t\t\t\"datalake_ts_\":{\n" +
69                 "\t\t\t\t\t\"type\":\"date\",\n" +
70                 "\t\t\t\t\t\"format\":\"epoch_millis\"\n" +
71                 "\t\t\t\t},\n" +
72                 "\t\t\t\t\"event.commonEventHeader.startEpochMicrosec\":{\n" +
73                 "\t\t\t\t\t\"type\":\"date\",\n" +
74                 "\t\t\t\t\t\"format\":\"epoch_millis\"\n" +
75                 "\t\t\t\t},\n" +
76                 "\t\t\t\t\"event.commonEventHeader.lastEpochMicrosec\":{\n" +
77                 "\t\t\t\t\t\"type\":\"date\",\n" +
78                 "\t\t\t\t\t\"format\":\"epoch_millis\"\n" +
79                 "\t\t\t\t}\n" +
80                 "\t\t\t}\n" +
81                 "\t\t}\n" +
82                 "\t}\n" +
83                 "}";
84         String testFlag = "ElasticsearchMappingTemplate";
85 //        when(restTemplate.postForEntity(testUrl, httpEntity, String.class)).thenReturn(responseEntity);
86 //        when(responseEntity.getStatusCodeValue()).thenReturn(200);
87 //        when(responseEntity.getBody()).thenReturn("{ \"acknowledged\": true }");
88
89         assertEquals(false, HttpClientUtil.sendPostKibana(testUrl, testJson, testFlag));
90     }
91 }