@Test public void configMustNotContainLocations() throws Exception { expectedException.expect(IllegalStateException.class); expectedException.expectMessage(containsString("does not support resource locations")); AnnotationConfigWebContextLoader loader = new AnnotationConfigWebContextLoader(); WebMergedContextConfiguration mergedConfig = new WebMergedContextConfiguration(getClass(), new String[] { "config.xml" }, EMPTY_CLASS_ARRAY, null, EMPTY_STRING_ARRAY, EMPTY_STRING_ARRAY, EMPTY_STRING_ARRAY, "resource/path", loader, null, null); loader.loadContext(mergedConfig); }
/** * Process <em>annotated classes</em> in the supplied {@link ContextConfigurationAttributes}. * <p>If the <em>annotated classes</em> are {@code null} or empty and * {@link #isGenerateDefaultLocations()} returns {@code true}, this * {@code SmartContextLoader} will attempt to {@linkplain * #detectDefaultConfigurationClasses detect default configuration classes}. * If defaults are detected they will be * {@linkplain ContextConfigurationAttributes#setClasses(Class[]) set} in the * supplied configuration attributes. Otherwise, properties in the supplied * configuration attributes will not be modified. * @param configAttributes the context configuration attributes to process * @see org.springframework.test.context.SmartContextLoader#processContextConfiguration(ContextConfigurationAttributes) * @see #isGenerateDefaultLocations() * @see #detectDefaultConfigurationClasses(Class) */ @Override public void processContextConfiguration(ContextConfigurationAttributes configAttributes) { if (!configAttributes.hasClasses() && isGenerateDefaultLocations()) { configAttributes.setClasses(detectDefaultConfigurationClasses(configAttributes.getDeclaringClass())); } }
public WebDelegatingSmartContextLoader() { if (groovyPresent) { try { Class<?> loaderClass = ClassUtils.forName(GROOVY_XML_WEB_CONTEXT_LOADER_CLASS_NAME, WebDelegatingSmartContextLoader.class.getClassLoader()); this.xmlLoader = (SmartContextLoader) BeanUtils.instantiateClass(loaderClass); } catch (Throwable ex) { throw new IllegalStateException("Failed to enable support for Groovy scripts; " + "could not load class: " + GROOVY_XML_WEB_CONTEXT_LOADER_CLASS_NAME, ex); } } else { this.xmlLoader = new GenericXmlWebContextLoader(); } this.annotationConfigLoader = new AnnotationConfigWebContextLoader(); }
@Override protected void prepareContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) { // Set the application context in the context holder for access by static @Bean methods. ApplicationContextHolder.setApplicationContext(context); // Perform standard functionality. super.prepareContext(context, mergedConfig); } }
public WebDelegatingSmartContextLoader() { if (groovyPresent) { try { Class<?> loaderClass = ClassUtils.forName(GROOVY_XML_WEB_CONTEXT_LOADER_CLASS_NAME, WebDelegatingSmartContextLoader.class.getClassLoader()); this.xmlLoader = (SmartContextLoader) BeanUtils.instantiateClass(loaderClass); } catch (Throwable ex) { throw new IllegalStateException("Failed to enable support for Groovy scripts; " + "could not load class: " + GROOVY_XML_WEB_CONTEXT_LOADER_CLASS_NAME, ex); } } else { this.xmlLoader = new GenericXmlWebContextLoader(); } this.annotationConfigLoader = new AnnotationConfigWebContextLoader(); }
/** * Process <em>annotated classes</em> in the supplied {@link ContextConfigurationAttributes}. * <p>If the <em>annotated classes</em> are {@code null} or empty and * {@link #isGenerateDefaultLocations()} returns {@code true}, this * {@code SmartContextLoader} will attempt to {@linkplain * #detectDefaultConfigurationClasses detect default configuration classes}. * If defaults are detected they will be * {@linkplain ContextConfigurationAttributes#setClasses(Class[]) set} in the * supplied configuration attributes. Otherwise, properties in the supplied * configuration attributes will not be modified. * @param configAttributes the context configuration attributes to process * @see org.springframework.test.context.SmartContextLoader#processContextConfiguration(ContextConfigurationAttributes) * @see #isGenerateDefaultLocations() * @see #detectDefaultConfigurationClasses(Class) */ @Override public void processContextConfiguration(ContextConfigurationAttributes configAttributes) { if (!configAttributes.hasClasses() && isGenerateDefaultLocations()) { configAttributes.setClasses(detectDefaultConfigurationClasses(configAttributes.getDeclaringClass())); } }
public WebDelegatingSmartContextLoader() { if (groovyPresent) { try { Class<?> loaderClass = ClassUtils.forName(GROOVY_XML_WEB_CONTEXT_LOADER_CLASS_NAME, WebDelegatingSmartContextLoader.class.getClassLoader()); this.xmlLoader = (SmartContextLoader) BeanUtils.instantiateClass(loaderClass); } catch (Throwable ex) { throw new IllegalStateException("Failed to enable support for Groovy scripts; " + "could not load class: " + GROOVY_XML_WEB_CONTEXT_LOADER_CLASS_NAME, ex); } } else { this.xmlLoader = new GenericXmlWebContextLoader(); } this.annotationConfigLoader = new AnnotationConfigWebContextLoader(); }
/** * Process <em>annotated classes</em> in the supplied {@link ContextConfigurationAttributes}. * <p>If the <em>annotated classes</em> are {@code null} or empty and * {@link #isGenerateDefaultLocations()} returns {@code true}, this * {@code SmartContextLoader} will attempt to {@linkplain * #detectDefaultConfigurationClasses detect default configuration classes}. * If defaults are detected they will be * {@linkplain ContextConfigurationAttributes#setClasses(Class[]) set} in the * supplied configuration attributes. Otherwise, properties in the supplied * configuration attributes will not be modified. * @param configAttributes the context configuration attributes to process * @see org.springframework.test.context.SmartContextLoader#processContextConfiguration(ContextConfigurationAttributes) * @see #isGenerateDefaultLocations() * @see #detectDefaultConfigurationClasses(Class) */ @Override public void processContextConfiguration(ContextConfigurationAttributes configAttributes) { if (!configAttributes.hasClasses() && isGenerateDefaultLocations()) { configAttributes.setClasses(detectDefaultConfigurationClasses(configAttributes.getDeclaringClass())); } }