doodzio commented on code in PR #6335:
URL: https://github.com/apache/nifi/pull/6335#discussion_r972339643
##########
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/StandardNiFiServiceFacadeTest.java:
##########
@@ -555,4 +580,183 @@ private RemoteProcessGroupDTO
createRemoteProcessGroupDTO(String id, boolean tra
return remoteProcessGroup;
}
+
+ @Test
+ public void testUpdateProcessGroup_WithProcessorBulletin() {
+ //GIVEN
+ final String groupId = UUID.randomUUID().toString();
+ final ProcessGroup processGroup = mock(ProcessGroup.class);
+ when(processGroup.getIdentifier()).thenReturn(groupId);
+
+ ProcessGroupStatus processGroupStatus = new ProcessGroupStatus();
+ processGroupStatus.setId(groupId);
+ processGroupStatus.setName(GROUP_NAME_1);
+
+ final ControllerFacade controllerFacade = mock(ControllerFacade.class);
+
when(controllerFacade.getProcessGroupStatus(any())).thenReturn(processGroupStatus);
+
+ final StandardNiFiServiceFacade serviceFacadeSpy = spy(serviceFacade);
+ serviceFacadeSpy.setControllerFacade(controllerFacade);
+ ProcessGroupDTO processGroupDTO = new ProcessGroupDTO();
+ processGroupDTO.setId(groupId);
+
when(processGroupDAO.getProcessGroup(groupId)).thenReturn(processGroup);
+
when(processGroupDAO.updateProcessGroup(processGroupDTO)).thenReturn(processGroup);
+
+ final RevisionManager revisionManager = mock(RevisionManager.class);
+ Revision revision = new Revision(1L, "a", "b");
+ final FlowModification lastModification = new
FlowModification(revision, "a");
+ RevisionUpdate<Object> snapshot = new
StandardRevisionUpdate<>(processGroupDTO, lastModification);
+ when(revisionManager.updateRevision(any(), any(),
any())).thenReturn((RevisionUpdate<Object> )snapshot);
+ serviceFacadeSpy.setRevisionManager(revisionManager);
+
+ MockTestBulletinRepository bulletinRepository = new
MockTestBulletinRepository();
+ serviceFacadeSpy.setBulletinRepository(bulletinRepository);
+
+ //add a bulletin for a processor in the current processor group
+ bulletinRepository.addBulletin(
+ BulletinFactory.createBulletin(groupId, GROUP_NAME_1,
PROCESSOR_ID_1,
+ ComponentType.PROCESSOR, PROCESSOR_NAME_1,
+ BULLETIN_CATEGORY, BULLETIN_SEVERITY, BULLETIN_MESSAGE_1,
PATH_TO_GROUP_1));
+
+ //add a bulletin for a processor in a different processor group
+ bulletinRepository.addBulletin(
+ BulletinFactory.createBulletin(RANDOM_GROUP_ID, GROUP_NAME_2,
PROCESSOR_ID_2,
+ ComponentType.PROCESSOR, PROCESSOR_NAME_2,
+ BULLETIN_CATEGORY, BULLETIN_SEVERITY, BULLETIN_MESSAGE_2,
PATH_TO_GROUP_2));
+
+ //WHEN
+ ProcessGroupEntity result =
serviceFacadeSpy.updateProcessGroup(revision, processGroupDTO);
+
+ //THEN
+ Assert.assertNotNull(result);
+ Assert.assertEquals(1, result.getBulletins().size());
+ Assert.assertEquals(groupId,
result.getBulletins().get(0).getGroupId());
+ }
+
+ @Test
+ public void testUpdateProcessGroup_WithNoBulletinForProcessGroup() {
+ //GIVEN
+ final String groupId = UUID.randomUUID().toString();
+ final ProcessGroup processGroup = mock(ProcessGroup.class);
+ when(processGroup.getIdentifier()).thenReturn(groupId);
+
+ ProcessGroupStatus processGroupStatus = new ProcessGroupStatus();
+ processGroupStatus.setId(groupId);
+ processGroupStatus.setName(GROUP_NAME_1);
+
+ final ControllerFacade controllerFacade = mock(ControllerFacade.class);
+
when(controllerFacade.getProcessGroupStatus(any())).thenReturn(processGroupStatus);
+
+ final StandardNiFiServiceFacade serviceFacadeSpy = spy(serviceFacade);
+ serviceFacadeSpy.setControllerFacade(controllerFacade);
+
+ ProcessGroupDTO processGroupDTO = new ProcessGroupDTO();
+ processGroupDTO.setId(groupId);
+
when(processGroupDAO.getProcessGroup(groupId)).thenReturn(processGroup);
+
when(processGroupDAO.updateProcessGroup(processGroupDTO)).thenReturn(processGroup);
+
+ final RevisionManager revisionManager = mock(RevisionManager.class);
+ Revision revision = new Revision(1L, "a", "b");
+ final FlowModification lastModification = new
FlowModification(revision, "a");
+
+ RevisionUpdate<Object> snapshot = new
StandardRevisionUpdate<>(processGroupDTO,lastModification);
+ when(revisionManager.updateRevision(any(), any(),
any())).thenReturn((RevisionUpdate<Object> )snapshot);
+ serviceFacadeSpy.setRevisionManager(revisionManager);
+
+ MockTestBulletinRepository bulletinRepository = new
MockTestBulletinRepository();
+ serviceFacadeSpy.setBulletinRepository(bulletinRepository);
+
+ //add a bulletin for a processor in a different processor group
+ bulletinRepository.addBulletin(
+ BulletinFactory.createBulletin(RANDOM_GROUP_ID, GROUP_NAME_2,
PROCESSOR_ID_2,
+ ComponentType.PROCESSOR, PROCESSOR_NAME_2,
+ BULLETIN_CATEGORY, BULLETIN_SEVERITY, BULLETIN_MESSAGE_2,
PATH_TO_GROUP_2));
+
+ //WHEN
+ ProcessGroupEntity result =
serviceFacadeSpy.updateProcessGroup(revision, processGroupDTO);
+
+ //THEN
+ Assert.assertNotNull(result);
+ Assert.assertEquals(0, result.getBulletins().size());
+ }
+
+ @Test
+ public void testUpdateProcessGroup_WithProcessorGroupBulletin() {
+ //GIVEN
+ final String groupId = UUID.randomUUID().toString();
+ final ProcessGroup processGroup = mock(ProcessGroup.class);
+ when(processGroup.getIdentifier()).thenReturn(groupId);
+
+ ProcessGroupStatus processGroupStatus = new ProcessGroupStatus();
+ processGroupStatus.setId(groupId);
+ processGroupStatus.setName(GROUP_NAME_1);
+
+ final ControllerFacade controllerFacade = mock(ControllerFacade.class);
+
when(controllerFacade.getProcessGroupStatus(any())).thenReturn(processGroupStatus);
+
+ final StandardNiFiServiceFacade serviceFacadeSpy = spy(serviceFacade);
+ serviceFacadeSpy.setControllerFacade(controllerFacade);
+
+ ProcessGroupDTO processGroupDTO = new ProcessGroupDTO();
+ processGroupDTO.setId(groupId);
+
when(processGroupDAO.getProcessGroup(groupId)).thenReturn(processGroup);
+
when(processGroupDAO.updateProcessGroup(processGroupDTO)).thenReturn(processGroup);
+
+ final RevisionManager revisionManager = mock(RevisionManager.class);
+ Revision revision = new Revision(1L, "a", "b");
+ final FlowModification lastModification = new
FlowModification(revision, "a");
+
+ RevisionUpdate<Object> snapshot = new
StandardRevisionUpdate<>(processGroupDTO,lastModification);
+ when(revisionManager.updateRevision(any(), any(),
any())).thenReturn((RevisionUpdate<Object> )snapshot);
+ serviceFacadeSpy.setRevisionManager(revisionManager);
+
+ MockTestBulletinRepository bulletinRepository = new
MockTestBulletinRepository();
+ serviceFacadeSpy.setBulletinRepository(bulletinRepository);
+
+ //add a bulletin for current processor group, meaning the source is
also the process group
+ bulletinRepository.addBulletin(
+ BulletinFactory.createBulletin(groupId, GROUP_NAME_1, groupId,
+ ComponentType.PROCESSOR, GROUP_NAME_1,
+ BULLETIN_CATEGORY, BULLETIN_SEVERITY, BULLETIN_MESSAGE_1,
PATH_TO_GROUP_1));
+
+ //add a bulletin for a processor in a different processor group
+ bulletinRepository.addBulletin(
+ BulletinFactory.createBulletin(RANDOM_GROUP_ID,GROUP_NAME_2,
PROCESSOR_ID_2,
+ ComponentType.PROCESSOR, PROCESSOR_NAME_2,
+ BULLETIN_CATEGORY, BULLETIN_SEVERITY, BULLETIN_MESSAGE_2,
PATH_TO_GROUP_2));
+
+ //WHEN
+ ProcessGroupEntity result =
serviceFacadeSpy.updateProcessGroup(revision, processGroupDTO);
+
+ //THEN
+ Assert.assertNotNull(result);
+ Assert.assertEquals(1, result.getBulletins().size());
+ Assert.assertEquals(groupId,
result.getBulletins().get(0).getGroupId());
+ }
+
+
+ private static class MockTestBulletinRepository extends
MockBulletinRepository {
+
+ List<Bulletin> bulletinList;
+
+ public MockTestBulletinRepository() {
+ bulletinList = new ArrayList<>();
+ }
+
+ @Override
+ public void addBulletin(Bulletin bulletin) {
+ bulletinList.add(bulletin);
+ }
+
+ public List<Bulletin> findBulletinsForGroupBySource(String groupId) {
Review Comment:
I didn't catch this previously.
Seems that you missed `@Override` annotation.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]