use of org.apache.cxf.jaxrs.Customer in project cxf by apache.
the class JAXRSUtilsTest method testContextAnnotationOnMethod.
@SuppressWarnings("unchecked")
@Test
public void testContextAnnotationOnMethod() throws Exception {
ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
Customer c = new Customer();
cri.setResourceProvider(new SingletonResourceProvider(c));
InjectionUtils.injectContextProxies(cri, cri.getResourceProvider().getInstance(null));
OperationResourceInfo ori = new OperationResourceInfo(Customer.class.getMethods()[0], cri);
Message message = createMessage();
InjectionUtils.injectContextMethods(c, ori.getClassResourceInfo(), message);
assertNotNull(c.getUriInfo());
assertSame(ThreadLocalUriInfo.class, c.getUriInfo().getClass());
assertSame(UriInfoImpl.class, ((ThreadLocalProxy<UriInfo>) c.getUriInfo()).get().getClass());
assertSame(ThreadLocalServletConfig.class, c.getSuperServletConfig().getClass());
assertSame(ThreadLocalHttpServletRequest.class, c.getHttpServletRequest().getClass());
}
use of org.apache.cxf.jaxrs.Customer in project cxf by apache.
the class JAXRSUtilsTest method testSingletonHttpResourceFields.
@SuppressWarnings("unchecked")
@Test
public void testSingletonHttpResourceFields() throws Exception {
ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
Customer c = new Customer();
cri.setResourceProvider(new SingletonResourceProvider(c));
Message m = createMessage();
ServletContext servletContextMock = EasyMock.createNiceMock(ServletContext.class);
m.put(AbstractHTTPDestination.HTTP_CONTEXT, servletContextMock);
HttpServletRequest httpRequest = EasyMock.createNiceMock(HttpServletRequest.class);
m.put(AbstractHTTPDestination.HTTP_REQUEST, httpRequest);
HttpServletResponse httpResponse = EasyMock.createMock(HttpServletResponse.class);
m.put(AbstractHTTPDestination.HTTP_RESPONSE, httpResponse);
InjectionUtils.injectContextProxies(cri, cri.getResourceProvider().getInstance(null));
InjectionUtils.injectContextFields(c, cri, m);
assertSame(servletContextMock, ((ThreadLocalProxy<ServletContext>) c.getServletContextResource()).get());
HttpServletRequest currentReq = ((ThreadLocalProxy<HttpServletRequest>) c.getServletRequestResource()).get();
assertSame(httpRequest, ((HttpServletRequestFilter) currentReq).getRequest());
HttpServletResponseFilter filter = (HttpServletResponseFilter) ((ThreadLocalProxy<HttpServletResponse>) c.getServletResponseResource()).get();
assertSame(httpResponse, filter.getResponse());
}
use of org.apache.cxf.jaxrs.Customer in project cxf by apache.
the class JAXRSUtilsTest method testContextResolverFields.
@Test
public void testContextResolverFields() 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);
Message m = createMessage();
HttpServletResponse response = EasyMock.createMock(HttpServletResponse.class);
m.put(AbstractHTTPDestination.HTTP_RESPONSE, response);
Customer c = new Customer();
ContextResolver<JAXBContext> cr = new JAXBContextProvider();
ProviderFactory.getInstance(m).registerUserProvider(cr);
m.put(Message.BASE_PATH, "/");
InjectionUtils.injectContextFields(c, ori.getClassResourceInfo(), m);
assertSame(cr.getClass(), c.getContextResolver().getClass());
}
Aggregations