use of uk.gov.justice.services.core.interceptor.Interceptor 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));
}
use of uk.gov.justice.services.core.interceptor.Interceptor 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.Interceptor in project microservice_framework by CJSCommonPlatform.
the class EventFilterInterceptorCodeGeneratorTest method buildTheClassForTest.
private Interceptor buildTheClassForTest(final Class<?> generatedClass, final MyCustomEventFilter myCustomEventFilter) throws Exception {
final Object myCustomEventFilterInterceptor = generatedClass.newInstance();
final Field eventFilterField = generatedClass.getDeclaredField("eventFilter");
eventFilterField.setAccessible(true);
eventFilterField.set(myCustomEventFilterInterceptor, myCustomEventFilter);
return (Interceptor) myCustomEventFilterInterceptor;
}
use of uk.gov.justice.services.core.interceptor.Interceptor in project microservice_framework by CJSCommonPlatform.
the class InputStreamFileInterceptorTest method setup.
@Before
public void setup() throws Exception {
final Deque<Interceptor> interceptors = new LinkedList<>();
interceptors.add(inputStreamFileInterceptor);
interceptorChain = new DefaultInterceptorChain(interceptors, this::processResult);
}
use of uk.gov.justice.services.core.interceptor.Interceptor in project microservice_framework by CJSCommonPlatform.
the class LocalAccessControlInterceptorTest method setup.
@Before
public void setup() throws Exception {
final Deque<Interceptor> interceptors = new LinkedList<>();
interceptors.add(localAccessControlInterceptor);
final Target target = context -> context;
interceptorChain = new DefaultInterceptorChain(interceptors, target);
}
Aggregations