Search in sources :

Example 11 with Parameter

use of uk.gov.justice.services.adapter.rest.parameter.Parameter in project microservice_framework by CJSCommonPlatform.

the class RestAdapterGenerator_GETMethodBodyTest method shouldPassTwoPathParamsToRestProcessor.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void shouldPassTwoPathParamsToRestProcessor() throws Exception {
    generator.run(restRamlWithQueryApiDefaults().with(resource("/some/path/{param1}/{param2}", "param1", "param2").with(httpActionWithDefaultMapping(GET).withDefaultResponseType())).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
    final Class<?> resourceClass = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultQueryApiSomePathParam1Param2Resource");
    final Object resourceObject = getInstanceOf(resourceClass);
    final Method method = firstMethodOf(resourceClass).get();
    method.invoke(resourceObject, "paramValueABC", "paramValueDEF");
    final ArgumentCaptor<Collection> pathParamsCaptor = ArgumentCaptor.forClass(Collection.class);
    verify(restProcessor).process(anyString(), any(Function.class), anyString(), any(HttpHeaders.class), pathParamsCaptor.capture());
    final Collection<Parameter> pathParams = pathParamsCaptor.getValue();
    assertThat(pathParams, hasSize(2));
    assertThat(pathParams, hasItems(allOf(hasProperty("name", equalTo("param1")), hasProperty("stringValue", equalTo("paramValueABC"))), allOf(hasProperty("name", equalTo("param2")), hasProperty("stringValue", equalTo("paramValueDEF")))));
}
Also used : Function(java.util.function.Function) HttpHeaders(javax.ws.rs.core.HttpHeaders) ThreadLocalHttpHeaders(org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpHeaders) Collection(java.util.Collection) Parameter(uk.gov.justice.services.adapter.rest.parameter.Parameter) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 12 with Parameter

use of uk.gov.justice.services.adapter.rest.parameter.Parameter in project microservice_framework by CJSCommonPlatform.

the class RestAdapterGenerator_POSTMethodBodyTest method shouldPassMapWithTwoPathParamsToRestProcessor.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void shouldPassMapWithTwoPathParamsToRestProcessor() throws Exception {
    generator.run(restRamlWithCommandApiDefaults().with(resource("/some/path/{param1}/{param2}", "param1", "param2").with(httpActionWithDefaultMapping(POST).withHttpActionOfDefaultRequestType())).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
    final Class<?> resourceClass = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultCommandApiSomePathParam1Param2Resource");
    final Object resourceObject = getInstanceOf(resourceClass);
    final Method method = firstMethodOf(resourceClass).get();
    method.invoke(resourceObject, "paramValueABC", "paramValueDEF", NOT_USED_JSONOBJECT);
    final ArgumentCaptor<Collection> pathParamsCaptor = ArgumentCaptor.forClass(Collection.class);
    verify(restProcessor).process(anyString(), any(Function.class), anyString(), any(Optional.class), any(HttpHeaders.class), pathParamsCaptor.capture());
    final Collection<Parameter> pathParams = pathParamsCaptor.getValue();
    assertThat(pathParams, hasSize(2));
    assertThat(pathParams, hasItems(allOf(hasProperty("name", equalTo("param1")), hasProperty("stringValue", equalTo("paramValueABC"))), allOf(hasProperty("name", equalTo("param2")), hasProperty("stringValue", equalTo("paramValueDEF")))));
}
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) Collection(java.util.Collection) Parameter(uk.gov.justice.services.adapter.rest.parameter.Parameter) CommonGeneratorProperties(uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties) JsonObject(javax.json.JsonObject) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 13 with Parameter

use of uk.gov.justice.services.adapter.rest.parameter.Parameter 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")))));
}
Also used : InterceptorContext(uk.gov.justice.services.core.interceptor.InterceptorContext) DefaultParameter(uk.gov.justice.services.adapter.rest.parameter.DefaultParameter) Parameter(uk.gov.justice.services.adapter.rest.parameter.Parameter) JsonEnvelope(uk.gov.justice.services.messaging.JsonEnvelope) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

Parameter (uk.gov.justice.services.adapter.rest.parameter.Parameter)13 Test (org.junit.Test)12 Collection (java.util.Collection)11 Function (java.util.function.Function)11 HttpHeaders (javax.ws.rs.core.HttpHeaders)11 Method (java.lang.reflect.Method)10 ThreadLocalHttpHeaders (org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpHeaders)10 CommonGeneratorProperties (uk.gov.justice.services.generators.commons.config.CommonGeneratorProperties)10 JsonObject (javax.json.JsonObject)5 Optional (java.util.Optional)4 InterceptorContext (uk.gov.justice.services.core.interceptor.InterceptorContext)3 JsonEnvelope (uk.gov.justice.services.messaging.JsonEnvelope)3 Matchers.anyString (org.mockito.Matchers.anyString)2 DefaultParameter (uk.gov.justice.services.adapter.rest.parameter.DefaultParameter)2 String.format (java.lang.String.format)1 List (java.util.List)1 Optional.empty (java.util.Optional.empty)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Inject (javax.inject.Inject)1 Response (javax.ws.rs.core.Response)1