• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java WebMergedContextConfiguration类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.springframework.test.context.web.WebMergedContextConfiguration的典型用法代码示例。如果您正苦于以下问题:Java WebMergedContextConfiguration类的具体用法?Java WebMergedContextConfiguration怎么用?Java WebMergedContextConfiguration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



WebMergedContextConfiguration类属于org.springframework.test.context.web包,在下文中一共展示了WebMergedContextConfiguration类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: buildMergedConfigWithAtWebAppConfigurationWithAnnotationAndClassesOnSuperclass

import org.springframework.test.context.web.WebMergedContextConfiguration; //导入依赖的package包/类
/**
 * Introduced to investigate claims made in a discussion on
 * <a href="http://stackoverflow.com/questions/24725438/what-could-cause-a-class-implementing-applicationlistenercontextrefreshedevent">Stack Overflow</a>.
 */
@Test
public void buildMergedConfigWithAtWebAppConfigurationWithAnnotationAndClassesOnSuperclass() {
	Class<?> webTestClass = WebClassesFoo.class;
	Class<?> standardTestClass = ClassesFoo.class;
	WebMergedContextConfiguration webMergedConfig = (WebMergedContextConfiguration) buildMergedContextConfiguration(webTestClass);
	MergedContextConfiguration standardMergedConfig = buildMergedContextConfiguration(standardTestClass);

	assertEquals(webMergedConfig, webMergedConfig);
	assertEquals(standardMergedConfig, standardMergedConfig);
	assertNotEquals(standardMergedConfig, webMergedConfig);
	assertNotEquals(webMergedConfig, standardMergedConfig);

	assertMergedConfig(webMergedConfig, webTestClass, EMPTY_STRING_ARRAY, new Class<?>[] { FooConfig.class },
		WebDelegatingSmartContextLoader.class);
	assertMergedConfig(standardMergedConfig, standardTestClass, EMPTY_STRING_ARRAY,
		new Class<?>[] { FooConfig.class }, DelegatingSmartContextLoader.class);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:BootstrapTestUtilsMergedConfigTests.java


示例2: loadContext

import org.springframework.test.context.web.WebMergedContextConfiguration; //导入依赖的package包/类
@Override
public ApplicationContext loadContext(final MergedContextConfiguration config)
		throws Exception {
	assertValidAnnotations(config.getTestClass());
	SpringApplication application = getSpringApplication();
	application.setMainApplicationClass(config.getTestClass());
	application.setSources(getSources(config));
	ConfigurableEnvironment environment = new StandardEnvironment();
	if (!ObjectUtils.isEmpty(config.getActiveProfiles())) {
		setActiveProfiles(environment, config.getActiveProfiles());
	}
	Map<String, Object> properties = getEnvironmentProperties(config);
	addProperties(environment, properties);
	application.setEnvironment(environment);
	List<ApplicationContextInitializer<?>> initializers = getInitializers(config,
			application);
	if (config instanceof WebMergedContextConfiguration) {
		new WebConfigurer().configure(config, application, initializers);
	}
	else {
		application.setWebEnvironment(false);
	}
	application.setInitializers(initializers);
	ConfigurableApplicationContext applicationContext = application.run();
	return applicationContext;
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:27,代码来源:SpringApplicationContextLoader.java


示例3: configure

import org.springframework.test.context.web.WebMergedContextConfiguration; //导入依赖的package包/类
void configure(MergedContextConfiguration configuration,
		SpringApplication application,
		List<ApplicationContextInitializer<?>> initializers) {
	if (!TestAnnotations.isIntegrationTest(configuration)) {
		WebMergedContextConfiguration webConfiguration = (WebMergedContextConfiguration) configuration;
		addMockServletContext(initializers, webConfiguration);
		application.setApplicationContextClass(WEB_CONTEXT_CLASS);
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:10,代码来源:SpringApplicationContextLoader.java


示例4: addMockServletContext

import org.springframework.test.context.web.WebMergedContextConfiguration; //导入依赖的package包/类
private void addMockServletContext(
		List<ApplicationContextInitializer<?>> initializers,
		WebMergedContextConfiguration webConfiguration) {
	SpringBootMockServletContext servletContext = new SpringBootMockServletContext(
			webConfiguration.getResourceBasePath());
	initializers.add(0, new ServletContextApplicationContextInitializer(
			servletContext, true));
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:9,代码来源:SpringApplicationContextLoader.java


示例5: loadContext

import org.springframework.test.context.web.WebMergedContextConfiguration; //导入依赖的package包/类
@Override
public ApplicationContext loadContext(MergedContextConfiguration config)
		throws Exception {
	SpringApplication application = getSpringApplication();
	application.setMainApplicationClass(config.getTestClass());
	application.setSources(getSources(config));
	ConfigurableEnvironment environment = new StandardEnvironment();
	if (!ObjectUtils.isEmpty(config.getActiveProfiles())) {
		setActiveProfiles(environment, config.getActiveProfiles());
	}
	TestPropertySourceUtils.addPropertiesFilesToEnvironment(environment,
			application.getResourceLoader() == null
					? new DefaultResourceLoader(getClass().getClassLoader())
					: application.getResourceLoader(),
			config.getPropertySourceLocations());
	TestPropertySourceUtils.addInlinedPropertiesToEnvironment(environment,
			getInlinedProperties(config));
	application.setEnvironment(environment);
	List<ApplicationContextInitializer<?>> initializers = getInitializers(config,
			application);
	if (config instanceof WebMergedContextConfiguration) {
		application.setWebEnvironment(true);
		if (!isEmbeddedWebEnvironment(config)) {
			new WebConfigurer().configure(config, application, initializers);
		}
	}
	else {
		application.setWebEnvironment(false);
	}
	application.setInitializers(initializers);
	ConfigurableApplicationContext context = application.run();
	return context;
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:34,代码来源:SpringBootContextLoader.java


示例6: configure

import org.springframework.test.context.web.WebMergedContextConfiguration; //导入依赖的package包/类
void configure(MergedContextConfiguration configuration,
		SpringApplication application,
		List<ApplicationContextInitializer<?>> initializers) {
	WebMergedContextConfiguration webConfiguration = (WebMergedContextConfiguration) configuration;
	addMockServletContext(initializers, webConfiguration);
	application.setApplicationContextClass(WEB_CONTEXT_CLASS);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:8,代码来源:SpringBootContextLoader.java


示例7: customizeContext

import org.springframework.test.context.web.WebMergedContextConfiguration; //导入依赖的package包/类
/**
 * Customização para iniciar o singular
 *
 * @param context
 * @param webMergedConfig
 */
protected void customizeContext(AnnotationConfigWebApplicationContext context, WebMergedContextConfiguration webMergedConfig) {
    try {
        new SingularInitializer( new CommonsInitializerMock(context)).onStartup(context.getServletContext());
    } catch (ServletException e) {
        throw SingularException.rethrow(e);
    }
}
 
开发者ID:opensingular,项目名称:singular-server,代码行数:14,代码来源:AbstractSingularContextLoader.java


示例8: customizeContext

import org.springframework.test.context.web.WebMergedContextConfiguration; //导入依赖的package包/类
/**
 * Customização para iniciar o singular
 * @param context
 * @param webMergedConfig
 */
protected void customizeContext(AnnotationConfigWebApplicationContext context, WebMergedContextConfiguration webMergedConfig) {
    try {
        new SingularInitializer( new CommonsInitializerMock(context)).onStartup(context.getServletContext());
    } catch (ServletException e) {
        throw SingularException.rethrow(e);
    }
}
 
开发者ID:opensingular,项目名称:singular-server,代码行数:13,代码来源:SingularCommonsContextLoader.java


示例9: customizeContext

import org.springframework.test.context.web.WebMergedContextConfiguration; //导入依赖的package包/类
@Override
protected void customizeContext(AnnotationConfigWebApplicationContext context, WebMergedContextConfiguration webMergedConfig) {
    try {
        new SingularInitializer(new ServerInitializerMock(context)).onStartup(context.getServletContext());
    } catch (ServletException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}
 
开发者ID:opensingular,项目名称:singular-server,代码行数:9,代码来源:SingularServerContextLoader.java


示例10: addMockServletContext

import org.springframework.test.context.web.WebMergedContextConfiguration; //导入依赖的package包/类
private void addMockServletContext(
		List<ApplicationContextInitializer<?>> initializers,
		WebMergedContextConfiguration webConfiguration) {
	SpringBootMockServletContext servletContext = new SpringBootMockServletContext(
			webConfiguration.getResourceBasePath());
	initializers.add(0,
			new ServletContextApplicationContextInitializer(servletContext));
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:9,代码来源:SpringApplicationContextLoader.java


示例11: validateMergedContextConfiguration

import org.springframework.test.context.web.WebMergedContextConfiguration; //导入依赖的package包/类
/**
 * {@code BroadleafGenericGroovyXmlWebContextLoader} supports the XML merging that
 * Broadleaf's framework features, but this is handled during the .refresh() method
 * in the loadContext method so this method was only pulled from the original class
 * {@link GenericXmlWebContextLoader} in case of the Spring-Test framework requiring
 * this method to have a particular behavior.
 *
 * @see AbstractGenericWebContextLoader#validateMergedContextConfiguration
 */
protected void validateMergedContextConfiguration(WebMergedContextConfiguration webMergedConfig) {
    if (webMergedConfig.hasClasses()) {
        String msg = String.format(
                "Test class [%s] has been configured with @ContextConfiguration's 'classes' attribute %s, "
                        + "but %s does not support annotated classes.", webMergedConfig.getTestClass().getName(),
                ObjectUtils.nullSafeToString(webMergedConfig.getClasses()), getClass().getSimpleName());
        throw new IllegalStateException(msg);
    }
}
 
开发者ID:takbani,项目名称:blcdemo,代码行数:19,代码来源:BroadleafGenericGroovyXmlWebContextLoader.java


示例12: processMergedContextConfiguration

import org.springframework.test.context.web.WebMergedContextConfiguration; //导入依赖的package包/类
@Override
protected MergedContextConfiguration processMergedContextConfiguration(
		MergedContextConfiguration mergedConfig) {
	return new WebMergedContextConfiguration(
			super.processMergedContextConfiguration(mergedConfig), "");
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:7,代码来源:WebMvcTestContextBootstrapper.java


示例13: customizeContext

import org.springframework.test.context.web.WebMergedContextConfiguration; //导入依赖的package包/类
@Override
protected void customizeContext(GenericWebApplicationContext context, WebMergedContextConfiguration webMergedConfig) {
    super.customizeContext(context, webMergedConfig);
    loader.registerMocksAndSpies(context);
}
 
开发者ID:SEEG-Oxford,项目名称:ABRAID-MP,代码行数:6,代码来源:SpringockitoWebContextLoader.java


示例14: loadContext

import org.springframework.test.context.web.WebMergedContextConfiguration; //导入依赖的package包/类
/**
 * Load a Spring {@link WebApplicationContext} from the supplied
 * {@link MergedContextConfiguration}.
 * <p/>
 * <p>Implementation details:
 * <p/>
 * <ul>
 * <li>Calls {@link #validateMergedContextConfiguration(WebMergedContextConfiguration)}
 * to allow subclasses to validate the supplied configuration before proceeding.</li>
 * <li>Creates a {@link GenericWebApplicationContext} instance.</li>
 * <li>If the supplied {@code MergedContextConfiguration} references a
 * {@linkplain MergedContextConfiguration#getParent() parent configuration},
 * the corresponding {@link MergedContextConfiguration#getParentApplicationContext()
 * ApplicationContext} will be retrieved and
 * {@linkplain GenericWebApplicationContext#setParent(ApplicationContext) set as the parent}
 * for the context created by this method.</li>
 * <li>Delegates to {@link #configureWebResources} to create the
 * {@link MockServletContext} and set it in the {@code WebApplicationContext}.</li>
 * <li>Calls {@link #prepareContext} to allow for customizing the context
 * before bean definitions are loaded.</li>
 * <li>Delegates to {@link #loadBeanDefinitions} to populate the context
 * from the locations or classes in the supplied {@code MergedContextConfiguration}.</li>
 * <li>Delegates to {@link AnnotationConfigUtils} for
 * {@linkplain AnnotationConfigUtils#registerAnnotationConfigProcessors registering}
 * annotation configuration processors.</li>
 * <li>Calls {@link #customizeContext} to allow for customizing the context
 * before it is refreshed.</li>
 * <li>{@link ConfigurableApplicationContext#refresh Refreshes} the
 * context and registers a JVM shutdown hook for it.</li>
 * </ul>
 *
 * @return a new web application context
 * @see org.springframework.test.context.SmartContextLoader#loadContext(MergedContextConfiguration)
 * @see GenericWebApplicationContext
 */
@Override
public final AnnotationConfigWebApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception {
    SingularContextSetup.reset();

    if (!(mergedConfig instanceof WebMergedContextConfiguration)) {
        throw new IllegalArgumentException(String.format(
                "Cannot load WebApplicationContext from non-web merged context configuration %s. "
                        + "Consider annotating your test class with @WebAppConfiguration.", mergedConfig));
    }
    WebMergedContextConfiguration webMergedConfig = (WebMergedContextConfiguration) mergedConfig;

    if (logger.isDebugEnabled()) {
        logger.debug(String.format("Loading WebApplicationContext for merged context configuration %s.",
                webMergedConfig));
    }

    validateMergedContextConfiguration(webMergedConfig);

    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();

    ApplicationContext parent = mergedConfig.getParentApplicationContext();
    if (parent != null) {
        context.setParent(parent);
    }
    configureWebResources(context, webMergedConfig);
    prepareContext(context, webMergedConfig);
    customizeContext(context, webMergedConfig);
    loadBeanDefinitions(context, webMergedConfig);
    mockRequest();
    context.refresh();
    context.registerShutdownHook();
    return context;
}
 
开发者ID:opensingular,项目名称:singular-server,代码行数:69,代码来源:AbstractSingularContextLoader.java


示例15: loadBeanDefinitions

import org.springframework.test.context.web.WebMergedContextConfiguration; //导入依赖的package包/类
/**
 * Load bean definitions into the supplied {@link GenericWebApplicationContext context}
 * from the locations or classes in the supplied {@code WebMergedContextConfiguration}.
 * <p/>
 * <p>Concrete subclasses must provide an appropriate implementation.
 *
 * @param context         the context into which the bean definitions should be loaded
 * @param webMergedConfig the merged context configuration to use to load the
 *                        web application context
 * @see #loadContext(MergedContextConfiguration)
 */
protected void loadBeanDefinitions(AnnotationConfigWebApplicationContext context,
                                   WebMergedContextConfiguration webMergedConfig) {
    Class<?>[] annotatedClasses = webMergedConfig.getClasses();
    if (logger.isDebugEnabled()) {
        logger.debug("Registering annotated classes: " + ObjectUtils.nullSafeToString(annotatedClasses));
    }
    context.register(annotatedClasses);
}
 
开发者ID:opensingular,项目名称:singular-server,代码行数:20,代码来源:AbstractSingularContextLoader.java


示例16: loadContext

import org.springframework.test.context.web.WebMergedContextConfiguration; //导入依赖的package包/类
/**
 * Load a {@link MergeXmlWebApplicationContext} from the supplied {@link MergedContextConfiguration}
 * 
 * <p>Implementation details:
 * 
 * <ul>
 * <li>Calls {@link #validateMergedContextConfiguration(WebMergedContextConfiguration)}
 * to allow subclasses to validate the supplied configuration before proceeding.</li>
 * <li>Creates a {@link MergeXmlWebApplicationContext} instance.</li>
 * <li>If the supplied {@link MergeXmlWebApplicationContext} references a
 * {@linkplain MergeXmlWebApplicationContext#getParent() parent configuration},
 * the corresponding {@link MergeXmlWebApplicationContext#getParentApplicationContext()
 * ApplicationContext} will be retrieved and 
 * {@linkplain MergeXmlWebApplicationContext#setParent(ApplicationContext) set as the parent}
 * for the context created by this method.</li>
 * <li>Converts the patch locations into a single string to be set via
 * {@link MergeXmlWebApplicationContext#setPatchLocation(String)}</li>
 * <li>Sets the patch locations via {@link MergeXmlWebApplicationContext#setStandardLocationTypes(String)}
 * to the {@link StandardConfigLocations.TESTCONTEXTTYPE} for integration tests.</li>
 * <li>Delegates to {@link #configureWebResources} to create the {@link MockServletContext} and
 * set it in the {@code MergeXmlWebApplicationContext}.</li>
 * <li>Calls {@link #prepareContext} to allow for customizing the context before bean
 * definitions are loaded.</li>
 * <li>{@link ConfigurableApplicationContext#refresh Refreshes} the context and registers
 * a JVM shutdown hook for it.</li>
 * </ul></p>
 * 
 * Refactored from {@link org.springframework.test.context.web.AbstractGenericWebContextLoader#loadContext(MergedContextConfiguration)}
 * 
 * @return a new merge xml web application context
 * @see org.springframework.test.context.SmartContextLoader#loadContext(MergedContextConfiguration)
 * @see MergeXmlWebApplicationContext
 */
@Override
public ConfigurableApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception {

    if (!(mergedConfig instanceof WebMergedContextConfiguration)) {
        throw new IllegalArgumentException(String.format(
                "Cannot load WebApplicationContext from non-web merged context configuration %s. "
                        + "Consider annotating your test class with @WebAppConfiguration.", mergedConfig));
    }
    WebMergedContextConfiguration webMergedConfig = (WebMergedContextConfiguration) mergedConfig;

    validateMergedContextConfiguration(webMergedConfig);

    MergeXmlWebApplicationContext context = new MergeXmlWebApplicationContext();
    context.setPatchLocation("");

    ApplicationContext parent = mergedConfig.getParentApplicationContext();
    if (parent != null) {
        context.setParent(parent);
        context.setPatchLocation(StringUtils.removeEnd(((MergeXmlWebApplicationContext) parent).getPatchLocation(), "classpath:/bl-applicationContext-test.xml"));
        System.out.println(context.getPatchLocation());
    }
    //Calls unique to Broadleaf Implementation of the Smart Context Loader
    // the ";classpath:/bl-applicationContext-test.xml" is required by all integration tests so we add it here.
    context.setPatchLocation(context.getPatchLocation() + StringUtils.join(mergedConfig.getLocations(), ";") +";classpath:/bl-applicationContext-test.xml");
    context.setStandardLocationTypes(StandardConfigLocations.TESTCONTEXTTYPE);
    
    configureWebResources(context, webMergedConfig);
    prepareContext(context, webMergedConfig);
    context.refresh();
    context.registerShutdownHook();
    return context;
}
 
开发者ID:takbani,项目名称:blcdemo,代码行数:66,代码来源:BroadleafGenericGroovyXmlWebContextLoader.java


示例17: validateMergedContextConfiguration

import org.springframework.test.context.web.WebMergedContextConfiguration; //导入依赖的package包/类
/**
 * Validate the supplied {@link WebMergedContextConfiguration} with respect to
 * what this context loader supports.
 * <p>The default implementation is a <em>no-op</em> but can be overridden by
 * subclasses as appropriate.
 *
 * @param mergedConfig the merged configuration to validate
 * @throws IllegalStateException if the supplied configuration is not valid
 *                               for this context loader
 * @since 4.0.4
 */
protected void validateMergedContextConfiguration(WebMergedContextConfiguration mergedConfig) {
    /* no-op */
}
 
开发者ID:opensingular,项目名称:singular-server,代码行数:15,代码来源:AbstractSingularContextLoader.java



注:本文中的org.springframework.test.context.web.WebMergedContextConfiguration类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Organization类代码示例发布时间:2022-05-23
下一篇:
Java PsiJavaPatterns类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap