summaryrefslogtreecommitdiffstats
path: root/components/datalake-handler/feeder
diff options
context:
space:
mode:
authorZhangZihao <zhangzihao@chinamobile.com>2019-07-22 15:15:14 +0800
committerZihao Zhang <zhangzihao@chinamobile.com>2019-07-22 07:30:22 +0000
commit8891e4097a3655adf434734efa38b0e7cb76e6c5 (patch)
tree5496b84b44afe22ab4ef4f097bc0453b0ffe5888 /components/datalake-handler/feeder
parent8d0fdceb9f3fbb34bd459f0afbd9c3987f46cb53 (diff)
kafka test
Change-Id: I1ff274c218a19fd7cedfeda7c07bfa0245687070 Issue-ID: DCAEGEN2-1631 Signed-off-by: ZhangZihao <zhangzihao@chinamobile.com>
Diffstat (limited to 'components/datalake-handler/feeder')
-rw-r--r--components/datalake-handler/feeder/src/assembly/scripts/init_db.sql1
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/KafkaConfigTest.java34
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/util/HttpClientUtilTest.java114
3 files changed, 147 insertions, 2 deletions
diff --git a/components/datalake-handler/feeder/src/assembly/scripts/init_db.sql b/components/datalake-handler/feeder/src/assembly/scripts/init_db.sql
index 028305dd..72892a27 100644
--- a/components/datalake-handler/feeder/src/assembly/scripts/init_db.sql
+++ b/components/datalake-handler/feeder/src/assembly/scripts/init_db.sql
@@ -41,7 +41,6 @@ CREATE TABLE `design_type` (
`db_type_id` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
KEY `FKm8rkv2qkq01gsmeq1c3y4w02x` (`db_type_id`),
- KEY `FKs2nspbhf5wv5d152l4j69yjhi` (`portal`),
CONSTRAINT `FKm8rkv2qkq01gsmeq1c3y4w02x` FOREIGN KEY (`db_type_id`) REFERENCES `db_type` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/KafkaConfigTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/KafkaConfigTest.java
index 7ab22733..0aefa1ae 100644
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/KafkaConfigTest.java
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/KafkaConfigTest.java
@@ -20,14 +20,46 @@
package org.onap.datalake.feeder.dto;
import org.junit.Test;
+import org.onap.datalake.feeder.domain.Kafka;
+import org.onap.datalake.feeder.util.TestUtil;
import static org.junit.Assert.*;
+/**
+ * Test Kafka
+ *
+ * @author guochunmeng
+ */
public class KafkaConfigTest {
+ private static String ZOO_KEEPER = "test-zookeeper:2181";
+ private static String BROKER_KAFKA = "test-kafka:9092";
+
@Test
public void testKafkaConfig(){
- KafkaConfig kafkaConfig = new KafkaConfig();
+ Kafka testKafka = new Kafka();
+
+ KafkaConfig testKafkaConfig = testKafka.getKafkaConfig();
+
+ testKafkaConfig.setZooKeeper(ZOO_KEEPER);
+ testKafkaConfig.setTimeout(1000);
+ testKafkaConfig.setSecurityProtocol("");
+ testKafkaConfig.setSecure(true);
+ testKafkaConfig.setPass("pass");
+ testKafkaConfig.setLogin("testLogin");
+ testKafkaConfig.setName("test");
+ testKafkaConfig.setIncludedTopic("");
+ testKafkaConfig.setExcludedTopic("__consumer_offsets");
+ testKafkaConfig.setGroup("testGroup");
+ testKafkaConfig.setEnabled(true);
+ testKafkaConfig.setConsumerCount(3);
+ testKafkaConfig.setBrokerList(BROKER_KAFKA);
+ testKafkaConfig.setId(1);
+
+ KafkaConfig testKafkaConfig2 = TestUtil.newKafka("test").getKafkaConfig();
+ assertNotEquals(testKafkaConfig, testKafkaConfig2);
+ assertNotEquals(testKafkaConfig, null);
+ assertNotEquals(testKafkaConfig.hashCode(), testKafkaConfig2.hashCode());
}
} \ No newline at end of file
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/util/HttpClientUtilTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/util/HttpClientUtilTest.java
new file mode 100644
index 00000000..b8998575
--- /dev/null
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/util/HttpClientUtilTest.java
@@ -0,0 +1,114 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : DataLake
+ * ================================================================================
+ * Copyright 2019 China Mobile
+ *=================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.datalake.feeder.util;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpPost;
+import org.junit.Test;
+import org.mockito.Mock;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+
+import static org.junit.Assert.*;
+
+/**
+ * Test HtpClient
+ *
+ * @author guochunmeng
+ */
+
+public class HttpClientUtilTest {
+
+ @Mock
+ private HttpClient httpClient;
+
+ @Mock
+ private HttpPost httpPost;
+
+ @Mock
+ private HttpResponse httpResponse;
+
+ @Test(expected = RuntimeException.class)
+ public void testSendPostHttpClient() {
+
+ String testUrl = "http://localhost:5601/api/kibana/dashboards/import?exclude=index-pattern";
+ String testJson = "{\n" +
+ " \"objects\": [\n" +
+ " {\n" +
+ " \"id\": \"80b956f0-b2cd-11e8-ad8e-85441f0c2e5c\",\n" +
+ " \"type\": \"visualization\",\n" +
+ " \"updated_at\": \"2018-09-07T18:40:33.247Z\",\n" +
+ " \"version\": 1,\n" +
+ " \"attributes\": {\n" +
+ " \"title\": \"Count Example\",\n" +
+ " \"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" +
+ " \"uiStateJSON\": \"{}\",\n" +
+ " \"description\": \"\",\n" +
+ " \"version\": 1,\n" +
+ " \"kibanaSavedObjectMeta\": {\n" +
+ " \"searchSourceJSON\": \"{\\\"index\\\":\\\"90943e30-9a47-11e8-b64d-95841ca0b247\\\",\\\"query\\\":{\\\"query\\\":\\\"\\\",\\\"language\\\":\\\"lucene\\\"},\\\"filter\\\":[]}\"\n" +
+ " }\n" +
+ " }\n" +
+ " },\n" +
+ " {\n" +
+ " \"id\": \"90943e30-9a47-11e8-b64d-95841ca0b247\",\n" +
+ " \"type\": \"index-pattern\",\n" +
+ " \"updated_at\": \"2018-09-07T18:39:47.683Z\",\n" +
+ " \"version\": 1,\n" +
+ " \"attributes\": {\n" +
+ " \"title\": \"kibana_sample_data_logs\",\n" +
+ " \"timeFieldName\": \"timestamp\",\n" +
+ " \"fields\": \"<truncated for example>\",\n" +
+ " \"fieldFormatMap\": \"{\\\"hour_of_day\\\":{}}\"\n" +
+ " }\n" +
+ " },\n" +
+ " {\n" +
+ " \"id\": \"942dcef0-b2cd-11e8-ad8e-85441f0c2e5c\",\n" +
+ " \"type\": \"dashboard\",\n" +
+ " \"updated_at\": \"2018-09-07T18:41:05.887Z\",\n" +
+ " \"version\": 1,\n" +
+ " \"attributes\": {\n" +
+ " \"title\": \"Example Dashboard\",\n" +
+ " \"hits\": 0,\n" +
+ " \"description\": \"\",\n" +
+ " \"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" +
+ " \"optionsJSON\": \"{\\\"darkTheme\\\":false,\\\"useMargins\\\":true,\\\"hidePanelTitles\\\":false}\",\n" +
+ " \"version\": 1,\n" +
+ " \"timeRestore\": false,\n" +
+ " \"kibanaSavedObjectMeta\": {\n" +
+ " \"searchSourceJSON\": \"{\\\"query\\\":{\\\"query\\\":\\\"\\\",\\\"language\\\":\\\"lucene\\\"},\\\"filter\\\":[]}\"\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ " ]\n" +
+ "}";
+ String testFlag = "KibanaDashboardImport";
+ try {
+ when(httpClient.execute(httpPost)).thenReturn(httpResponse);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ assertEquals(true, HttpClientUtil.sendPostHttpClient(testUrl, testJson, testFlag));
+
+ }
+} \ No newline at end of file