aksharau commented on code in PR #6335: URL: https://github.com/apache/nifi/pull/6335#discussion_r971684990
########## nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/StandardNiFiServiceFacadeTest.java: ########## @@ -555,4 +583,179 @@ 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); + final DtoFactory dtoFactory = new DtoFactory(); + 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); + serviceFacadeSpy.setDtoFactory(dtoFactory); + + MockTestBulletinRepository bulletinRepository = new MockTestBulletinRepository(); + serviceFacadeSpy.setBulletinRepository(bulletinRepository); + 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)); + 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); + + final DtoFactory dtoFactory = new DtoFactory(); + + 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); + serviceFacadeSpy.setDtoFactory(dtoFactory); + + MockTestBulletinRepository bulletinRepository = new MockTestBulletinRepository(); + serviceFacadeSpy.setBulletinRepository(bulletinRepository); + + 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 Review Comment: done ########## nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/StandardNiFiServiceFacadeTest.java: ########## @@ -555,4 +583,179 @@ 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); + final DtoFactory dtoFactory = new DtoFactory(); + 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); + serviceFacadeSpy.setDtoFactory(dtoFactory); + + MockTestBulletinRepository bulletinRepository = new MockTestBulletinRepository(); + serviceFacadeSpy.setBulletinRepository(bulletinRepository); + 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)); + 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); + + final DtoFactory dtoFactory = new DtoFactory(); + + 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); + serviceFacadeSpy.setDtoFactory(dtoFactory); + + MockTestBulletinRepository bulletinRepository = new MockTestBulletinRepository(); + serviceFacadeSpy.setBulletinRepository(bulletinRepository); + + 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); + + final DtoFactory dtoFactory = new DtoFactory(); + + 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); + serviceFacadeSpy.setDtoFactory(dtoFactory); + + MockTestBulletinRepository bulletinRepository = new MockTestBulletinRepository(); + serviceFacadeSpy.setBulletinRepository(bulletinRepository); + + 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)); + 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) { + List<Bulletin> ans = new ArrayList<Bulletin>(); Review Comment: done -- 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: issues-unsubscr...@nifi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org