Search in sources :

Example 41 with Action

use of com.redhat.service.smartevents.infra.models.gateways.Action in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorServiceConnectorTest method createConnectorFailureOnExternalConnectorCreation.

@Test
void createConnectorFailureOnExternalConnectorCreation() {
    Bridge b = createPersistBridge(READY);
    Action slackAction = createSlackAction();
    ProcessorRequest processorRequest = new ProcessorRequest("ManagedConnectorProcessor", slackAction);
    doThrow(new InternalPlatformException(RhoasServiceImpl.createFailureErrorMessageFor("errorDeletingConnector"), new RuntimeException("error"))).when(connectorsApiClient).deleteConnector(anyString());
    Processor processor = processorService.createProcessor(b.getId(), b.getCustomerId(), b.getOwner(), processorRequest);
    waitForProcessorAndConnectorToFail(processor);
}
Also used : Action(com.redhat.service.smartevents.infra.models.gateways.Action) SlackAction(com.redhat.service.smartevents.processor.actions.slack.SlackAction) Processor(com.redhat.service.smartevents.manager.models.Processor) InternalPlatformException(com.redhat.service.smartevents.infra.exceptions.definitions.platform.InternalPlatformException) ProcessorRequest(com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest) Bridge(com.redhat.service.smartevents.manager.models.Bridge) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 42 with Action

use of com.redhat.service.smartevents.infra.models.gateways.Action in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorServiceConnectorTest method createConnectorFailureOnKafkaTopicCreation.

@Test
void createConnectorFailureOnKafkaTopicCreation() {
    Bridge b = createPersistBridge(READY);
    Action slackAction = createSlackAction();
    ProcessorRequest processorRequest = new ProcessorRequest("ManagedConnectorProcessor", slackAction);
    when(rhoasService.createTopicAndGrantAccessFor(anyString(), any())).thenThrow(new InternalPlatformException(RhoasServiceImpl.createFailureErrorMessageFor("errorTopic"), new RuntimeException("error")));
    when(connectorsApiClient.createConnector(any(ConnectorRequest.class))).thenReturn(new Connector());
    Processor processor = processorService.createProcessor(b.getId(), b.getCustomerId(), b.getOwner(), processorRequest);
    waitForProcessorAndConnectorToFail(processor);
    verify(rhoasService, atLeast(1)).createTopicAndGrantAccessFor(anyString(), eq(RhoasTopicAccessType.PRODUCER));
    verify(connectorsApiClient, never()).createConnector(any(ConnectorRequest.class));
}
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) InternalPlatformException(com.redhat.service.smartevents.infra.exceptions.definitions.platform.InternalPlatformException) ProcessorRequest(com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest) Bridge(com.redhat.service.smartevents.manager.models.Bridge) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 43 with Action

use of com.redhat.service.smartevents.infra.models.gateways.Action in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorServiceTest method createKafkaTopicAction.

private static Action createKafkaTopicAction() {
    Action action = new Action();
    action.setType(KafkaTopicAction.TYPE);
    action.setMapParameters(Map.of(KafkaTopicAction.TOPIC_PARAM, TestConstants.DEFAULT_KAFKA_TOPIC));
    return action;
}
Also used : Action(com.redhat.service.smartevents.infra.models.gateways.Action) KafkaTopicAction(com.redhat.service.smartevents.processor.actions.kafkatopic.KafkaTopicAction)

Example 44 with Action

use of com.redhat.service.smartevents.infra.models.gateways.Action in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorServiceTest method testUpdateProcessorWithGateway.

@ParameterizedTest
@MethodSource("updateProcessorParams")
void testUpdateProcessorWithGateway(ProcessorRequest request) {
    Processor existingProcessor = createReadyProcessorFromRequest(request);
    when(processorDAO.findByIdBridgeIdAndCustomerId(DEFAULT_BRIDGE_ID, DEFAULT_PROCESSOR_ID, DEFAULT_CUSTOMER_ID)).thenReturn(existingProcessor);
    if (request.getType() == ProcessorType.SOURCE) {
        Source dummyNewSource = new Source();
        dummyNewSource.setType("DummySource");
        request.setSource(dummyNewSource);
    } else if (request.getType() == SINK) {
        Action dummyNewAction = new Action();
        dummyNewAction.setType("DummyAction");
        request.setAction(dummyNewAction);
    }
    assertThatExceptionOfType(BadRequestException.class).isThrownBy(() -> processorService.updateProcessor(DEFAULT_BRIDGE_ID, DEFAULT_PROCESSOR_ID, DEFAULT_CUSTOMER_ID, request));
}
Also used : Action(com.redhat.service.smartevents.infra.models.gateways.Action) KafkaTopicAction(com.redhat.service.smartevents.processor.actions.kafkatopic.KafkaTopicAction) Processor(com.redhat.service.smartevents.manager.models.Processor) BadRequestException(com.redhat.service.smartevents.infra.exceptions.definitions.user.BadRequestException) MethodSource(org.junit.jupiter.params.provider.MethodSource) Source(com.redhat.service.smartevents.infra.models.gateways.Source) SlackSource(com.redhat.service.smartevents.processor.sources.slack.SlackSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 45 with Action

use of com.redhat.service.smartevents.infra.models.gateways.Action in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorServiceTest method testToResponse.

@Test
void testToResponse() {
    Bridge b = Fixtures.createBridge();
    Processor p = Fixtures.createProcessor(b, READY);
    Action action = Fixtures.createKafkaAction();
    ProcessorDefinition definition = new ProcessorDefinition(Collections.emptySet(), "", action);
    p.setDefinition(definition);
    ProcessorResponse r = processorService.toResponse(p);
    assertThat(r).isNotNull();
    assertThat(r.getHref()).isEqualTo(APIConstants.USER_API_BASE_PATH + b.getId() + "/processors/" + p.getId());
    assertThat(r.getName()).isEqualTo(p.getName());
    assertThat(r.getStatus()).isEqualTo(p.getStatus());
    assertThat(r.getType()).isEqualTo(p.getType());
    assertThat(r.getId()).isEqualTo(p.getId());
    assertThat(r.getSubmittedAt()).isEqualTo(p.getSubmittedAt());
    assertThat(r.getPublishedAt()).isEqualTo(p.getPublishedAt());
    assertThat(r.getKind()).isEqualTo("Processor");
    assertThat(r.getTransformationTemplate()).isEmpty();
    assertThat(r.getAction().getType()).isEqualTo(KafkaTopicAction.TYPE);
}
Also used : Action(com.redhat.service.smartevents.infra.models.gateways.Action) KafkaTopicAction(com.redhat.service.smartevents.processor.actions.kafkatopic.KafkaTopicAction) Processor(com.redhat.service.smartevents.manager.models.Processor) ProcessorResponse(com.redhat.service.smartevents.manager.api.models.responses.ProcessorResponse) ProcessorDefinition(com.redhat.service.smartevents.infra.models.processors.ProcessorDefinition) Bridge(com.redhat.service.smartevents.manager.models.Bridge) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Action (com.redhat.service.smartevents.infra.models.gateways.Action)62 KafkaTopicAction (com.redhat.service.smartevents.processor.actions.kafkatopic.KafkaTopicAction)23 QuarkusTest (io.quarkus.test.junit.QuarkusTest)23 Test (org.junit.jupiter.api.Test)23 WebhookAction (com.redhat.service.smartevents.processor.actions.webhook.WebhookAction)21 SlackAction (com.redhat.service.smartevents.processor.actions.slack.SlackAction)13 HashMap (java.util.HashMap)13 ProcessorDefinition (com.redhat.service.smartevents.infra.models.processors.ProcessorDefinition)12 Processor (com.redhat.service.smartevents.manager.models.Processor)12 SendToBridgeAction (com.redhat.service.smartevents.processor.actions.sendtobridge.SendToBridgeAction)12 ProcessorRequest (com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest)9 Source (com.redhat.service.smartevents.infra.models.gateways.Source)7 BaseFilter (com.redhat.service.smartevents.infra.models.filters.BaseFilter)6 BridgeResponse (com.redhat.service.smartevents.manager.api.models.responses.BridgeResponse)6 Bridge (com.redhat.service.smartevents.manager.models.Bridge)6 TestSecurity (io.quarkus.test.security.TestSecurity)6 ProcessorResponse (com.redhat.service.smartevents.manager.api.models.responses.ProcessorResponse)5 Response (io.restassured.response.Response)5 ProcessorDTO (com.redhat.service.smartevents.infra.models.dto.ProcessorDTO)4 StringEquals (com.redhat.service.smartevents.infra.models.filters.StringEquals)4