public void shouldActivateCommand()

in component-test/src/main/java/org/apache/fineract/cn/group/TestGroup.java [104:156]


  public void shouldActivateCommand ( ) 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());

    final Group fetchedGroup = this.testSubject.findGroup(randomGroup.getIdentifier());
    Assert.assertEquals(Group.Status.PENDING.name(), fetchedGroup.getStatus());

    final GroupCommand activate = new GroupCommand();
    activate.setAction(GroupCommand.Action.ACTIVATE.name());
    activate.setNote(RandomStringUtils.randomAlphanumeric(256));
    activate.setCreatedBy(TestGroup.TEST_USER);
    activate.setCreatedOn(ZonedDateTime.now(Clock.systemUTC()).format(DateTimeFormatter.ISO_ZONED_DATE_TIME));

    this.testSubject.processGroupCommand(randomGroup.getIdentifier(), activate);
    this.eventRecorder.wait(EventConstants.ACTIVATE_GROUP, randomGroup.getIdentifier());

    final Group activatedGroup = this.testSubject.findGroup(randomGroup.getIdentifier());
    Assert.assertEquals(Group.Status.ACTIVE.name(), activatedGroup.getStatus());

    final List <GroupCommand> groupCommands = this.testSubject.fetchGroupCommands(activatedGroup.getIdentifier());
    Assert.assertTrue(groupCommands.size() == 1);
    final GroupCommand groupCommand = groupCommands.get(0);
    Assert.assertEquals(activate.getAction(), groupCommand.getAction());
    Assert.assertEquals(activate.getNote(), groupCommand.getNote());
    Assert.assertEquals(activate.getCreatedBy(), groupCommand.getCreatedBy());
    Assert.assertNotNull(groupCommand.getCreatedOn());

    final List <Meeting> meetings = this.testSubject.fetchMeetings(activatedGroup.getIdentifier(), Boolean.FALSE);
    Assert.assertNotNull(meetings);
    Assert.assertEquals(randomGroupDefinition.getCycle().getNumberOfMeetings(), Integer.valueOf(meetings.size()));

    final Meeting meeting2signOff = meetings.get(0);
    final SignOffMeeting signOffMeeting = new SignOffMeeting();
    signOffMeeting.setCycle(meeting2signOff.getCurrentCycle());
    signOffMeeting.setSequence(meeting2signOff.getMeetingSequence());
    signOffMeeting.setDuration(120L);
    signOffMeeting.setAttendees(meeting2signOff.getAttendees()
            .stream()
            .map(attendee -> {
              attendee.setStatus(Attendee.Status.ATTENDED.name());
              return attendee;
            })
            .collect(Collectors.toSet())
    );

    this.testSubject.closeMeeting(activatedGroup.getIdentifier(), signOffMeeting);
    this.eventRecorder.wait(EventConstants.PUT_GROUP, activatedGroup.getIdentifier());
  }