Search in sources :

Example 1 with InterceptorChain

use of uk.gov.justice.services.core.interceptor.InterceptorChain 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));
}
Also used : InterceptorChain(uk.gov.justice.services.core.interceptor.InterceptorChain) InterceptorContext(uk.gov.justice.services.core.interceptor.InterceptorContext) Metadata(uk.gov.justice.services.messaging.Metadata) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Interceptor(uk.gov.justice.services.core.interceptor.Interceptor)

Example 2 with InterceptorChain

use of uk.gov.justice.services.core.interceptor.InterceptorChain 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);
}
Also used : InjectMocks(org.mockito.InjectMocks) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Deque(java.util.Deque) DefaultInterceptorChain(uk.gov.justice.services.core.interceptor.DefaultInterceptorChain) InterceptorContext.interceptorContextWithInput(uk.gov.justice.services.core.interceptor.InterceptorContext.interceptorContextWithInput) Mockito.verify(org.mockito.Mockito.verify) Inject(javax.inject.Inject) Rule(org.junit.Rule) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) InterceptorChain(uk.gov.justice.services.core.interceptor.InterceptorChain) InterceptorContext(uk.gov.justice.services.core.interceptor.InterceptorContext) InterceptorChainProcessor(uk.gov.justice.services.core.interceptor.InterceptorChainProcessor) Target(uk.gov.justice.services.core.interceptor.Target) Optional(java.util.Optional) Adapter(uk.gov.justice.services.core.annotation.Adapter) LinkedList(java.util.LinkedList) COMMAND_API(uk.gov.justice.services.core.annotation.Component.COMMAND_API) ExpectedException(org.junit.rules.ExpectedException) Interceptor(uk.gov.justice.services.core.interceptor.Interceptor) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Before(org.junit.Before) Target(uk.gov.justice.services.core.interceptor.Target) Interceptor(uk.gov.justice.services.core.interceptor.Interceptor) LinkedList(java.util.LinkedList) DefaultInterceptorChain(uk.gov.justice.services.core.interceptor.DefaultInterceptorChain) Before(org.junit.Before)

Example 3 with InterceptorChain

use of uk.gov.justice.services.core.interceptor.InterceptorChain in project microservice_framework by CJSCommonPlatform.

the class LocalAuditInterceptorTest method setup.

@Before
public void setup() throws Exception {
    final Deque<Interceptor> interceptors = new LinkedList<>();
    interceptors.add(localAuditInterceptor);
    final Target target = context -> context.copyWithOutput(outputEnvelope);
    interceptorChain = new DefaultInterceptorChain(interceptors, target);
}
Also used : InjectMocks(org.mockito.InjectMocks) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) Deque(java.util.Deque) DefaultInterceptorChain(uk.gov.justice.services.core.interceptor.DefaultInterceptorChain) InterceptorContext.interceptorContextWithInput(uk.gov.justice.services.core.interceptor.InterceptorContext.interceptorContextWithInput) Mockito.verify(org.mockito.Mockito.verify) Inject(javax.inject.Inject) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) InterceptorChain(uk.gov.justice.services.core.interceptor.InterceptorChain) InterceptorContext(uk.gov.justice.services.core.interceptor.InterceptorContext) InterceptorChainProcessor(uk.gov.justice.services.core.interceptor.InterceptorChainProcessor) Target(uk.gov.justice.services.core.interceptor.Target) Adapter(uk.gov.justice.services.core.annotation.Adapter) LinkedList(java.util.LinkedList) COMMAND_API(uk.gov.justice.services.core.annotation.Component.COMMAND_API) Interceptor(uk.gov.justice.services.core.interceptor.Interceptor) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Before(org.junit.Before) Target(uk.gov.justice.services.core.interceptor.Target) Interceptor(uk.gov.justice.services.core.interceptor.Interceptor) LinkedList(java.util.LinkedList) DefaultInterceptorChain(uk.gov.justice.services.core.interceptor.DefaultInterceptorChain) Before(org.junit.Before)

Example 4 with InterceptorChain

use of uk.gov.justice.services.core.interceptor.InterceptorChain in project microservice_framework by CJSCommonPlatform.

the class EventFilterInterceptorCodeGeneratorTest method nowTestTheGeneratedClass.

private void nowTestTheGeneratedClass(final Class<?> generatedClass) throws Exception {
    final String eventName = "an.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(eventName);
    when(interceptorChain.processNext(interceptorContext_1)).thenReturn(interceptorContext_2);
    assertThat(interceptor.process(interceptorContext_1, interceptorChain), is(interceptorContext_2));
}
Also used : InterceptorChain(uk.gov.justice.services.core.interceptor.InterceptorChain) InterceptorContext(uk.gov.justice.services.core.interceptor.InterceptorContext) Metadata(uk.gov.justice.services.messaging.Metadata) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Interceptor(uk.gov.justice.services.core.interceptor.Interceptor)

Aggregations

Interceptor (uk.gov.justice.services.core.interceptor.Interceptor)4 InterceptorChain (uk.gov.justice.services.core.interceptor.InterceptorChain)4 InterceptorContext (uk.gov.justice.services.core.interceptor.InterceptorContext)4 JsonEnvelope (uk.gov.justice.services.messaging.JsonEnvelope)4 Deque (java.util.Deque)2 LinkedList (java.util.LinkedList)2 Inject (javax.inject.Inject)2 Before (org.junit.Before)2 Test (org.junit.Test)2 RunWith (org.junit.runner.RunWith)2 InjectMocks (org.mockito.InjectMocks)2 Mock (org.mockito.Mock)2 Mockito.verify (org.mockito.Mockito.verify)2 MockitoJUnitRunner (org.mockito.runners.MockitoJUnitRunner)2 Adapter (uk.gov.justice.services.core.annotation.Adapter)2 COMMAND_API (uk.gov.justice.services.core.annotation.Component.COMMAND_API)2 DefaultInterceptorChain (uk.gov.justice.services.core.interceptor.DefaultInterceptorChain)2 InterceptorChainProcessor (uk.gov.justice.services.core.interceptor.InterceptorChainProcessor)2 InterceptorContext.interceptorContextWithInput (uk.gov.justice.services.core.interceptor.InterceptorContext.interceptorContextWithInput)2 Target (uk.gov.justice.services.core.interceptor.Target)2