From 59af21d85188c9538cdd3b784feffa94fa645aa5 Mon Sep 17 00:00:00 2001 From: Reshmasree Date: Mon, 3 Aug 2020 16:08:41 +0530 Subject: Add seed code for slice-analysis-ms Issue-ID: DCAEGEN2-2376 Signed-off-by: Reshmasree Change-Id: I946ebb346f8a77c22aa4c7590a077c8b3b7d1aa2 --- .../onap/slice/analysis/ms/ApplicationTest.java | 37 ++++++ .../slice/analysis/ms/beans/ConfigPolicyTest.java | 43 +++++++ .../slice/analysis/ms/beans/ConfigurationTest.java | 73 ++++++++++++ .../data/beans/PerformanceNotificationsTest.java | 43 +++++++ .../slice/analysis/ms/dmaap/DmaapClientTest.java | 129 +++++++++++++++++++++ .../analysis/ms/dmaap/NewPmNotificationTest.java | 42 +++++++ .../ms/dmaap/NotificationConsumerTest.java | 66 +++++++++++ .../ms/dmaap/NotificationProducerTest.java | 63 ++++++++++ .../ms/dmaap/PmNotificationCallbackTest.java | 59 ++++++++++ .../analysis/ms/dmaap/PolicyDmaapClientTest.java | 90 ++++++++++++++ .../ms/dmaap/PolicyNotificationCallbackTest.java | 35 ++++++ 11 files changed, 680 insertions(+) create mode 100644 components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/ApplicationTest.java create mode 100644 components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/beans/ConfigPolicyTest.java create mode 100644 components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/beans/ConfigurationTest.java create mode 100644 components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/data/beans/PerformanceNotificationsTest.java create mode 100644 components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/DmaapClientTest.java create mode 100644 components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/NewPmNotificationTest.java create mode 100644 components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/NotificationConsumerTest.java create mode 100644 components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/NotificationProducerTest.java create mode 100644 components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/PmNotificationCallbackTest.java create mode 100644 components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/PolicyDmaapClientTest.java create mode 100644 components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/PolicyNotificationCallbackTest.java (limited to 'components/slice-analysis-ms/src/test/java/org/onap/slice/analysis') diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/ApplicationTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/ApplicationTest.java new file mode 100644 index 00000000..38c2bacc --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/ApplicationTest.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * ============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.slice.analysis.ms; + +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() { + + } +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/beans/ConfigPolicyTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/beans/ConfigPolicyTest.java new file mode 100644 index 00000000..66f97d96 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/beans/ConfigPolicyTest.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * ============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.slice.analysis.ms.beans; + +import static org.junit.Assert.assertEquals; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; + + +public class ConfigPolicyTest { + + @Test + public void configPolicyTest() { + ConfigPolicy configPolicy = ConfigPolicy.getInstance(); + Map config = new HashMap(); + config.put("policyName", "pcims_policy"); + configPolicy.setConfig(config); + assertEquals(config, configPolicy.getConfig()); + } +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/beans/ConfigurationTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/beans/ConfigurationTest.java new file mode 100644 index 00000000..a3487773 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/beans/ConfigurationTest.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * ============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.slice.analysis.ms.beans; + +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 list = new ArrayList(); + list.add("server"); + Map 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.setPgHost("pg"); + configuration.setPgPort(5432); + configuration.setPgPassword("password"); + configuration.setPgUsername("user"); + configuration.setPollingInterval(30); + configuration.setPollingTimeout(100); + configuration.setConfigDbService("sdnrService"); + + assertEquals("cg", configuration.getCg()); + assertEquals("cid", configuration.getCid()); + assertEquals("user", configuration.getAafUsername()); + assertEquals("password", configuration.getAafPassword()); + assertEquals("user", configuration.getPgUsername()); + assertEquals("password", configuration.getPgPassword()); + assertEquals("pg", configuration.getPgHost()); + assertEquals(5432, configuration.getPgPort()); + assertEquals(30, configuration.getPollingInterval()); + assertEquals(100, configuration.getPollingTimeout()); + assertEquals("sdnrService", configuration.getConfigDbService()); + assertEquals(list, configuration.getDmaapServers()); + } +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/data/beans/PerformanceNotificationsTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/data/beans/PerformanceNotificationsTest.java new file mode 100644 index 00000000..e8654003 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/data/beans/PerformanceNotificationsTest.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * ============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.slice.analysis.ms.data.beans; + +import static org.junit.Assert.*; + +import java.sql.Timestamp; + +import org.junit.Test; + +public class PerformanceNotificationsTest { + + private Timestamp createdAt; + + @Test + public void test() { + + PerformanceNotifications performanceNotifications = new PerformanceNotifications(); + performanceNotifications.setNotification("notification"); + performanceNotifications.setCreatedAt(createdAt); + assertEquals("notification", performanceNotifications.getNotification()); + assertEquals(createdAt, performanceNotifications.getCreatedAt()); } + +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/DmaapClientTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/DmaapClientTest.java new file mode 100644 index 00000000..f2420b02 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/DmaapClientTest.java @@ -0,0 +1,129 @@ +/******************************************************************************* + * ============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.slice.analysis.ms.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.slice.analysis.ms.beans.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 topics = new HashSet(); + topics.add("topic1"); + topics.add("topic2"); + Configuration configuration = Configuration.getInstance(); + List list = new ArrayList(); + list.add("server"); + configuration.setDmaapServers(list); + configuration.setCg("cg"); + configuration.setCid("cid"); + configuration.setPollingInterval(30); + configuration.setPollingTimeout(100); + configuration.setConfigDbService("sdnrService"); + + 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"); + + 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/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/NewPmNotificationTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/NewPmNotificationTest.java new file mode 100644 index 00000000..7c11d03a --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/NewPmNotificationTest.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * ============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.slice.analysis.ms.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/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/NotificationConsumerTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/NotificationConsumerTest.java new file mode 100644 index 00000000..f4b64397 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/NotificationConsumerTest.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * ============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.slice.analysis.ms.dmaap; + +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 static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +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 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/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/NotificationProducerTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/NotificationProducerTest.java new file mode 100644 index 00000000..9dc51412 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/NotificationProducerTest.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * ============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.slice.analysis.ms.dmaap; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; + +import com.att.nsa.cambria.client.CambriaBatchingPublisher; + +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.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = NotificationProducerTest.class) +public class NotificationProducerTest { + + @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(); + } + + } +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/PmNotificationCallbackTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/PmNotificationCallbackTest.java new file mode 100644 index 00000000..8b47ba58 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/PmNotificationCallbackTest.java @@ -0,0 +1,59 @@ + +/******************************************************************************* + * ============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.slice.analysis.ms.dmaap; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.onap.slice.analysis.ms.data.repository.PerformanceNotificationsRepository; +import org.onap.slice.analysis.ms.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 + PerformanceNotificationsRepository performanceNotificationsRepository; + + @Mock + NewPmNotification newPmNotif; + + @Test + public void testActivateCallBack() { + PowerMockito.mockStatic(BeanUtil.class); + PowerMockito.when(BeanUtil.getBean(PerformanceNotificationsRepository.class)).thenReturn(performanceNotificationsRepository); + PowerMockito.when(BeanUtil.getBean(NewPmNotification.class)).thenReturn(newPmNotif); + PmNotificationCallback pmNotificationCallback = new PmNotificationCallback(); + pmNotificationCallback.activateCallBack("pmNotification"); + } + +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/PolicyDmaapClientTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/PolicyDmaapClientTest.java new file mode 100644 index 00000000..a458d33c --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/PolicyDmaapClientTest.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * ============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.slice.analysis.ms.dmaap; + +import static org.junit.Assert.*; + +import com.att.nsa.cambria.client.CambriaBatchingPublisher; +import com.att.nsa.cambria.client.CambriaConsumer; + +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.slice.analysis.ms.beans.Configuration; +import org.onap.slice.analysis.ms.utils.DmaapUtils; +import org.springframework.boot.test.context.SpringBootTest; + +@RunWith(MockitoJUnitRunner.class) +@SpringBootTest(classes = PolicyDmaapClient.class) +public class PolicyDmaapClientTest { + + @Mock + Configuration configurationMock; + + @Mock + DmaapUtils dmaapUtilsMock; + + @InjectMocks + PolicyDmaapClient policyDmaapClient; + + @Mock + CambriaConsumer policyResponseCambriaConsumerMock; + + @Mock + CambriaBatchingPublisher cambriaBatchingPublisherMock; + + @Mock + NotificationProducer notificationProducerMock; + + @Before + public void setup() { + policyDmaapClient = new PolicyDmaapClient(dmaapUtilsMock, configurationMock); + } + + @Test + public void sendNotificationToPolicyTest() { + Map streamsPublishes = new HashMap<>(); + Map topics = new HashMap<>(); + Map dmaapInfo = new HashMap<>(); + topics.put("topic_url", "https://message-router.onap.svc.cluster.local:3905/events/DCAE_CL_OUTPUT"); + dmaapInfo.put("dmaap_info", topics); + streamsPublishes.put("CL_topic", dmaapInfo); + Mockito.when(configurationMock.getStreamsPublishes()).thenReturn(streamsPublishes); + Mockito.when(dmaapUtilsMock.buildPublisher(configurationMock, "DCAE_CL_OUTPUT")).thenReturn(cambriaBatchingPublisherMock); + try { + Mockito.when(cambriaBatchingPublisherMock.send("", "hello")).thenReturn(0); + } catch (IOException e) { + e.printStackTrace(); + } + assertTrue(policyDmaapClient.sendNotificationToPolicy("hello")); + + } +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/PolicyNotificationCallbackTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/PolicyNotificationCallbackTest.java new file mode 100644 index 00000000..6793a167 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/PolicyNotificationCallbackTest.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * ============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.slice.analysis.ms.dmaap; + +import org.junit.Test; + +public class PolicyNotificationCallbackTest { + + @Test + public void testPolicyActivateCallback() { + + PolicyNotificationCallback policyNotificationCallback = new PolicyNotificationCallback(); + policyNotificationCallback.activateCallBack("newPolicyNotificationMsg"); + } + +} -- cgit 1.2.3-korg