From d126dba33d4033e9f5af5e00d3830d2e05474b26 Mon Sep 17 00:00:00 2001 From: ChuanyuChen Date: Tue, 11 Apr 2023 16:43:51 +0800 Subject: Fix some issues and Add UT Fix some issues and add UT Issue-ID: USECASEUI-794 Signed-off-by: ChuanyuChen Change-Id: I013553ded90ff342653f01383cf4512885939479 --- .../dcae/dmaap/DCAENotificationCallback.java | 7 ++- .../adapters/dmaap/MRTopicMonitor.java | 3 +- .../adapters/dmaap/NotificationEventModel.java | 2 +- .../policy/dmaap/PolicyNotificationCallback.java | 6 +++ .../resources/dmaapConfig/dcae_dmaap_config.json | 2 +- .../resources/dmaapConfig/policy_dmaap_config.json | 2 +- .../intentanalysis/util/DmaapUtilTest.java | 56 ++++++++++++++++++++++ 7 files changed, 71 insertions(+), 7 deletions(-) create mode 100644 intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/util/DmaapUtilTest.java diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/dcae/dmaap/DCAENotificationCallback.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/dcae/dmaap/DCAENotificationCallback.java index 158cf91..04f06ce 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/dcae/dmaap/DCAENotificationCallback.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/dcae/dmaap/DCAENotificationCallback.java @@ -18,13 +18,16 @@ package org.onap.usecaseui.intentanalysis.adapters.dcae.dmaap; import com.google.gson.Gson; import org.onap.usecaseui.intentanalysis.adapters.dmaap.NotificationCallback; import org.onap.usecaseui.intentanalysis.adapters.dmaap.NotificationEventModel; +import org.onap.usecaseui.intentanalysis.adapters.policy.dmaap.PolicyNotificationCallback; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class DCAENotificationCallback implements NotificationCallback { - + private static final Logger logger = LoggerFactory.getLogger(DCAENotificationCallback.class); @Override public void activateCallBack(String msg) { + logger.info("Received event from DCAE: \n" + msg); NotificationEventModel event = (new Gson()).fromJson(msg, NotificationEventModel.class); - //Todo analyze the event and Report to the Intent Flow; } } diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/dmaap/MRTopicMonitor.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/dmaap/MRTopicMonitor.java index 528805d..48047e1 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/dmaap/MRTopicMonitor.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/dmaap/MRTopicMonitor.java @@ -100,10 +100,9 @@ public class MRTopicMonitor implements Runnable { public void run() { while (running) { try { - logger.debug("Topic: {} getting new msg...", consumerWrapper.getTopicName()); List dmaapMsgs = consumerWrapper.fetch(); for (JsonElement msg : dmaapMsgs) { - logger.debug("Received message: {}" + "\r\n and processing start", msg); + logger.debug("Event {} Received message: {}" + "\r\n and processing start", consumerWrapper.getTopicName(), msg); process(msg.toString()); } } catch (IOException | RuntimeException e) { diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/dmaap/NotificationEventModel.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/dmaap/NotificationEventModel.java index 2b4c44f..d465eba 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/dmaap/NotificationEventModel.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/dmaap/NotificationEventModel.java @@ -21,7 +21,7 @@ public class NotificationEventModel { private String source; - private Date timestamp; + private String timestamp; private NotificationEventEntity entity; } diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/policy/dmaap/PolicyNotificationCallback.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/policy/dmaap/PolicyNotificationCallback.java index a93aac9..44ad9ca 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/policy/dmaap/PolicyNotificationCallback.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/policy/dmaap/PolicyNotificationCallback.java @@ -18,10 +18,16 @@ package org.onap.usecaseui.intentanalysis.adapters.policy.dmaap; import com.google.gson.Gson; import org.onap.usecaseui.intentanalysis.adapters.dmaap.NotificationCallback; import org.onap.usecaseui.intentanalysis.adapters.dmaap.NotificationEventModel; +import org.onap.usecaseui.intentanalysis.adapters.policy.impl.PolicyServiceImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class PolicyNotificationCallback implements NotificationCallback { + + private static final Logger logger = LoggerFactory.getLogger(PolicyNotificationCallback.class); @Override public void activateCallBack(String msg) { + logger.info("Received event from Policy: \n" + msg); NotificationEventModel event = (new Gson()).fromJson(msg, NotificationEventModel.class); //Todo analyze the event and Report to the Intent Flow; diff --git a/intentanalysis/src/main/resources/dmaapConfig/dcae_dmaap_config.json b/intentanalysis/src/main/resources/dmaapConfig/dcae_dmaap_config.json index 892d77e..a7b5a07 100644 --- a/intentanalysis/src/main/resources/dmaapConfig/dcae_dmaap_config.json +++ b/intentanalysis/src/main/resources/dmaapConfig/dcae_dmaap_config.json @@ -10,7 +10,7 @@ "fetch_timeout" : 15000, "fetch_limit" : 100, "dmaap_info":{ - "topic_url":"http://message-router:3904/events/CCVPN-CL-DCAE-EVENT", + "topic_url":"http://message-router:3904/events/unauthenticated.CCVPN_CL_DCAE_EVENT", "client_role":"org.onap.uui.intentanalysisSub", "location":"onap", "client_id":"intent-analysis-1" diff --git a/intentanalysis/src/main/resources/dmaapConfig/policy_dmaap_config.json b/intentanalysis/src/main/resources/dmaapConfig/policy_dmaap_config.json index e4d06b1..6a97c28 100644 --- a/intentanalysis/src/main/resources/dmaapConfig/policy_dmaap_config.json +++ b/intentanalysis/src/main/resources/dmaapConfig/policy_dmaap_config.json @@ -10,7 +10,7 @@ "fetch_timeout" : 15000, "fetch_limit" : 100, "dmaap_info": { - "topic_url":"http://message-router:3904/events/CCVPN-CL-POLICY-EVENT", + "topic_url":"http://message-router:3904/events/unauthenticated.CCVPN_CL_POLICY_EVENT", "client_role":"org.onap.uui.intentanalysisSub", "location":"onap", "client_id":"intent-analysis-1" diff --git a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/util/DmaapUtilTest.java b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/util/DmaapUtilTest.java new file mode 100644 index 0000000..be2a020 --- /dev/null +++ b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/util/DmaapUtilTest.java @@ -0,0 +1,56 @@ +package org.onap.usecaseui.intentanalysis.util; + +import java.io.IOException; +import org.apache.http.util.Asserts; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.api.MessageRouterPublisher; +import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.api.MessageRouterSubscriber; +import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterPublishRequest; +import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterSubscribeRequest; +import org.onap.usecaseui.intentanalysis.IntentAnalysisApplicationTests; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@SpringBootTest(classes = IntentAnalysisApplicationTests.class) +@RunWith(SpringRunner.class) +public class DmaapUtilTest { + + private static final String testMRURl = "http://mrhost:30607/events/unauthenticated.CCVPN_CL_DCAE_EVENT"; + + private static final String testConsumerGroup = "testGroup"; + + private static final String testConsumerId = "testUd"; + + private static final String testSubscriberName = "testName"; + + private static final String testPublisherName = "testName"; + + private static final String testTopicUrl = "http://mrhost:30607/topics/create"; + + @Test + public void testBuildSubscriberSuccess() { + MessageRouterSubscriber subscriber = DmaapUtil.buildSubscriber(); + Assert.assertNotNull(subscriber); + } + + @Test + public void testBuildSubscriberRequestSuccess() { + MessageRouterSubscribeRequest request = DmaapUtil.buildSubscriberRequest(testSubscriberName, testMRURl, + testConsumerGroup, testConsumerId); + Assert.assertNotNull(request); + } + + @Test + public void testBuildPublisherSuccess(){ + MessageRouterPublisher publisher = DmaapUtil.buildPublisher(); + Assert.assertNotNull(publisher); + } + + @Test + public void testBuildPublisherRequestSuccess(){ + MessageRouterPublishRequest publishRequest = DmaapUtil.buildPublisherRequest(testPublisherName,testTopicUrl); + Assert.assertNotNull(publishRequest); + } +} -- cgit 1.2.3-korg