summaryrefslogtreecommitdiffstats
path: root/components/datalake-handler/feeder
diff options
context:
space:
mode:
Diffstat (limited to 'components/datalake-handler/feeder')
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DmaapServiceTest.java84
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/ElasticsearchServiceTest.java95
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/MongodbServiceTest.java88
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/PullServiceTest.java74
4 files changed, 341 insertions, 0 deletions
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DmaapServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DmaapServiceTest.java
new file mode 100644
index 00000000..7efe9806
--- /dev/null
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DmaapServiceTest.java
@@ -0,0 +1,84 @@
+/*
+ * ============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.service;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.datalake.feeder.config.ApplicationConfiguration;
+import org.onap.datalake.feeder.domain.Topic;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.mockito.Mockito.when;
+import static org.junit.Assert.*;
+
+@RunWith(MockitoJUnitRunner.class)
+public class DmaapServiceTest {
+
+ static String DMAPP_ZOOKEEPER_HOST_PORT = "message-router-zookeeper:2181";
+
+ @InjectMocks
+ private DmaapService dmaapService;
+
+ @Mock
+ private ApplicationConfiguration config;
+ @Mock
+ private TopicService topicService;
+
+ @Test
+ public void testGetTopics() {
+
+ List<String> list = new ArrayList<>();
+ list.add("unauthenticated.DCAE_CL_OUTPUT");
+ list.add("AAI-EVENT");
+ list.add("__consumer_offsets");
+ list.add("unauthenticated.SEC_FAULT_OUTPUT");
+ list.add("msgrtr.apinode.metrics.dmaap");
+ when(config.getDmaapZookeeperHostPort()).thenReturn(DMAPP_ZOOKEEPER_HOST_PORT);
+ assertNotEquals(list, dmaapService.getTopics());
+ }
+
+ /*@Test
+ public void testGetActiveTopics() throws IOException {
+
+ List<String> list = new ArrayList<>();
+ list.add("unauthenticated.DCAE_CL_OUTPUT");
+ list.add("AAI-EVENT");
+ list.add("__consumer_offsets");
+ list.add("unauthenticated.SEC_FAULT_OUTPUT");
+ list.add("msgrtr.apinode.metrics.dmaap");
+
+ when(config.getDmaapZookeeperHostPort()).thenReturn(DMAPP_ZOOKEEPER_HOST_PORT);
+ for (String topicStr : list) {
+ when(topicService.getEffectiveTopic(topicStr, true)).thenReturn(new Topic());
+ }
+ try {
+ assertEquals(new ArrayList<>(), dmaapService.getActiveTopics());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }*/
+} \ No newline at end of file
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/ElasticsearchServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/ElasticsearchServiceTest.java
new file mode 100644
index 00000000..de2c1674
--- /dev/null
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/ElasticsearchServiceTest.java
@@ -0,0 +1,95 @@
+/*
+ * ============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.service;
+
+import org.elasticsearch.action.ActionListener;
+import org.elasticsearch.action.bulk.BulkResponse;
+import org.elasticsearch.client.RestHighLevelClient;
+import org.json.JSONObject;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.datalake.feeder.config.ApplicationConfiguration;
+import org.onap.datalake.feeder.domain.Topic;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ElasticsearchServiceTest {
+
+ static String DEFAULT_TOPIC_NAME = "_DL_DEFAULT_";
+
+ @InjectMocks
+ private ElasticsearchService elasticsearchService;
+
+ @Mock
+ private ApplicationConfiguration config;
+
+ @Mock
+ private RestHighLevelClient client;
+
+ @Mock
+ ActionListener<BulkResponse> listener;
+
+ @Mock
+ private DbService dbService;
+
+ @Test(expected = NullPointerException.class)
+ public void testCleanUp() throws IOException {
+
+ elasticsearchService.cleanUp();
+
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testEnsureTableExist() throws IOException {
+
+ elasticsearchService.ensureTableExist(DEFAULT_TOPIC_NAME);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testSaveJsons() {
+
+ Topic topic = new Topic();
+ topic.setName("unauthenticated.SEC_FAULT_OUTPUT");
+ topic.setCorrelateClearedMessage(true);
+ topic.setMessageIdPath("/event/commonEventHeader/eventName,/event/commonEventHeader/reportingEntityName,/event/faultFields/specificProblem");
+ String jsonString = "{\"event\":{\"commonEventHeader\":{\"sourceId\":\"vnf_test_999\",\"startEpochMicrosec\":2222222222222,\"eventId\":\"ab305d54-85b4-a31b-7db2-fb6b9e546016\",\"sequence\":1,\"domain\":\"fautt\",\"lastEpochMicrosec\":1234567890987,\"eventName\":\"Fault_MultiCloud_VMFailure\",\"sourceName\":\"vSBC00\",\"priority\":\"Low\",\"version\":3,\"reportingEntityName\":\"vnf_test_2_rname\"},\"faultFields\":{\"eventSeverity\":\"CRITILLL\",\"alarmCondition\":\"Guest_Os_FaiLLL\",\"faultFieldsVersion\":3,\"specificProblem\":\"Fault_MultiCloud_VMFailure\",\"alarmInterfaceA\":\"aaaa\",\"alarmAdditionalInformation\":[{\"name\":\"objectType3\",\"value\":\"VIN\"},{\"name\":\"objectType4\",\"value\":\"VIN\"}],\"eventSourceType\":\"single\",\"vfStatus\":\"Active\"}}}";
+ String jsonString2 = "{\"event\":{\"commonEventHeader\":{\"sourceId\":\"vnf_test_999\",\"startEpochMicrosec\":2222222222222,\"eventId\":\"ab305d54-85b4-a31b-7db2-fb6b9e546016\",\"sequence\":1,\"domain\":\"fautt\",\"lastEpochMicrosec\":1234567890987,\"eventName\":\"Fault_MultiCloud_VMFailureCleared\",\"sourceName\":\"vSBC00\",\"priority\":\"Low\",\"version\":3,\"reportingEntityName\":\"vnf_test_2_rname\"},\"faultFields\":{\"eventSeverity\":\"CRITILLL\",\"alarmCondition\":\"Guest_Os_FaiLLL\",\"faultFieldsVersion\":3,\"specificProblem\":\"Fault_MultiCloud_VMFailure\",\"alarmInterfaceA\":\"aaaa\",\"alarmAdditionalInformation\":[{\"name\":\"objectType3\",\"value\":\"VIN\"},{\"name\":\"objectType4\",\"value\":\"VIN\"}],\"eventSourceType\":\"single\",\"vfStatus\":\"Active\"}}}";
+
+ JSONObject jsonObject = new JSONObject(jsonString);
+ JSONObject jsonObject2 = new JSONObject(jsonString2);
+
+ List<JSONObject> jsons = new ArrayList<>();
+ jsons.add(jsonObject);
+ jsons.add(jsonObject2);
+ when(config.getElasticsearchType()).thenReturn("doc");
+ when(config.isAsync()).thenReturn(true);
+
+ elasticsearchService.saveJsons(topic, jsons);
+
+ }
+} \ No newline at end of file
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/MongodbServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/MongodbServiceTest.java
new file mode 100644
index 00000000..41856760
--- /dev/null
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/MongodbServiceTest.java
@@ -0,0 +1,88 @@
+/*
+ * ============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.service;
+
+import com.mongodb.MongoClient;
+import com.mongodb.client.MongoCollection;
+import com.mongodb.client.MongoDatabase;
+import org.bson.Document;
+import org.json.JSONObject;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.datalake.feeder.config.ApplicationConfiguration;
+import org.onap.datalake.feeder.domain.Topic;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@RunWith(MockitoJUnitRunner.class)
+public class MongodbServiceTest {
+
+ @InjectMocks
+ private MongodbService mongodbService;
+
+ @Mock
+ private ApplicationConfiguration config;
+
+ @Mock
+ private DbService dbService;
+
+ @Mock
+ private MongoDatabase database;
+
+ @Mock
+ private MongoClient mongoClient;
+
+ @Mock
+ private Map<String, MongoCollection<Document>> mongoCollectionMap = new HashMap<>();
+
+
+ @Test
+ public void cleanUp() {
+
+ mongodbService.cleanUp();
+ }
+
+ @Test
+ public void saveJsons() {
+
+ Topic topic = new Topic();
+ topic.setName("unauthenticated.SEC_FAULT_OUTPUT");
+ topic.setCorrelateClearedMessage(true);
+ topic.setMessageIdPath("/event/commonEventHeader/eventName,/event/commonEventHeader/reportingEntityName,/event/faultFields/specificProblem");
+ String jsonString = "{\"event\":{\"commonEventHeader\":{\"sourceId\":\"vnf_test_999\",\"startEpochMicrosec\":2222222222222,\"eventId\":\"ab305d54-85b4-a31b-7db2-fb6b9e546016\",\"sequence\":1,\"domain\":\"fautt\",\"lastEpochMicrosec\":1234567890987,\"eventName\":\"Fault_MultiCloud_VMFailure\",\"sourceName\":\"vSBC00\",\"priority\":\"Low\",\"version\":3,\"reportingEntityName\":\"vnf_test_2_rname\"},\"faultFields\":{\"eventSeverity\":\"CRITILLL\",\"alarmCondition\":\"Guest_Os_FaiLLL\",\"faultFieldsVersion\":3,\"specificProblem\":\"Fault_MultiCloud_VMFailure\",\"alarmInterfaceA\":\"aaaa\",\"alarmAdditionalInformation\":[{\"name\":\"objectType3\",\"value\":\"VIN\"},{\"name\":\"objectType4\",\"value\":\"VIN\"}],\"eventSourceType\":\"single\",\"vfStatus\":\"Active\"}}}";
+ String jsonString2 = "{\"event\":{\"commonEventHeader\":{\"sourceId\":\"vnf_test_999\",\"startEpochMicrosec\":2222222222222,\"eventId\":\"ab305d54-85b4-a31b-7db2-fb6b9e546016\",\"sequence\":1,\"domain\":\"fautt\",\"lastEpochMicrosec\":1234567890987,\"eventName\":\"Fault_MultiCloud_VMFailureCleared\",\"sourceName\":\"vSBC00\",\"priority\":\"Low\",\"version\":3,\"reportingEntityName\":\"vnf_test_2_rname\"},\"faultFields\":{\"eventSeverity\":\"CRITILLL\",\"alarmCondition\":\"Guest_Os_FaiLLL\",\"faultFieldsVersion\":3,\"specificProblem\":\"Fault_MultiCloud_VMFailure\",\"alarmInterfaceA\":\"aaaa\",\"alarmAdditionalInformation\":[{\"name\":\"objectType3\",\"value\":\"VIN\"},{\"name\":\"objectType4\",\"value\":\"VIN\"}],\"eventSourceType\":\"single\",\"vfStatus\":\"Active\"}}}";
+
+ JSONObject jsonObject = new JSONObject(jsonString);
+ JSONObject jsonObject2 = new JSONObject(jsonString2);
+
+ List<JSONObject> jsons = new ArrayList<>();
+ jsons.add(jsonObject);
+ jsons.add(jsonObject2);
+
+ mongodbService.saveJsons(topic, jsons);
+ }
+} \ No newline at end of file
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/PullServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/PullServiceTest.java
new file mode 100644
index 00000000..020bcc55
--- /dev/null
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/PullServiceTest.java
@@ -0,0 +1,74 @@
+/*
+ * ============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.service;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.datalake.feeder.config.ApplicationConfiguration;
+import org.springframework.context.ApplicationContext;
+
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class PullServiceTest {
+
+ @InjectMocks
+ private PullService pullService;
+
+ @Mock
+ private ApplicationContext context;
+
+ @Mock
+ private ApplicationConfiguration config;
+
+ private boolean isRunning = false;
+
+ @Mock
+ private ExecutorService executorService;
+
+ @Mock
+ private List<PullThread> consumers;
+
+ @Test
+ public void isRunning() {
+ assertEquals(pullService.isRunning(), false);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void start() {
+
+ when(config.getKafkaConsumerCount()).thenReturn(1);
+
+ pullService.start();
+ }
+
+ @Test
+ public void shutdown() {
+ pullService.shutdown();
+ }
+} \ No newline at end of file