use of org.apache.cxf.jaxrs.Customer in project cxf by apache.
the class ProviderFactoryTest method testCustomProviderSortingParamConverterProvider.
@Test
public void testCustomProviderSortingParamConverterProvider() {
ParamConverterProvider h = new CustomerParameterHandler();
ParamConverterProvider hp = new PriorityCustomerParameterHandler();
ProviderFactory pf = ServerProviderFactory.getInstance();
pf.setUserProviders(Arrays.asList(h, hp));
Comparator<ProviderInfo<ParamConverterProvider>> comp = new Comparator<ProviderInfo<ParamConverterProvider>>() {
@Override
public int compare(ProviderInfo<ParamConverterProvider> o1, ProviderInfo<ParamConverterProvider> o2) {
ParamConverterProvider provider1 = o1.getProvider();
ParamConverterProvider provider2 = o2.getProvider();
return provider1.getClass().getName().compareTo(provider2.getClass().getName());
}
};
pf.setProviderComparator(comp);
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 testInjectApplicationInSingleton.
@Test
public void testInjectApplicationInSingleton() throws Exception {
CustomerApplication app = new CustomerApplication();
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
Customer customer = new Customer();
sf.setServiceBeanObjects(customer);
sf.setApplication(app);
sf.setStart(false);
Server server = sf.create();
assertSame(app, customer.getApplication1());
assertSame(app, customer.getApplication2());
@SuppressWarnings("unchecked") ThreadLocalProxy<UriInfo> proxy = (ThreadLocalProxy<UriInfo>) app.getUriInfo();
assertNotNull(proxy);
invokeCustomerMethod(sf.getServiceFactory().getClassResourceInfo().get(0), customer, server);
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 testServletResourceFields.
@Test
public void testServletResourceFields() 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();
// Creating mocks for the servlet request, response and context
HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class);
HttpServletResponse response = EasyMock.createMock(HttpServletResponse.class);
ServletContext context = EasyMock.createMock(ServletContext.class);
EasyMock.replay(request);
EasyMock.replay(response);
EasyMock.replay(context);
Message m = createMessage();
m.put(AbstractHTTPDestination.HTTP_REQUEST, request);
m.put(AbstractHTTPDestination.HTTP_RESPONSE, response);
m.put(AbstractHTTPDestination.HTTP_CONTEXT, context);
InjectionUtils.injectContextFields(c, ori.getClassResourceInfo(), m);
assertSame(request.getClass(), ((HttpServletRequestFilter) c.getServletRequestResource()).getRequest().getClass());
HttpServletResponseFilter filter = (HttpServletResponseFilter) c.getServletResponseResource();
assertSame(response.getClass(), filter.getResponse().getClass());
assertSame(context.getClass(), c.getServletContextResource().getClass());
assertNotNull(c.getServletRequest());
assertNotNull(c.getServletResponse());
assertNotNull(c.getServletContext());
assertNotNull(c.getServletRequestResource());
assertNotNull(c.getServletResponseResource());
assertNotNull(c.getServletContextResource());
assertSame(request.getClass(), ((HttpServletRequestFilter) c.getServletRequestResource()).getRequest().getClass());
filter = (HttpServletResponseFilter) c.getServletResponse();
assertSame(response.getClass(), filter.getResponse().getClass());
assertSame(context.getClass(), c.getServletContext().getClass());
}
use of org.apache.cxf.jaxrs.Customer in project cxf by apache.
the class PerRequestResourceProviderTest method testGetInstance.
@Test
public void testGetInstance() {
PerRequestResourceProvider rp = new PerRequestResourceProvider(Customer.class);
Message message = createMessage();
message.put(Message.QUERY_STRING, "a=aValue");
Customer c = (Customer) rp.getInstance(message);
assertNotNull(c.getUriInfo());
assertEquals("aValue", c.getQueryParam());
assertTrue(c.isPostConstuctCalled());
rp.releaseInstance(message, c);
assertTrue(c.isPreDestroyCalled());
}
use of org.apache.cxf.jaxrs.Customer in project cxf by apache.
the class JAXRSUtilsTest method testInjectCustomContext.
@Test
public void testInjectCustomContext() throws Exception {
final CustomerContext contextImpl = new CustomerContext() {
public String get() {
return "customerContext";
}
};
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
Customer customer = new Customer();
sf.setServiceBeanObjects(customer);
sf.setProvider(new ContextProvider<CustomerContext>() {
public CustomerContext createContext(Message message) {
return contextImpl;
}
});
sf.setStart(false);
Server s = sf.create();
assertTrue(customer.getCustomerContext() instanceof ThreadLocalProxy<?>);
invokeCustomerMethod(sf.getServiceFactory().getClassResourceInfo().get(0), customer, s);
CustomerContext context = customer.getCustomerContext();
assertEquals("customerContext", context.get());
}
Aggregations