use of uk.gov.justice.services.core.interceptor.InterceptorContext 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.core.interceptor.InterceptorContext 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);
}
use of uk.gov.justice.services.core.interceptor.InterceptorContext in project microservice_framework by CJSCommonPlatform.
the class EventFilterInterceptorTest method shouldReturnInterceptorContextIfFilterRejectsMessage.
@Test
public void shouldReturnInterceptorContextIfFilterRejectsMessage() throws Exception {
when(eventFilter.accepts("nameBCD")).thenReturn(false);
final InterceptorContext currentContext = interceptorContextWithInput(envelope().with(metadataWithRandomUUID("nameBCD")).build());
eventFilterInterceptor.process(currentContext, interceptorChain);
assertThat(eventFilterInterceptor.process(currentContext, interceptorChain), is(currentContext));
}
use of uk.gov.justice.services.core.interceptor.InterceptorContext in project microservice_framework by CJSCommonPlatform.
the class EventFilterInterceptorTest method shouldProcessNextInChainIfFilterAcceptsMessage.
@Test
public void shouldProcessNextInChainIfFilterAcceptsMessage() throws Exception {
when(eventFilter.accepts("nameABC")).thenReturn(true);
final InterceptorContext currentContext = interceptorContextWithInput(envelope().with(metadataWithRandomUUID("nameABC")).build());
final InterceptorContext nextInChain = interceptorContextWithInput(mock(JsonEnvelope.class));
when(interceptorChain.processNext(currentContext)).thenReturn(nextInChain);
assertThat(eventFilterInterceptor.process(currentContext, interceptorChain), is(nextInChain));
}
use of uk.gov.justice.services.core.interceptor.InterceptorContext in project microservice_framework by CJSCommonPlatform.
the class LocalAuditInterceptor method process.
@Override
public InterceptorContext process(final InterceptorContext interceptorContext, final InterceptorChain interceptorChain) {
final String component = interceptorContext.getComponentName();
recordAudit(interceptorContext.inputEnvelope(), component);
final InterceptorContext outputContext = interceptorChain.processNext(interceptorContext);
final Optional<JsonEnvelope> jsonEnvelope = outputContext.outputEnvelope();
jsonEnvelope.ifPresent(envelope -> recordAudit(envelope, component));
return outputContext;
}
Aggregations