/** * 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); }
private MergedContextConfiguration buildDefaultMergedContextConfiguration(Class<?> testClass, CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate) { List<ContextConfigurationAttributes> defaultConfigAttributesList = Collections.singletonList(new ContextConfigurationAttributes(testClass)); ContextLoader contextLoader = resolveContextLoader(testClass, defaultConfigAttributesList); if (logger.isInfoEnabled()) { logger.info(String.format( "Neither @ContextConfiguration nor @ContextHierarchy found for test class [%s], using %s", testClass.getName(), contextLoader.getClass().getSimpleName())); } return buildMergedContextConfiguration(testClass, defaultConfigAttributesList, null, cacheAwareContextLoaderDelegate, false); }
@Test public void processContextConfigurationWithDefaultXmlConfigAndConfigurationClassGeneration() { expectedException.expect(IllegalStateException.class); expectedException.expectMessage(containsString("both default locations AND default configuration classes were detected")); ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes( ImproperDuplicateDefaultXmlAndConfigClassTestCase.class, EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, true, null, true, ContextLoader.class); loader.processContextConfiguration(configAttributes); }
@Test public void processContextConfigurationWithConfigurationClass() { Class<?>[] classes = new Class<?>[] {getClass()}; ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes( getClass(), EMPTY_STRING_ARRAY, classes, true, null, true, ContextLoader.class); loader.processContextConfiguration(configAttributes); assertArrayEquals(classes, configAttributes.getClasses()); assertEmpty(configAttributes.getLocations()); }
@Test public void processContextConfigurationWithLocation() { String[] locations = new String[] {"classpath:/foo.xml"}; ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes( getClass(), locations, EMPTY_CLASS_ARRAY, true, null, true, ContextLoader.class); loader.processContextConfiguration(configAttributes); assertArrayEquals(locations, configAttributes.getLocations()); assertEmpty(configAttributes.getClasses()); }
@Test public void processContextConfigurationWithDefaultConfigurationClassGeneration() { ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes( ConfigClassTestCase.class, EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, true, null, true, ContextLoader.class); loader.processContextConfiguration(configAttributes); assertEquals(1, configAttributes.getClasses().length); assertEmpty(configAttributes.getLocations()); }
@Test public void processContextConfigurationWithDefaultXmlConfigGeneration() { ContextConfigurationAttributes configAttributes = new ContextConfigurationAttributes( XmlTestCase.class, EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, true, null, true, ContextLoader.class); loader.processContextConfiguration(configAttributes); assertEquals(1, configAttributes.getLocations().length); assertEmpty(configAttributes.getClasses()); }
/** * 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); }
/** * 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); }
private MergedContextConfiguration buildDefaultMergedContextConfiguration(Class<?> testClass, CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate) { List<ContextConfigurationAttributes> defaultConfigAttributesList = Collections.singletonList(new ContextConfigurationAttributes(testClass)); ContextLoader contextLoader = resolveContextLoader(testClass, defaultConfigAttributesList); if (logger.isInfoEnabled()) { logger.info(String.format( "Neither @ContextConfiguration nor @ContextHierarchy found for test class [%s], using %s", testClass.getName(), contextLoader.getClass().getSimpleName())); } return buildMergedContextConfiguration(testClass, defaultConfigAttributesList, null, cacheAwareContextLoaderDelegate, false); }
private MergedContextConfiguration buildDefaultMergedContextConfiguration(Class<?> testClass, CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate) { List<ContextConfigurationAttributes> defaultConfigAttributesList = Collections.singletonList(new ContextConfigurationAttributes(testClass)); ContextLoader contextLoader = resolveContextLoader(testClass, defaultConfigAttributesList); if (logger.isInfoEnabled()) { logger.info(String.format( "Neither @ContextConfiguration nor @ContextHierarchy found for test class [%s], using %s", testClass.getName(), contextLoader.getClass().getSimpleName())); } return buildMergedContextConfiguration(testClass, defaultConfigAttributesList, null, cacheAwareContextLoaderDelegate, false); }
private boolean isFromConfiguration(MergedContextConfiguration candidateConfig, ContextConfiguration configuration) { ContextConfigurationAttributes attributes = new ContextConfigurationAttributes( candidateConfig.getTestClass(), configuration); Set<Class<?>> configurationClasses = new HashSet<>( Arrays.asList(attributes.getClasses())); for (Class<?> candidate : candidateConfig.getClasses()) { if (configurationClasses.contains(candidate)) { return true; } } return false; }