use of uk.gov.justice.services.core.interceptor.InterceptorContext 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));
}
use of uk.gov.justice.services.core.interceptor.InterceptorContext in project microservice_framework by CJSCommonPlatform.
the class DefaultDirectAdapterProcessorTest method shouldApplyInterceptorChainFunctionToTheIncomingTheEnvelope.
@Test
public void shouldApplyInterceptorChainFunctionToTheIncomingTheEnvelope() throws Exception {
when(interceptorChainFunction.apply(any(InterceptorContext.class))).thenReturn(Optional.of(envelope().build()));
final JsonEnvelope incomingEnvelope = envelope().with(metadataWithRandomUUID("action1")).build();
directAdapterProcessor.process(incomingEnvelope, interceptorChainFunction);
ArgumentCaptor<InterceptorContext> interceptorContextCaptor = ArgumentCaptor.forClass(InterceptorContext.class);
verify(interceptorChainFunction).apply(interceptorContextCaptor.capture());
assertThat(interceptorContextCaptor.getValue().inputEnvelope(), is(incomingEnvelope));
}
use of uk.gov.justice.services.core.interceptor.InterceptorContext in project microservice_framework by CJSCommonPlatform.
the class InputStreamFileInterceptorTest method shouldNotStoreTheInputStreamIfNoFileDetailsFoundInTheInterceptorContext.
@Test
public void shouldNotStoreTheInputStreamIfNoFileDetailsFoundInTheInterceptorContext() throws Exception {
final InterceptorContext inputInterceptorContext = createEmptyInterceptorContext();
final InterceptorContext outputInterceptorContext = interceptorChain.processNext(inputInterceptorContext);
final Optional<JsonEnvelope> jsonEnvelope = outputInterceptorContext.outputEnvelope();
assertThat(jsonEnvelope.isPresent(), is(true));
assertThat(jsonEnvelope.get(), is(outputEnvelope));
assertThat(resultJsonEnvelope, is(inputEnvelope));
verifyZeroInteractions(multipleFileInputDetailsService);
}
use of uk.gov.justice.services.core.interceptor.InterceptorContext in project microservice_framework by CJSCommonPlatform.
the class InputStreamFileInterceptorTest method shouldStoreTheInputStreamInTheFileStoreAndUpdateTheInputEnvelope.
@Test
public void shouldStoreTheInputStreamInTheFileStoreAndUpdateTheInputEnvelope() throws Exception {
final FileInputDetails fileInputDetails = mock(FileInputDetails.class);
final List<FileInputDetails> fileInputDetailsList = singletonList(fileInputDetails);
final Map<String, UUID> results = ImmutableMap.of("fieldName", randomUUID());
final InterceptorContext inputInterceptorContext = createInterceptorContext(fileInputDetailsList);
when(multipleFileInputDetailsService.storeFileDetails(fileInputDetailsList)).thenReturn(results);
when(resultsHandler.addResultsTo(inputEnvelope, results)).thenReturn(inputEnvelope);
final InterceptorContext outputInterceptorContext = interceptorChain.processNext(inputInterceptorContext);
final Optional<JsonEnvelope> jsonEnvelope = outputInterceptorContext.outputEnvelope();
assertThat(jsonEnvelope.isPresent(), is(true));
assertThat(jsonEnvelope.get(), is(outputEnvelope));
assertThat(resultJsonEnvelope, is(inputEnvelope));
}
use of uk.gov.justice.services.core.interceptor.InterceptorContext in project microservice_framework by CJSCommonPlatform.
the class DefaultRestProcessorTest method shouldPassEnvelopeWithEmptyPayloadToInterceptorChain.
@Test
public void shouldPassEnvelopeWithEmptyPayloadToInterceptorChain() throws Exception {
final String action = "actionABC";
final String userId = "usrABC";
final List<Parameter> pathParams = singletonList(DefaultParameter.valueOf("name", "value123", ParameterType.STRING));
when(responseStrategyCache.responseStrategyOf(anyString())).thenReturn(responseStrategy);
restProcessor.process(NOT_USED_RESPONSE_STRATEGY_NAME, interceptorChain, action, 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(withJsonPath("$.name", equalTo("value123")))));
}
Aggregations