use of uk.gov.justice.services.core.sender.Sender in project microservice_framework by CJSCommonPlatform.
the class ServiceComponents method verifyPassThroughCommandHandlerMethod.
/**
* Verify a list of method names of a Command handler. Verifies there is a ServiceComponent
* annotation, each method has a Handles annotation, the Sender field is present, and the
* sender.send method is called with the original command passed to the handler method.
*
* @param handlerClass the handler class to verify
* @param methods the method names to verify
* @throws Exception if non pass through method or an error occurs
*/
public static void verifyPassThroughCommandHandlerMethod(final Class<?> handlerClass, final List<Method> methods) throws Exception {
assertIsServiceComponent(handlerClass);
assertHandlerHasMethods(handlerClass, methods);
for (final Method method : methods) {
assertMethodHasHandlesAnnotation(method);
final Sender sender = mock(Sender.class, withSettings().name(format("%s.sender.send", method.getName())).invocationListeners(SKIP_JSON_VALIDATION_LISTENER).defaultAnswer(RETURNS_DEFAULTS.get()));
final JsonEnvelope command = envelope().with(metadataWithDefaults()).build();
final Object handlerInstance = handlerClass.newInstance();
final Field senderField = findField(handlerClass, Sender.class);
senderField.setAccessible(true);
senderField.set(handlerInstance, sender);
method.invoke(handlerInstance, command);
verify(sender).send(command);
}
}
use of uk.gov.justice.services.core.sender.Sender in project microservice_framework by CJSCommonPlatform.
the class HandlerMethodMatcher method isSenderPassThrough.
private boolean isSenderPassThrough(final Class<?> handlerClass, final Method method) throws Exception {
final Sender sender = mock(Sender.class, withSettings().name(format("%s.sender.send", method.getName())).invocationListeners(SKIP_JSON_VALIDATION_LISTENER).defaultAnswer(RETURNS_DEFAULTS.get()));
final JsonEnvelope command = envelope().with(metadataWithDefaults()).build();
final Object handlerInstance = handlerClass.newInstance();
final Field senderField = findField(handlerClass, Sender.class);
senderField.setAccessible(true);
senderField.set(handlerInstance, sender);
method.invoke(handlerInstance, command);
verify(sender, times(ONCE)).send(command);
return true;
}
Aggregations