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);
}
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);
}
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));
}
}
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);
}
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();
}
Aggregations