use of uk.gov.justice.services.core.interceptor.InterceptorContext in project microservice_framework by CJSCommonPlatform.
the class SubscriptionJmsEndpointGeneratorTest method shouldCallJmsProcessorWhenOnMessageIsInvoked.
@Test
@SuppressWarnings("unchecked")
public void shouldCallJmsProcessorWhenOnMessageIsInvoked() throws Exception {
SubscriptionDescriptor subscriptionDescriptor = setUpMessageSubscription("jms:topic:somecontext.controller.command", "somecontext.command1", serviceName, componentName);
generator.run(subscriptionDescriptor, configurationWithBasePackage(BASE_PACKAGE, outputFolder, generatorProperties));
Class<?> clazz = compiler.compiledClassOf(BASE_PACKAGE, "ContextEventProcessorSomecontextControllerCommandJmsListener");
Object object = instantiate(clazz);
assertThat(object, is(instanceOf(MessageListener.class)));
MessageListener jmsListener = (MessageListener) object;
Message message = mock(Message.class);
jmsListener.onMessage(message);
ArgumentCaptor<Consumer> consumerCaptor = ArgumentCaptor.forClass(Consumer.class);
verify(jmsProcessor).process(consumerCaptor.capture(), eq(message));
JsonEnvelope envelope = mock(JsonEnvelope.class);
final InterceptorContext interceptorContext = interceptorContextWithInput(envelope);
consumerCaptor.getValue().accept(interceptorContext);
verify(interceptorChainProcessor).process(interceptorContext);
}
use of uk.gov.justice.services.core.interceptor.InterceptorContext in project microservice_framework by CJSCommonPlatform.
the class EventFilterInterceptorCodeGeneratorTest method nowTestTheFailureCase.
private void nowTestTheFailureCase(final Class<?> generatedClass) throws Exception {
final String eventName = "an.event.name";
final String aDifferentventName = "a.different.event.name";
final Interceptor interceptor = buildTheClassForTest(generatedClass, new MyCustomEventFilter(eventName));
final InterceptorContext interceptorContext_1 = mock(InterceptorContext.class, "interceptorContext_1");
final InterceptorContext interceptorContext_2 = mock(InterceptorContext.class, "interceptorContext_2");
final InterceptorChain interceptorChain = mock(InterceptorChain.class);
final JsonEnvelope jsonEnvelope = mock(JsonEnvelope.class);
final Metadata metadata = mock(Metadata.class);
when(interceptorContext_1.inputEnvelope()).thenReturn(jsonEnvelope);
when(jsonEnvelope.metadata()).thenReturn(metadata);
when(metadata.name()).thenReturn(aDifferentventName);
when(interceptorChain.processNext(interceptorContext_1)).thenReturn(interceptorContext_2);
assertThat(interceptor.process(interceptorContext_1, interceptorChain), is(interceptorContext_1));
}
use of uk.gov.justice.services.core.interceptor.InterceptorContext in project microservice_framework by CJSCommonPlatform.
the class QueryViewDirectAdapterTest method shouldPassEnvelopeToInterceptorChain.
@Test
public void shouldPassEnvelopeToInterceptorChain() throws Exception {
when(interceptorChainProcessor.process(any(InterceptorContext.class))).thenReturn(Optional.of(envelope().build()));
final JsonEnvelope envelopePassedToAdapter = envelope().build();
directAdapter.process(envelopePassedToAdapter);
ArgumentCaptor<InterceptorContext> interceptorContext = ArgumentCaptor.forClass(InterceptorContext.class);
verify(interceptorChainProcessor).process(interceptorContext.capture());
assertThat(interceptorContext.getValue().inputEnvelope(), is(envelopePassedToAdapter));
}
use of uk.gov.justice.services.core.interceptor.InterceptorContext in project microservice_framework by CJSCommonPlatform.
the class DefaultRestProcessor method process.
private Response process(final String responseStrategyName, final Function<InterceptorContext, Optional<JsonEnvelope>> interceptorChain, final String action, final Optional<JsonObject> initialPayload, final HttpHeaders headers, final Collection<Parameter> params, final Optional<List<FileInputDetails>> fileInputDetails) {
traceLogger.trace(logger, () -> format("Processing REST message: %s", httpTraceLoggerHelper.toHttpHeaderTrace(headers)));
final JsonEnvelope envelope = envelopeBuilderFactory.builder().withInitialPayload(initialPayload).withAction(action).withHeaders(headers).withParams(params).build();
traceLogger.trace(logger, () -> format("REST message converted to envelope: %s", envelope));
final InterceptorContext interceptorContext = fileInputDetails.map(value -> fileBasedInterceptorContextFactory.create(value, envelope)).orElseGet(() -> interceptorContextWithInput(envelope));
final Optional<JsonEnvelope> result = interceptorChain.apply(interceptorContext);
traceLogger.trace(logger, () -> format("REST message processed: %s", envelope));
return responseStrategyCache.responseStrategyOf(responseStrategyName).responseFor(action, result);
}
use of uk.gov.justice.services.core.interceptor.InterceptorContext in project microservice_framework by CJSCommonPlatform.
the class DefaultRestProcessorTest method shouldPassEnvelopeWithPayloadToInterceptorChain.
@Test
public void shouldPassEnvelopeWithPayloadToInterceptorChain() throws Exception {
final String userId = "userId1234";
final String action = "anAction123";
final String payloadIdValue = "payloadIdValue1";
final List<Parameter> pathParams = singletonList(DefaultParameter.valueOf("paramName", "someParamValue", ParameterType.STRING));
final JsonObject payload = createObjectBuilder().add("payloadId", payloadIdValue).build();
when(responseStrategyCache.responseStrategyOf(anyString())).thenReturn(responseStrategy);
restProcessor.process(NOT_USED_RESPONSE_STRATEGY_NAME, interceptorChain, action, Optional.of(payload), headersWithUserId(userId), pathParams);
final ArgumentCaptor<InterceptorContext> interceptorContextCaptor = forClass(InterceptorContext.class);
verify(interceptorChain).apply(interceptorContextCaptor.capture());
final InterceptorContext interceptorContext = interceptorContextCaptor.getValue();
final JsonEnvelope envelope = interceptorContext.inputEnvelope();
assertThat(envelope, jsonEnvelope().withMetadataOf(metadata().withName(action).withUserId(userId)).withPayloadOf(payloadIsJson(allOf(withJsonPath("$.payloadId", equalTo(payloadIdValue)), withJsonPath("$.paramName", equalTo("someParamValue"))))));
}
Aggregations