Search in sources :

Example 71 with JsonEnvelope

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);
}
Also used : Function(java.util.function.Function) HttpHeaders(javax.ws.rs.core.HttpHeaders) ThreadLocalHttpHeaders(org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpHeaders) Optional(java.util.Optional) InterceptorContext(uk.gov.justice.services.core.interceptor.InterceptorContext) Collection(java.util.Collection) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) JsonObject(javax.json.JsonObject) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 72 with JsonEnvelope

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);
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders) ThreadLocalHttpHeaders(org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpHeaders) Optional(java.util.Optional) HashMap(java.util.HashMap) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Matchers.anyString(org.mockito.Matchers.anyString) Method(java.lang.reflect.Method) Response(javax.ws.rs.core.Response) Function(java.util.function.Function) InterceptorContext(uk.gov.justice.services.core.interceptor.InterceptorContext) Collection(java.util.Collection) JsonObject(javax.json.JsonObject) Test(org.junit.Test)

Example 73 with JsonEnvelope

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))))));
}
Also used : JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Test(org.junit.Test)

Example 74 with JsonEnvelope

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))))));
}
Also used : JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Test(org.junit.Test)

Example 75 with JsonEnvelope

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))))));
}
Also used : JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Test(org.junit.Test)

Aggregations

JsonEnvelope (uk.gov.justice.services.messaging.JsonEnvelope)276 Test (org.junit.Test)249 UUID (java.util.UUID)69 UUID.randomUUID (java.util.UUID.randomUUID)64 JsonObject (javax.json.JsonObject)30 JsonValue (javax.json.JsonValue)26 InterceptorContext (uk.gov.justice.services.core.interceptor.InterceptorContext)24 Metadata (uk.gov.justice.services.messaging.Metadata)18 Method (java.lang.reflect.Method)17 Function (java.util.function.Function)14 StreamBufferEvent (uk.gov.justice.services.event.buffer.core.repository.streambuffer.StreamBufferEvent)10 EventStream (uk.gov.justice.services.eventsourcing.source.core.EventStream)9 JsonObjects.getJsonObject (uk.gov.justice.services.messaging.JsonObjects.getJsonObject)9 EndpointDefinition (uk.gov.justice.services.clients.core.EndpointDefinition)8 MediaType (uk.gov.justice.services.core.mapping.MediaType)8 StreamStatus (uk.gov.justice.services.event.buffer.core.repository.streamstatus.StreamStatus)7 ZonedDateTime (java.time.ZonedDateTime)6 Collection (java.util.Collection)6 Optional (java.util.Optional)6 HttpHeaders (javax.ws.rs.core.HttpHeaders)6