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.apache.http.HttpResponse;
24 import org.apache.http.client.HttpClient;
25 import org.apache.http.client.methods.HttpPost;
26 import org.junit.Test;
27 import org.mockito.Mock;
28 import static org.mockito.Mockito.when;
30 import java.io.IOException;
32 import static org.junit.Assert.*;
40 public class HttpClientUtilTest {
43 private HttpClient httpClient;
46 private HttpPost httpPost;
49 private HttpResponse httpResponse;
51 @Test(expected = RuntimeException.class)
52 public void testSendPostHttpClient() {
54 String testUrl = "http://localhost:5601/api/kibana/dashboards/import?exclude=index-pattern";
55 String testJson = "{\n" +
58 " \"id\": \"80b956f0-b2cd-11e8-ad8e-85441f0c2e5c\",\n" +
59 " \"type\": \"visualization\",\n" +
60 " \"updated_at\": \"2018-09-07T18:40:33.247Z\",\n" +
61 " \"version\": 1,\n" +
62 " \"attributes\": {\n" +
63 " \"title\": \"Count Example\",\n" +
64 " \"visState\": \"{\\\"title\\\":\\\"Count Example\\\",\\\"type\\\":\\\"metric\\\",\\\"params\\\":{\\\"addTooltip\\\":true,\\\"addLegend\\\":false,\\\"type\\\":\\\"metric\\\",\\\"metric\\\":{\\\"percentageMode\\\":false,\\\"useRanges\\\":false,\\\"colorSchema\\\":\\\"Green to Red\\\",\\\"metricColorMode\\\":\\\"None\\\",\\\"colorsRange\\\":[{\\\"from\\\":0,\\\"to\\\":10000}],\\\"labels\\\":{\\\"show\\\":true},\\\"invertColors\\\":false,\\\"style\\\":{\\\"bgFill\\\":\\\"#000\\\",\\\"bgColor\\\":false,\\\"labelColor\\\":false,\\\"subText\\\":\\\"\\\",\\\"fontSize\\\":60}}},\\\"aggs\\\":[{\\\"id\\\":\\\"1\\\",\\\"enabled\\\":true,\\\"type\\\":\\\"count\\\",\\\"schema\\\":\\\"metric\\\",\\\"params\\\":{}}]}\",\n" +
65 " \"uiStateJSON\": \"{}\",\n" +
66 " \"description\": \"\",\n" +
67 " \"version\": 1,\n" +
68 " \"kibanaSavedObjectMeta\": {\n" +
69 " \"searchSourceJSON\": \"{\\\"index\\\":\\\"90943e30-9a47-11e8-b64d-95841ca0b247\\\",\\\"query\\\":{\\\"query\\\":\\\"\\\",\\\"language\\\":\\\"lucene\\\"},\\\"filter\\\":[]}\"\n" +
74 " \"id\": \"90943e30-9a47-11e8-b64d-95841ca0b247\",\n" +
75 " \"type\": \"index-pattern\",\n" +
76 " \"updated_at\": \"2018-09-07T18:39:47.683Z\",\n" +
77 " \"version\": 1,\n" +
78 " \"attributes\": {\n" +
79 " \"title\": \"kibana_sample_data_logs\",\n" +
80 " \"timeFieldName\": \"timestamp\",\n" +
81 " \"fields\": \"<truncated for example>\",\n" +
82 " \"fieldFormatMap\": \"{\\\"hour_of_day\\\":{}}\"\n" +
86 " \"id\": \"942dcef0-b2cd-11e8-ad8e-85441f0c2e5c\",\n" +
87 " \"type\": \"dashboard\",\n" +
88 " \"updated_at\": \"2018-09-07T18:41:05.887Z\",\n" +
89 " \"version\": 1,\n" +
90 " \"attributes\": {\n" +
91 " \"title\": \"Example Dashboard\",\n" +
93 " \"description\": \"\",\n" +
94 " \"panelsJSON\": \"[{\\\"gridData\\\":{\\\"w\\\":24,\\\"h\\\":15,\\\"x\\\":0,\\\"y\\\":0,\\\"i\\\":\\\"1\\\"},\\\"version\\\":\\\"7.0.0-alpha1\\\",\\\"panelIndex\\\":\\\"1\\\",\\\"type\\\":\\\"visualization\\\",\\\"id\\\":\\\"80b956f0-b2cd-11e8-ad8e-85441f0c2e5c\\\",\\\"embeddableConfig\\\":{}}]\",\n" +
95 " \"optionsJSON\": \"{\\\"darkTheme\\\":false,\\\"useMargins\\\":true,\\\"hidePanelTitles\\\":false}\",\n" +
96 " \"version\": 1,\n" +
97 " \"timeRestore\": false,\n" +
98 " \"kibanaSavedObjectMeta\": {\n" +
99 " \"searchSourceJSON\": \"{\\\"query\\\":{\\\"query\\\":\\\"\\\",\\\"language\\\":\\\"lucene\\\"},\\\"filter\\\":[]}\"\n" +
105 String testFlag = "KibanaDashboardImport";
107 when(httpClient.execute(httpPost)).thenReturn(httpResponse);
108 } catch (IOException e) {
111 assertEquals(true, HttpClientUtil.sendPostHttpClient(testUrl, testJson, testFlag));