Search in sources :

Example 61 with Processor

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);
}
Also used : StringEquals(com.redhat.service.smartevents.infra.models.filters.StringEquals) Processor(com.redhat.service.smartevents.manager.models.Processor) StringBeginsWith(com.redhat.service.smartevents.infra.models.filters.StringBeginsWith) BaseFilter(com.redhat.service.smartevents.infra.models.filters.BaseFilter) StringIn(com.redhat.service.smartevents.infra.models.filters.StringIn) StringContains(com.redhat.service.smartevents.infra.models.filters.StringContains) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 62 with Processor

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);
}
Also used : Processor(com.redhat.service.smartevents.manager.models.Processor) ProcessorResponse(com.redhat.service.smartevents.manager.api.models.responses.ProcessorResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 63 with Processor

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);
}
Also used : Processor(com.redhat.service.smartevents.manager.models.Processor) BridgeLifecycleException(com.redhat.service.smartevents.infra.exceptions.definitions.user.BridgeLifecycleException) Bridge(com.redhat.service.smartevents.manager.models.Bridge) ItemNotFoundException(com.redhat.service.smartevents.infra.exceptions.definitions.user.ItemNotFoundException) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 64 with Processor

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());
}
Also used : Processor(com.redhat.service.smartevents.manager.models.Processor) ProcessorDefinition(com.redhat.service.smartevents.infra.models.processors.ProcessorDefinition)

Example 65 with Processor

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;
}
Also used : Processor(com.redhat.service.smartevents.manager.models.Processor) ProcessorDefinition(com.redhat.service.smartevents.infra.models.processors.ProcessorDefinition)

Aggregations

Processor (com.redhat.service.smartevents.manager.models.Processor)82 Bridge (com.redhat.service.smartevents.manager.models.Bridge)45 QuarkusTest (io.quarkus.test.junit.QuarkusTest)36 Test (org.junit.jupiter.api.Test)36 Transactional (javax.transaction.Transactional)20 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 Action (com.redhat.service.smartevents.infra.models.gateways.Action)13 QueryProcessorResourceInfo (com.redhat.service.smartevents.infra.models.QueryProcessorResourceInfo)12 ProcessorDefinition (com.redhat.service.smartevents.infra.models.processors.ProcessorDefinition)9 MethodSource (org.junit.jupiter.params.provider.MethodSource)9 ProcessorRequest (com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest)8 ConnectorEntity (com.redhat.service.smartevents.manager.models.ConnectorEntity)8 Connector (com.openshift.cloud.api.connector.models.Connector)7 Work (com.redhat.service.smartevents.manager.models.Work)7 ConnectorStatusStatus (com.openshift.cloud.api.connector.models.ConnectorStatusStatus)6 ProcessorResponse (com.redhat.service.smartevents.manager.api.models.responses.ProcessorResponse)6 KafkaTopicAction (com.redhat.service.smartevents.processor.actions.kafkatopic.KafkaTopicAction)6 InternalPlatformException (com.redhat.service.smartevents.infra.exceptions.definitions.platform.InternalPlatformException)5 BaseFilter (com.redhat.service.smartevents.infra.models.filters.BaseFilter)5 SlackAction (com.redhat.service.smartevents.processor.actions.slack.SlackAction)5