Search in sources :

Example 1 with InterceptorContext

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

the class DefaultInterceptorContextProviderTest method shouldProvideInterceptorContext.

@Test
public void shouldProvideInterceptorContext() {
    final DefaultInterceptorContextProvider provider = new DefaultInterceptorContextProvider();
    final JsonEnvelope jsonEnvelope = new DefaultJsonEnvelopeProvider().envelopeFrom(metadata, payload);
    InterceptorContext interceptorContext = provider.interceptorContextWithInput(jsonEnvelope);
    assertThat(interceptorContext, instanceOf(DefaultInterceptorContext.class));
}
Also used : InterceptorContext(uk.gov.justice.services.core.interceptor.InterceptorContext) DefaultInterceptorContext(uk.gov.justice.services.core.interceptor.DefaultInterceptorContext) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) DefaultJsonEnvelopeProvider(uk.gov.justice.services.messaging.spi.DefaultJsonEnvelopeProvider) DefaultInterceptorContext(uk.gov.justice.services.core.interceptor.DefaultInterceptorContext) Test(org.junit.Test)

Example 2 with InterceptorContext

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

the class LocalAccessControlInterceptorTest method shouldThrowAccessControlViolationExceptionIfAccessControlFailsForInput.

@Test
public void shouldThrowAccessControlViolationExceptionIfAccessControlFailsForInput() throws Exception {
    final InterceptorContext inputContext = interceptorContextWithInput(envelope);
    inputContext.setInputParameter("component", "command");
    final AccessControlViolation accessControlViolation = new AccessControlViolation("reason");
    when(accessControlService.checkAccessControl("command", envelope)).thenReturn(Optional.of(accessControlViolation));
    when(accessControlFailureMessageGenerator.errorMessageFrom(envelope, accessControlViolation)).thenReturn("Error message");
    exception.expect(AccessControlViolationException.class);
    exception.expectMessage("Error message");
    interceptorChain.processNext(inputContext);
}
Also used : InterceptorContext(uk.gov.justice.services.core.interceptor.InterceptorContext) Test(org.junit.Test)

Example 3 with InterceptorContext

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

the class LocalAccessControlInterceptorTest method shouldApplyAccessControlToInputIfLocalComponent.

@Test
public void shouldApplyAccessControlToInputIfLocalComponent() throws Exception {
    final InterceptorContext inputContext = interceptorContextWithInput(envelope);
    inputContext.setInputParameter("component", "command");
    when(accessControlService.checkAccessControl("command", envelope)).thenReturn(Optional.empty());
    interceptorChain.processNext(inputContext);
    verify(accessControlService).checkAccessControl("command", envelope);
}
Also used : InterceptorContext(uk.gov.justice.services.core.interceptor.InterceptorContext) Test(org.junit.Test)

Example 4 with InterceptorContext

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

the class RestAdapterGenerator_GETMethodBodyTest method shouldCallInterceptorChainProcessor.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void shouldCallInterceptorChainProcessor() throws Exception {
    generator.run(restRamlWithQueryApiDefaults().with(resource("/path").with(httpActionWithDefaultMapping(GET).withDefaultResponseType())).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
    final Class<?> resourceClass = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultQueryApiPathResource");
    final Object resourceObject = getInstanceOf(resourceClass);
    final Method method = firstMethodOf(resourceClass).get();
    method.invoke(resourceObject);
    ArgumentCaptor<Function> consumerCaptor = ArgumentCaptor.forClass(Function.class);
    verify(restProcessor).process(anyString(), consumerCaptor.capture(), anyString(), any(HttpHeaders.class), any(Collection.class));
    final InterceptorContext interceptorContext = interceptorContextWithInput(mock(JsonEnvelope.class));
    consumerCaptor.getValue().apply(interceptorContext);
    verify(interceptorChainProcessor).process(interceptorContext);
}
Also used : Function(java.util.function.Function) HttpHeaders(javax.ws.rs.core.HttpHeaders) ThreadLocalHttpHeaders(org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpHeaders) InterceptorContext(uk.gov.justice.services.core.interceptor.InterceptorContext) Collection(java.util.Collection) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 5 with InterceptorContext

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

the class RestAdapterGenerator_POSTMethodBodyTest method shouldCallInterceptorChainProcessor.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void shouldCallInterceptorChainProcessor() throws Exception {
    generator.run(restRamlWithCommandApiDefaults().with(resource("/path").with(httpActionWithDefaultMapping(POST).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) ThreadLocalHttpHeaders(org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpHeaders) 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)

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