StandardFDProcessGroupFlowService implements FDProcessGroupFlowService { @Override public FDProcessGroupFlow get(final String flowId, final String processGroupId, final boolean includeChildren) { final Optional<FDFlow> flowOptional = flowManager.getFlow(flowId); if (!flowOptional.isPresent()) { throw new ResourceNotFoundException("A flow does not exist with the given id"); } final FDFlow flow = flowOptional.get(); final FDFlowMetadata flowMetadata = flow.getFlowMetadata(); final VersionedProcessGroup flowContents = flow.getFlowContent(); final FDVersionInfo versionInfo = flow.getVersionInfo(); final BigInteger localFlowRevision = flow.getLocalFlowRevision(); final VersionedProcessGroup versionedProcessGroup = ROOT_GROUP_ID.equals(processGroupId) ? flowContents : ComponentUtils.getProcessGroupOrNotFound(processGroupId, flowContents); final FDProcessGroupFlowContent processGroupFlowConfig = createProcessGroupFlowConfig(flow, versionedProcessGroup, includeChildren); final FDProcessGroupFlow processGroupFlow = new FDProcessGroupFlow(); processGroupFlow.setFlowContent(processGroupFlowConfig); processGroupFlow.setFlowMetadata(flowMetadata); processGroupFlow.setVersionInfo(versionInfo); processGroupFlow.setLocalFlowRevision(localFlowRevision); return processGroupFlow; } @Autowired  StandardFDProcessGroupFlowService(final FDFlowManager flowManager,
                                             final FDProcessorService processorService,
                                             final FDControllerServiceService controllerServiceService,
                                             final ValidationService validationService,
                                             final ControllerServiceLookup serviceLookup); @Override FDProcessGroupFlow get(final String flowId, final String processGroupId, final boolean includeChildren); static final String ROOT_GROUP_ID; }
@Test(expected = ResourceNotFoundException.class) public void testGetProcessGroupWhenWhenProcessGroupDoesNotExist() { final String flowId = "1"; when(flowManager.getFlow(flowId)).thenReturn(Optional.of(flow)); processGroupFlowService.get(flowId, "DOES-NOT-EXIST", true); }
@Test public void testGetProcessGroupWithChildren() { final String flowId = "1"; when(flowManager.getFlow(flowId)).thenReturn(Optional.of(flow)); when(processorService.getComponentDefinition(any(String.class), any(VersionedProcessor.class))).thenReturn(processorDefinition); when(controllerServiceService.getComponentDefinition(any(String.class), any(VersionedControllerService.class))).thenReturn(controllerServiceDefinition); final FDProcessGroupFlow processGroupFlow = processGroupFlowService.get(flowId, flowContent.getIdentifier(), true); assertNotNull(processGroupFlow); final FDProcessGroupFlowContent processGroupFlowContent = processGroupFlow.getFlowContent(); assertTrue(processGroupFlowContent.getProcessGroups().size() > 0); assertEquals(flowContent.getProcessGroups().size(), processGroupFlowContent.getProcessGroups().size()); final int totalProcessors = getNumberOfProcessors(processGroupFlowContent); assertEquals(5, totalProcessors); final int totalServices = getNumberOfControllerServices(processGroupFlowContent); assertEquals(1, totalServices); }
@Test public void testGetProcessGroupWithoutChildren() { final String flowId = "1"; when(flowManager.getFlow(flowId)).thenReturn(Optional.of(flow)); final FDProcessGroupFlow processGroupFlow = processGroupFlowService.get(flowId, flowContent.getIdentifier(), false); assertNotNull(processGroupFlow); final FDProcessGroupFlowContent processGroupFlowContent = processGroupFlow.getFlowContent(); assertEquals(0, processGroupFlowContent.getProcessGroups().size()); }
@Test public void testGetProcessGroupUsingRootAlias() { final String flowId = "1"; when(flowManager.getFlow(flowId)).thenReturn(Optional.of(flow)); when(processorService.getComponentDefinition(any(String.class), any(VersionedProcessor.class))).thenReturn(processorDefinition); when(controllerServiceService.getComponentDefinition(any(String.class), any(VersionedControllerService.class))).thenReturn(controllerServiceDefinition); final FDProcessGroupFlow processGroupFlow = processGroupFlowService.get(flowId, "root", true); assertNotNull(processGroupFlow); final FDProcessGroupFlowContent processGroupFlowContent = processGroupFlow.getFlowContent(); assertTrue(processGroupFlowContent.getProcessGroups().size() > 0); assertEquals(flowContent.getProcessGroups().size(), processGroupFlowContent.getProcessGroups().size()); }
@Test public void testGetProcessGroupNonRootGroup() { final String flowId = "1"; when(flowManager.getFlow(flowId)).thenReturn(Optional.of(flow)); when(processorService.getComponentDefinition(any(String.class), any(VersionedProcessor.class))).thenReturn(processorDefinition); when(controllerServiceService.getComponentDefinition(any(String.class), any(VersionedControllerService.class))).thenReturn(controllerServiceDefinition); final FDProcessGroupFlow processGroupFlow = processGroupFlowService.get(flowId, group3.getIdentifier(), true); assertNotNull(processGroupFlow); final FDProcessGroupFlowContent processGroupFlowContent = processGroupFlow.getFlowContent(); assertEquals(0, processGroupFlowContent.getProcessGroups().size()); assertEquals(group3.getProcessGroups().size(), processGroupFlowContent.getProcessGroups().size()); final int totalProcessors = getNumberOfProcessors(processGroupFlowContent); assertEquals(1, totalProcessors); }
@Test(expected = ResourceNotFoundException.class) public void testGetProcessGroupWhenFlowDoesNotExist() { final String flowId = "1"; when(flowManager.getFlow(flowId)).thenReturn(Optional.empty()); processGroupFlowService.get(flowId, flowContent.getIdentifier(), true); }