Search in sources :

Example 1 with GatewayProviderException

use of com.redhat.service.smartevents.infra.exceptions.definitions.user.GatewayProviderException in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BaseGatewayConstraintValidator method isValidGateway.

protected <T extends Gateway> boolean isValidGateway(T gateway, ConstraintValidatorContext context, Function<String, GatewayValidator<T>> validatorGetter) {
    if (gateway.getType() == null) {
        addConstraintViolation(context, GATEWAY_TYPE_MISSING_ERROR, Collections.singletonMap(GATEWAY_CLASS_PARAM, gateway.getClass().getSimpleName()));
        return false;
    }
    if (gateway.getParameters() == null) {
        addConstraintViolation(context, GATEWAY_PARAMETERS_MISSING_ERROR, Collections.singletonMap(GATEWAY_CLASS_PARAM, gateway.getClass().getSimpleName()));
        return false;
    }
    GatewayValidator<T> validator;
    try {
        validator = validatorGetter.apply(gateway.getType());
    } catch (GatewayProviderException e) {
        addConstraintViolation(context, GATEWAY_TYPE_NOT_RECOGNISED_ERROR, Map.of(GATEWAY_CLASS_PARAM, gateway.getClass().getSimpleName(), TYPE_PARAM, gateway.getType()));
        return false;
    }
    ValidationResult v = validator.isValid(gateway);
    if (!v.isValid()) {
        String message = v.getMessage();
        if (message == null) {
            addConstraintViolation(context, GATEWAY_PARAMETERS_NOT_VALID_ERROR, Map.of(GATEWAY_CLASS_PARAM, gateway.getClass().getSimpleName(), TYPE_PARAM, gateway.getType()));
        } else {
            addConstraintViolation(context, InterpolationHelper.escapeMessageParameter(message), Collections.emptyMap());
        }
    }
    return v.isValid();
}
Also used : GatewayProviderException(com.redhat.service.smartevents.infra.exceptions.definitions.user.GatewayProviderException) ValidationResult(com.redhat.service.smartevents.infra.validations.ValidationResult)

Example 2 with GatewayProviderException

use of com.redhat.service.smartevents.infra.exceptions.definitions.user.GatewayProviderException in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ExecutorImplTest method setup.

@BeforeEach
void setup() {
    actionInvokerMock = mock(ActionInvoker.class);
    ActionInvokerBuilder actionInvokerBuilder = mock(ActionInvokerBuilder.class);
    when(actionInvokerBuilder.build(any(), any())).thenReturn(actionInvokerMock);
    actionRuntime = mock(ActionRuntime.class);
    when(actionRuntime.getInvokerBuilder(KafkaTopicAction.TYPE)).thenReturn(actionInvokerBuilder);
    when(actionRuntime.getInvokerBuilder(WebhookAction.TYPE)).thenReturn(actionInvokerBuilder);
    when(actionRuntime.getInvokerBuilder(not(or(eq(KafkaTopicAction.TYPE), eq(WebhookAction.TYPE))))).thenThrow(new GatewayProviderException("Unknown action type"));
    meterRegistry = new SimpleMeterRegistry();
}
Also used : ActionInvoker(com.redhat.service.smartevents.processor.actions.ActionInvoker) ActionInvokerBuilder(com.redhat.service.smartevents.processor.actions.ActionInvokerBuilder) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) GatewayProviderException(com.redhat.service.smartevents.infra.exceptions.definitions.user.GatewayProviderException) ActionRuntime(com.redhat.service.smartevents.processor.actions.ActionRuntime) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with GatewayProviderException

use of com.redhat.service.smartevents.infra.exceptions.definitions.user.GatewayProviderException in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorGatewayConstraintValidatorTest method beforeEach.

@BeforeEach
public void beforeEach() {
    lenient().when(actionValidatorMock.isValid(any(Action.class))).thenReturn(ValidationResult.valid());
    lenient().when(sourceValidatorMock.isValid(any(Source.class))).thenReturn(ValidationResult.valid());
    lenient().when(gatewayConfiguratorMock.getActionValidator(TEST_ACTION_TYPE)).thenReturn(actionValidatorMock);
    lenient().when(gatewayConfiguratorMock.getActionValidator(not(eq(TEST_ACTION_TYPE)))).thenThrow(new GatewayProviderException("No action provider found"));
    lenient().when(gatewayConfiguratorMock.getSourceValidator(TEST_SOURCE_TYPE)).thenReturn(sourceValidatorMock);
    lenient().when(gatewayConfiguratorMock.getSourceValidator(not(eq(TEST_SOURCE_TYPE)))).thenThrow(new GatewayProviderException("No source provider found"));
    lenient().when(validatorContextMock.buildConstraintViolationWithTemplate(any(String.class))).thenReturn(builderMock);
    lenient().when(validatorContextMock.unwrap(HibernateConstraintValidatorContext.class)).thenReturn(validatorContextMock);
    constraintValidator = new ProcessorGatewayConstraintValidator(gatewayConfiguratorMock);
}
Also used : Action(com.redhat.service.smartevents.infra.models.gateways.Action) GatewayProviderException(com.redhat.service.smartevents.infra.exceptions.definitions.user.GatewayProviderException) MethodSource(org.junit.jupiter.params.provider.MethodSource) Source(com.redhat.service.smartevents.infra.models.gateways.Source) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with GatewayProviderException

use of com.redhat.service.smartevents.infra.exceptions.definitions.user.GatewayProviderException in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class SendToBridgeActionResolver method resolve.

@Override
public Action resolve(Action action, String customerId, String bridgeId, String processorId) {
    String destinationBridgeId = action.getParameterOrDefault(SendToBridgeAction.BRIDGE_ID_PARAM, bridgeId);
    Map<String, String> parameters = new HashMap<>();
    try {
        String bridgeEndpoint = gatewayConfiguratorService.getBridgeEndpoint(destinationBridgeId, customerId);
        String bridgeWebhookUrl = getBridgeWebhookUrl(bridgeEndpoint);
        parameters.put(WebhookAction.ENDPOINT_PARAM, bridgeWebhookUrl);
        parameters.put(WebhookAction.USE_TECHNICAL_BEARER_TOKEN_PARAM, "true");
    } catch (MalformedURLException e) {
        throw new GatewayProviderException("Can't find events webhook for bridge " + destinationBridgeId);
    }
    Action transformedAction = new Action();
    transformedAction.setType(WebhookAction.TYPE);
    transformedAction.setMapParameters(parameters);
    return transformedAction;
}
Also used : MalformedURLException(java.net.MalformedURLException) Action(com.redhat.service.smartevents.infra.models.gateways.Action) WebhookAction(com.redhat.service.smartevents.processor.actions.webhook.WebhookAction) HashMap(java.util.HashMap) GatewayProviderException(com.redhat.service.smartevents.infra.exceptions.definitions.user.GatewayProviderException)

Aggregations

GatewayProviderException (com.redhat.service.smartevents.infra.exceptions.definitions.user.GatewayProviderException)4 Action (com.redhat.service.smartevents.infra.models.gateways.Action)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Source (com.redhat.service.smartevents.infra.models.gateways.Source)1 ValidationResult (com.redhat.service.smartevents.infra.validations.ValidationResult)1 ActionInvoker (com.redhat.service.smartevents.processor.actions.ActionInvoker)1 ActionInvokerBuilder (com.redhat.service.smartevents.processor.actions.ActionInvokerBuilder)1 ActionRuntime (com.redhat.service.smartevents.processor.actions.ActionRuntime)1 WebhookAction (com.redhat.service.smartevents.processor.actions.webhook.WebhookAction)1 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)1 MalformedURLException (java.net.MalformedURLException)1 HashMap (java.util.HashMap)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1