ContextParameterResolver implements ParameterResolver<Context> { @Override public Object resolve(org.everrest.core.Parameter parameter, ApplicationContext context) throws Exception { Class<?> parameterClass = parameter.getParameterClass(); if (parameterClass == HttpHeaders.class) { return context.getHttpHeaders(); } else if (parameterClass == SecurityContext.class) { return context.getSecurityContext(); } else if (parameterClass == Request.class) { return context.getRequest(); } else if (parameterClass == UriInfo.class) { return context.getUriInfo(); } else if (parameterClass == Providers.class) { return context.getProviders(); } else if (parameterClass == Application.class) { return context.getApplication(); } else if (parameterClass == InitialProperties.class) { return context.getInitialProperties(); } return EnvironmentContext.getCurrent().get(parameter.getParameterClass()); }  @Override Object resolve(org.everrest.core.Parameter parameter, ApplicationContext context);  }
@Test public void resolvesHttpHeaders() throws Exception { HttpHeaders httpHeaders = mock(HttpHeaders.class); when(applicationContext.getHttpHeaders()).thenReturn(httpHeaders); when(parameter.getParameterClass()).thenReturn((Class)HttpHeaders.class); assertSame(httpHeaders, contextParameterResolver.resolve(parameter, applicationContext)); verify(environmentContext, never()).get(any(Class.class)); }
@Test public void resolvesSecurityContext() throws Exception { SecurityContext securityContext = mock(SecurityContext.class); when(applicationContext.getSecurityContext()).thenReturn(securityContext); when(parameter.getParameterClass()).thenReturn((Class)SecurityContext.class); assertSame(securityContext, contextParameterResolver.resolve(parameter, applicationContext)); verify(environmentContext, never()).get(any(Class.class)); }
@Test public void resolvesRequest() throws Exception { Request request = mock(Request.class); when(applicationContext.getRequest()).thenReturn(request); when(parameter.getParameterClass()).thenReturn((Class)Request.class); assertSame(request, contextParameterResolver.resolve(parameter, applicationContext)); verify(environmentContext, never()).get(any(Class.class)); }
@Test public void resolvesUriInfo() throws Exception { UriInfo uriInfo = mock(UriInfo.class); when(applicationContext.getUriInfo()).thenReturn(uriInfo); when(parameter.getParameterClass()).thenReturn((Class)UriInfo.class); assertSame(uriInfo, contextParameterResolver.resolve(parameter, applicationContext)); verify(environmentContext, never()).get(any(Class.class)); }
@Test public void resolvesProviders() throws Exception { ProviderBinder providers = mock(ProviderBinder.class); when(applicationContext.getProviders()).thenReturn(providers); when(parameter.getParameterClass()).thenReturn((Class)Providers.class); assertSame(providers, contextParameterResolver.resolve(parameter, applicationContext)); verify(environmentContext, never()).get(any(Class.class)); }
@Test public void resolvesApplication() throws Exception { Application application = mock(Application.class); when(applicationContext.getApplication()).thenReturn(application); when(parameter.getParameterClass()).thenReturn((Class)Application.class); assertSame(application, contextParameterResolver.resolve(parameter, applicationContext)); verify(environmentContext, never()).get(any(Class.class)); }
@Test public void resolvesInitialProperties() throws Exception { InitialProperties initialProperties = mock(InitialProperties.class); when(applicationContext.getInitialProperties()).thenReturn(initialProperties); when(parameter.getParameterClass()).thenReturn((Class)InitialProperties.class); assertSame(initialProperties, contextParameterResolver.resolve(parameter, applicationContext)); verify(environmentContext, never()).get(any(Class.class)); }
@Test public void usesEnvironmentContextToResolveContextParameters() throws Exception { HttpServletRequest servletRequest = mock(HttpServletRequest.class); when(environmentContext.get(eq(HttpServletRequest.class))).thenReturn(servletRequest); when(parameter.getParameterClass()).thenReturn((Class)HttpServletRequest.class); assertSame(servletRequest, contextParameterResolver.resolve(parameter, applicationContext)); verify(environmentContext, times(1)).get(any(Class.class)); }