Search in sources :

Example 21 with ProcessorRequest

use of com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorGatewayConstraintValidatorTest method isValid_messageFromGatewayValidatorAddedOnFailure.

@ParameterizedTest
@MethodSource("gateways")
void isValid_messageFromGatewayValidatorAddedOnFailure(Gateway gateway) {
    String testErrorMessage = "This is a test error message returned from validator";
    lenient().when(actionValidatorMock.isValid(any())).thenReturn(ValidationResult.invalid(testErrorMessage));
    lenient().when(sourceValidatorMock.isValid(any())).thenReturn(ValidationResult.invalid(testErrorMessage));
    ProcessorRequest p = buildTestRequest(gateway);
    assertThat(constraintValidator.isValid(p, validatorContextMock)).isFalse();
    verifyGetValidatorCall(gateway, times(1), gateway.getType());
    verifyIsValidCall(gateway, times(1));
    verifyErrorMessage(testErrorMessage);
}
Also used : ProcessorRequest(com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 22 with ProcessorRequest

use of com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorGatewayConstraintValidatorTest method isValid_nullGatewayTypeIsNotValid.

@ParameterizedTest
@MethodSource("gateways")
void isValid_nullGatewayTypeIsNotValid(Gateway gateway) {
    gateway.setType(null);
    ProcessorRequest p = buildTestRequest(gateway);
    assertThat(constraintValidator.isValid(p, validatorContextMock)).isFalse();
    verifyGetValidatorCall(gateway, never(), ArgumentMatchers::anyString);
    verifyIsValidCall(gateway, never());
    verifyErrorMessage(GATEWAY_TYPE_MISSING_ERROR, gateway, false);
}
Also used : ArgumentMatchers(org.mockito.ArgumentMatchers) ProcessorRequest(com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 23 with ProcessorRequest

use of com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorGatewayConstraintValidatorTest method isValid_sourceWithTransformationIsNotValid.

@ParameterizedTest
@MethodSource("gateways")
void isValid_sourceWithTransformationIsNotValid(Gateway gateway) {
    ProcessorRequest p = buildTestRequest(gateway);
    p.setTransformationTemplate("template");
    if (p.getType() == ProcessorType.SOURCE) {
        assertThat(constraintValidator.isValid(p, validatorContextMock)).isFalse();
        verifyGetValidatorCall(gateway, never(), ArgumentMatchers::anyString);
        verifyIsValidCall(gateway, never());
        verifyErrorMessage(SOURCE_PROCESSOR_WITH_TRANSFORMATION_ERROR);
    } else {
        assertThat(constraintValidator.isValid(p, validatorContextMock)).isTrue();
        verifyGetValidatorCall(gateway, times(1), gateway.getType());
        verifyIsValidCall(gateway, times(1));
    }
}
Also used : ArgumentMatchers(org.mockito.ArgumentMatchers) ProcessorRequest(com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 24 with ProcessorRequest

use of com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgeWorker method createErrorHandlerProcessor.

/**
 * Creates error handler processor if required
 *
 * @param bridge input bridge
 * @return true if the work can proceed (either the error handler processor
 *         is not required or it's created and ready), false otherwise.
 */
private void createErrorHandlerProcessor(Bridge bridge) {
    // If an ErrorHandler is not needed, consider it ready
    Action errorHandlerAction = bridge.getDefinition().getErrorHandler();
    boolean errorHandlerProcessorIsNotRequired = Objects.isNull(errorHandlerAction);
    if (errorHandlerProcessorIsNotRequired) {
        return;
    }
    String bridgeId = bridge.getId();
    String customerId = bridge.getCustomerId();
    ListResult<Processor> processors = processorService.getHiddenProcessors(bridgeId, customerId);
    // This assumes we can only have one ErrorHandler Processor per Bridge
    if (processors.getTotal() > 0) {
        return;
    }
    // create error handler processor if not present
    String errorHandlerName = String.format("Back-channel for Bridge '%s'", bridge.getId());
    ProcessorRequest errorHandlerProcessor = new ProcessorRequest(errorHandlerName, errorHandlerAction);
    processorService.createErrorHandlerProcessor(bridge.getId(), bridge.getCustomerId(), bridge.getOwner(), errorHandlerProcessor);
}
Also used : Action(com.redhat.service.smartevents.infra.models.gateways.Action) Processor(com.redhat.service.smartevents.manager.models.Processor) ProcessorRequest(com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest)

Example 25 with ProcessorRequest

use of com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorServiceConnectorTest method createConnectorSuccess.

@Test
void createConnectorSuccess() {
    Bridge b = createPersistBridge(READY);
    Action slackAction = createSlackAction();
    ProcessorRequest processorRequest = new ProcessorRequest("ManagedConnectorProcessor", slackAction);
    // Emulate successful External Connector creation
    Connector externalConnector = stubbedExternalConnector("connectorExternalId");
    ConnectorStatusStatus externalConnectorStatus = new ConnectorStatusStatus();
    externalConnectorStatus.setState(ConnectorState.READY);
    externalConnector.setStatus(externalConnectorStatus);
    when(connectorsApiClient.getConnector(any())).thenReturn(externalConnector);
    when(connectorsApiClient.createConnector(any(ConnectorEntity.class))).thenCallRealMethod();
    when(connectorsApiClient.createConnector(any(ConnectorRequest.class))).thenReturn(externalConnector);
    when(rhoasService.createTopicAndGrantAccessFor(anyString(), any())).thenReturn(new Topic());
    Processor processor = processorService.createProcessor(b.getId(), b.getCustomerId(), b.getOwner(), processorRequest);
    // There will be 2 re-tries at 5s each. Add 5s to be certain everything completes.
    await().atMost(15, SECONDS).untilAsserted(() -> {
        ConnectorEntity connector = connectorsDAO.findByProcessorIdAndName(processor.getId(), resourceNamesProvider.getProcessorConnectorName(processor.getId()));
        assertThat(connector).isNotNull();
        assertThat(connector.getError()).isNullOrEmpty();
        assertThat(connector.getStatus()).isEqualTo(READY);
    });
    verify(rhoasService, atLeast(1)).createTopicAndGrantAccessFor(anyString(), eq(RhoasTopicAccessType.PRODUCER));
    ArgumentCaptor<ConnectorRequest> connectorCaptor = ArgumentCaptor.forClass(ConnectorRequest.class);
    verify(connectorsApiClient).createConnector(connectorCaptor.capture());
    ConnectorRequest calledConnector = connectorCaptor.getValue();
    assertThat(calledConnector.getKafka()).isNotNull();
}
Also used : Connector(com.openshift.cloud.api.connector.models.Connector) Action(com.redhat.service.smartevents.infra.models.gateways.Action) SlackAction(com.redhat.service.smartevents.processor.actions.slack.SlackAction) ConnectorRequest(com.openshift.cloud.api.connector.models.ConnectorRequest) Processor(com.redhat.service.smartevents.manager.models.Processor) ProcessorRequest(com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest) ConnectorEntity(com.redhat.service.smartevents.manager.models.ConnectorEntity) Topic(com.openshift.cloud.api.kas.auth.models.Topic) Bridge(com.redhat.service.smartevents.manager.models.Bridge) ConnectorStatusStatus(com.openshift.cloud.api.connector.models.ConnectorStatusStatus) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Aggregations

ProcessorRequest (com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest)59 Test (org.junit.jupiter.api.Test)49 QuarkusTest (io.quarkus.test.junit.QuarkusTest)47 BridgeResponse (com.redhat.service.smartevents.manager.api.models.responses.BridgeResponse)41 TestSecurity (io.quarkus.test.security.TestSecurity)40 ProcessorListResponse (com.redhat.service.smartevents.manager.api.models.responses.ProcessorListResponse)36 ProcessorResponse (com.redhat.service.smartevents.manager.api.models.responses.ProcessorResponse)36 Response (io.restassured.response.Response)27 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)13 BaseFilter (com.redhat.service.smartevents.infra.models.filters.BaseFilter)11 StringEquals (com.redhat.service.smartevents.infra.models.filters.StringEquals)11 Bridge (com.redhat.service.smartevents.manager.models.Bridge)11 Action (com.redhat.service.smartevents.infra.models.gateways.Action)10 Processor (com.redhat.service.smartevents.manager.models.Processor)8 SlackAction (com.redhat.service.smartevents.processor.actions.slack.SlackAction)8 MethodSource (org.junit.jupiter.params.provider.MethodSource)8 BridgeDTO (com.redhat.service.smartevents.infra.models.dto.BridgeDTO)6 BridgeRequest (com.redhat.service.smartevents.manager.api.models.requests.BridgeRequest)6 KafkaTopicAction (com.redhat.service.smartevents.processor.actions.kafkatopic.KafkaTopicAction)6 SendToBridgeAction (com.redhat.service.smartevents.processor.actions.sendtobridge.SendToBridgeAction)6