summaryrefslogtreecommitdiffstats
path: root/components/datalake-handler/feeder/src/test
diff options
context:
space:
mode:
authorGuobiao Mo <guobiaomo@chinamobile.com>2019-03-28 14:37:41 -0700
committerGuobiao Mo <guobiaomo@chinamobile.com>2019-03-29 16:03:09 -0700
commit3cb79e621ef9982d039d3770fbe02a0bed208481 (patch)
treeafea2c7bf5c460d36e1a1a996c02861138700040 /components/datalake-handler/feeder/src/test
parent84066f315a1692ddfe9caab607c438e884c31cc6 (diff)
Unit test for seed code
This project depends heavily on outside infrastructure, thus there are not much unit test cases. Issue-ID: DCAEGEN2-1309 Change-Id: I8893f4029014673139e67bf373fd77e9e5c42f83 Signed-off-by: Guobiao Mo <guobiaomo@chinamobile.com>
Diffstat (limited to 'components/datalake-handler/feeder/src/test')
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/config/ApplicationConfigurationTest.java73
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/TopicTest.java66
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/enumeration/DataFormatTest.java45
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/util/DruidSupervisorGeneratorTest.java59
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/util/UtilTest.java43
-rw-r--r--components/datalake-handler/feeder/src/test/resources/application.properties42
6 files changed, 328 insertions, 0 deletions
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/config/ApplicationConfigurationTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/config/ApplicationConfigurationTest.java
new file mode 100644
index 00000000..934451fe
--- /dev/null
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/config/ApplicationConfigurationTest.java
@@ -0,0 +1,73 @@
+/*
+* ============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.config;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.datalake.feeder.Application;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * test ApplicationConfiguration
+ *
+ * @author Guobiao Mo
+ *
+ */
+//@RunWith(SpringRunner.class)
+//@SpringBootTest
+/*
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(classes = Application.class,
+ initializers = ConfigFileApplicationContextInitializer.class)
+*/
+@RunWith(SpringJUnit4ClassRunner.class)
+@SpringBootTest(classes = ApplicationConfiguration.class)
+//@ActiveProfiles("test")
+public class ApplicationConfigurationTest {
+
+ @Autowired
+ private ApplicationConfiguration config;
+
+ @Test
+ public void readConfig() {
+ assertNotNull(config.getCouchbaseHost());
+ assertNotNull(config.getCouchbaseUser());
+ assertNotNull(config.getCouchbasePass());
+ assertNotNull(config.getCouchbaseBucket());
+
+ assertNotNull(config.getDmaapZookeeperHostPort());
+ assertNotNull(config.getDmaapKafkaHostPort());
+ assertNotNull(config.getDmaapKafkaGroup());
+ assertTrue(config.getDmaapKafkaTimeout() > 0L);
+ assertTrue(config.getDmaapCheckNewTopicIntervalInSec() > 0);
+
+ assertTrue(config.getKafkaConsumerCount() > 0);
+ }
+
+}
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/TopicTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/TopicTest.java
new file mode 100644
index 00000000..23ec3b10
--- /dev/null
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/TopicTest.java
@@ -0,0 +1,66 @@
+/*
+* ============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.domain;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.json.JSONObject;
+import org.junit.Test;
+
+/**
+ * Test Topic
+ *
+ * @author Guobiao Mo
+ *
+ */
+
+public class TopicTest {
+
+ @Test
+ public void getMessageId() {
+ String text = "{ data: { data2 : { value : 'hello'}}}";
+
+ JSONObject json = new JSONObject(text);
+
+ Topic topic = new Topic("test getMessageId");
+ topic.setMessageIdPath("/data/data2/value");
+
+ String value = topic.getMessageId(json);
+
+ assertEquals(value, "hello");
+ }
+
+ @Test
+ public void testIs() {
+ Topic defaultTopic=new Topic("default");
+ Topic testTopic = new Topic("test");
+ testTopic.setDefaultTopic(defaultTopic);
+
+ defaultTopic.setSupportElasticsearch(true);
+ boolean b = testTopic.isSupportElasticsearch();
+ assertTrue(b);
+
+ defaultTopic.setSupportElasticsearch(false);
+ b = testTopic.isSupportElasticsearch();
+ assertFalse(b);
+ }
+}
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/enumeration/DataFormatTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/enumeration/DataFormatTest.java
new file mode 100644
index 00000000..f1c0d853
--- /dev/null
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/enumeration/DataFormatTest.java
@@ -0,0 +1,45 @@
+/*
+* ============LICENSE_START=======================================================
+* ONAP : DCAE
+* ================================================================================
+* Copyright 2018 TechMahindra
+*=================================================================================
+* 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.enumeration;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+/**
+ * Test Data format of DMaaP messages
+ *
+ * @author Guobiao Mo
+ *
+ */
+public class DataFormatTest {
+ @Test
+ public void fromString() {
+ assertEquals(DataFormat.JSON, DataFormat.fromString("json"));
+ assertEquals(DataFormat.XML, DataFormat.fromString("xml"));
+ assertEquals(DataFormat.YAML, DataFormat.fromString("YAML"));
+ assertEquals(DataFormat.TEXT, DataFormat.fromString("Text"));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void fromStringWithException() {
+ DataFormat.fromString("test");
+ }
+}
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/util/DruidSupervisorGeneratorTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/util/DruidSupervisorGeneratorTest.java
new file mode 100644
index 00000000..f5a42bbb
--- /dev/null
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/util/DruidSupervisorGeneratorTest.java
@@ -0,0 +1,59 @@
+/*
+* ============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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.apache.velocity.VelocityContext;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.datalake.feeder.config.ApplicationConfiguration;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+/**
+ * Test DruidSupervisorGenerator
+ * @author Guobiao Mo
+ *
+ */
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@SpringBootTest(classes = ApplicationConfiguration.class)
+
+public class DruidSupervisorGeneratorTest {
+
+ @Autowired
+ private ApplicationConfiguration config;
+
+ @Test
+ public void testConstructor() {
+ DruidSupervisorGenerator gen = new DruidSupervisorGenerator();
+ VelocityContext context= gen.getContext();
+
+ assertNotNull(context);
+ assertNotNull(gen.getDimensions() );
+ assertNotNull(gen.getTemplate() );
+
+ String host = (String) context.get("host");
+ assertEquals(host, config.getDmaapKafkaHostPort());
+ }
+}
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/util/UtilTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/util/UtilTest.java
new file mode 100644
index 00000000..b0f5492d
--- /dev/null
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/util/UtilTest.java
@@ -0,0 +1,43 @@
+/*
+* ============LICENSE_START=======================================================
+* ONAP : DCAE
+* ================================================================================
+* 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 static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+/**
+ * test utils
+ *
+ * @author Guobiao Mo
+ *
+ */
+public class UtilTest {
+
+ @Test
+ //only dot(.) in key got replaced
+ public void replaceDotInKey() {
+ String a = "\"u-y.t.y-t\":\"u.gfh\",\\\"jg.h\\\":\"j_9889\"";
+ String b = "\"u-y_t_y-t\":\"u.gfh\",\\\"jg_h\\\":\"j_9889\"";
+
+ assertEquals(Util.replaceDotInKey(a), b);
+ }
+}
diff --git a/components/datalake-handler/feeder/src/test/resources/application.properties b/components/datalake-handler/feeder/src/test/resources/application.properties
new file mode 100644
index 00000000..ede5999b
--- /dev/null
+++ b/components/datalake-handler/feeder/src/test/resources/application.properties
@@ -0,0 +1,42 @@
+
+server.port = 1680
+
+
+
+#For Beijing lab
+#dmaapZookeeperHostPort=zookeeper.mr01.onap.vip:80
+#dmaapKafkaHostPort=kafka.mr01.onap.vip:80
+#spring.couchbase.bootstrap-hosts=172.30.1.74
+#couchbaseHost=172.30.1.74
+
+
+#DMaaP
+#dmaapZookeeperHostPort=127.0.0.1:2181
+#dmaapKafkaHostPort=127.0.0.1:9092
+dmaapZookeeperHostPort=message-router-zookeeper:2181
+dmaapKafkaHostPort=message-router-kafka:9092
+dmaapKafkaGroup=dlgroup10
+dmaapKafkaTimeout=60
+#check for new topics
+dmaapCheckNewTopicIntervalInSec=3000
+
+kafkaConsumerCount=1
+
+#tolerate inconsistency when system crash, see PullThread.run()
+async=true
+
+#Logging
+logging.level.org.springframework.web=ERROR
+logging.level.com.att.nsa.apiClient.http=ERROR
+logging.level.org.onap.datalake=DEBUG
+
+
+#DL Feeder DB: Couchbase
+couchbaseHost=dl_couchbase
+#couchbaseHost=172.30.1.74
+couchbaseUser=dmaap
+couchbasePass=dmaap1234
+couchbaseBucket=dmaap
+
+#DL Feeder DB: Elasticsearch
+elasticsearchHost=dl_es