@Test
public void testSingletonHttpContextFields() throws Exception {
ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
Customer c = new Customer();
cri.setResourceProvider(new SingletonResourceProvider(c));
Message m = createMessage();
m.put(Message.PROTOCOL_HEADERS, new HashMap<String, List<String>>());
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);
InjectionUtils.injectContextMethods(c, cri, m);
assertSame(ThreadLocalUriInfo.class, c.getUriInfo2().getClass());
assertSame(UriInfoImpl.class,
((ThreadLocalProxy)c.getUriInfo2()).get().getClass());
assertSame(HttpHeadersImpl.class,
((ThreadLocalProxy)c.getHeaders()).get().getClass());
assertSame(RequestImpl.class,
((ThreadLocalProxy)c.getRequest()).get().getClass());
assertSame(SecurityContextImpl.class,
((ThreadLocalProxy)c.getSecurityContext()).get().getClass());
assertSame(ProvidersImpl.class,
((ThreadLocalProxy)c.getBodyWorkers()).get().getClass());
assertSame(ProvidersImpl.class,
((ThreadLocalProxy)c.getBodyWorkers()).get().getClass());
assertSame(servletContextMock,
((ThreadLocalProxy)c.getThreadLocalServletContext()).get());
assertSame(servletContextMock,
((ThreadLocalProxy)c.getServletContext()).get());
assertSame(servletContextMock,
((ThreadLocalProxy)c.getSuperServletContext()).get());
assertSame(httpRequest,
((ThreadLocalProxy)c.getServletRequest()).get());
HttpServletResponseFilter filter = (
HttpServletResponseFilter)((ThreadLocalProxy)c.getServletResponse()).get();
assertSame(httpResponse, filter.getResponse());
}