use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class RestClientGenerator_MethodBodyTest method shouldCallRestClientWithEndpointDefinitionContainingMediaType.
@Test
@SuppressWarnings("unchecked")
public void shouldCallRestClientWithEndpointDefinitionContainingMediaType() throws Exception {
generateRemoteSomeComponent2ServiceCommandApi();
final JsonEnvelope envelope = mock(JsonEnvelope.class);
final JsonEnvelope outputEnvelope = mock(JsonEnvelope.class);
final Function function = mock(Function.class);
final Class<?> clazz = compiler.compiledClassOf(BASE_PACKAGE, "RemoteSomeComponent2ServiceCommandApi");
final Object remoteClient = instanceOfRemoteClient(clazz);
final Method method = firstMethodOf(clazz).get();
when(enveloper.withMetadataFrom(envelope, "ctx.defcmd")).thenReturn(function);
when(function.apply(envelope.payload())).thenReturn(outputEnvelope);
method.invoke(remoteClient, envelope);
assertThat(capturedPostEndpointDefinition().getResponseMediaType(), is("ctx.defcmd"));
}
use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class RestClientGenerator_MethodBodyTest method shouldSetNameAndPassEnvelopeToRestClient.
@Test
@SuppressWarnings("unchecked")
public void shouldSetNameAndPassEnvelopeToRestClient() throws Exception {
generateRemoteSomeComponent2ServiceCommandApi();
final JsonEnvelope envelope = mock(JsonEnvelope.class);
final JsonEnvelope outputEnvelope = mock(JsonEnvelope.class);
final Function function = mock(Function.class);
final Class<?> clazz = compiler.compiledClassOf(BASE_PACKAGE, "RemoteSomeComponent2ServiceCommandApi");
final Object remoteClient = instanceOfRemoteClient(clazz);
final Method method = firstMethodOf(clazz).get();
when(enveloper.withMetadataFrom(envelope, "ctx.defcmd")).thenReturn(function);
when(function.apply(envelope.payload())).thenReturn(outputEnvelope);
method.invoke(remoteClient, envelope);
verify(restClientProcessor).post(any(EndpointDefinition.class), eq(outputEnvelope));
}
use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class RestClientGenerator_MethodBodyTest method shouldCallSynchronousPutRestClientMethod.
@Test
@SuppressWarnings("unchecked")
public void shouldCallSynchronousPutRestClientMethod() throws Exception {
generator.run(restRamlWithCommandApiDefaults().with(resource("/pathabc/{anId}").with(httpAction().withHttpActionType(PUT).withMediaTypeWithDefaultSchema("application/vnd.ctx.defcmd+json").withResponseTypes("application/vnd.ctx.response+json").with(mapping().withName("action1").withRequestType("application/vnd.ctx.defcmd+json").withResponseType("application/vnd.ctx.response+json")))).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, generatorProperties().withServiceComponentOf("SOME_COMPONENT")));
final JsonEnvelope envelope = mock(JsonEnvelope.class);
final JsonEnvelope outputEnvelope = mock(JsonEnvelope.class);
final Function function = mock(Function.class);
final Class<?> clazz = compiler.compiledClassOf(BASE_PACKAGE, "RemoteSomeComponent2ServiceCommandApi");
final Object remoteClient = instanceOfRemoteClient(clazz);
final Method method = firstMethodOf(clazz).get();
when(enveloper.withMetadataFrom(envelope, "ctx.defcmd")).thenReturn(function);
when(function.apply(envelope.payload())).thenReturn(outputEnvelope);
method.invoke(remoteClient, envelope);
verify(restClientProcessor).synchronousPut(any(EndpointDefinition.class), eq(outputEnvelope));
}
use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class RestClientGenerator_MethodBodyTest method shouldCallSynchronousPostRestClientMethod.
@Test
@SuppressWarnings("unchecked")
public void shouldCallSynchronousPostRestClientMethod() throws Exception {
generator.run(restRamlWithCommandApiDefaults().with(resource("/pathabc/{anId}").with(httpAction().withHttpActionType(POST).withMediaTypeWithDefaultSchema("application/vnd.ctx.defcmd+json").withResponseTypes("application/vnd.ctx.response+json").with(mapping().withName("action1").withRequestType("application/vnd.ctx.defcmd+json").withResponseType("application/vnd.ctx.response+json")))).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, generatorProperties().withServiceComponentOf("SOME_COMPONENT")));
final JsonEnvelope envelope = mock(JsonEnvelope.class);
final JsonEnvelope outputEnvelope = mock(JsonEnvelope.class);
final Function function = mock(Function.class);
final Class<?> clazz = compiler.compiledClassOf(BASE_PACKAGE, "RemoteSomeComponent2ServiceCommandApi");
final Object remoteClient = instanceOfRemoteClient(clazz);
final Method method = firstMethodOf(clazz).get();
when(enveloper.withMetadataFrom(envelope, "ctx.defcmd")).thenReturn(function);
when(function.apply(envelope.payload())).thenReturn(outputEnvelope);
method.invoke(remoteClient, envelope);
verify(restClientProcessor).synchronousPost(any(EndpointDefinition.class), eq(outputEnvelope));
}
use of uk.gov.justice.services.messaging.JsonEnvelope in project microservice_framework by CJSCommonPlatform.
the class EventBufferInterceptorTest method ensureStreamCLosedIfExceptionOccurs.
@Test
public void ensureStreamCLosedIfExceptionOccurs() throws Exception {
final Deque<Interceptor> interceptors = new LinkedList<>();
interceptors.add(eventBufferInterceptor);
interceptors.add(new ExceptionThrowingInterceptor());
target = new TestTarget();
interceptorChain = new DefaultInterceptorChain(interceptors, target);
final InterceptorContext inputContext = interceptorContextWithInput(envelope_1);
final StreamCloseSpy streamSpy = new StreamCloseSpy();
final Stream<JsonEnvelope> envelopes = Stream.of(this.envelope_1, envelope_2).onClose(streamSpy);
when(eventBufferService.currentOrderedEventsWith(this.envelope_1)).thenReturn(envelopes);
try {
interceptorChain.processNext(inputContext);
} catch (TestException expected) {
// do nothing
}
assertThat(streamSpy.streamClosed(), is(true));
}
Aggregations