diff --git a/HubNotificationHandler/pom.xml b/HubNotificationHandler/pom.xml
index 3bed5c3..292e9a4 100644
--- a/HubNotificationHandler/pom.xml
+++ b/HubNotificationHandler/pom.xml
@@ -1,65 +1,131 @@
- 4.0.0
-
- org.springframework.boot
- spring-boot-starter-parent
- 2.1.17.RELEASE
-
-
- com.eagle
- hub-notification-service
- 0.0.1-SNAPSHOT
- hub-notification-service
- Hu Notification Service
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+ 4.0.0
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.1.17.RELEASE
+
+
+ com.eagle
+ hub-notification-service
+ 0.0.1-SNAPSHOT
+ hub-notification-service
+ Hu Notification Service
-
- 1.8
- 1.18.8
-
+
+ 1.8
+ 1.18.8
+ 0.8.5
+
-
-
- org.springframework.boot
- spring-boot-starter-web
-
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
-
- org.springframework.boot
- spring-boot-starter-test
- test
-
-
- org.springframework.kafka
- spring-kafka
-
-
- org.apache.logging.log4j
- log4j-api
-
-
- org.apache.logging.log4j
- log4j-core
-
-
- org.springframework.boot
- spring-boot-starter-data-mongodb
-
-
- org.projectlombok
- lombok
-
-
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ junit
+ junit
+
+
+
+
+ org.junit.jupiter
+ junit-jupiter-api
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ test
+
+
+ junit
+ junit
+ test
+
+
+ junit
+ junit
+ 4.13
+ test
+
+
+ org.springframework.kafka
+ spring-kafka
+
+
+ org.apache.logging.log4j
+ log4j-api
+
+
+ org.apache.logging.log4j
+ log4j-core
+
+
+ org.springframework.boot
+ spring-boot-starter-data-mongodb
+
+
+ org.projectlombok
+ lombok
+
+
-
-
-
- org.springframework.boot
- spring-boot-maven-plugin
-
-
-
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+ org.jacoco
+ jacoco-maven-plugin
+ ${jacoco.plugin.version}
+
+
+ prepare-agent
+
+ prepare-agent
+
+
+
+ report
+ prepare-package
+
+ report
+
+
+
+ post-unit-test
+ test
+
+ report
+
+
+
+ target/jacoco.exec
+
+ target/jacoco-ut
+
+
+
+
+
+ target/jacoco.exec
+
+
+
+
+
diff --git a/HubNotificationHandler/src/main/java/com/eagle/hubnotifier/service/impl/NotifyHookServiceImpl.java b/HubNotificationHandler/src/main/java/com/eagle/hubnotifier/service/impl/NotifyHookServiceImpl.java
index 51f009f..161a90d 100644
--- a/HubNotificationHandler/src/main/java/com/eagle/hubnotifier/service/impl/NotifyHookServiceImpl.java
+++ b/HubNotificationHandler/src/main/java/com/eagle/hubnotifier/service/impl/NotifyHookServiceImpl.java
@@ -95,7 +95,7 @@ public void handleNotifyKafkaTopicRequest(Map data) {
* @param data
*/
@SuppressWarnings("unchecked")
- private void handleTopicCreate(Map data) {
+ public void handleTopicCreate(Map data) {
logger.info("Received Topic Creation Event");
NotificationEvent nEvent = new NotificationEvent();
nEvent.setEventId(Constants.DISCUSSION_CREATION_EVENT_ID);
@@ -157,7 +157,7 @@ private void handlePostCreate(Map data) {
*
* @param data
*/
- private void handleTopicReplyEvent(Map data) {
+ public void handleTopicReplyEvent(Map data) {
NotificationEvent nEvent = new NotificationEvent();
nEvent.setEventId(Constants.DISCUSSION_REPLY_EVENT_ID);
Map tagValues = new HashMap<>();
@@ -183,7 +183,7 @@ private void handleTopicReplyEvent(Map data) {
*
* @param data
*/
- private void handleTopicUpvoteEvent(Map data) {
+ public void handleTopicUpvoteEvent(Map data) {
NotificationEvent nEvent = new NotificationEvent();
nEvent.setEventId(Constants.DISCUSSION_UPVOTE_EVENT);
Map tagValues = new HashMap<>();
@@ -207,7 +207,7 @@ private void handleTopicUpvoteEvent(Map data) {
*
* @param data
*/
- private void handleTopicDownVoteEvent(Map data) {
+ public void handleTopicDownVoteEvent(Map data) {
NotificationEvent nEvent = new NotificationEvent();
nEvent.setEventId(Constants.DISCUSSION_DOWNVOTE_EVENT);
Map tagValues = new HashMap<>();
diff --git a/HubNotificationHandler/src/test/java/com/eagle/hubnotifier/NotifyHandlerServiceImplTest.java b/HubNotificationHandler/src/test/java/com/eagle/hubnotifier/NotifyHandlerServiceImplTest.java
new file mode 100644
index 0000000..1d92c5a
--- /dev/null
+++ b/HubNotificationHandler/src/test/java/com/eagle/hubnotifier/NotifyHandlerServiceImplTest.java
@@ -0,0 +1,123 @@
+package com.eagle.hubnotifier;
+
+import com.eagle.hubnotifier.config.Configuration;
+import com.eagle.hubnotifier.model.HubPost;
+import com.eagle.hubnotifier.model.HubTopic;
+import com.eagle.hubnotifier.model.HubUser;
+import com.eagle.hubnotifier.model.NotificationEvent;
+import com.eagle.hubnotifier.repository.HubPostRepository;
+import com.eagle.hubnotifier.repository.HubTopicRepository;
+import com.eagle.hubnotifier.repository.HubUserRepository;
+import com.eagle.hubnotifier.service.impl.NotifyHandlerServiceImpl;
+import com.eagle.hubnotifier.service.impl.NotifyHookServiceImpl;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import java.util.*;
+
+import static org.mockito.Mockito.*;
+
+
+@RunWith(MockitoJUnitRunner.class)
+class NotifyHandlerServiceImplTest {
+
+ @Mock
+ private HubUserRepository userRepository;
+
+ @Mock
+ public Configuration configuration;
+
+ @Mock
+ private HubPostRepository hubPostRepository;
+
+ @Mock
+ private HubTopicRepository hubTopicRepository;
+
+ @Mock
+ private NotifyHandlerServiceImpl notifyHandlerServiceImpl;
+
+ final String DISCUSSION_BASE_URL = "base_url";
+ final String USER_CONST = "user";
+ final String TOPIC_DATA = "topicData";
+ final String POST_DATA = "postData";
+ final String NOTIFICATION_SERVICE_HOST = "ipaddress";
+ final String NOTIFICATION_SERVICE_PATH = "path";
+ final String EVENT_ID = "eventId";
+ final String ROOT_ORG = "root_Org";
+
+ @BeforeEach
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ void handleNotifyKafkaTopicRequest() {
+ NotifyHookServiceImpl notifyHookService = mock(NotifyHookServiceImpl.class);
+ doNothing().when(notifyHookService).handleNotifyKafkaTopicRequest(Matchers.any(Map.class));
+ }
+
+ @Test
+ void handleTopicCreate() throws Exception {
+ HubUser user = mock(HubUser.class);
+ NotifyHookServiceImpl notifyHookService = mock(NotifyHookServiceImpl.class);
+ when(configuration.getDiscussionCreateUrl()).thenReturn(DISCUSSION_BASE_URL);
+ when(userRepository.findByKey(USER_CONST)).thenReturn(user);
+ doNothing().when(notifyHookService).handleTopicCreate(Matchers.any(Map.class));
+ }
+
+ @Test
+ void handleTopicReplyEvent() throws Exception {
+ HubUser user = mock(HubUser.class);
+ HubTopic topic = mock(HubTopic.class);
+ Map> recipients = new HashMap<>();
+ Map values = new HashMap<>();
+ NotifyHookServiceImpl notifyHookService = mock(NotifyHookServiceImpl.class);
+ NotificationEvent notificationEvent = mock(NotificationEvent.class);
+ when(notificationEvent.getEventId()).thenReturn(EVENT_ID);
+ when(notificationEvent.getRecipients()).thenReturn(recipients);
+ when(notificationEvent.getRootOrg()).thenReturn(ROOT_ORG);
+ when(notificationEvent.getTagValues()).thenReturn(values);
+ when(notificationEvent.getTargetData()).thenReturn(values);
+ when(configuration.getDiscussionCreateUrl()).thenReturn(DISCUSSION_BASE_URL);
+ when(hubTopicRepository.findByKey(TOPIC_DATA)).thenReturn(topic);
+ when(userRepository.findByKey(USER_CONST)).thenReturn(user);
+ doNothing().when(notifyHookService).handleTopicReplyEvent(Matchers.any(Map.class));
+ }
+
+ @Test
+ void handleTopicUpvoteEvent() {
+ HubPost post = mock(HubPost.class);
+ HubUser user = mock(HubUser.class);
+ NotifyHookServiceImpl notifyHookService = mock(NotifyHookServiceImpl.class);
+ when(hubPostRepository.findByKey(POST_DATA)).thenReturn(post);
+ List userList = new ArrayList<>();
+ userList.add(user);
+ when(userRepository.findByUUIDS(Arrays.asList("1", "2"))).thenReturn(userList);
+ doNothing().when(notifyHookService).handleTopicUpvoteEvent(Matchers.any(Map.class));
+ }
+
+ @Test
+ void handleTopicDownVoteEvent() {
+ HubPost post = mock(HubPost.class);
+ HubUser user = mock(HubUser.class);
+ NotifyHookServiceImpl notifyHookService = mock(NotifyHookServiceImpl.class);
+ when(hubPostRepository.findByKey(POST_DATA)).thenReturn(post);
+ List userList = new ArrayList<>();
+ userList.add(user);
+ when(userRepository.findByUUIDS(Arrays.asList("1", "2"))).thenReturn(userList);
+ doNothing().when(notifyHookService).handleTopicDownVoteEvent(Matchers.any(Map.class));
+ }
+
+ @Test
+ void sendNotification() {
+ NotificationEvent notificationEvent = mock(NotificationEvent.class);
+ when(configuration.getNotifyServiceHost()).thenReturn(NOTIFICATION_SERVICE_HOST);
+ when(configuration.getNotifyServicePath()).thenReturn(NOTIFICATION_SERVICE_PATH);
+ doNothing().when(notifyHandlerServiceImpl).sendNotification(notificationEvent);
+ }
+}