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")))));
}
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);
}
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);
}
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);
}
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);
}
Aggregations