use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class JsonEnvelopeListMatcherTest method shouldNotMatchJsonEnvelopesInAListIfThereAreTooMany.
@Test(expected = AssertionError.class)
public void shouldNotMatchJsonEnvelopesInAListIfThereAreTooMany() throws Exception {
final JsonEnvelope event_1 = jsonEnvelopeWith(ID_1, NAME_1);
final JsonEnvelope event_2 = jsonEnvelopeWith(ID_2, NAME_2);
final List<JsonEnvelope> events = asList(event_1, event_2);
assertThat(events, JsonEnvelopeListMatcher.listContaining(jsonEnvelope(metadata().withName("event.action"), payloadIsJson(allOf(withJsonPath("$.someId", equalTo(ID_1.toString())), withJsonPath("$.name", equalTo(NAME_1)))))));
}
use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class JsonEnvelopeMetadataMatcherTest method shouldMatchAGivenMetadataWhereEnvelopedFromJsonEnvelope.
@Test
public void shouldMatchAGivenMetadataWhereEnvelopedFromJsonEnvelope() throws Exception {
final Metadata testMetadata = defaultMetadataRandomIdWithName(EVENT_NAME).withCausation(ID, CAUSATION_ID).build();
final JsonEnvelope jsonEnvelope = envelope().with(defaultMetadataWithName(COMMAND_ACTION)).withPayloadOf("Test", "value").build();
assertThat(testMetadata, JsonEnvelopeMetadataMatcher.withMetadataEnvelopedFrom(jsonEnvelope));
}
use of uk.gov.justice.services.messaging.JsonEnvelope 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.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class HandlerMethodMatcher method isRequesterPassThrough.
private boolean isRequesterPassThrough(final Class<?> handlerClass, final Method method) throws Exception {
final Requester requester = mock(Requester.class, withSettings().name(format("%s.requester.request", method.getName())).invocationListeners(SKIP_JSON_VALIDATION_LISTENER).defaultAnswer(RETURNS_DEFAULTS.get()));
final JsonEnvelope query = envelope().with(metadataWithDefaults()).build();
final JsonEnvelope response = envelope().with(metadataWithDefaults()).build();
final Object handlerInstance = handlerClass.newInstance();
final Field requesterField = findField(handlerClass, Requester.class);
requesterField.setAccessible(true);
requesterField.set(handlerInstance, requester);
when(requester.request(query)).thenReturn(response);
assertThat(method.invoke(handlerInstance, query), is(response));
verify(requester, times(ONCE)).request(query);
return true;
}
use of uk.gov.justice.services.messaging.JsonEnvelope 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