2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.datalake.feeder.util;
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;
32 import static org.mockito.Mockito.when;
34 import static org.junit.Assert.*;
41 public class HttpClientUtilTest {
44 private RestTemplate restTemplate;
47 private HttpEntity httpEntity;
50 private ResponseEntity responseEntity;
53 // public void before() {
54 // responseEntity = restTemplate.postForEntity("", httpEntity, String.class);
58 public void testSendPostKibana() {
60 String templateName = "unauthenticated.test";
61 String testUrl = "http://localhost:9200/_template/"+templateName;
62 String testJson = "{\n" +
63 "\t\"template\":\"unauthenticated.test\",\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" +
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" +
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" +
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 }");
89 assertEquals(false, HttpClientUtil.sendPostKibana(testUrl, testJson, testFlag));