use of com.redhat.service.bridge.infra.exceptions.definitions.user.ActionProviderException in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ExecutorTest method setup.
@BeforeEach
void setup() {
actionProviderFactoryMock = mock(ActionProviderFactory.class);
actionInvokerMock = mock(ActionInvoker.class);
InvokableActionProvider actionProvider = mock(InvokableActionProvider.class);
when(actionProvider.getActionInvoker(any(), any())).thenReturn(actionInvokerMock);
when(actionProviderFactoryMock.getInvokableActionProvider(KafkaTopicAction.TYPE)).thenReturn(actionProvider);
when(actionProviderFactoryMock.getInvokableActionProvider(WebhookAction.TYPE)).thenReturn(actionProvider);
when(actionProviderFactoryMock.getInvokableActionProvider(not(or(eq(KafkaTopicAction.TYPE), eq(WebhookAction.TYPE))))).thenThrow(new ActionProviderException("Unknown action type"));
meterRegistry = new SimpleMeterRegistry();
}
use of com.redhat.service.bridge.infra.exceptions.definitions.user.ActionProviderException in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ActionParamValidatorContainer method isValid.
@Override
public boolean isValid(ProcessorRequest value, ConstraintValidatorContext context) {
/*
* Centralised handling of Action parameters. The idea here being that for each Action we support, we
* provide the ability to check:
*
* - The action 'type' is recognised
* - The parameters supplied to configure the Action are valid.
*/
BaseAction baseAction = value.getAction();
if (baseAction == null) {
return false;
}
if (baseAction.getParameters() == null) {
return false;
}
ActionProvider actionProvider;
try {
actionProvider = actionProviderFactory.getActionProvider(baseAction.getType());
} catch (ActionProviderException e) {
context.disableDefaultConstraintViolation();
HibernateConstraintValidatorContext hibernateContext = context.unwrap(HibernateConstraintValidatorContext.class);
hibernateContext.addMessageParameter(TYPE_PARAM, baseAction.getType());
hibernateContext.buildConstraintViolationWithTemplate(ACTION_TYPE_NOT_RECOGNISED_ERROR).addConstraintViolation();
return false;
}
ValidationResult v = actionProvider.getParameterValidator().isValid(baseAction);
if (!v.isValid()) {
String message = v.getMessage();
context.disableDefaultConstraintViolation();
if (message == null) {
message = ACTION_PARAMETERS_NOT_VALID_ERROR;
HibernateConstraintValidatorContext hibernateContext = context.unwrap(HibernateConstraintValidatorContext.class);
hibernateContext.addMessageParameter(TYPE_PARAM, baseAction.getType());
} else {
message = InterpolationHelper.escapeMessageParameter(message);
}
context.buildConstraintViolationWithTemplate(message).addConstraintViolation();
}
return v.isValid();
}
use of com.redhat.service.bridge.infra.exceptions.definitions.user.ActionProviderException in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class SendToBridgeActionTransformer method transform.
@Override
public BaseAction transform(BaseAction action, String bridgeId, String customerId, String processorId) {
String destinationBridgeId = action.getParameters().getOrDefault(SendToBridgeAction.BRIDGE_ID_PARAM, bridgeId);
Bridge destinationBridge = bridgesService.getReadyBridge(destinationBridgeId, customerId);
Map<String, String> parameters = new HashMap<>();
try {
parameters.put(WebhookAction.ENDPOINT_PARAM, getBridgeWebhookUrl(destinationBridge.getEndpoint()));
parameters.put(WebhookAction.USE_TECHNICAL_BEARER_TOKEN, "true");
} catch (MalformedURLException e) {
throw new ActionProviderException("Can't find events webhook for bridge " + destinationBridgeId);
}
BaseAction transformedAction = new BaseAction();
transformedAction.setType(WebhookAction.TYPE);
transformedAction.setParameters(parameters);
return transformedAction;
}
use of com.redhat.service.bridge.infra.exceptions.definitions.user.ActionProviderException in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ActionParamValidatorContainerTest method beforeEach.
@BeforeEach
public void beforeEach() {
actionValidatorMock = mock(ActionParameterValidator.class);
when(actionValidatorMock.isValid(any())).thenReturn(ValidationResult.valid());
ActionProvider actionProviderMock = mock(ActionProvider.class);
when(actionProviderMock.getParameterValidator()).thenReturn(actionValidatorMock);
reset(actionProviderFactoryMock);
when(actionProviderFactoryMock.getActionProvider(TEST_ACTION_TYPE)).thenReturn(actionProviderMock);
when(actionProviderFactoryMock.getActionProvider(not(eq(TEST_ACTION_TYPE)))).thenThrow(new ActionProviderException("No action provider found"));
validatorContext = mock(HibernateConstraintValidatorContext.class);
builderMock = mock(HibernateConstraintViolationBuilder.class);
when(validatorContext.buildConstraintViolationWithTemplate(any(String.class))).thenReturn(builderMock);
when(validatorContext.unwrap(HibernateConstraintValidatorContext.class)).thenReturn(validatorContext);
}
Aggregations