use of com.redhat.service.smartevents.manager.models.Processor in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorServiceTest method testUpdateProcessorWithNoChange.
@ParameterizedTest
@MethodSource("updateProcessorParams")
void testUpdateProcessorWithNoChange(ProcessorRequest request) {
Set<BaseFilter> filters = Set.of(new StringBeginsWith("source", List.of("Storage")), new StringContains("source", List.of("StorageService")), new StringEquals("source", "StorageService"), new StringIn("source", List.of("StorageService")));
request.setFilters(filters);
Processor existingProcessor = createReadyProcessorFromRequest(request);
when(processorDAO.findByIdBridgeIdAndCustomerId(DEFAULT_BRIDGE_ID, DEFAULT_PROCESSOR_ID, DEFAULT_CUSTOMER_ID)).thenReturn(existingProcessor);
Processor updatedProcessor = processorService.updateProcessor(DEFAULT_BRIDGE_ID, DEFAULT_PROCESSOR_ID, DEFAULT_CUSTOMER_ID, request);
assertThat(updatedProcessor.getStatus()).isEqualTo(READY);
assertThat(updatedProcessor).isEqualTo(existingProcessor);
}
use of com.redhat.service.smartevents.manager.models.Processor in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorServiceTest method testUpdateProcessorWithTemplate.
@ParameterizedTest
@MethodSource("updateProcessorParams")
void testUpdateProcessorWithTemplate(ProcessorRequest request) {
Processor existingProcessor = createReadyProcessorFromRequest(request);
when(processorDAO.findByIdBridgeIdAndCustomerId(DEFAULT_BRIDGE_ID, DEFAULT_PROCESSOR_ID, DEFAULT_CUSTOMER_ID)).thenReturn(existingProcessor);
String updatedTransformationTemplate = "template";
request.setTransformationTemplate(updatedTransformationTemplate);
Processor updatedProcessor = processorService.updateProcessor(DEFAULT_BRIDGE_ID, DEFAULT_PROCESSOR_ID, DEFAULT_CUSTOMER_ID, request);
ProcessorResponse updatedResponse = processorService.toResponse(updatedProcessor);
assertThat(updatedResponse.getStatus()).isEqualTo(ACCEPTED);
assertThat(updatedResponse.getFilters()).isNull();
assertThat(updatedResponse.getTransformationTemplate()).isEqualTo(updatedTransformationTemplate);
}
use of com.redhat.service.smartevents.manager.models.Processor in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorServiceTest method cleanUp.
@BeforeEach
public void cleanUp() {
reset(bridgesServiceMock);
reset(processorDAO);
Bridge bridge = createReadyBridge();
Processor processor = createReadyProcessor();
Processor provisioningProcessor = createProvisioningProcessor();
Processor failedProcessor = createFailedProcessor();
Processor errorHandlerProcessor = createErrorHandlerProcessor();
when(bridgesServiceMock.getBridge(DEFAULT_BRIDGE_ID)).thenReturn(bridge);
when(bridgesServiceMock.getBridge(not(eq(DEFAULT_BRIDGE_ID)))).thenThrow(new ItemNotFoundException("Bridge not found"));
when(bridgesServiceMock.getBridge(DEFAULT_BRIDGE_ID, DEFAULT_CUSTOMER_ID)).thenReturn(bridge);
when(bridgesServiceMock.getBridge(not(eq(DEFAULT_BRIDGE_ID)), eq(DEFAULT_CUSTOMER_ID))).thenThrow(new ItemNotFoundException("Bridge not found"));
when(bridgesServiceMock.getBridge(any(), not(eq(DEFAULT_CUSTOMER_ID)))).thenThrow(new ItemNotFoundException("Bridge not found"));
when(bridgesServiceMock.getReadyBridge(DEFAULT_BRIDGE_ID, DEFAULT_CUSTOMER_ID)).thenReturn(bridge);
when(bridgesServiceMock.getReadyBridge(NOT_READY_BRIDGE_ID, DEFAULT_CUSTOMER_ID)).thenThrow(new BridgeLifecycleException("Bridge not ready"));
when(bridgesServiceMock.getReadyBridge(not(or(eq(DEFAULT_BRIDGE_ID), eq(NOT_READY_BRIDGE_ID))), eq(DEFAULT_CUSTOMER_ID))).thenThrow(new ItemNotFoundException("Bridge not found"));
when(processorDAO.findById(DEFAULT_PROCESSOR_ID)).thenReturn(processor);
when(processorDAO.findByBridgeIdAndName(DEFAULT_BRIDGE_ID, DEFAULT_PROCESSOR_NAME)).thenReturn(processor);
when(processorDAO.findByIdBridgeIdAndCustomerId(DEFAULT_BRIDGE_ID, DEFAULT_PROCESSOR_ID, DEFAULT_CUSTOMER_ID)).thenReturn(processor);
when(processorDAO.findByIdBridgeIdAndCustomerId(DEFAULT_BRIDGE_ID, PROVISIONING_PROCESSOR_ID, DEFAULT_CUSTOMER_ID)).thenReturn(provisioningProcessor);
when(processorDAO.findByIdBridgeIdAndCustomerId(DEFAULT_BRIDGE_ID, FAILED_PROCESSOR_ID, DEFAULT_CUSTOMER_ID)).thenReturn(failedProcessor);
when(processorDAO.findByIdBridgeIdAndCustomerId(DEFAULT_BRIDGE_ID, ERROR_HANDLER_PROCESSOR_ID, DEFAULT_CUSTOMER_ID)).thenReturn(errorHandlerProcessor);
when(processorDAO.findUserVisibleByBridgeIdAndCustomerId(eq(DEFAULT_BRIDGE_ID), eq(DEFAULT_CUSTOMER_ID), any())).thenReturn(new ListResult<>(List.of(processor, provisioningProcessor, failedProcessor), 0, 3));
when(processorDAO.countByBridgeIdAndCustomerId(DEFAULT_BRIDGE_ID, DEFAULT_CUSTOMER_ID)).thenReturn(3L);
}
use of com.redhat.service.smartevents.manager.models.Processor in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorServiceTest method doAssertProcessorCreation.
private void doAssertProcessorCreation(Processor processor, ProcessorRequest request, ProcessorType type) {
assertThat(processor.getBridge().getId()).isEqualTo(DEFAULT_BRIDGE_ID);
assertThat(processor.getType()).isEqualTo(type);
assertThat(processor.getName()).isEqualTo(request.getName());
assertThat(processor.getStatus()).isEqualTo(ACCEPTED);
assertThat(processor.getSubmittedAt()).isNotNull();
assertThat(processor.getDefinition()).isNotNull();
ArgumentCaptor<Processor> processorCaptor1 = ArgumentCaptor.forClass(Processor.class);
verify(processorDAO, times(1)).persist(processorCaptor1.capture());
assertThat(processorCaptor1.getValue()).isEqualTo(processor);
ArgumentCaptor<Processor> processorCaptor2 = ArgumentCaptor.forClass(Processor.class);
verify(connectorServiceMock, times(1)).createConnectorEntity(processorCaptor2.capture());
assertThat(processorCaptor2.getValue()).isEqualTo(processor);
assertThat(processorCaptor2.getValue().getDefinition().getRequestedAction()).isEqualTo(request.getAction());
ArgumentCaptor<Processor> processorCaptor3 = ArgumentCaptor.forClass(Processor.class);
verify(workManagerMock, times(1)).schedule(processorCaptor3.capture());
assertThat(processorCaptor3.getValue()).isEqualTo(processor);
ProcessorDefinition definition = processor.getDefinition();
assertThat(definition.getTransformationTemplate()).isEqualTo(request.getTransformationTemplate());
}
use of com.redhat.service.smartevents.manager.models.Processor in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorServiceTest method createReadyProcessorFromRequest.
private static Processor createReadyProcessorFromRequest(ProcessorRequest request) {
ProcessorDefinition definition = request.getType() == ProcessorType.SOURCE ? new ProcessorDefinition(request.getFilters(), request.getTransformationTemplate(), request.getSource(), null) : new ProcessorDefinition(request.getFilters(), request.getTransformationTemplate(), request.getAction(), null);
Processor processor = Fixtures.createProcessor(createReadyBridge(), READY);
processor.setId(DEFAULT_PROCESSOR_ID);
processor.setType(request.getType());
processor.setName(request.getName());
processor.setDefinition(definition);
return processor;
}
Aggregations