Announcement Announcement Module
Collapse
No announcement yet.
Too much configuration in a test class. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Too much configuration in a test class.

    Running STS 3.1.0, using a maven project.
    I have two tests in two different packages in src/test/java:
    c.i.i.g.p.test.PersistenceTests.java
    c.i.i.g.x.test.ParserTests.java

    PersistenceTests uses java configuration as follows:
    @ContextConfiguration(loader=AnnotationConfigConte xtLoader.class)
    @RunWith(SpringJUnit4ClassRunner.class)

    ParserTests uses xml configuration as follows:
    @ContextConfiguration(locations = "classpath:/META-INF/spring/app-context.xml")
    @RunWith(SpringJUnit4ClassRunner.class)

    When I run the ParserTests using Run As -> JUnit Test the log output shows the proper
    /META-INF/spring/app-context.xml being loaded, but then the java configuration that is an inner class in PersistenceTests is also loaded. The two test classes have no code in common (no common base class etc). So it looks like the test run is discovering java configuration classes, even inner classes of other tests, and applying them after loading the requested context.

    For example, here is the log output ...

    12:18:38.899 [main] INFO o.s.b.f.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [META-INF/spring/app-context.xml]
    12:18:38.911 [main] DEBUG o.s.b.f.xml.DefaultDocumentLoader - Using JAXP provider [com.sun.org.apache.xerces.internal.jaxp.DocumentBu ilderFactoryImpl]
    --- snipped some out ---
    12:18:39.098 [main] DEBUG o.s.b.f.x.DefaultBeanDefinitionDocumentReader - Loading bean definitions
    12:18:39.256 [main] DEBUG o.s.c.a.ClassPathBeanDefinitionScanner - Identified candidate component class: file [/Users/dlaidlaw/Infor/workspaces/MDM/com.infor.itr.geoname/target/test-classes/com/infor/itr/geoname/persistence/test/UploadTest$ConfigurationContext.class]
    12:18:39.294 [main] DEBUG o.s.c.a.ClassPathBeanDefinitionScanner - Identified candidate component class: file [/Users/dlaidlaw/Infor/workspaces/MDM/com.infor.itr.geoname/target/classes/com/infor/itr/geoname/service/GeoNameService.class]
    12:18:39.339 [main] DEBUG o.s.b.f.x.BeanDefinitionParserDelegate - Using generated bean name [util:constant#12ac0f75] for nested custom element 'util:constant'
    12:18:39.350 [main] DEBUG o.s.d.r.c.RepositoryComponentProvider - Identified candidate component class: file [/Users/dlaidlaw/Infor/workspaces/MDM/com.infor.itr.geoname/target/classes/com/infor/itr/geoname/repository/AdminCodeRepository.class]
    12:18:39.351 [main] DEBUG o.s.d.r.c.RepositoryComponentProvider - Identified candidate component class: file [/Users/dlaidlaw/Infor/workspaces/MDM/com.infor.itr.geoname/target/classes/com/infor/itr/geoname/repository/CountryRepository.class]
    12:18:39.351 [main] DEBUG o.s.d.r.c.RepositoryComponentProvider - Identified candidate component class: file [/Users/dlaidlaw/Infor/workspaces/MDM/com.infor.itr.geoname/target/classes/com/infor/itr/geoname/repository/FeatureCodeRepository.class]
    12:18:39.351 [main] DEBUG o.s.d.r.c.RepositoryComponentProvider - Identified candidate component class: file [/Users/dlaidlaw/Infor/workspaces/MDM/com.infor.itr.geoname/target/classes/com/infor/itr/geoname/repository/GeoNameRepository.class]
    12:18:39.352 [main] DEBUG o.s.d.r.c.RepositoryComponentProvider - Identified candidate component class: file [/Users/dlaidlaw/Infor/workspaces/MDM/com.infor.itr.geoname/target/classes/com/infor/itr/geoname/repository/PostalCodeRepository.class]
    12:18:39.364 [main] DEBUG o.s.d.r.c.RepositoryBeanDefinitionParser - Registering repository: featureCodeRepository - Interface: com.infor.itr.geoname.repository.FeatureCodeReposi tory - Factory: org.springframework.data.mongodb.repository.suppor t.MongoRepositoryFactoryBean
    12:18:39.369 [main] DEBUG o.s.d.r.c.RepositoryBeanDefinitionParser - Registering repository: postalCodeRepository - Interface: com.infor.itr.geoname.repository.PostalCodeReposit ory - Factory: org.springframework.data.mongodb.repository.suppor t.MongoRepositoryFactoryBean
    12:18:39.373 [main] DEBUG o.s.d.r.c.RepositoryBeanDefinitionParser - Registering repository: adminCodeRepository - Interface: com.infor.itr.geoname.repository.AdminCodeReposito ry - Factory: org.springframework.data.mongodb.repository.suppor t.MongoRepositoryFactoryBean
    12:18:39.377 [main] DEBUG o.s.d.r.c.RepositoryBeanDefinitionParser - Registering repository: geoNameRepository - Interface: com.infor.itr.geoname.repository.GeoNameRepository - Factory: org.springframework.data.mongodb.repository.suppor t.MongoRepositoryFactoryBean
    12:18:39.381 [main] DEBUG o.s.d.r.c.RepositoryBeanDefinitionParser - Registering repository: countryRepository - Interface: com.infor.itr.geoname.repository.CountryRepository - Factory: org.springframework.data.mongodb.repository.suppor t.MongoRepositoryFactoryBean
    12:18:39.384 [main] DEBUG o.s.b.f.xml.XmlBeanDefinitionReader - Loaded 20 bean definitions from location pattern [classpath:/META-INF/spring/app-context.xml]
    12:18:39.389 [main] INFO o.s.c.s.GenericApplicationContext - Refreshing org.springframework.context.support.GenericApplica tionContext@37f12d4f: startup date [Wed Feb 27 12:18:39 AST 2013]; root of context hierarchy
    12:18:39.389 [main] DEBUG o.s.c.s.GenericApplicationContext - Bean factory for org.springframework.context.support.GenericApplica tionContext@37f12d4f: org.springframework.beans.factory.support.DefaultL istableBeanFactory@162a657e: defining beans [uploadTest.ConfigurationContext,geoNameService,org.springframework.context.annota tion.internalConfigurationAnnotationProcessor,org. springframework.context.annotation.internalAutowir edAnnotationProcessor,org.springframework.context. annotation.internalRequiredAnnotationProcessor,org .springframework.context.annotation.internalCommon AnnotationProcessor,mongo,org.springframework.bean s.factory.config.CustomEditorConfigurer#0,org.spri ngframework.beans.factory.config.CustomEditorConfi gurer#1,org.springframework.beans.factory.config.C ustomEditorConfigurer#2,mongoDbFactory,mongoTempla te,featureCodeRepository,postalCodeRepository,admi nCodeRepository,geoNameRepository,countryRepositor y,org.springframework.data.repository.core.support .RepositoryInterfaceAwareBeanPostProcessor#0,geoco dingService,parser]; root of factory hierarchy


    How can I stop that java configuration class from being loaded by other tests???

  • #2
    I can answer this myself - I guess I just was not thinking.

    The answer is to ensure your <context:component-scan> excludes the test code. Since all my test code resided in packages with ".test." somewhere in the package name, this worked for me:

    <context:component-scan base-package="com.infor.itr.geoname">
    <context:exclude-filter type="regex" expression=".*\.test\..*"/>
    </context:component-scan>


    Thanks!

    Comment

    Working...
    X