use of com.redhat.service.bridge.infra.models.actions.BaseAction in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ExecutorTest method testMetricsAreProduced.
@Test
public void testMetricsAreProduced() throws JsonProcessingException {
Set<BaseFilter> filters = new HashSet<>();
filters.add(new StringEquals("data.key", "value"));
BaseAction action = new BaseAction();
action.setType(KafkaTopicAction.TYPE);
String transformationTemplate = "{\"test\": \"{data.key}\"}";
ProcessorDTO processorDTO = createProcessor(new ProcessorDefinition(filters, transformationTemplate, action));
Executor executor = new Executor(processorDTO, filterEvaluatorFactory, transformationEvaluatorFactory, actionProviderFactoryMock, meterRegistry);
CloudEvent cloudEvent = createCloudEvent();
executor.onEvent(cloudEvent);
assertThat(meterRegistry.getMeters().stream().anyMatch(x -> x.getId().getName().equals(MetricsConstants.PROCESSOR_PROCESSING_TIME_METRIC_NAME))).isTrue();
assertThat(meterRegistry.getMeters().stream().anyMatch(x -> x.getId().getName().equals(MetricsConstants.FILTER_PROCESSING_TIME_METRIC_NAME))).isTrue();
assertThat(meterRegistry.getMeters().stream().anyMatch(x -> x.getId().getName().equals(MetricsConstants.TRANSFORMATION_PROCESSING_TIME_METRIC_NAME))).isTrue();
assertThat(meterRegistry.getMeters().stream().anyMatch(x -> x.getId().getName().equals(MetricsConstants.ACTION_PROCESSING_TIME_METRIC_NAME))).isTrue();
}
use of com.redhat.service.bridge.infra.models.actions.BaseAction in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorServiceTest method createConnectorFailureOnKafkaTopicCreation.
@Test
public void createConnectorFailureOnKafkaTopicCreation() {
Bridge b = createPersistBridge(ManagedResourceStatus.READY);
BaseAction slackAction = createSlackAction();
ProcessorRequest processorRequest = new ProcessorRequest("ManagedConnectorProcessor", slackAction);
when(rhoasService.createTopicAndGrantAccessFor(anyString(), any())).thenThrow(new InternalPlatformException(createFailureErrorMessageFor("errorTopic"), new RuntimeException("error")));
when(connectorsApiClient.createConnector(any(ConnectorRequest.class))).thenReturn(new Connector());
Processor processor = processorService.createProcessor(b.getId(), b.getCustomerId(), processorRequest);
waitForProcessorAndConnectorToFail(processor);
verify(rhoasService, atLeast(1)).createTopicAndGrantAccessFor(anyString(), eq(RhoasTopicAccessType.PRODUCER));
verify(connectorsApiClient, never()).createConnector(any(ConnectorRequest.class));
}
use of com.redhat.service.bridge.infra.models.actions.BaseAction in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorServiceTest method createKafkaAction.
private BaseAction createKafkaAction() {
BaseAction a = new BaseAction();
a.setType(KafkaTopicAction.TYPE);
Map<String, String> params = new HashMap<>();
params.put(KafkaTopicAction.TOPIC_PARAM, TestConstants.DEFAULT_KAFKA_TOPIC);
a.setParameters(params);
return a;
}
use of com.redhat.service.bridge.infra.models.actions.BaseAction in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorServiceTest method createConnectorSuccess.
@Test
void createConnectorSuccess() {
Bridge b = createPersistBridge(ManagedResourceStatus.READY);
BaseAction 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);
// Emulate the connector not being found when first looked up, to force provisioning
when(connectorsApiClient.getConnector(any())).thenReturn(null, 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(), 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(), String.format("OpenBridge-slack_sink_0.1-%s", processor.getId()));
assertThat(connector).isNotNull();
assertThat(connector.getError()).isNullOrEmpty();
assertThat(connector.getStatus()).isEqualTo(ManagedResourceStatus.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();
}
use of com.redhat.service.bridge.infra.models.actions.BaseAction in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class SlackActionTest method createSlackPayload.
@Test
public void createSlackPayload() throws JsonProcessingException {
final String channelValue = "channel";
final String webhookUrlValue = "webhook_url";
final String topicValue = "topic";
BaseAction baseAction = new BaseAction();
Map<String, String> parameters = baseAction.getParameters();
parameters.put(SlackAction.CHANNEL_PARAMETER, channelValue);
parameters.put(SlackAction.WEBHOOK_URL_PARAMETER, webhookUrlValue);
parameters.put(KafkaTopicAction.TOPIC_PARAM, topicValue);
JsonNode slackConnectorPayload = slackAction.connectorPayload(baseAction);
JsonNode expected = new ObjectMapper().readTree("{" + " \"" + CONNECTOR_CHANNEL_PARAMETER + "\":\"" + channelValue + "\"," + " \"" + CONNECTOR_WEBHOOK_URL_PARAMETER + "\":\"" + webhookUrlValue + "\"," + " \"" + CONNECTOR_TOPIC_PARAMETER + "\":\"" + topicValue + "\"" + "}");
assertThat(slackConnectorPayload).isEqualTo(expected);
}
Aggregations