@Override protected WebApplicationContext createRootApplicationContext() { StaticWebApplicationContext rootContext = new StaticWebApplicationContext(); rootContext.registerSingleton(BEAN_NAME, MyBean.class); return rootContext; } }
@Override protected WebApplicationContext createServletApplicationContext() { StaticWebApplicationContext servletContext = new StaticWebApplicationContext(); servletContext.registerSingleton("bean", MyBean.class); return servletContext; }
public void defaultHandlerMappings() throws Exception { StaticWebApplicationContext cxt = new StaticWebApplicationContext(); cxt.refresh(); List<HandlerMapping> actual = getIntrospector(cxt).getHandlerMappings(); assertEquals(2, actual.size()); assertEquals(BeanNameUrlHandlerMapping.class, actual.get(0).getClass()); assertEquals(RequestMappingHandlerMapping.class, actual.get(1).getClass()); }
@Before public void setup() { this.context = new StaticWebApplicationContext(); this.handlerMapping = new TestHandlerMapping(); this.request = new MockHttpServletRequest(); }
@Before public void setup() { this.configurer = new ScriptTemplateConfigurer(); this.wac = new StaticWebApplicationContext(); this.wac.getBeanFactory().registerSingleton("scriptTemplateConfigurer", this.configurer); this.view = new ScriptTemplateView(); }
@BeforeClass public static void setupOnce() { RequestMappingHandlerAdapter adapter = new RequestMappingHandlerAdapter(); adapter.setApplicationContext(new StaticWebApplicationContext()); adapter.afterPropertiesSet(); RESOLVER_COUNT = adapter.getArgumentResolvers().size(); INIT_BINDER_RESOLVER_COUNT = adapter.getInitBinderArgumentResolvers().size(); HANDLER_COUNT = adapter.getReturnValueHandlers().size(); }
@Before public void setup() { StaticWebApplicationContext context = new StaticWebApplicationContext(); context.registerSingleton("freeMarkerConfigurer", FreeMarkerConfigurer.class); context.registerSingleton("scriptTemplateConfigurer", ScriptTemplateConfigurer.class); this.registry = new ViewResolverRegistry(context); }
@Test public void getMatchable() throws Exception { MutablePropertyValues pvs = new MutablePropertyValues( Collections.singletonMap("urlMap", Collections.singletonMap("/path", new Object()))); StaticWebApplicationContext cxt = new StaticWebApplicationContext(); cxt.registerSingleton("hm", SimpleUrlHandlerMapping.class, pvs); cxt.refresh(); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/path"); MatchableHandlerMapping hm = getIntrospector(cxt).getMatchableHandlerMapping(request); assertEquals(cxt.getBean("hm"), hm); assertNull("Attributes changes not ignored", request.getAttribute(BEST_MATCHING_PATTERN_ATTRIBUTE)); }
@Before public void setup() { StaticWebApplicationContext context = new StaticWebApplicationContext(); this.handlerMapping = new TestHandlerMapping(); this.handlerMapping.setApplicationContext(context); this.request = new MockHttpServletRequest(); this.request.setRemoteHost("domain1.com"); }
@Before public void setup() throws Exception { this.webAppContext = new StaticWebApplicationContext(); this.handlerAdapter = new RequestMappingHandlerAdapter(); this.handlerAdapter.setApplicationContext(this.webAppContext); this.request = new MockHttpServletRequest("GET", "/"); this.response = new MockHttpServletResponse(); }
@Test public void getCorsConfigWithBeanNameHandler() throws Exception { String key = "foo"; String beanName = "handler1"; StaticWebApplicationContext context = new StaticWebApplicationContext(); context.registerSingleton(beanName, MyHandler.class); this.mapping.setApplicationContext(context); this.mapping.registerMapping(key, beanName, this.method1); HandlerMethod handlerMethod = this.mapping.getHandlerInternal(new MockHttpServletRequest("GET", key)); CorsConfiguration config = this.mapping.getMappingRegistry().getCorsConfiguration(handlerMethod); assertNotNull(config); assertEquals("http://" + beanName.hashCode() + this.method1.getName(), config.getAllowedOrigins().get(0)); }
@Test(expected = IllegalStateException.class) public void getMatchableWhereHandlerMappingDoesNotImplementMatchableInterface() throws Exception { StaticWebApplicationContext cxt = new StaticWebApplicationContext(); cxt.registerSingleton("hm1", TestHandlerMapping.class); cxt.refresh(); MockHttpServletRequest request = new MockHttpServletRequest(); getIntrospector(cxt).getMatchableHandlerMapping(request); }
@Test public void controllerAdviceWithNestedException() { StaticWebApplicationContext ctx = new StaticWebApplicationContext(); ctx.registerSingleton("exceptionHandler", ApplicationExceptionHandler.class); ctx.refresh(); ExceptionHandlerExceptionResolver resolver = new ExceptionHandlerExceptionResolver(); resolver.setApplicationContext(ctx); resolver.afterPropertiesSet(); IllegalStateException ex = new IllegalStateException(new ServletRequestBindingException("message")); assertNull(resolver.resolveException(this.servletRequest, this.servletResponse, null, ex)); }
@Test public void modelAttributeAdviceInParentContext() throws Exception { StaticWebApplicationContext parent = new StaticWebApplicationContext(); parent.registerSingleton("maa", ModelAttributeAdvice.class); parent.refresh(); this.webAppContext.setParent(parent); this.webAppContext.refresh(); HandlerMethod handlerMethod = handlerMethod(new SimpleController(), "handle"); this.handlerAdapter.afterPropertiesSet(); ModelAndView mav = this.handlerAdapter.handle(this.request, this.response, handlerMethod); assertEquals("lAttr1", mav.getModel().get("attr1")); assertEquals("gAttr2", mav.getModel().get("attr2")); }
@Test public void detectHandlerMappings() throws Exception { StaticWebApplicationContext cxt = new StaticWebApplicationContext(); cxt.registerSingleton("hmA", SimpleUrlHandlerMapping.class); cxt.registerSingleton("hmB", SimpleUrlHandlerMapping.class); cxt.registerSingleton("hmC", SimpleUrlHandlerMapping.class); cxt.refresh(); List<?> expected = Arrays.asList(cxt.getBean("hmA"), cxt.getBean("hmB"), cxt.getBean("hmC")); List<HandlerMapping> actual = getIntrospector(cxt).getHandlerMappings(); assertEquals(expected, actual); }
@Test public void staticWebApplicationContext() { StaticWebApplicationContext ctx = new StaticWebApplicationContext(); assertHasStandardServletEnvironment(ctx); registerEnvironmentBeanDefinition(ctx); ctx.setEnvironment(prodWebEnv); ctx.refresh(); assertHasEnvironment(ctx, prodWebEnv); assertEnvironmentBeanRegistered(ctx); assertEnvironmentAwareInvoked(ctx, prodWebEnv); }
@Before public void setUp() { StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(new MockServletContext()); wac.refresh(); this.renderer = mock(Renderer.class); this.viewResolver = new TilesViewResolver(); this.viewResolver.setRenderer(this.renderer); this.viewResolver.setApplicationContext(wac); }
@Before public void setup() { StaticWebApplicationContext context = new StaticWebApplicationContext(); context.registerSingleton("freeMarkerConfigurer", FreeMarkerConfigurer.class); context.registerSingleton("tilesConfigurer", TilesConfigurer.class); context.registerSingleton("groovyMarkupConfigurer", GroovyMarkupConfigurer.class); context.registerSingleton("scriptTemplateConfigurer", ScriptTemplateConfigurer.class); this.registry = new ViewResolverRegistry(new ContentNegotiationManager(), context); }
@Before public void createViewResolver() { StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(new MockServletContext()); wac.refresh(); viewResolver = new ContentNegotiatingViewResolver(); viewResolver.setApplicationContext(wac); request = new MockHttpServletRequest("GET", "/test"); RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request)); }
@Before public void setUp() { this.context = new StaticWebApplicationContext(); this.context.setServletContext(new MockServletContext(new FileSystemResourceLoader())); this.context.registerSingleton("controller", TestController.class); this.context.registerSingleton("userController", UserController.class); this.config = new TestWebMvcConfigurationSupport(); this.config.setApplicationContext(this.context); this.config.setServletContext(this.context.getServletContext()); }