-
Notifications
You must be signed in to change notification settings - Fork 1
Feature amit unit test case #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
amit-kumaryadav
wants to merge
2
commits into
hubNotifier-dev
Choose a base branch
from
feature-amit-unitTestCase
base: hubNotifier-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,65 +1,131 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| 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"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <parent> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-parent</artifactId> | ||
| <version>2.1.17.RELEASE</version> | ||
| <relativePath /> <!-- lookup parent from repository --> | ||
| </parent> | ||
| <groupId>com.eagle</groupId> | ||
| <artifactId>hub-notification-service</artifactId> | ||
| <version>0.0.1-SNAPSHOT</version> | ||
| <name>hub-notification-service</name> | ||
| <description>Hu Notification Service</description> | ||
| 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"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <parent> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-parent</artifactId> | ||
| <version>2.1.17.RELEASE</version> | ||
| <relativePath/> <!-- lookup parent from repository --> | ||
| </parent> | ||
| <groupId>com.eagle</groupId> | ||
| <artifactId>hub-notification-service</artifactId> | ||
| <version>0.0.1-SNAPSHOT</version> | ||
| <name>hub-notification-service</name> | ||
| <description>Hu Notification Service</description> | ||
|
|
||
| <properties> | ||
| <java.version>1.8</java.version> | ||
| <lombok.version>1.18.8</lombok.version> | ||
| </properties> | ||
| <properties> | ||
| <java.version>1.8</java.version> | ||
| <lombok.version>1.18.8</lombok.version> | ||
| <jacoco.plugin.version>0.8.5</jacoco.plugin.version> | ||
| </properties> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-web</artifactId> | ||
| </dependency> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-web</artifactId> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-test</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.kafka</groupId> | ||
| <artifactId>spring-kafka</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.logging.log4j</groupId> | ||
| <artifactId>log4j-api</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.logging.log4j</groupId> | ||
| <artifactId>log4j-core</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-data-mongodb</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.projectlombok</groupId> | ||
| <artifactId>lombok</artifactId> | ||
| </dependency> | ||
| </dependencies> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-test</artifactId> | ||
| <scope>test</scope> | ||
| <exclusions> | ||
| <exclusion> | ||
| <groupId>junit</groupId> | ||
| <artifactId>junit</artifactId> | ||
| </exclusion> | ||
| </exclusions> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.junit.jupiter</groupId> | ||
| <artifactId>junit-jupiter-api</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.junit.jupiter</groupId> | ||
| <artifactId>junit-jupiter-engine</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>junit</groupId> | ||
| <artifactId>junit</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>junit</groupId> | ||
| <artifactId>junit</artifactId> | ||
| <version>4.13</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.kafka</groupId> | ||
| <artifactId>spring-kafka</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.logging.log4j</groupId> | ||
| <artifactId>log4j-api</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.logging.log4j</groupId> | ||
| <artifactId>log4j-core</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-data-mongodb</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.projectlombok</groupId> | ||
| <artifactId>lombok</artifactId> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-maven-plugin</artifactId> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-maven-plugin</artifactId> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.jacoco</groupId> | ||
| <artifactId>jacoco-maven-plugin</artifactId> | ||
| <version>${jacoco.plugin.version}</version> | ||
| <executions> | ||
| <execution> | ||
| <id>prepare-agent</id> | ||
| <goals> | ||
| <goal>prepare-agent</goal> | ||
| </goals> | ||
| </execution> | ||
| <execution> | ||
| <id>report</id> | ||
| <phase>prepare-package</phase> | ||
| <goals> | ||
| <goal>report</goal> | ||
| </goals> | ||
| </execution> | ||
| <execution> | ||
| <id>post-unit-test</id> | ||
| <phase>test</phase> | ||
| <goals> | ||
| <goal>report</goal> | ||
| </goals> | ||
| <configuration> | ||
| <!-- Sets the path to the file which contains the execution data. --> | ||
| <dataFile>target/jacoco.exec</dataFile> | ||
| <!-- Sets the output directory for the code coverage report. --> | ||
| <outputDirectory>target/jacoco-ut</outputDirectory> | ||
| </configuration> | ||
| </execution> | ||
| </executions> | ||
| <configuration> | ||
| <systemPropertyVariables> | ||
| <jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile> | ||
| </systemPropertyVariables> | ||
| </configuration> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
|
|
||
| </project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
HubNotificationHandler/src/test/java/com/eagle/hubnotifier/NotifyHandlerServiceImplTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<String, List<String>> recipients = new HashMap<>(); | ||
| Map<String, Object> 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<HubUser> 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<HubUser> 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); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please look into this again. using this code it will not do any operation when notifyHandlerServiceImpl class will be called. |
||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please look into this again. using this code it will not do any operation when notifyHookService class will be called.