Search in sources :

Example 21 with InterceptorContext

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

the class DefaultRestProcessorTest method shouldCreateTheInterceptorContextUsingTheFileBasedInterceptorContextFactoryIfTheInputPartExists.

@Test
public void shouldCreateTheInterceptorContextUsingTheFileBasedInterceptorContextFactoryIfTheInputPartExists() throws Exception {
    final List<FileInputDetails> fileInputDetails = emptyList();
    final InterceptorContext interceptorContext = mock(InterceptorContext.class);
    when(fileBasedInterceptorContextFactory.create(eq(fileInputDetails), any(JsonEnvelope.class))).thenReturn(interceptorContext);
    when(responseStrategyCache.responseStrategyOf(anyString())).thenReturn(responseStrategy);
    restProcessor.process(NOT_USED_RESPONSE_STRATEGY_NAME, interceptorChain, NOT_USED_ACTION, NOT_USED_HEADERS, NOT_USED_PATH_PARAMS, fileInputDetails);
    final ArgumentCaptor<InterceptorContext> interceptorContextCaptor = forClass(InterceptorContext.class);
    verify(interceptorChain).apply(interceptorContextCaptor.capture());
    final InterceptorContext resultInterceptorContext = interceptorContextCaptor.getValue();
    assertThat(resultInterceptorContext, equalTo(interceptorContext));
}
Also used : FileInputDetails(uk.gov.justice.services.adapter.rest.multipart.FileInputDetails) InterceptorContext(uk.gov.justice.services.core.interceptor.InterceptorContext) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Test(org.junit.Test)

Example 22 with InterceptorContext

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

the class DefaultRestProcessorTest method shouldReturnResponseFromResponseStrategyForCallWithInputPart.

@Test
public void shouldReturnResponseFromResponseStrategyForCallWithInputPart() throws Exception {
    final List<FileInputDetails> fileInputDetails = mock(List.class);
    final InterceptorContext interceptorContext = mock(InterceptorContext.class);
    when(fileBasedInterceptorContextFactory.create(eq(fileInputDetails), any(JsonEnvelope.class))).thenReturn(interceptorContext);
    when(interceptorChain.apply(interceptorContext)).thenReturn(Optional.of(jsonEnvelope));
    final String responseStrategyName = "someOtherStrategy123";
    when(responseStrategyCache.responseStrategyOf(responseStrategyName)).thenReturn(responseStrategy);
    when(responseStrategy.responseFor(NOT_USED_ACTION, Optional.of(jsonEnvelope))).thenReturn(response);
    final Response result = restProcessor.process(responseStrategyName, interceptorChain, NOT_USED_ACTION, NOT_USED_HEADERS, NOT_USED_PATH_PARAMS, fileInputDetails);
    verify(responseStrategy).responseFor(NOT_USED_ACTION, Optional.of(jsonEnvelope));
    assertThat(result, equalTo(response));
}
Also used : Response(javax.ws.rs.core.Response) FileInputDetails(uk.gov.justice.services.adapter.rest.multipart.FileInputDetails) InterceptorContext(uk.gov.justice.services.core.interceptor.InterceptorContext) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 23 with InterceptorContext

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

the class RestAdapterGenerator_DELETEMethodBodyTest method shouldCallInterceptorChainProcessor.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void shouldCallInterceptorChainProcessor() throws Exception {
    generator.run(restRamlWithCommandApiDefaults().with(resource("/path").with(httpActionWithDefaultMapping(DELETE).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);
}
Also used : Function(java.util.function.Function) HttpHeaders(javax.ws.rs.core.HttpHeaders) Optional(java.util.Optional) InterceptorContext(uk.gov.justice.services.core.interceptor.InterceptorContext) Collection(java.util.Collection) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) JsonObject(javax.json.JsonObject) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 24 with InterceptorContext

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

the class FileBasedInterceptorContextFactoryTest method shouldCreateAnInterceptorContextContainingTheFileDetailsList.

@Test
@SuppressWarnings("unchecked")
public void shouldCreateAnInterceptorContextContainingTheFileDetailsList() throws Exception {
    final JsonEnvelope inputEnvelope = mock(JsonEnvelope.class);
    final FileInputDetails fileInputDetails_1 = mock(FileInputDetails.class);
    final FileInputDetails fileInputDetails_2 = mock(FileInputDetails.class);
    final List<FileInputDetails> fileInputDetailss = asList(fileInputDetails_1, fileInputDetails_2);
    final InterceptorContext interceptorContext = fileBasedInterceptorContextFactory.create(fileInputDetailss, inputEnvelope);
    assertThat(interceptorContext.inputEnvelope(), is(inputEnvelope));
    final Optional<Object> inputParameter = interceptorContext.getInputParameter(FILE_INPUT_DETAILS_LIST);
    assertThat(inputParameter.isPresent(), is(true));
    final List<FileInputDetails> fileInputDetailsList = (List<FileInputDetails>) inputParameter.get();
    assertThat(fileInputDetailsList.size(), is(2));
    assertThat(fileInputDetailsList, hasItem(fileInputDetails_1));
    assertThat(fileInputDetailsList, hasItem(fileInputDetails_2));
}
Also used : FileInputDetails(uk.gov.justice.services.adapter.rest.multipart.FileInputDetails) InterceptorContext(uk.gov.justice.services.core.interceptor.InterceptorContext) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) List(java.util.List) Arrays.asList(java.util.Arrays.asList) Test(org.junit.Test)

Example 25 with InterceptorContext

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

the class InputStreamFileInterceptorTest method createInterceptorContext.

private InterceptorContext createInterceptorContext(final List<FileInputDetails> fileInputDetails) {
    final InterceptorContext inputInterceptorContext = interceptorContextWithInput(inputEnvelope);
    inputInterceptorContext.setInputParameter(FILE_INPUT_DETAILS_LIST, fileInputDetails);
    return inputInterceptorContext;
}
Also used : InterceptorContext(uk.gov.justice.services.core.interceptor.InterceptorContext)

Aggregations

InterceptorContext (uk.gov.justice.services.core.interceptor.InterceptorContext)35 Test (org.junit.Test)29 JsonEnvelope (uk.gov.justice.services.messaging.JsonEnvelope)28 Collection (java.util.Collection)7 Function (java.util.function.Function)7 JsonObject (javax.json.JsonObject)7 HttpHeaders (javax.ws.rs.core.HttpHeaders)7 Method (java.lang.reflect.Method)6 Optional (java.util.Optional)6 CommonGeneratorProperties (uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties)6 FileInputDetails (uk.gov.justice.services.adapter.rest.multipart.FileInputDetails)5 Matchers.anyString (org.mockito.Matchers.anyString)4 Response (javax.ws.rs.core.Response)3 ThreadLocalHttpHeaders (org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpHeaders)3 Parameter (uk.gov.justice.services.adapter.rest.parameter.Parameter)3 Interceptor (uk.gov.justice.services.core.interceptor.Interceptor)3 OptimisticLockingRetryException (uk.gov.justice.services.eventsourcing.repository.jdbc.exception.OptimisticLockingRetryException)3 List (java.util.List)2 UUID (java.util.UUID)2 DefaultParameter (uk.gov.justice.services.adapter.rest.parameter.DefaultParameter)2