当前位置: 首页>>代码示例>>Java>>正文


Java ContextConfiguration类代码示例

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


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

示例1: resolveContextConfigurationAttributes

import org.springframework.test.context.ContextConfiguration; //导入依赖的package包/类
/**
 * Resolve the list of {@linkplain ContextConfigurationAttributes context
 * configuration attributes} for the supplied {@linkplain Class test class} and its
 * superclasses.
 * <p>Note that the {@link ContextConfiguration#inheritLocations inheritLocations} and
 * {@link ContextConfiguration#inheritInitializers() inheritInitializers} flags of
 * {@link ContextConfiguration @ContextConfiguration} will <strong>not</strong>
 * be taken into consideration. If these flags need to be honored, that must be
 * handled manually when traversing the list returned by this method.
 * @param testClass the class for which to resolve the configuration attributes
 * (must not be {@code null})
 * @return the list of configuration attributes for the specified class, ordered
 * <em>bottom-up</em> (i.e., as if we were traversing up the class hierarchy);
 * never {@code null}
 * @throws IllegalArgumentException if the supplied class is {@code null} or if
 * {@code @ContextConfiguration} is not <em>present</em> on the supplied class
 */
static List<ContextConfigurationAttributes> resolveContextConfigurationAttributes(Class<?> testClass) {
	Assert.notNull(testClass, "Class must not be null");

	List<ContextConfigurationAttributes> attributesList = new ArrayList<ContextConfigurationAttributes>();
	Class<ContextConfiguration> annotationType = ContextConfiguration.class;

	AnnotationDescriptor<ContextConfiguration> descriptor = findAnnotationDescriptor(testClass, annotationType);
	if (descriptor == null) {
		throw new IllegalArgumentException(String.format(
				"Could not find an 'annotation declaring class' for annotation type [%s] and class [%s]",
				annotationType.getName(), testClass.getName()));
	}

	while (descriptor != null) {
		convertContextConfigToConfigAttributesAndAddToList(descriptor.synthesizeAnnotation(),
				descriptor.getRootDeclaringClass(), attributesList);
		descriptor = findAnnotationDescriptor(descriptor.getRootDeclaringClass().getSuperclass(), annotationType);
	}

	return attributesList;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:39,代码来源:ContextLoaderUtils.java

示例2: assertContextConfigurationLocations

import org.springframework.test.context.ContextConfiguration; //导入依赖的package包/类
@Test
public void assertContextConfigurationLocations() throws Exception {

	final ContextConfiguration contextConfig = this.testClass.getAnnotation(ContextConfiguration.class);
	final ContextLoader contextLoader = new GenericXmlContextLoader();
	final String[] configuredLocations = (String[]) AnnotationUtils.getValue(contextConfig);
	final String[] processedLocations = contextLoader.processLocations(this.testClass, configuredLocations);

	if (logger.isDebugEnabled()) {
		logger.debug("----------------------------------------------------------------------");
		logger.debug("Configured locations: " + ObjectUtils.nullSafeToString(configuredLocations));
		logger.debug("Expected   locations: " + ObjectUtils.nullSafeToString(this.expectedLocations));
		logger.debug("Processed  locations: " + ObjectUtils.nullSafeToString(processedLocations));
	}

	assertArrayEquals("Verifying locations for test [" + this.testClass + "].", this.expectedLocations,
		processedLocations);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:GenericXmlContextLoaderResourceLocationsTests.java

示例3: findAnnotationDescriptorForTypesWithMetaAnnotationWithDefaultAttributes

import org.springframework.test.context.ContextConfiguration; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void findAnnotationDescriptorForTypesWithMetaAnnotationWithDefaultAttributes() throws Exception {
	Class<?> startClass = MetaConfigWithDefaultAttributesTestCase.class;
	Class<ContextConfiguration> annotationType = ContextConfiguration.class;

	UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(startClass, Service.class,
		ContextConfiguration.class, Order.class, Transactional.class);

	assertNotNull(descriptor);
	assertEquals(startClass, descriptor.getRootDeclaringClass());
	assertEquals(annotationType, descriptor.getAnnotationType());
	assertArrayEquals(new Class[] {}, ((ContextConfiguration) descriptor.getAnnotation()).value());
	assertArrayEquals(new Class[] { MetaConfig.DevConfig.class, MetaConfig.ProductionConfig.class },
		descriptor.getAnnotationAttributes().getClassArray("classes"));
	assertNotNull(descriptor.getComposedAnnotation());
	assertEquals(MetaConfig.class, descriptor.getComposedAnnotationType());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:MetaAnnotationUtilsTests.java

示例4: findAnnotationDescriptorForTypesWithMetaAnnotationWithOverriddenAttributes

import org.springframework.test.context.ContextConfiguration; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void findAnnotationDescriptorForTypesWithMetaAnnotationWithOverriddenAttributes() throws Exception {
	Class<?> startClass = MetaConfigWithOverriddenAttributesTestCase.class;
	Class<ContextConfiguration> annotationType = ContextConfiguration.class;

	UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(startClass, Service.class,
		ContextConfiguration.class, Order.class, Transactional.class);

	assertNotNull(descriptor);
	assertEquals(startClass, descriptor.getRootDeclaringClass());
	assertEquals(annotationType, descriptor.getAnnotationType());
	assertArrayEquals(new Class[] {}, ((ContextConfiguration) descriptor.getAnnotation()).value());
	assertArrayEquals(new Class[] { MetaAnnotationUtilsTests.class },
		descriptor.getAnnotationAttributes().getClassArray("classes"));
	assertNotNull(descriptor.getComposedAnnotation());
	assertEquals(MetaConfig.class, descriptor.getComposedAnnotationType());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:MetaAnnotationUtilsTests.java

示例5: overriddenContextConfigurationValue

import org.springframework.test.context.ContextConfiguration; //导入依赖的package包/类
@Test
public void overriddenContextConfigurationValue() throws Exception {
	Class<?> declaringClass = OverriddenMetaValueConfigTestCase.class;
	AnnotationDescriptor<ContextConfiguration> descriptor = findAnnotationDescriptor(declaringClass,
		ContextConfiguration.class);
	assertNotNull(descriptor);
	assertEquals(declaringClass, descriptor.getRootDeclaringClass());
	assertEquals(MetaValueConfig.class, descriptor.getComposedAnnotationType());
	assertEquals(ContextConfiguration.class, descriptor.getAnnotationType());
	assertNotNull(descriptor.getComposedAnnotation());
	assertEquals(MetaValueConfig.class, descriptor.getComposedAnnotationType());

	// direct access to annotation value:
	assertArrayEquals(new String[] { "foo.xml" }, descriptor.getAnnotation().value());

	// overridden attribute:
	AnnotationAttributes attributes = descriptor.getAnnotationAttributes();

	// NOTE: we would like to be able to override the 'value' attribute; however,
	// Spring currently does not allow overrides for the 'value' attribute.
	// See SPR-11393 for related discussions.
	assertArrayEquals(new String[] { "foo.xml" }, attributes.getStringArray("value"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:OverriddenMetaAnnotationAttributesTests.java

示例6: contextConfigurationLocationsAndInheritLocations

import org.springframework.test.context.ContextConfiguration; //导入依赖的package包/类
@Test
public void contextConfigurationLocationsAndInheritLocations() throws Exception {
	Class<MetaLocationsConfigTestCase> declaringClass = MetaLocationsConfigTestCase.class;
	AnnotationDescriptor<ContextConfiguration> descriptor = findAnnotationDescriptor(declaringClass,
		ContextConfiguration.class);
	assertNotNull(descriptor);
	assertEquals(declaringClass, descriptor.getRootDeclaringClass());
	assertEquals(MetaLocationsConfig.class, descriptor.getComposedAnnotationType());
	assertEquals(ContextConfiguration.class, descriptor.getAnnotationType());
	assertNotNull(descriptor.getComposedAnnotation());
	assertEquals(MetaLocationsConfig.class, descriptor.getComposedAnnotationType());

	// direct access to annotation attributes:
	assertArrayEquals(new String[] { "foo.xml" }, descriptor.getAnnotation().locations());
	assertFalse(descriptor.getAnnotation().inheritLocations());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:OverriddenMetaAnnotationAttributesTests.java

示例7: overriddenContextConfigurationLocationsAndInheritLocations

import org.springframework.test.context.ContextConfiguration; //导入依赖的package包/类
@Test
public void overriddenContextConfigurationLocationsAndInheritLocations() throws Exception {
	Class<?> declaringClass = OverriddenMetaLocationsConfigTestCase.class;
	AnnotationDescriptor<ContextConfiguration> descriptor = findAnnotationDescriptor(declaringClass,
		ContextConfiguration.class);
	assertNotNull(descriptor);
	assertEquals(declaringClass, descriptor.getRootDeclaringClass());
	assertEquals(MetaLocationsConfig.class, descriptor.getComposedAnnotationType());
	assertEquals(ContextConfiguration.class, descriptor.getAnnotationType());
	assertNotNull(descriptor.getComposedAnnotation());
	assertEquals(MetaLocationsConfig.class, descriptor.getComposedAnnotationType());

	// direct access to annotation attributes:
	assertArrayEquals(new String[] { "foo.xml" }, descriptor.getAnnotation().locations());
	assertFalse(descriptor.getAnnotation().inheritLocations());

	// overridden attributes:
	AnnotationAttributes attributes = descriptor.getAnnotationAttributes();
	assertArrayEquals(new String[] { "bar.xml" }, attributes.getStringArray("locations"));
	assertTrue(attributes.getBoolean("inheritLocations"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:OverriddenMetaAnnotationAttributesTests.java

示例8: initializeProcessEngine

import org.springframework.test.context.ContextConfiguration; //导入依赖的package包/类
@Override
protected void initializeProcessEngine() {
  ContextConfiguration contextConfiguration = getClass().getAnnotation(ContextConfiguration.class);
  String[] value = contextConfiguration.value();
  if (value==null) {
    throw new ActivitiException("value is mandatory in ContextConfiguration");
  }
  if (value.length!=1) {
    throw new ActivitiException("SpringActivitiTestCase requires exactly one value in annotation ContextConfiguration");
  }
  String configurationFile = value[0];
  processEngine = cachedProcessEngines.get(configurationFile);
  if (processEngine==null) {
    processEngine = applicationContext.getBean(ProcessEngine.class);
    cachedProcessEngines.put(configurationFile, processEngine);
  }
}
 
开发者ID:logicalhacking,项目名称:SecureBPMN,代码行数:18,代码来源:SpringActivitiTestCase.java

示例9: isSpringSupport

import org.springframework.test.context.ContextConfiguration; //导入依赖的package包/类
/**
 * 是否需要支持spring
 */
private boolean isSpringSupport(ExtensionContext context) {
    Class<?> clazz = context.getTestClass().get();
    boolean result = false;
    while (!clazz.equals(Object.class)) {
        boolean isContextConfiguration = clazz.isAnnotationPresent(ContextConfiguration.class);
        if (isContextConfiguration) {
            result = true;
            break;
        }
        clazz = clazz.getSuperclass();
    }
    return result;
}
 
开发者ID:ychaoyang,项目名称:autotest,代码行数:17,代码来源:AutoTestExtension.java

示例10: convertContextConfigToConfigAttributesAndAddToList

import org.springframework.test.context.ContextConfiguration; //导入依赖的package包/类
/**
 * Convenience method for creating a {@link ContextConfigurationAttributes}
 * instance from the supplied {@link ContextConfiguration} annotation and
 * declaring class and then adding the attributes to the supplied list.
 */
private static void convertContextConfigToConfigAttributesAndAddToList(ContextConfiguration contextConfiguration,
		Class<?> declaringClass, final List<ContextConfigurationAttributes> attributesList) {

	if (logger.isTraceEnabled()) {
		logger.trace(String.format("Retrieved @ContextConfiguration [%s] for declaring class [%s].",
				contextConfiguration, declaringClass.getName()));
	}
	ContextConfigurationAttributes attributes =
			new ContextConfigurationAttributes(declaringClass, contextConfiguration);
	if (logger.isTraceEnabled()) {
		logger.trace("Resolved context configuration attributes: " + attributes);
	}
	attributesList.add(attributes);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:ContextLoaderUtils.java

示例11: findAnnotationDescriptorForClassWithLocalMetaAnnotationAndAnnotatedSuperclass

import org.springframework.test.context.ContextConfiguration; //导入依赖的package包/类
@Test
public void findAnnotationDescriptorForClassWithLocalMetaAnnotationAndAnnotatedSuperclass() {
	AnnotationDescriptor<ContextConfiguration> descriptor = findAnnotationDescriptor(
		MetaAnnotatedAndSuperAnnotatedContextConfigClass.class, ContextConfiguration.class);

	assertNotNull("AnnotationDescriptor should not be null", descriptor);
	assertEquals("rootDeclaringClass", MetaAnnotatedAndSuperAnnotatedContextConfigClass.class, descriptor.getRootDeclaringClass());
	assertEquals("declaringClass", MetaConfig.class, descriptor.getDeclaringClass());
	assertEquals("annotationType", ContextConfiguration.class, descriptor.getAnnotationType());
	assertNotNull("composedAnnotation should not be null", descriptor.getComposedAnnotation());
	assertEquals("composedAnnotationType", MetaConfig.class, descriptor.getComposedAnnotationType());

	assertArrayEquals("configured classes", new Class[] { String.class },
		descriptor.getAnnotationAttributes().getClassArray("classes"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:16,代码来源:MetaAnnotationUtilsTests.java

示例12: contextConfigurationValue

import org.springframework.test.context.ContextConfiguration; //导入依赖的package包/类
@Test
public void contextConfigurationValue() throws Exception {
	Class<MetaValueConfigTestCase> declaringClass = MetaValueConfigTestCase.class;
	AnnotationDescriptor<ContextConfiguration> descriptor = findAnnotationDescriptor(declaringClass,
		ContextConfiguration.class);
	assertNotNull(descriptor);
	assertEquals(declaringClass, descriptor.getRootDeclaringClass());
	assertEquals(MetaValueConfig.class, descriptor.getComposedAnnotationType());
	assertEquals(ContextConfiguration.class, descriptor.getAnnotationType());
	assertNotNull(descriptor.getComposedAnnotation());
	assertEquals(MetaValueConfig.class, descriptor.getComposedAnnotationType());

	// direct access to annotation value:
	assertArrayEquals(new String[] { "foo.xml" }, descriptor.getAnnotation().value());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:16,代码来源:OverriddenMetaAnnotationAttributesTests.java

示例13: initializeContentEngine

import org.springframework.test.context.ContextConfiguration; //导入依赖的package包/类
@Override
protected void initializeContentEngine() {
    ContextConfiguration contextConfiguration = getClass().getAnnotation(ContextConfiguration.class);
    String[] value = contextConfiguration.value();
    boolean hasOneArg = value != null && value.length == 1;
    String key = hasOneArg ? value[0] : ContentEngine.class.getName();
    ContentEngine engine = this.cachedContentEngines.containsKey(key) ? this.cachedContentEngines.get(key) : this.applicationContext.getBean(ContentEngine.class);

    this.cachedContentEngines.put(key, engine);
    this.contentEngine = engine;
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:12,代码来源:SpringFlowableTestCase.java

示例14: initializeFormEngine

import org.springframework.test.context.ContextConfiguration; //导入依赖的package包/类
@Override
protected void initializeFormEngine() {
    ContextConfiguration contextConfiguration = getClass().getAnnotation(ContextConfiguration.class);
    String[] value = contextConfiguration.value();
    boolean hasOneArg = value != null && value.length == 1;
    String key = hasOneArg ? value[0] : FormEngine.class.getName();
    FormEngine engine = this.cachedFormEngines.containsKey(key) ? this.cachedFormEngines.get(key) : this.applicationContext.getBean(FormEngine.class);

    this.cachedFormEngines.put(key, engine);
    this.formEngine = engine;
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:12,代码来源:SpringFlowableTestCase.java

示例15: initializeDmnEngine

import org.springframework.test.context.ContextConfiguration; //导入依赖的package包/类
@Override
protected void initializeDmnEngine() {
    ContextConfiguration contextConfiguration = getClass().getAnnotation(ContextConfiguration.class);
    String[] value = contextConfiguration.value();
    boolean hasOneArg = value != null && value.length == 1;
    String key = hasOneArg ? value[0] : DmnEngine.class.getName();
    DmnEngine engine = this.cachedDmnEngines.containsKey(key) ? this.cachedDmnEngines.get(key) : this.applicationContext.getBean(DmnEngine.class);

    this.cachedDmnEngines.put(key, engine);
    this.dmnEngine = engine;
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:12,代码来源:SpringFlowableTestCase.java


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