Search in sources :

Example 6 with BaseAction

use of com.redhat.service.bridge.infra.models.actions.BaseAction in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ExecutorTest method testOnEventWithFiltersTransformationAndDifferentRequestedResolvedActions.

@Test
public void testOnEventWithFiltersTransformationAndDifferentRequestedResolvedActions() throws JsonProcessingException {
    Set<BaseFilter> filters = new HashSet<>();
    filters.add(new StringEquals("data.key", "value"));
    String transformationTemplate = "{\"test\": \"{data.key}\"}";
    BaseAction requestedAction = new BaseAction();
    requestedAction.setType("SendToBridge");
    BaseAction resolvedAction = new BaseAction();
    resolvedAction.setType(WebhookAction.TYPE);
    ProcessorDTO processorDTO = createProcessor(new ProcessorDefinition(filters, transformationTemplate, requestedAction, resolvedAction));
    Executor executor = new Executor(processorDTO, filterEvaluatorFactory, transformationEvaluatorFactory, actionProviderFactoryMock, meterRegistry);
    CloudEvent cloudEvent = createCloudEvent();
    executor.onEvent(cloudEvent);
    verify(actionProviderFactoryMock).getInvokableActionProvider(WebhookAction.TYPE);
    verify(actionInvokerMock, times(1)).onEvent(any());
}
Also used : StringEquals(com.redhat.service.bridge.infra.models.filters.StringEquals) ProcessorDTO(com.redhat.service.bridge.infra.models.dto.ProcessorDTO) ProcessorDefinition(com.redhat.service.bridge.infra.models.processors.ProcessorDefinition) BaseAction(com.redhat.service.bridge.infra.models.actions.BaseAction) BaseFilter(com.redhat.service.bridge.infra.models.filters.BaseFilter) CloudEvent(io.cloudevents.CloudEvent) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 7 with BaseAction

use of com.redhat.service.bridge.infra.models.actions.BaseAction in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ExecutorTest method testOnEventWithFiltersTransformationAndSameRequestedResolvedActions.

@Test
public void testOnEventWithFiltersTransformationAndSameRequestedResolvedActions() throws JsonProcessingException {
    Set<BaseFilter> filters = new HashSet<>();
    filters.add(new StringEquals("data.key", "value"));
    String transformationTemplate = "{\"test\": \"{data.key}\"}";
    BaseAction action = new BaseAction();
    action.setType(KafkaTopicAction.TYPE);
    ProcessorDTO processorDTO = createProcessor(new ProcessorDefinition(filters, transformationTemplate, action));
    Executor executor = new Executor(processorDTO, filterEvaluatorFactory, transformationEvaluatorFactory, actionProviderFactoryMock, meterRegistry);
    CloudEvent cloudEvent = createCloudEvent();
    executor.onEvent(cloudEvent);
    verify(actionProviderFactoryMock).getInvokableActionProvider(KafkaTopicAction.TYPE);
    verify(actionInvokerMock).onEvent(any());
}
Also used : StringEquals(com.redhat.service.bridge.infra.models.filters.StringEquals) ProcessorDTO(com.redhat.service.bridge.infra.models.dto.ProcessorDTO) ProcessorDefinition(com.redhat.service.bridge.infra.models.processors.ProcessorDefinition) BaseAction(com.redhat.service.bridge.infra.models.actions.BaseAction) BaseFilter(com.redhat.service.bridge.infra.models.filters.BaseFilter) CloudEvent(io.cloudevents.CloudEvent) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 8 with BaseAction

use of com.redhat.service.bridge.infra.models.actions.BaseAction in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ExecutorTest method testOnEventWithNullTemplate.

@Test
public void testOnEventWithNullTemplate() throws JsonProcessingException {
    Set<BaseFilter> filters = new HashSet<>();
    filters.add(new StringEquals("data.key", "value"));
    BaseAction action = new BaseAction();
    action.setType(KafkaTopicAction.TYPE);
    ProcessorDTO processorDTO = createProcessor(new ProcessorDefinition(filters, null, action));
    Executor executor = new Executor(processorDTO, filterEvaluatorFactory, transformationEvaluatorFactory, actionProviderFactoryMock, meterRegistry);
    CloudEvent cloudEvent = createCloudEvent();
    executor.onEvent(cloudEvent);
    verify(actionProviderFactoryMock).getInvokableActionProvider(KafkaTopicAction.TYPE);
    verify(actionInvokerMock).onEvent(any());
}
Also used : StringEquals(com.redhat.service.bridge.infra.models.filters.StringEquals) ProcessorDTO(com.redhat.service.bridge.infra.models.dto.ProcessorDTO) ProcessorDefinition(com.redhat.service.bridge.infra.models.processors.ProcessorDefinition) BaseAction(com.redhat.service.bridge.infra.models.actions.BaseAction) BaseFilter(com.redhat.service.bridge.infra.models.filters.BaseFilter) CloudEvent(io.cloudevents.CloudEvent) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 9 with BaseAction

use of com.redhat.service.bridge.infra.models.actions.BaseAction in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorServiceTest method createConnectorFailureOnExternalConnectorCreation.

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

Example 10 with BaseAction

use of com.redhat.service.bridge.infra.models.actions.BaseAction in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorServiceTest method createSlackAction.

private BaseAction createSlackAction() {
    BaseAction mcAction = new BaseAction();
    mcAction.setType(SlackAction.TYPE);
    Map<String, String> parameters = mcAction.getParameters();
    parameters.put("channel", "channel");
    parameters.put("webhookUrl", "webhook_url");
    return mcAction;
}
Also used : BaseAction(com.redhat.service.bridge.infra.models.actions.BaseAction) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString)

Aggregations

BaseAction (com.redhat.service.bridge.infra.models.actions.BaseAction)48 Test (org.junit.jupiter.api.Test)20 QuarkusTest (io.quarkus.test.junit.QuarkusTest)15 ProcessorDefinition (com.redhat.service.bridge.infra.models.processors.ProcessorDefinition)13 HashMap (java.util.HashMap)13 ProcessorDTO (com.redhat.service.bridge.infra.models.dto.ProcessorDTO)10 BaseFilter (com.redhat.service.bridge.infra.models.filters.BaseFilter)10 StringEquals (com.redhat.service.bridge.infra.models.filters.StringEquals)9 ProcessorRequest (com.redhat.service.bridge.manager.api.models.requests.ProcessorRequest)9 Processor (com.redhat.service.bridge.manager.models.Processor)7 Bridge (com.redhat.service.bridge.manager.models.Bridge)6 HashSet (java.util.HashSet)6 CloudEvent (io.cloudevents.CloudEvent)5 ProcessorResponse (com.redhat.service.bridge.manager.api.models.responses.ProcessorResponse)4 ValidationResult (com.redhat.service.bridge.actions.ValidationResult)3 BridgeResponse (com.redhat.service.bridge.manager.api.models.responses.BridgeResponse)3 TestSecurity (io.quarkus.test.security.TestSecurity)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 Connector (com.openshift.cloud.api.connector.models.Connector)2 ConnectorRequest (com.openshift.cloud.api.connector.models.ConnectorRequest)2