summaryrefslogtreecommitdiffstats
path: root/components/kpi-computation-ms/src/test/java/org/onap
diff options
context:
space:
mode:
Diffstat (limited to 'components/kpi-computation-ms/src/test/java/org/onap')
-rw-r--r--components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/ApplicationTest.java38
-rw-r--r--components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/computation/FileUtils.java89
-rw-r--r--components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/computation/KpiComputationTest.java56
-rw-r--r--components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/computation/KpiTest.java54
-rw-r--r--components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/DmaapClientTest.java125
-rw-r--r--components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/KpiDmaapClientTest.java89
-rw-r--r--components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/NewPmNotificationTest.java41
-rw-r--r--components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/NotificationConsumerTest.java65
-rw-r--r--components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/NotificationProducerTest.java94
-rw-r--r--components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/PmNotificationCallbackTest.java53
-rw-r--r--components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/models/ConfigurationTest.java79
-rw-r--r--components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/models/ModelsTest.java212
12 files changed, 995 insertions, 0 deletions
diff --git a/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/ApplicationTest.java b/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/ApplicationTest.java
new file mode 100644
index 00000000..c0827319
--- /dev/null
+++ b/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/ApplicationTest.java
@@ -0,0 +1,38 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.dcaegen2.kpi;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = ApplicationTest.class)
+public class ApplicationTest {
+
+ @Test
+ public void contextLoads() {
+ Application.getConfig();
+ Application.getStandaloneConfig("src/test/resources/kpi/cbs_config1.json");
+ Application.getStandaloneConfig("src/test/resources/config_all.json");
+ }
+}
diff --git a/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/computation/FileUtils.java b/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/computation/FileUtils.java
new file mode 100644
index 00000000..d40cc02a
--- /dev/null
+++ b/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/computation/FileUtils.java
@@ -0,0 +1,89 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020-2021 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.dcaegen2.kpi.computation;
+
+import static org.junit.jupiter.api.Assertions.fail;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+/**
+ * File read utils.
+ *
+ * @author Kai Lu
+ */
+public class FileUtils {
+
+ /**
+ * Reads contents of files inside the eventBodyDirectory, combines contents with
+ * metadata to make an Event Object. Fails test in the event of failure to read
+ * a file.
+ *
+ * @param targetDirectory Path to directory with files.
+ * @return List of Strings containing the body as acquired from files inside
+ * targetDirectory.
+ * @throws IOException in the event it fails to read from the files.
+ */
+ public static List<String> getFilesFromDirectory(Path targetDirectory) throws IOException {
+ try (Stream<Path> eventFileStream = Files.walk(targetDirectory)) {
+ return eventFileStream.filter(Files::isRegularFile).filter(Files::isReadable)
+ .map(FileUtils::getFileContents).collect(Collectors.toList());
+ }
+ }
+
+ /**
+ * reads contents of file into a string. fails a tests in the event failure
+ * occurs.
+ *
+ * @param path path to file.
+ * @return string containing files contents
+ */
+ public static String getFileContents(Path path) {
+ try {
+ return new String(Files.readAllBytes(path));
+ } catch (IOException exception) {
+ fail("IOException occurred while reading file.");
+ }
+ return null;
+ }
+
+ /**
+ * Reads contents of resource. fails a test in the event failure occurs.
+ *
+ * @param fileName of file in resources to be read.
+ * @return contents of file
+ */
+ public static String getFileContents(String fileName) {
+ try {
+ Path path = Paths.get(ClassLoader.getSystemResource(fileName).toURI());
+ return getFileContents(path);
+ } catch (URISyntaxException exception) {
+ fail("Exception occurred, failed to acquire resource URI.");
+ }
+ return null;
+ }
+}
diff --git a/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/computation/KpiComputationTest.java b/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/computation/KpiComputationTest.java
new file mode 100644
index 00000000..0bb3b184
--- /dev/null
+++ b/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/computation/KpiComputationTest.java
@@ -0,0 +1,56 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.dcaegen2.kpi.computation;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.onap.dcaegen2.kpi.computation.KpiComputation;
+import org.onap.dcaegen2.kpi.models.Configuration;
+import org.onap.dcaegen2.kpi.models.VesEvent;
+
+public class KpiComputationTest {
+
+ private static final String KPI_CONFIG_FILE = "kpi/kpi_config.json";
+ private static final String VES_MESSAGE_FILE = "kpi/ves_message.json";
+
+ @Test
+ public void testKpiComputation() {
+
+
+ String strKpiConfig = FileUtils.getFileContents(KPI_CONFIG_FILE);
+
+ String vesMessage = FileUtils.getFileContents(VES_MESSAGE_FILE);
+
+ Configuration config = mock(Configuration.class);
+ when(config.getKpiConfig()).thenReturn(strKpiConfig);
+ List<VesEvent> vesList = new KpiComputation().checkAndDoComputation(vesMessage, config);
+
+ VesEvent vesEvent = vesList.get(0);
+ assertEquals(vesEvent.getEvent().getPerf3gppFields().getMeasDataCollection().getMeasInfoList().get(0)
+ .getMeasValuesList().get(0).getMeasResults().get(0).getSvalue(), "40");
+ }
+
+}
diff --git a/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/computation/KpiTest.java b/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/computation/KpiTest.java
new file mode 100644
index 00000000..94aca96a
--- /dev/null
+++ b/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/computation/KpiTest.java
@@ -0,0 +1,54 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.dcaegen2.kpi.computation;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.onap.dcaegen2.kpi.config.KpiConfig;
+import org.onap.dcaegen2.kpi.config.KpiJsonConversion;
+import org.onap.dcaegen2.kpi.models.VesEvent;
+import org.onap.dcaegen2.kpi.utils.VesJsonConversion;
+
+public class KpiTest {
+
+ private static final String KPI_CONFIG_FILE = "kpi/kpi_config.json";
+ private static final String VES_MESSAGE_FILE = "kpi/ves_message.json";
+
+ @Test
+ public void testKpiConfigValidate() {
+
+ String strKpiConfig = FileUtils.getFileContents(KPI_CONFIG_FILE);
+
+ KpiConfig kpiConfig = KpiJsonConversion.convertKpiConfig(strKpiConfig);
+ assertEquals(kpiConfig.getDomain(), "measurementsForKpi");
+ }
+
+ @Test
+ public void testVesEventValidate() {
+
+ String vesMessage = FileUtils.getFileContents(VES_MESSAGE_FILE);
+
+ VesEvent vesEvent = VesJsonConversion.convertVesEvent(vesMessage);
+ assertEquals(vesEvent.getEvent().getCommonEventHeader().getDomain(), "perf3gpp");
+ }
+
+}
diff --git a/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/DmaapClientTest.java b/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/DmaapClientTest.java
new file mode 100644
index 00000000..8020f938
--- /dev/null
+++ b/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/DmaapClientTest.java
@@ -0,0 +1,125 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.dcaegen2.kpi.dmaap;
+
+import static org.mockito.Mockito.when;
+
+import com.att.nsa.cambria.client.CambriaTopicManager;
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.onap.dcaegen2.kpi.models.Configuration;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = DmaapClientTest.class)
+public class DmaapClientTest {
+
+ @Mock
+ private CambriaTopicManager topicManager;
+
+ @InjectMocks
+ DmaapClient client;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void getAllTopicsTest() {
+ Set<String> topics = new HashSet<String>();
+ topics.add("topic1");
+ topics.add("topic2");
+ Configuration configuration = Configuration.getInstance();
+ List<String> list = new ArrayList<String>();
+ list.add("server");
+ configuration.setDmaapServers(list);
+ configuration.setCg("cg");
+ configuration.setCid("cid");
+ configuration.setPollingInterval(30);
+ configuration.setPollingTimeout(100);
+
+ try {
+ when(topicManager.getTopics()).thenReturn(topics);
+
+ client = Mockito.mock(DmaapClient.class);
+ client.initClient();
+ Mockito.verify(client).initClient();
+ // Mockito.verifycreateAndConfigureTopics();
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void startClientTest() {
+ try {
+ Configuration configuration = Configuration.getInstance();
+ String configAllJson = readFromFile("src/test/resources/config_all.json");
+
+ JsonObject configAll = new Gson().fromJson(configAllJson, JsonObject.class);
+
+ JsonObject config = configAll.getAsJsonObject("config");
+ System.out.println(configuration);
+ configuration.updateConfigurationFromJsonObject(config);
+ DmaapClient client = new DmaapClient();
+ client.initClient();
+ // Mockito.verify(client).startClient();
+ // Mockito.verifycreateAndConfigureTopics();
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private static String readFromFile(String file) {
+ String content = "";
+ try (BufferedReader bufferedReader = new BufferedReader(new FileReader(file))) {
+ content = bufferedReader.readLine();
+ String temp;
+ while ((temp = bufferedReader.readLine()) != null) {
+ content = content.concat(temp);
+ }
+ content = content.trim();
+ } catch (Exception e) {
+ content = null;
+ }
+ return content;
+ }
+}
diff --git a/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/KpiDmaapClientTest.java b/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/KpiDmaapClientTest.java
new file mode 100644
index 00000000..e8fd9925
--- /dev/null
+++ b/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/KpiDmaapClientTest.java
@@ -0,0 +1,89 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.dcaegen2.kpi.dmaap;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.dcaegen2.kpi.models.Configuration;
+import org.onap.dcaegen2.kpi.utils.DmaapUtils;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import com.att.nsa.cambria.client.CambriaBatchingPublisher;
+import com.att.nsa.cambria.client.CambriaConsumer;
+
+@RunWith(MockitoJUnitRunner.class)
+@SpringBootTest(classes = KpiDmaapClient.class)
+public class KpiDmaapClientTest {
+
+ @Mock
+ Configuration configurationMock;
+
+ @Mock
+ DmaapUtils dmaapUtilsMock;
+
+ @InjectMocks
+ KpiDmaapClient kpiDmaapClient;
+
+ @Mock
+ CambriaConsumer kpiResponseCambriaConsumerMock;
+
+ @Mock
+ CambriaBatchingPublisher cambriaBatchingPublisherMock;
+
+ @Mock
+ NotificationProducer notificationProducerMock;
+
+ @Before
+ public void setup() {
+ kpiDmaapClient = new KpiDmaapClient(dmaapUtilsMock, configurationMock);
+ }
+
+ @Test
+ public void sendNotificationToPolicyTest() {
+ Map<String, Object> streamsPublishes = new HashMap<>();
+ Map<String, String> topics = new HashMap<>();
+ Map<String, Object> dmaapInfo = new HashMap<>();
+ topics.put("topic_url", "https://message-router.onap.svc.cluster.local:3905/events/DCAE_KPI_OUTPUT");
+ dmaapInfo.put("dmaap_info", topics);
+ streamsPublishes.put("kpi_topic", dmaapInfo);
+ Mockito.when(configurationMock.getStreamsPublishes()).thenReturn(streamsPublishes);
+ Mockito.when(dmaapUtilsMock.buildPublisher(configurationMock, "DCAE_KPI_OUTPUT"))
+ .thenReturn(cambriaBatchingPublisherMock);
+ try {
+ Mockito.when(cambriaBatchingPublisherMock.send("", "hello")).thenReturn(0);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ assertTrue(kpiDmaapClient.sendNotificationToDmaap("hello"));
+
+ }
+}
diff --git a/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/NewPmNotificationTest.java b/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/NewPmNotificationTest.java
new file mode 100644
index 00000000..db52c53d
--- /dev/null
+++ b/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/NewPmNotificationTest.java
@@ -0,0 +1,41 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.dcaegen2.kpi.dmaap;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class NewPmNotificationTest {
+
+ @Test
+ public void testNewPmNotif() {
+ NewPmNotification newPmNotif1 = new NewPmNotification(true);
+ NewPmNotification newPmNotif2 = new NewPmNotification();
+ newPmNotif2.setNewNotif(true);
+ assertTrue(newPmNotif2.getNewNotif());
+ newPmNotif2.init();
+ assertEquals(false, newPmNotif2.getNewNotif());
+ assertTrue(newPmNotif1.getNewNotif());
+
+ }
+}
diff --git a/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/NotificationConsumerTest.java b/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/NotificationConsumerTest.java
new file mode 100644
index 00000000..1d04a627
--- /dev/null
+++ b/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/NotificationConsumerTest.java
@@ -0,0 +1,65 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.dcaegen2.kpi.dmaap;
+
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import com.att.nsa.cambria.client.CambriaConsumer;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = NotificationConsumerTest.class)
+public class NotificationConsumerTest {
+
+ @Mock
+ CambriaConsumer cambriaConsumer;
+
+ @Mock
+ NotificationCallback notificationCallback;
+
+ @InjectMocks
+ NotificationConsumer notificationConsumer;
+
+ @Test
+ public void testNotificationConsumer() {
+ try {
+ List<String> notifications = new ArrayList<>();
+ notifications.add("notification1");
+ when(cambriaConsumer.fetch()).thenReturn(notifications);
+ Mockito.doNothing().when(notificationCallback).activateCallBack(Mockito.anyString());
+ notificationConsumer.run();
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/NotificationProducerTest.java b/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/NotificationProducerTest.java
new file mode 100644
index 00000000..c835d49b
--- /dev/null
+++ b/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/NotificationProducerTest.java
@@ -0,0 +1,94 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.dcaegen2.kpi.dmaap;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import com.att.nsa.cambria.client.CambriaBatchingPublisher;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+
+import java.io.IOException;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.onap.dcaegen2.kpi.computation.FileUtils;
+import org.onap.dcaegen2.kpi.models.Configuration;
+import org.powermock.api.mockito.PowerMockito;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = NotificationProducerTest.class)
+public class NotificationProducerTest {
+
+ private static final String VES_MESSAGE_FILE = "kpi/ves_message.json";
+ private static final String CBS_CONFIG_FILE = "kpi/cbs_config2.json";
+
+ @Mock
+ CambriaBatchingPublisher cambriaBatchingPublisher;
+
+ @InjectMocks
+ NotificationProducer notificationProducer;
+
+ @Test
+ public void notificationProducerTest() {
+
+ try {
+ when(cambriaBatchingPublisher.send(Mockito.anyString(), Mockito.anyString())).thenReturn(0);
+ int result = notificationProducer.sendNotification("msg");
+ assertEquals(0, result);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ @Test
+ public void kpiResultWithoutConfigTest() {
+
+ String vesMessage = FileUtils.getFileContents(VES_MESSAGE_FILE);
+ KpiComputationCallBack callback = new KpiComputationCallBack();
+ callback.activateCallBack(vesMessage);
+
+ }
+
+ @Test
+ public void kpiResultWithConfigTest() {
+
+ String vesMessage = FileUtils.getFileContents(VES_MESSAGE_FILE);
+ String strCbsConfig = FileUtils.getFileContents(CBS_CONFIG_FILE);
+
+ JsonObject jsonObject = new JsonParser().parse(strCbsConfig).getAsJsonObject().getAsJsonObject("config");
+ Configuration config = new Configuration();
+ config.updateConfigurationFromJsonObject(jsonObject);
+
+ KpiComputationCallBack callback = new KpiComputationCallBack();
+ callback.kpiComputation(vesMessage, config);
+
+ }
+
+}
diff --git a/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/PmNotificationCallbackTest.java b/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/PmNotificationCallbackTest.java
new file mode 100644
index 00000000..5241ecd9
--- /dev/null
+++ b/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/dmaap/PmNotificationCallbackTest.java
@@ -0,0 +1,53 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.dcaegen2.kpi.dmaap;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.onap.dcaegen2.kpi.utils.BeanUtil;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PowerMockIgnore;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(PowerMockRunner.class)
+@PowerMockIgnore({ "com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*" })
+@PowerMockRunnerDelegate(SpringRunner.class)
+@PrepareForTest({ BeanUtil.class })
+@SpringBootTest(classes = PmNotificationCallbackTest.class)
+public class PmNotificationCallbackTest {
+
+ @Mock
+ NewPmNotification newPmNotif;
+
+ @Test
+ public void testActivateCallBack() {
+ PowerMockito.mockStatic(BeanUtil.class);
+ PowerMockito.when(BeanUtil.getBean(NewPmNotification.class)).thenReturn(newPmNotif);
+ NotificationCallback pmNotificationCallback = new KpiComputationCallBack();
+ pmNotificationCallback.activateCallBack("pmNotification");
+ }
+
+}
diff --git a/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/models/ConfigurationTest.java b/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/models/ConfigurationTest.java
new file mode 100644
index 00000000..07ef51d2
--- /dev/null
+++ b/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/models/ConfigurationTest.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * slice-analysis-ms
+ * ================================================================================
+ * Copyright (C) 2020 Wipro Limited.
+ * ==============================================================================
+ * 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.dcaegen2.kpi.models;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Test;
+
+
+public class ConfigurationTest {
+ Configuration configuration = Configuration.getInstance();
+
+ @Test
+ public void configurationTest() {
+
+ List<String> list = new ArrayList<String>();
+ list.add("server");
+ Map<String, Object> subscribes = new HashMap<>();
+
+ configuration.setStreamsSubscribes(subscribes);
+ configuration.setStreamsPublishes(subscribes);
+ configuration.setDmaapServers(list);
+ configuration.setCg("cg");
+ configuration.setCid("cid");
+ configuration.setAafPassword("password");
+ configuration.setAafUsername("user");
+ configuration.setPollingInterval(30);
+ configuration.setPollingTimeout(100);
+ configuration.setHost("192.168.1.1");
+ configuration.setPort(21);
+ configuration.setPassword("password");
+ configuration.setUsername("user");
+ configuration.setDatabasename("database");
+ configuration.setEnablessl(true);
+ configuration.setCbsPollingInterval(10);
+ configuration.setKpiConfig("kpi config");
+
+ assertEquals("cg", configuration.getCg());
+ assertEquals("cid", configuration.getCid());
+ assertEquals("user", configuration.getAafUsername());
+ assertEquals("password", configuration.getAafPassword());
+ assertEquals(30, configuration.getPollingInterval());
+ assertEquals(100, configuration.getPollingTimeout());
+ assertEquals(list, configuration.getDmaapServers());
+ assertEquals("192.168.1.1", configuration.getHost());
+ assertEquals(21, configuration.getPort());
+ assertEquals("user", configuration.getUsername());
+ assertEquals("password", configuration.getPassword());
+ assertEquals("database", configuration.getDatabasename());
+ assertEquals(true, configuration.isEnablessl());
+ assertEquals("kpi config", configuration.getKpiConfig());
+ assertEquals(10, configuration.getCbsPollingInterval());
+ }
+}
diff --git a/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/models/ModelsTest.java b/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/models/ModelsTest.java
new file mode 100644
index 00000000..ad549bec
--- /dev/null
+++ b/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/models/ModelsTest.java
@@ -0,0 +1,212 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.dcaegen2.kpi.models;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onap.dcaegen2.kpi.computation.FileUtils;
+import org.onap.dcaegen2.kpi.config.BaseDynamicPropertiesProvider;
+import org.onap.dcaegen2.kpi.config.Kpi;
+import org.onap.dcaegen2.kpi.config.KpiConfig;
+import org.onap.dcaegen2.kpi.config.MethodForKpi;
+
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import com.openpojo.reflection.PojoClass;
+import com.openpojo.reflection.impl.PojoClassFactory;
+import com.openpojo.validation.Validator;
+import com.openpojo.validation.ValidatorBuilder;
+import com.openpojo.validation.rule.impl.GetterMustExistRule;
+import com.openpojo.validation.rule.impl.SetterMustExistRule;
+import com.openpojo.validation.test.impl.GetterTester;
+import com.openpojo.validation.test.impl.SerializableTester;
+import com.openpojo.validation.test.impl.SetterTester;
+
+public class ModelsTest {
+
+ private static final String CBS_CONFIG_FILE = "kpi/cbs_config1.json";
+
+ public void validateMd(PojoClass pojoclass) {
+ Validator validator = ValidatorBuilder.create()
+ .with(new SetterMustExistRule())
+ .with(new GetterMustExistRule())
+ .with(new SetterTester())
+ .with(new GetterTester())
+ .with(new SerializableTester())
+ .build();
+ validator.validate(pojoclass);
+ }
+
+ @Test
+ public void testGetterSetterPerformanceEvent() {
+ PojoClass pojoclass = PojoClassFactory.getPojoClass(PerformanceEvent.class);
+ validateMd(pojoclass);
+ PerformanceEvent x = new PerformanceEvent();
+ PerformanceEvent y = new PerformanceEvent();
+ Assert.assertTrue(x.equals(y) && y.equals(x));
+ Assert.assertTrue(x.hashCode() == y.hashCode());
+ }
+
+ @Test
+ public void testMeasTypes() {
+ PojoClass pojoclass = PojoClassFactory.getPojoClass(MeasTypes.class);
+ validateMd(pojoclass);
+ MeasTypes x = new MeasTypes();
+ MeasTypes y = new MeasTypes();
+ Assert.assertTrue(x.equals(y) && y.equals(x));
+ Assert.assertTrue(x.hashCode() == y.hashCode());
+ }
+
+ @Test
+ public void testMeasInfoId() {
+ PojoClass pojoclass = PojoClassFactory.getPojoClass(MeasInfoId.class);
+ validateMd(pojoclass);
+ MeasInfoId x = new MeasInfoId();
+ MeasInfoId y = new MeasInfoId();
+ Assert.assertTrue(x.equals(y) && y.equals(x));
+ Assert.assertTrue(x.hashCode() == y.hashCode());
+ }
+
+ @Test
+ public void testVesEvent() {
+ PojoClass pojoclass = PojoClassFactory.getPojoClass(VesEvent.class);
+ validateMd(pojoclass);
+ VesEvent x = new VesEvent();
+ VesEvent y = new VesEvent();
+ Assert.assertTrue(x.equals(y) && y.equals(x));
+ Assert.assertTrue(x.hashCode() == y.hashCode());
+ }
+
+ @Test
+ public void testMeasResult() {
+ PojoClass pojoclass = PojoClassFactory.getPojoClass(MeasResult.class);
+ validateMd(pojoclass);
+ MeasResult x = new MeasResult();
+ MeasResult y = new MeasResult();
+ Assert.assertTrue(x.equals(y) && y.equals(x));
+ Assert.assertTrue(x.hashCode() == y.hashCode());
+ }
+
+ @Test
+ public void testPerf3gppFields() {
+ PojoClass pojoclass = PojoClassFactory.getPojoClass(Perf3gppFields.class);
+ validateMd(pojoclass);
+ Perf3gppFields x = new Perf3gppFields();
+ Perf3gppFields y = new Perf3gppFields();
+ Assert.assertTrue(x.equals(y) && y.equals(x));
+ Assert.assertTrue(x.hashCode() == y.hashCode());
+ }
+
+ @Test
+ public void testMeasInfo() {
+ PojoClass pojoclass = PojoClassFactory.getPojoClass(MeasInfo.class);
+ validateMd(pojoclass);
+ MeasInfo x = new MeasInfo();
+ MeasInfo y = new MeasInfo();
+ Assert.assertTrue(x.equals(y) && y.equals(x));
+ Assert.assertTrue(x.hashCode() == y.hashCode());
+ }
+
+ @Test
+ public void testMeasValues() {
+ PojoClass pojoclass = PojoClassFactory.getPojoClass(MeasValues.class);
+ validateMd(pojoclass);
+ MeasValues x = new MeasValues();
+ MeasValues y = new MeasValues();
+ Assert.assertTrue(x.equals(y) && y.equals(x));
+ Assert.assertTrue(x.hashCode() == y.hashCode());
+ }
+
+ @Test
+ public void testMeasDataCollection() {
+ PojoClass pojoclass = PojoClassFactory.getPojoClass(MeasDataCollection.class);
+ validateMd(pojoclass);
+ MeasDataCollection x = new MeasDataCollection();
+ MeasDataCollection y = new MeasDataCollection();
+ Assert.assertTrue(x.equals(y) && y.equals(x));
+ Assert.assertTrue(x.hashCode() == y.hashCode());
+ }
+
+ @Test
+ public void testCommonEventHeader() {
+ PojoClass pojoclass = PojoClassFactory.getPojoClass(CommonEventHeader.class);
+ validateMd(pojoclass);
+ CommonEventHeader x = new CommonEventHeader();
+ CommonEventHeader y = new CommonEventHeader();
+ Assert.assertTrue(x.equals(y) && y.equals(x));
+ Assert.assertTrue(x.hashCode() == y.hashCode());
+ }
+
+ @Test
+ public void testGetterSetterKpiConfig() {
+ PojoClass pojoclass = PojoClassFactory.getPojoClass(KpiConfig.class);
+ validateMd(pojoclass);
+ KpiConfig x = new KpiConfig();
+ KpiConfig y = new KpiConfig();
+ Assert.assertTrue(x.equals(y) && y.equals(x));
+ Assert.assertTrue(x.hashCode() == y.hashCode());
+ }
+
+ @Test
+ public void testGetterSetterMethodForKpi() {
+ PojoClass pojoclass = PojoClassFactory.getPojoClass(MethodForKpi.class);
+ validateMd(pojoclass);
+ MethodForKpi x = new MethodForKpi();
+ MethodForKpi y = new MethodForKpi();
+ Assert.assertTrue(x.equals(y) && y.equals(x));
+ Assert.assertTrue(x.hashCode() == y.hashCode());
+ }
+
+ @Test
+ public void testGetterSetterKpi() {
+ PojoClass pojoclass = PojoClassFactory.getPojoClass(Kpi.class);
+ validateMd(pojoclass);
+ Kpi x = new Kpi();
+ Kpi y = new Kpi();
+ Assert.assertTrue(x.equals(y) && y.equals(x));
+ Assert.assertTrue(x.hashCode() == y.hashCode());
+ }
+
+ @Test
+ public void testGetterSetterConfiguration() {
+
+ String strCbsConfig = FileUtils.getFileContents(CBS_CONFIG_FILE);
+ JsonObject jsonObject = new JsonParser().parse(strCbsConfig).getAsJsonObject().getAsJsonObject("config");
+ Configuration config = new Configuration();
+ config.updateConfigurationFromJsonObject(jsonObject);
+
+ assertEquals(config.getAafPassword(), "demo123456!");
+
+ }
+
+ @Test
+ public void testBaseDynamicPropertiesProvider() {
+ PojoClass pojoclass = PojoClassFactory.getPojoClass(BaseDynamicPropertiesProvider.class);
+ validateMd(pojoclass);
+ BaseDynamicPropertiesProvider x = new BaseDynamicPropertiesProvider();
+ BaseDynamicPropertiesProvider y = new BaseDynamicPropertiesProvider();
+ Assert.assertTrue(x.equals(y) && y.equals(x));
+ Assert.assertTrue(x.hashCode() == y.hashCode());
+ }
+
+}