use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_POSTMethodBodyTest method shouldCallInterceptorChainProcessor.
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void shouldCallInterceptorChainProcessor() throws Exception {
generator.run(restRamlWithCommandApiDefaults().with(resource("/path").with(httpActionWithDefaultMapping(POST).withHttpActionOfDefaultRequestType())).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
final Class<?> resourceClass = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultCommandApiPathResource");
final Object resourceObject = getInstanceOf(resourceClass);
final Method method = firstMethodOf(resourceClass).get();
method.invoke(resourceObject, NOT_USED_JSONOBJECT);
final ArgumentCaptor<Function> functionCaptor = ArgumentCaptor.forClass(Function.class);
verify(restProcessor).process(anyString(), functionCaptor.capture(), anyString(), any(Optional.class), any(HttpHeaders.class), any(Collection.class));
final JsonEnvelope envelope = mock(JsonEnvelope.class);
final InterceptorContext interceptorContext = interceptorContextWithInput(envelope);
functionCaptor.getValue().apply(interceptorContext);
verify(interceptorChainProcessor).process(interceptorContext);
}
use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_POSTMethodBodyTest method shouldProcessAsynchronouslyIfAcceptedResponseTypePresent.
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void shouldProcessAsynchronouslyIfAcceptedResponseTypePresent() throws Exception {
final Map<String, org.raml.model.Response> responses = new HashMap<>();
responses.put(valueOf(INTERNAL_SERVER_ERROR.getStatusCode()), response().build());
responses.put(valueOf(BAD_REQUEST.getStatusCode()), response().build());
responses.put(valueOf(ACCEPTED.getStatusCode()), response().build());
generator.run(restRamlWithCommandApiDefaults().with(resource("/path").with(httpActionWithDefaultMapping(POST).withHttpActionOfDefaultRequestType().withResponsesFrom(responses))).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
final Class<?> resourceClass = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultCommandApiPathResource");
final Object resourceObject = getInstanceOf(resourceClass);
final Method method = firstMethodOf(resourceClass).get();
method.invoke(resourceObject, NOT_USED_JSONOBJECT);
final ArgumentCaptor<Function> functionCaptor = ArgumentCaptor.forClass(Function.class);
verify(restProcessor).process(anyString(), functionCaptor.capture(), anyString(), any(Optional.class), any(HttpHeaders.class), any(Collection.class));
final JsonEnvelope envelope = mock(JsonEnvelope.class);
final InterceptorContext interceptorContext = interceptorContextWithInput(envelope);
functionCaptor.getValue().apply(interceptorContext);
verify(interceptorChainProcessor).process(interceptorContext);
}
use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class RemoteExampleEventProcessorIT method shouldRequestSynchronousPostToRemoteService.
@Test
public void shouldRequestSynchronousPostToRemoteService() {
final String name = "people.create-group";
final String path = "/groups/" + GROUP_ID.toString();
final String mimeType = "application/vnd.people.group+json";
final String bodyPayload = createObjectBuilder().add("groupName", GROUP_NAME).build().toString();
stubFor(post(urlEqualTo(BASE_PATH + path)).withRequestBody(equalToJson(bodyPayload)).willReturn(aResponse().withStatus(200).withHeader("Content-Type", mimeType).withBody(RESPONSE.toDebugStringPrettyPrint())));
final JsonEnvelope group = envelope().with(metadataOf(randomUUID(), name)).withPayloadOf(GROUP_ID.toString(), "groupId").withPayloadOf(GROUP_NAME, "groupName").build();
final JsonEnvelope response = requester.request(group);
assertThat(response, jsonEnvelope(metadata().withName("people.group"), payloadIsJson(allOf(withJsonPath("$.groupId", is(GROUP_ID.toString())), withJsonPath("$.groupName", is(GROUP_NAME))))));
}
use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class RemoteExampleEventProcessorIT method shouldRequestSynchronousPatchToRemoteService.
@Test
public void shouldRequestSynchronousPatchToRemoteService() {
final String name = "people.modify-group";
final String path = "/groups/" + GROUP_ID.toString();
final String mimeType = "application/vnd.people.group+json";
final String bodyPayload = createObjectBuilder().add("groupName", GROUP_NAME).build().toString();
stubFor(patch(urlEqualTo(BASE_PATH + path)).withRequestBody(equalToJson(bodyPayload)).willReturn(aResponse().withStatus(200).withHeader("Content-Type", mimeType).withBody(RESPONSE.toDebugStringPrettyPrint())));
final JsonEnvelope group = envelope().with(metadataOf(randomUUID(), name)).withPayloadOf(GROUP_ID.toString(), "groupId").withPayloadOf(GROUP_NAME, "groupName").build();
final JsonEnvelope response = requester.request(group);
assertThat(response, jsonEnvelope(metadata().withName("people.group"), payloadIsJson(allOf(withJsonPath("$.groupId", is(GROUP_ID.toString())), withJsonPath("$.groupName", is(GROUP_NAME))))));
}
use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class RemoteExampleEventProcessorIT method shouldRequestSynchronousPutToRemoteService.
@Test
public void shouldRequestSynchronousPutToRemoteService() {
final String name = "people.update-group";
final String path = "/groups/" + GROUP_ID.toString();
final String mimeType = "application/vnd.people.group+json";
final String bodyPayload = createObjectBuilder().add("groupName", GROUP_NAME).build().toString();
stubFor(put(urlEqualTo(BASE_PATH + path)).withRequestBody(equalToJson(bodyPayload)).willReturn(aResponse().withStatus(200).withHeader("Content-Type", mimeType).withBody(RESPONSE.toDebugStringPrettyPrint())));
final JsonEnvelope group = envelope().with(metadataOf(randomUUID(), name)).withPayloadOf(GROUP_ID.toString(), "groupId").withPayloadOf(GROUP_NAME, "groupName").build();
final JsonEnvelope response = requester.request(group);
assertThat(response, jsonEnvelope(metadata().withName("people.group"), payloadIsJson(allOf(withJsonPath("$.groupId", is(GROUP_ID.toString())), withJsonPath("$.groupName", is(GROUP_NAME))))));
}
Aggregations