use of org.apache.cxf.jaxrs.Customer in project cxf by apache.
the class ProviderFactoryTest method testParameterHandlerProvider.
@Test
public void testParameterHandlerProvider() throws Exception {
ProviderFactory pf = ServerProviderFactory.getInstance();
ParamConverterProvider h = new CustomerParameterHandler();
pf.registerUserProvider(h);
ParamConverter<Customer> h2 = pf.createParameterHandler(Customer.class, Customer.class, null, new MessageImpl());
assertSame(h2, h);
}
use of org.apache.cxf.jaxrs.Customer in project cxf by apache.
the class JAXRSUtilsTest method testPerRequestContextFields.
@Test
public void testPerRequestContextFields() throws Exception {
ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
cri.setResourceProvider(new PerRequestResourceProvider(Customer.class));
OperationResourceInfo ori = new OperationResourceInfo(Customer.class.getMethod("postConstruct", new Class[] {}), cri);
Customer c = new Customer();
Message m = createMessage();
m.put(Message.PROTOCOL_HEADERS, new HashMap<String, List<String>>());
HttpServletResponse response = EasyMock.createMock(HttpServletResponse.class);
m.put(AbstractHTTPDestination.HTTP_RESPONSE, response);
InjectionUtils.injectContextFields(c, ori.getClassResourceInfo(), m);
assertSame(UriInfoImpl.class, c.getUriInfo2().getClass());
assertSame(HttpHeadersImpl.class, c.getHeaders().getClass());
assertSame(RequestImpl.class, c.getRequest().getClass());
assertSame(SecurityContextImpl.class, c.getSecurityContext().getClass());
assertSame(ProvidersImpl.class, c.getBodyWorkers().getClass());
}
use of org.apache.cxf.jaxrs.Customer in project cxf by apache.
the class JAXRSUtilsTest method testDefaultValueOnField.
@Test
public void testDefaultValueOnField() throws Exception {
ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
Customer c = new Customer();
OperationResourceInfo ori = new OperationResourceInfo(Customer.class.getMethods()[0], cri);
Message m = createMessage();
m.put(Message.QUERY_STRING, "");
JAXRSUtils.injectParameters(ori, c, m);
assertEquals("bQuery", c.getB());
}
use of org.apache.cxf.jaxrs.Customer in project cxf by apache.
the class JAXRSUtilsTest method testInjectApplicationInPerRequestResource.
@Test
public void testInjectApplicationInPerRequestResource() throws Exception {
CustomerApplication app = new CustomerApplication();
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setServiceClass(Customer.class);
sf.setApplication(app);
sf.setStart(false);
Server server = sf.create();
@SuppressWarnings("unchecked") ThreadLocalProxy<UriInfo> proxy = (ThreadLocalProxy<UriInfo>) app.getUriInfo();
assertNotNull(proxy);
ClassResourceInfo cri = sf.getServiceFactory().getClassResourceInfo().get(0);
Customer customer = (Customer) cri.getResourceProvider().getInstance(createMessage());
assertNull(customer.getApplication1());
assertNull(customer.getApplication2());
invokeCustomerMethod(cri, customer, server);
assertSame(app, customer.getApplication1());
assertSame(app, customer.getApplication2());
assertTrue(proxy.get() instanceof UriInfo);
}
use of org.apache.cxf.jaxrs.Customer in project cxf by apache.
the class JAXRSUtilsTest method testParamAnnotationOnField.
@Test
public void testParamAnnotationOnField() throws Exception {
ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
Customer c = new Customer();
OperationResourceInfo ori = new OperationResourceInfo(Customer.class.getMethods()[0], cri);
Message m = createMessage();
MultivaluedMap<String, String> headers = new MetadataMap<>();
headers.add("AHeader", "theAHeader");
m.put(Message.PROTOCOL_HEADERS, headers);
m.put(Message.QUERY_STRING, "b=bValue");
JAXRSUtils.injectParameters(ori, c, m);
assertEquals("bValue", c.getB());
assertEquals("theAHeader", c.getAHeader());
}
Aggregations