Search in sources :

Example 81 with JsonEnvelope

use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.

the class RemoteExampleQueryApiIT method shouldSendQueryRemoteServiceAndReturnResponse.

@Test
public void shouldSendQueryRemoteServiceAndReturnResponse() {
    final JsonEnvelope query = envelope().with(metadataOf(randomUUID(), PEOPLE_GET_USER1)).withPayloadOf(USER_ID, "userId").build();
    final JsonEnvelope response = requester.request(query);
    assertThat(response, jsonEnvelope(metadata().withName("people.get-user1"), payloadIsJson(withJsonPath("$.result", is("SUCCESS")))));
}
Also used : JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Test(org.junit.Test)

Example 82 with JsonEnvelope

use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.

the class RemoteExampleQueryApiIT method shouldThrowAccessControlExceptionInCaseOf403Response.

@Test(expected = AccessControlViolationException.class)
public void shouldThrowAccessControlExceptionInCaseOf403Response() {
    final JsonEnvelope query = envelope().with(metadataOf(randomUUID(), PEOPLE_GET_USER1)).withPayloadOf(USER_ID, "userId").build();
    final String path = format("/users/%s", USER_ID);
    final String mimeType = format("application/vnd.%s+json", PEOPLE_QUERY_USER1);
    stubFor(get(urlEqualTo(BASE_PATH + path)).withHeader("Accept", equalTo(mimeType)).willReturn(aResponse().withStatus(403)));
    requester.request(query);
}
Also used : JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Test(org.junit.Test)

Example 83 with JsonEnvelope

use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.

the class RetryInterceptorTest method shouldThrowExceptionIfRetryMaxValueIsExceeded.

@Test
public void shouldThrowExceptionIfRetryMaxValueIsExceeded() throws Exception {
    final UUID streamId = UUID.randomUUID();
    final JsonEnvelope envelope = envelope().with(metadataWithRandomUUID("nameABC").withStreamId(streamId)).build();
    final InterceptorContext currentContext = interceptorContextWithInput(envelope);
    when(interceptorChain.processNext(currentContext)).thenThrow(new OptimisticLockingRetryException("Locking Error"));
    retryInterceptor.maxRetry = "1";
    retryInterceptor.waitTime = "500";
    retryInterceptor.immediateRetries = "0";
    expectedException.expect(OptimisticLockingRetryFailedException.class);
    expectedException.expectMessage("Retry count of 1 exceeded for command " + envelope.metadata().asJsonObject());
    retryInterceptor.process(currentContext, interceptorChain);
}
Also used : InterceptorContext(uk.gov.justice.services.core.interceptor.InterceptorContext) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) UUID(java.util.UUID) MetadataBuilderFactory.metadataWithRandomUUID(uk.gov.justice.services.test.utils.core.messaging.MetadataBuilderFactory.metadataWithRandomUUID) OptimisticLockingRetryException(uk.gov.justice.services.eventsourcing.repository.jdbc.exception.OptimisticLockingRetryException) Test(org.junit.Test)

Example 84 with JsonEnvelope

use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.

the class RestAdapterGenerator_PATCHMethodBodyTest method shouldCallInterceptorChainProcessor.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void shouldCallInterceptorChainProcessor() throws Exception {
    generator.run(restRamlWithCommandApiDefaults().with(resource("/path").with(httpActionWithDefaultMapping(PATCH).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) 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 85 with JsonEnvelope

use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.

the class RestAdapterGenerator_PUTMethodBodyTest method shouldCallInterceptorChainProcessor.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void shouldCallInterceptorChainProcessor() throws Exception {
    generator.run(restRamlWithCommandApiDefaults().with(resource("/path").with(httpActionWithDefaultMapping(PUT).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) 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)

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