public SpringTestContext configLocations(String... configLocations) { XmlWebApplicationContext context = new XmlWebApplicationContext(); context.setConfigLocations(configLocations); this.context = context; return this; }
@Before public void setUp() { XmlWebApplicationContext wac = new XmlWebApplicationContext(); wac.setConfigLocations(CONTEXT); wac.refresh(); this.context = wac; }
@Test @SuppressWarnings("resource") public void withoutMessageSource() throws Exception { MockServletContext sc = new MockServletContext(""); XmlWebApplicationContext wac = new XmlWebApplicationContext(); wac.setParent(root); wac.setServletContext(sc); wac.setNamespace("testNamespace"); wac.setConfigLocations(new String[] {"/org/springframework/web/context/WEB-INF/test-servlet.xml"}); wac.refresh(); try { wac.getMessage("someMessage", null, Locale.getDefault()); fail("Should have thrown NoSuchMessageException"); } catch (NoSuchMessageException ex) { // expected; } String msg = wac.getMessage("someMessage", null, "default", Locale.getDefault()); assertTrue("Default message returned", "default".equals(msg)); }
@Test @SuppressWarnings("resource") public void handlerBeanNotFound() { MockServletContext sc = new MockServletContext(""); XmlWebApplicationContext root = new XmlWebApplicationContext(); root.setServletContext(sc); root.setConfigLocations("/org/springframework/web/servlet/handler/map1.xml"); root.refresh(); XmlWebApplicationContext wac = new XmlWebApplicationContext(); wac.setParent(root); wac.setServletContext(sc); wac.setNamespace("map2err"); wac.setConfigLocations("/org/springframework/web/servlet/handler/map2err.xml"); try { wac.refresh(); fail("Should have thrown NoSuchBeanDefinitionException"); } catch (FatalBeanException ex) { NoSuchBeanDefinitionException nestedEx = (NoSuchBeanDefinitionException) ex.getCause(); assertEquals("mainControlle", nestedEx.getBeanName()); } }
private void loadConfig(String... configLocations) { for (int i=0; i<configLocations.length; i++) { configLocations[i] = getClass().getName().replaceAll("\\.", "/") + "-" + configLocations[i]; } XmlWebApplicationContext context = new XmlWebApplicationContext(); context.setConfigLocations(configLocations); context.setServletContext(new MockServletContext()); context.refresh(); this.context = context; context.getAutowireCapableBeanFactory().autowireBean(this); Filter springSecurityFilterChain = context.getBean("springSecurityFilterChain", Filter.class); mockMvc = MockMvcBuilders .standaloneSetup(new FooController()) .addFilters(springSecurityFilterChain) .build(); }
public static void clearDatabase() { webApplicationContext = new XmlWebApplicationContext(); webApplicationContext.setEnvironment(getMockEnvironment()); webApplicationContext.setConfigLocations("classpath:spring/env.xml", "classpath:spring/data-source.xml"); webApplicationContext.refresh(); webApplicationContext.getBean(Flyway.class).clean(); webApplicationContext.destroy(); }
@Test public void configureWhenUserDetailsServiceInParentContextThenLocatesSuccessfully() { assertThatCode(() -> this.spring.configLocations(this.xml("MissingUserDetailsService")).autowire()) .isInstanceOf(BeansException.class); try ( XmlWebApplicationContext parent = new XmlWebApplicationContext() ) { parent.setConfigLocations(this.xml("AutoConfig")); parent.refresh(); try ( XmlWebApplicationContext child = new XmlWebApplicationContext() ) { child.setParent(parent); child.setConfigLocation(this.xml("MissingUserDetailsService")); child.refresh(); } } }
public void setUp(MockEnvironment environment) throws Exception { this.environment = environment; webApplicationContext = new XmlWebApplicationContext(); webApplicationContext.setEnvironment(environment); webApplicationContext.setConfigLocations(new String[]{"classpath:spring/env.xml", "classpath:spring/data-source.xml"}); webApplicationContext.refresh(); flyway = webApplicationContext.getBean(Flyway.class); jdbcTemplate = webApplicationContext.getBean(JdbcTemplate.class); dataSource = webApplicationContext.getBean(DataSource.class); limitSqlAdapter = webApplicationContext.getBean(LimitSqlAdapter.class); validationQuery = webApplicationContext.getBean("validationQuery", String.class); IdentityZoneHolder.setProvisioning(new JdbcIdentityZoneProvisioning(jdbcTemplate)); IdentityZoneHolder.get().getConfig().getUserConfig().setDefaultGroups(emptyList()); }
wac.setServletContext(sc); wac.setNamespace("test-servlet"); wac.setConfigLocations(new String[] {"/org/springframework/web/context/WEB-INF/test-servlet.xml"}); wac.refresh(); return wac;
String[] names = ctx.getBeanNamesForType(Bus.class); if (names == null || names.length == 0) { ctx2.setConfigLocations(new String[] {"classpath:/META-INF/cxf/cxf.xml", location}); } else { ctx2.setConfigLocations(new String[] {location}); ctx2.setConfigLocations(new String[] {"classpath:/META-INF/cxf/cxf.xml", location}); createdContext = ctx2;
@Override public final ConfigurableApplicationContext loadContext(String... locations) throws Exception { XmlWebApplicationContext context = new XmlWebApplicationContext(); context.setConfigLocations(locations); MockServletContext sc = new MockServletContext(); sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, context); context.setServletContext(sc); context.refresh(); return context; }
XmlWebApplicationContext wac = new XmlWebApplicationContext(); wac.setServletContext(sc); wac.setConfigLocations("/org/springframework/web/servlet/handler/map2.xml"); wac.refresh(); Object bean = wac.getBean("mainController");
/** * Build a {@link MockMvc} from XML-based Spring configuration. * @param configLocations XML configuration file locations: * <ul> * <li>{@code classpath:org/example/config/*-context.xml} * <li>{@code file:src/main/webapp/WEB-INF/config/*-context.xml} * <li>etc. * </ul> */ public static ContextMockMvcBuilder xmlConfigSetup(String... configLocations) { Assert.notEmpty(configLocations, "At least one XML config location is required"); XmlWebApplicationContext context = new XmlWebApplicationContext(); context.setConfigLocations(configLocations); return new ContextMockMvcBuilder(context); }
protected WebApplicationContext createContextLoader(ServletContext servletContext) { XmlWebApplicationContext xmlWebApplicationContext = new XmlWebApplicationContext(); xmlWebApplicationContext.setServletContext(servletContext); xmlWebApplicationContext.setConfigLocations(getConfigLocations()); return xmlWebApplicationContext; }
@Override public void onStartup(ServletContext servletContext) throws ServletException { XmlWebApplicationContext appContext = new XmlWebApplicationContext(); appContext.setConfigLocations( "classpath:/spring/bootstrap-servlet-context.xml", "classpath:/jobs/main-job-context.xml", "classpath:/jobs/steps/handle-max-months-job-context.xml", "classpath:/jobs/steps/handle-more-than-one-hour-delays-job-context.xml", "classpath:/jobs/steps/load-gtfs-into-database-job-context.xml"); servletContext.addListener(new ContextLoaderListener(appContext)); } }
@Override protected ConfigurableApplicationContext createApplicationContext( String[] locations) { FileSystemResourceLoader rl = new FileSystemResourceLoader(); ServletContext servletContext = new MockServletContext(rl); XmlWebApplicationContext context = new XmlWebApplicationContext(); context.setServletContext(servletContext); context.setConfigLocations(locations); context.refresh(); return context; }
@Override protected ConfigurableApplicationContext createApplicationContext( String[] locations) { FileSystemResourceLoader rl = new FileSystemResourceLoader(); ServletContext servletContext = new MockServletContext(rl); XmlWebApplicationContext context = new XmlWebApplicationContext(); context.setServletContext(servletContext); context.setConfigLocations(locations); context.refresh(); return context; } }
public void afterPropertiesSet() throws Exception { if (loadContext) { context = new XmlWebApplicationContext(); context.setParent(parent); context.setDisplayName(displayName); context.setConfigLocations(configLocations); context.setServletContext(servletContext); context.refresh(); } }
private void migrateDatabase(final Map<String, Object> dbProperties) { try (XmlWebApplicationContext ctx = new XmlWebApplicationContext()) { ctx.setServletContext(FacesUtils.getServletContext()); ctx.setConfigLocations("classpath:META-INF/standalone/spring/security-hibernate-beans.xml"); ctx.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() { @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { beanFactory.registerSingleton("dbConfig", dbProperties); } }); ctx.refresh(); ctx.getBean("dbMigration"); } }
public DispatcherServletChannelInitializer() throws ServletException { MockServletContext servletContext = new MockServletContext(); MockServletConfig servletConfig = new MockServletConfig(servletContext); XmlWebApplicationContext wac = new XmlWebApplicationContext(); wac.setServletContext(servletContext); wac.setServletConfig(servletConfig); wac.setConfigLocations(new String[] { "classpath:/servlet-context.xml", "classpath:dubbo-consumer.xml" }); wac.refresh(); this.dispatcherServlet = new DispatcherServlet(wac); this.dispatcherServlet.init(servletConfig); }