本文整理汇总了Java中org.springframework.test.context.MergedContextConfiguration类的典型用法代码示例。如果您正苦于以下问题:Java MergedContextConfiguration类的具体用法?Java MergedContextConfiguration怎么用?Java MergedContextConfiguration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MergedContextConfiguration类属于org.springframework.test.context包,在下文中一共展示了MergedContextConfiguration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: customizeContext
import org.springframework.test.context.MergedContextConfiguration; //导入依赖的package包/类
@Override
public void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) {
Class<?> testClass = mergedConfig.getTestClass();
FlywayTest flywayAnnotation = AnnotatedElementUtils.findMergedAnnotation(testClass, FlywayTest.class);
BeanDefinitionRegistry registry = getBeanDefinitionRegistry(context);
RootBeanDefinition registrarDefinition = new RootBeanDefinition();
registrarDefinition.setBeanClass(PreloadableEmbeddedPostgresRegistrar.class);
registrarDefinition.getConstructorArgumentValues()
.addIndexedArgumentValue(0, databaseAnnotation);
registrarDefinition.getConstructorArgumentValues()
.addIndexedArgumentValue(1, flywayAnnotation);
registry.registerBeanDefinition("preloadableEmbeddedPostgresRegistrar", registrarDefinition);
}
开发者ID:zonkyio,项目名称:embedded-database-spring-test,代码行数:17,代码来源:EmbeddedPostgresContextCustomizerFactory.java
示例2: loadContext
import org.springframework.test.context.MergedContextConfiguration; //导入依赖的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;
}
示例3: put
import org.springframework.test.context.MergedContextConfiguration; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void put(MergedContextConfiguration key, ApplicationContext context) {
Assert.notNull(key, "Key must not be null");
Assert.notNull(context, "ApplicationContext must not be null");
this.contextMap.put(key, context);
MergedContextConfiguration child = key;
MergedContextConfiguration parent = child.getParent();
while (parent != null) {
Set<MergedContextConfiguration> list = this.hierarchyMap.get(parent);
if (list == null) {
list = new HashSet<MergedContextConfiguration>();
this.hierarchyMap.put(parent, list);
}
list.add(child);
child = parent;
parent = child.getParent();
}
}
示例4: remove
import org.springframework.test.context.MergedContextConfiguration; //导入依赖的package包/类
private void remove(List<MergedContextConfiguration> removedContexts, MergedContextConfiguration key) {
Assert.notNull(key, "Key must not be null");
Set<MergedContextConfiguration> children = this.hierarchyMap.get(key);
if (children != null) {
for (MergedContextConfiguration child : children) {
// Recurse through lower levels
remove(removedContexts, child);
}
// Remove the set of children for the current context from the hierarchy map.
this.hierarchyMap.remove(key);
}
// Physically remove and close leaf nodes first (i.e., on the way back up the
// stack as opposed to prior to the recursive call).
ApplicationContext context = this.contextMap.remove(key);
if (context instanceof ConfigurableApplicationContext) {
((ConfigurableApplicationContext) context).close();
}
removedContexts.add(key);
}
示例5: loadContextInternal
import org.springframework.test.context.MergedContextConfiguration; //导入依赖的package包/类
/**
* Load the {@code ApplicationContext} for the supplied merged context configuration.
* <p>Supports both the {@link SmartContextLoader} and {@link ContextLoader} SPIs.
* @throws Exception if an error occurs while loading the application context
*/
protected ApplicationContext loadContextInternal(MergedContextConfiguration mergedContextConfiguration)
throws Exception {
ContextLoader contextLoader = mergedContextConfiguration.getContextLoader();
Assert.notNull(contextLoader, "Cannot load an ApplicationContext with a NULL 'contextLoader'. " +
"Consider annotating your test class with @ContextConfiguration or @ContextHierarchy.");
ApplicationContext applicationContext;
if (contextLoader instanceof SmartContextLoader) {
SmartContextLoader smartContextLoader = (SmartContextLoader) contextLoader;
applicationContext = smartContextLoader.loadContext(mergedContextConfiguration);
}
else {
String[] locations = mergedContextConfiguration.getLocations();
Assert.notNull(locations, "Cannot load an ApplicationContext with a NULL 'locations' array. " +
"Consider annotating your test class with @ContextConfiguration or @ContextHierarchy.");
applicationContext = contextLoader.loadContext(locations);
}
return applicationContext;
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:28,代码来源:DefaultCacheAwareContextLoaderDelegate.java
示例6: assertMergedConfig
import org.springframework.test.context.MergedContextConfiguration; //导入依赖的package包/类
void assertMergedConfig(
MergedContextConfiguration mergedConfig,
Class<?> expectedTestClass,
String[] expectedLocations,
Class<?>[] expectedClasses,
Set<Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>> expectedInitializerClasses,
Class<? extends ContextLoader> expectedContextLoaderClass) {
assertNotNull(mergedConfig);
assertEquals(expectedTestClass, mergedConfig.getTestClass());
assertNotNull(mergedConfig.getLocations());
assertArrayEquals(expectedLocations, mergedConfig.getLocations());
assertNotNull(mergedConfig.getClasses());
assertArrayEquals(expectedClasses, mergedConfig.getClasses());
assertNotNull(mergedConfig.getActiveProfiles());
if (expectedContextLoaderClass == null) {
assertNull(mergedConfig.getContextLoader());
}
else {
assertEquals(expectedContextLoaderClass, mergedConfig.getContextLoader().getClass());
}
assertNotNull(mergedConfig.getContextInitializerClasses());
assertEquals(expectedInitializerClasses, mergedConfig.getContextInitializerClasses());
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:AbstractContextConfigurationUtilsTests.java
示例7: loadContext
import org.springframework.test.context.MergedContextConfiguration; //导入依赖的package包/类
@Override
public ApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception {
Class<?> testClass = getTestClass();
if (logger.isDebugEnabled()) {
logger.debug("Loading ApplicationContext for merged context configuration [{}].", mergedConfig);
}
// Pre CamelContext(s) instantiation setup
CamelAnnotationsHandler.handleDisableJmx(null, testClass);
try {
SpringCamelContext.setNoStart(true);
System.setProperty("skipStartingCamelContext", "true");
ConfigurableApplicationContext context = (ConfigurableApplicationContext) super.loadContext(mergedConfig);
SpringCamelContext.setNoStart(false);
System.clearProperty("skipStartingCamelContext");
return loadContext(context, testClass);
} finally {
cleanup(testClass);
}
}
示例8: loadContext
import org.springframework.test.context.MergedContextConfiguration; //导入依赖的package包/类
@Override
public ApplicationContext loadContext(MergedContextConfiguration config)
throws Exception {
SpringApplication application = new SpringApplication();
application.setMainApplicationClass(config.getTestClass());
application.setWebEnvironment(false);
application.setSources(
new LinkedHashSet<Object>(Arrays.asList(config.getClasses())));
ConfigurableEnvironment environment = new StandardEnvironment();
Map<String, Object> properties = new LinkedHashMap<String, Object>();
properties.put("spring.jmx.enabled", "false");
properties.putAll(TestPropertySourceUtils
.convertInlinedPropertiesToMap(config.getPropertySourceProperties()));
environment.getPropertySources().addAfter(
StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME,
new MapPropertySource("integrationTest", properties));
application.setEnvironment(environment);
return application.run();
}
示例9: getOrFindConfigurationClasses
import org.springframework.test.context.MergedContextConfiguration; //导入依赖的package包/类
protected Class<?>[] getOrFindConfigurationClasses(
MergedContextConfiguration mergedConfig) {
Class<?>[] classes = mergedConfig.getClasses();
if (containsNonTestComponent(classes) || mergedConfig.hasLocations()
|| !mergedConfig.getContextInitializerClasses().isEmpty()) {
return classes;
}
Class<?> found = new SpringBootConfigurationFinder()
.findFromClass(mergedConfig.getTestClass());
Assert.state(found != null,
"Unable to find a @SpringBootConfiguration, you need to use "
+ "@ContextConfiguration or @SpringBootTest(classes=...) "
+ "with your test");
logger.info("Found @SpringBootConfiguration " + found.getName() + " for test "
+ mergedConfig.getTestClass());
return merge(found, classes);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:18,代码来源:SpringBootTestContextBootstrapper.java
示例10: loadContext
import org.springframework.test.context.MergedContextConfiguration; //导入依赖的package包/类
/**
* Modeled after the Spring implementation in {@link AbstractGenericContextLoader},
* this method creates and refreshes the application context while providing for
* processing of additional Camel specific post-refresh actions. We do not provide the
* pre-post hooks for customization seen in {@link AbstractGenericContextLoader} because
* they probably are unnecessary for 90+% of users.
* <p/>
* For some functionality, we cannot use {@link org.springframework.test.context.TestExecutionListener} because we need
* to both produce the desired outcome during application context loading, and also cleanup
* after ourselves even if the test class never executes. Thus the listeners, which
* only run if the application context is successfully initialized are insufficient to
* provide the behavior described above.
*/
@Override
public ApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception {
Class<?> testClass = getTestClass();
if (LOG.isDebugEnabled()) {
LOG.debug("Loading ApplicationContext for merged context configuration [{}].", mergedConfig);
}
try {
GenericApplicationContext context = createContext(testClass, mergedConfig);
context.getEnvironment().setActiveProfiles(mergedConfig.getActiveProfiles());
loadBeanDefinitions(context, mergedConfig);
return loadContext(context, testClass);
} finally {
cleanup(testClass);
}
}
示例11: customizeContext
import org.springframework.test.context.MergedContextConfiguration; //导入依赖的package包/类
/**
* <p>Will register mock factory and all additional beans required by springmock.</p>
* <p>
* <p>It is possible to register and inject more beans passing additionalDefinitions to the constructor</p>
*
* @param configurableApplicationContext
* @param mergedContextConfiguration
*/
public final void customizeContext(ConfigurableApplicationContext configurableApplicationContext, MergedContextConfiguration mergedContextConfiguration) {
final BeanDefinitionRegistry registry = (BeanDefinitionRegistry) configurableApplicationContext;
registerDoubleRegistry(registry);
registerDoubleFactory(configurableApplicationContext.getBeanFactory(), registry);
registerMockClassResolver(registry);
registerDoubleDefinitionRegisteringProcessor(registry);
registerSpyRegistrationPostProcessor(registry);
registerAdditionalBeanDefinitions(registry, additionalDefinitions);
}
示例12: getEnvironmentProperties
import org.springframework.test.context.MergedContextConfiguration; //导入依赖的package包/类
private Map<String, Object> getEnvironmentProperties(Class<?> testClass)
throws Exception {
TestContext context = new ExposedTestContextManager(testClass)
.getExposedTestContext();
MergedContextConfiguration config = (MergedContextConfiguration) ReflectionTestUtils
.getField(context, "mergedContextConfiguration");
return TestPropertySourceUtils
.convertInlinedPropertiesToMap(config.getPropertySourceProperties());
}
示例13: processMergedContextConfiguration
import org.springframework.test.context.MergedContextConfiguration; //导入依赖的package包/类
/**
* Returns a {@link WebMergedContextConfiguration} if the test class in the
* supplied {@code MergedContextConfiguration} is annotated with
* {@link WebAppConfiguration @WebAppConfiguration} and otherwise returns
* the supplied instance unmodified.
*/
@Override
protected MergedContextConfiguration processMergedContextConfiguration(MergedContextConfiguration mergedConfig) {
WebAppConfiguration webAppConfiguration = AnnotationUtils.findAnnotation(mergedConfig.getTestClass(),
WebAppConfiguration.class);
if (webAppConfiguration != null) {
return new WebMergedContextConfiguration(mergedConfig, webAppConfiguration.value());
}
// else...
return mergedConfig;
}
示例14: customizeContext
import org.springframework.test.context.MergedContextConfiguration; //导入依赖的package包/类
@Override
public void customizeContext(ConfigurableApplicationContext context,
MergedContextConfiguration mergedContextConfiguration) {
if (context instanceof BeanDefinitionRegistry) {
MockitoPostProcessor.register((BeanDefinitionRegistry) context,
this.definitions);
}
}
示例15: validateMergedContextConfiguration
import org.springframework.test.context.MergedContextConfiguration; //导入依赖的package包/类
/**
* Ensure that the supplied {@link MergedContextConfiguration} does not
* contain {@link MergedContextConfiguration#getClasses() classes}.
* @since 4.0.4
* @see AbstractGenericContextLoader#validateMergedContextConfiguration
*/
@Override
protected void validateMergedContextConfiguration(MergedContextConfiguration mergedConfig) {
if (mergedConfig.hasClasses()) {
String msg = String.format(
"Test class [%s] has been configured with @ContextConfiguration's 'classes' attribute %s, "
+ "but %s does not support annotated classes.", mergedConfig.getTestClass().getName(),
ObjectUtils.nullSafeToString(mergedConfig.getClasses()), getClass().getSimpleName());
logger.error(msg);
throw new IllegalStateException(msg);
}
}