This is an automated email from the ASF dual-hosted git repository. awasum pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/fineract-cn-group.git
commit 4b1b30b9e40180b7f6c4005d11c342cc51ec70a1 Author: kengneruphine <[email protected]> AuthorDate: Thu Sep 6 13:25:12 2018 +0100 implementing Unit test on Group and GroupDefinition --- .../org/apache/fineract/cn/group/TestGroup.java | 23 ++++++++++++++++ .../fineract/cn/group/TestGroupDefinition.java | 31 +++++++++++++++++++++- .../listener/GroupDefinitionEventListener.java | 11 ++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/component-test/src/main/java/org/apache/fineract/cn/group/TestGroup.java b/component-test/src/main/java/org/apache/fineract/cn/group/TestGroup.java index 1307d66..1b485f9 100644 --- a/component-test/src/main/java/org/apache/fineract/cn/group/TestGroup.java +++ b/component-test/src/main/java/org/apache/fineract/cn/group/TestGroup.java @@ -262,6 +262,29 @@ public class TestGroup { Assert.assertEquals(anotherEmployee.getIdentifier(), fetchedGroup.getAssignedEmployee()); } + @Test + public void shouldUpdateGroup() throws Exception{ + final GroupDefinition randomGroupDefinition = GroupDefinitionGenerator.createRandomGroupDefinition(); + this.testSubject.createGroupDefinition(randomGroupDefinition); + this.eventRecorder.wait(EventConstants.POST_GROUP_DEFINITION, randomGroupDefinition.getIdentifier()); + + final Group randomGroup = GroupGenerator.createRandomGroup(randomGroupDefinition.getIdentifier()); + this.testSubject.createGroup(randomGroup); + + this.eventRecorder.wait(EventConstants.POST_GROUP, randomGroup.getIdentifier()); + + randomGroup.setName(RandomStringUtils.randomAlphanumeric(256)); + + this.testSubject.updateGroup(randomGroup.getIdentifier(), randomGroup); + + this.eventRecorder.wait(EventConstants.PUT_GROUP,randomGroup.getIdentifier()); + + final Group updatedGroup = this.testSubject.findGroup(randomGroup.getIdentifier()); + Assert.assertEquals(randomGroup.getName(), updatedGroup.getName()); + + + } + @Configuration @EnableEventRecording @EnableFeignClients(basePackages = {"org.apache.fineract.cn.group.api.v1.client"}) diff --git a/component-test/src/main/java/org/apache/fineract/cn/group/TestGroupDefinition.java b/component-test/src/main/java/org/apache/fineract/cn/group/TestGroupDefinition.java index 608cf64..e7a75f0 100644 --- a/component-test/src/main/java/org/apache/fineract/cn/group/TestGroupDefinition.java +++ b/component-test/src/main/java/org/apache/fineract/cn/group/TestGroupDefinition.java @@ -54,6 +54,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) + public class TestGroupDefinition { private static final String APP_NAME = "group-v1"; private static final String TEST_USER = "ranefer"; @@ -92,7 +93,7 @@ public class TestGroupDefinition { @After public void cleanTest() { - TenantContextHolder.clear(); + //TenantContextHolder.clear(); userContext.close(); } @@ -127,6 +128,34 @@ public class TestGroupDefinition { Assert.assertNull(fetchedGroupDefinition.getLastModifiedOn()); } + + @Test + public void shouldUpdateGroupDefinition() throws Exception{ + final GroupDefinition randomGroupDefinition = GroupDefinitionGenerator.createRandomGroupDefinition(); + this.testSubject.createGroupDefinition(randomGroupDefinition); + + this.eventRecorder.wait(EventConstants.POST_GROUP_DEFINITION, randomGroupDefinition.getIdentifier()); + + final GroupDefinition updatedGroupDefinition = GroupDefinitionGenerator.createRandomGroupDefinition(); + updatedGroupDefinition.setIdentifier(randomGroupDefinition.getIdentifier()); + + this.testSubject.updateGroupDefinition(updatedGroupDefinition.getIdentifier(),updatedGroupDefinition); + + this.eventRecorder.wait(EventConstants.PUT_GROUP_DEFINITION, randomGroupDefinition.getIdentifier()); + + final GroupDefinition fetchedGroupDefinition = this.testSubject.findGroupDefinition(updatedGroupDefinition.getIdentifier()); + Assert.assertNotNull(fetchedGroupDefinition); + Assert.assertEquals(updatedGroupDefinition.getIdentifier(), fetchedGroupDefinition.getIdentifier()); + Assert.assertEquals(updatedGroupDefinition.getDescription(), fetchedGroupDefinition.getDescription()); + Assert.assertEquals(updatedGroupDefinition.getMinimalSize(), fetchedGroupDefinition.getMinimalSize()); + Assert.assertEquals(updatedGroupDefinition.getMaximalSize(), fetchedGroupDefinition.getMaximalSize()); + Assert.assertNotNull(fetchedGroupDefinition.getCycle()); + Assert.assertEquals(updatedGroupDefinition.getCycle().getNumberOfMeetings(), fetchedGroupDefinition.getCycle().getNumberOfMeetings()); + Assert.assertEquals(updatedGroupDefinition.getCycle().getFrequency(), fetchedGroupDefinition.getCycle().getFrequency()); + } + + + @Configuration @EnableEventRecording @EnableFeignClients(basePackages = {"org.apache.fineract.cn.group.api.v1.client"}) diff --git a/component-test/src/main/java/org/apache/fineract/cn/group/listener/GroupDefinitionEventListener.java b/component-test/src/main/java/org/apache/fineract/cn/group/listener/GroupDefinitionEventListener.java index 13dad62..42452a5 100644 --- a/component-test/src/main/java/org/apache/fineract/cn/group/listener/GroupDefinitionEventListener.java +++ b/component-test/src/main/java/org/apache/fineract/cn/group/listener/GroupDefinitionEventListener.java @@ -47,4 +47,15 @@ public class GroupDefinitionEventListener { final String payload) { this.eventRecorder.event(tenant, EventConstants.POST_GROUP_DEFINITION, payload, String.class); } + + @JmsListener( + subscription = EventConstants.DESTINATION, + destination = EventConstants.DESTINATION, + selector = EventConstants.SELECTOR_PUT_GROUP_DEFINITION + ) + public void onGroupDefinitionUpdated(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant, + final String payload) { + this.eventRecorder.event(tenant, EventConstants.PUT_GROUP_DEFINITION, payload, String.class); + } + }
