StandardFDProcessorService extends BaseExtensionComponentService<VersionedProcessor, ProcessorDefinition, FDProcessor> implements FDProcessorService { @Override public FDProcessor create(final String flowId, final String processGroupId, final VersionedProcessor requestComponentConfig) { final FDFlow currentFlow = getFlowOrNotFound(flowId); validateRequestValues(requestComponentConfig); final String requestType = requestComponentConfig.getType(); final Bundle requestBundle = requestComponentConfig.getBundle(); final FDProcessor createdComponent = createExtensionComponent( currentFlow, processGroupId, requestType, requestComponentConfig, (em) -> em.createProcessor(requestType, requestBundle), VersionedProcessGroup::getProcessors, this::validate ); ComponentUtils.populateControllerServicePropertyDescriptors(currentFlow, processGroupId, createdComponent.getComponentDefinition()); return createdComponent; } @Autowired  StandardFDProcessorService(final FDFlowManager flowManager, final FDExtensionManagers extensionManagers, final ValidationService validationService); @Override FDComponentTypes getProcessorTypes(final String flowId); @Override FDPropertyDescriptor getPropertyDescriptor(final String flowId, final String processorId, final String propertyName); @Override FDProcessor create(final String flowId, final String processGroupId, final VersionedProcessor requestComponentConfig); @Override FDProcessor get(final String flowId, final String processorId); @Override FDProcessor update(final String flowId, final VersionedProcessor requestComponentConfig); @Override void delete(final String flowId, final String processorId); @Override ProcessorDefinition getComponentDefinition(final String agentClass, final VersionedProcessor componentConfig);  }
@Test(expected = ResourceNotFoundException.class) public void testCreateProcessorWhenFlowDoesNotExist() { final String flowId = "DOES-NOT-EXIST"; when(flowManager.getFlow(flowId)).thenReturn(Optional.empty()); processorService.create(flowId, "pgId", new VersionedProcessor()); }
@Test(expected = ResourceNotFoundException.class) public void testCreateProcessorWhenProcessGroupDoesNotExist() { final String flowId = "1"; final String processGroupId = "DOES-NOT-EXIST"; when(flowManager.getFlow(flowId)).thenReturn(Optional.of(flow)); processorService.create(flowId, processGroupId, new VersionedProcessor()); }
@Test(expected = IllegalStateException.class) public void testCreateProcessorWhenExtensionManagerDoesNotExist() { final String flowId = "1"; final String processGroupId = "child-level-2"; when(flowManager.getFlow(flowId)).thenReturn(Optional.of(flow)); when(extensionManagers.getExtensionManager(flow.getFlowMetadata().getAgentClass())) .thenReturn(Optional.empty()); processorService.create(flowId, processGroupId, new VersionedProcessor()); }
@Test(expected = IllegalArgumentException.class) public void testCreateProcessorWhenManifestProcessorDoesNotExist() { final String flowId = "1"; final String processGroupId = "child-level-2"; when(flowManager.getFlow(flowId)).thenReturn(Optional.of(flow)); when(extensionManagers.getExtensionManager(flow.getFlowMetadata().getAgentClass())) .thenReturn(Optional.of(extensionManager)); final VersionedProcessor requestProcessor = createVersionedProcessor(); when(extensionManager.createProcessor( requestProcessor.getType(), requestProcessor.getBundle())) .thenThrow(new IllegalArgumentException("Bundle does not exist")); processorService.create(flowId, processGroupId, requestProcessor); }
@Test(expected = IllegalArgumentException.class) public void testCreateProcessorWithInvalidSchedulingStrategy() { final String flowId = "1"; final String processGroupId = "child-level-2"; when(flowManager.getFlow(flowId)).thenReturn(Optional.of(flow)); when(extensionManagers.getExtensionManager(flow.getFlowMetadata().getAgentClass())) .thenReturn(Optional.of(extensionManager)); final VersionedProcessor requestProcessor = createVersionedProcessor(); requestProcessor.setSchedulingStrategy("INVALID"); final FDProcessor resultProcessor = new FDProcessor(); resultProcessor.setComponentConfiguration(requestProcessor); resultProcessor.setComponentDefinition(new ProcessorDefinition()); when(extensionManager.createProcessor( requestProcessor.getType(), requestProcessor.getBundle())) .thenReturn(resultProcessor); processorService.create(flowId, processGroupId, requestProcessor); }
@Test(expected = IllegalArgumentException.class) public void testCreateProcessorWithInvalidSchedulingPeriod() { final String flowId = "1"; final String processGroupId = "child-level-2"; when(flowManager.getFlow(flowId)).thenReturn(Optional.of(flow)); when(extensionManagers.getExtensionManager(flow.getFlowMetadata().getAgentClass())) .thenReturn(Optional.of(extensionManager)); final VersionedProcessor requestProcessor = createVersionedProcessor(); requestProcessor.setSchedulingPeriod("INVALID"); final FDProcessor resultProcessor = new FDProcessor(); resultProcessor.setComponentConfiguration(requestProcessor); resultProcessor.setComponentDefinition(new ProcessorDefinition()); when(extensionManager.createProcessor( requestProcessor.getType(), requestProcessor.getBundle())) .thenReturn(resultProcessor); processorService.create(flowId, processGroupId, requestProcessor); }
@Test(expected = IllegalArgumentException.class) public void testCreateProcessorWithInvalidPenaltyDuration() { final String flowId = "1"; final String processGroupId = "child-level-2"; when(flowManager.getFlow(flowId)).thenReturn(Optional.of(flow)); when(extensionManagers.getExtensionManager(flow.getFlowMetadata().getAgentClass())) .thenReturn(Optional.of(extensionManager)); final VersionedProcessor requestProcessor = createVersionedProcessor(); requestProcessor.setPenaltyDuration("INVALID"); final FDProcessor resultProcessor = new FDProcessor(); resultProcessor.setComponentConfiguration(requestProcessor); resultProcessor.setComponentDefinition(new ProcessorDefinition()); when(extensionManager.createProcessor( requestProcessor.getType(), requestProcessor.getBundle())) .thenReturn(resultProcessor); processorService.create(flowId, processGroupId, requestProcessor); }
@Test(expected = IllegalArgumentException.class) public void testCreateProcessorWithInvalidYieldDuration() { final String flowId = "1"; final String processGroupId = "child-level-2"; when(flowManager.getFlow(flowId)).thenReturn(Optional.of(flow)); when(extensionManagers.getExtensionManager(flow.getFlowMetadata().getAgentClass())) .thenReturn(Optional.of(extensionManager)); final VersionedProcessor requestProcessor = createVersionedProcessor(); requestProcessor.setYieldDuration("INVALID"); final FDProcessor resultProcessor = new FDProcessor(); resultProcessor.setComponentConfiguration(requestProcessor); resultProcessor.setComponentDefinition(new ProcessorDefinition()); when(extensionManager.createProcessor( requestProcessor.getType(), requestProcessor.getBundle())) .thenReturn(resultProcessor); processorService.create(flowId, processGroupId, requestProcessor); }