Hi,
I'm having a problem loading my test application context (same result with either STS m2eclipse or 'mvn clean test' from a shell). Does anyone see what's wrong in my setup? Thanks in advance for your suggestions!
Here's my test (it looks odd because it just waits 1s before doing an assert - that's because it attempts to test the effect of a @Scheduled annotated processor which is instantiated by the application context):
I verified that Maven's resource plugin copies my test-context.xml from /src/test/resources/nl/rivm/vubis2warp/task/impl to /target/test-classes/nl/rivm/vubis2warp/task/impl.Code:package nl.rivm.vubis2warp.task.impl; import org.junit.Test; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; import org.springframework.util.Assert; @ContextConfiguration(locations={"classpath:/nl/rivm/vubis2warp/task/impl/test-context.xml"}) public class SchedulerImplTest extends AbstractJUnit4SpringContextTests { @Test public void test() throws InterruptedException { Thread.sleep(1000); Assert.notNull(this.getClass().getResource("/work/sent/210231001.xml")); } }
However, Spring's TestContext fails to load the ApplicationContext, because class path resource [nl/rivm/vubis2warp/task/impl/test-context.xml] does not exist. Also tried moving test-context.xml to /src/test/resources/ and changing @ContextConfiguration as follows, but to no avail:
@ContextConfiguration(locations={"classpath:/test-context.xml"})
@ContextConfiguration(locations={"classpath:test-context.xml"})
@ContextConfiguration(locations={"test-context.xml"})
Below is the stack trace plus some preliminary log output (org.springframework.test at debug level):
TIA,Code:Running nl.rivm.vubis2warp.task.impl.SchedulerImplTest DEBUG: org.springframework.test.context.junit4.SpringJUnit4ClassRunner - SpringJUnit4ClassRunner constructor called with [class nl.rivm.vubis2warp.task.impl.SchedulerImplTest]. DEBUG: org.springframework.test.context.support.DelegatingSmartContextLoader - Delegating to GenericXmlContextLoader to process context configuration [ContextConfigurationAttributes@1593ce6 declaringClass = 'nl.rivm.vubis2warp.task.impl.SchedulerImplTest', locations = '{classpath:/nl/rivm/vubis2warp/task/impl/test-context.xml}', classes = '{}', inheritLocations = true, contextLoaderClass = 'org.springframework.test.context.ContextLoader']. DEBUG: org.springframework.test.context.ContextLoaderUtils - Could not find an 'annotation declaring class' for annotation type [interface org.springframework.test.context.ActiveProfiles] and class [class nl.rivm.vubis2warp.task.impl.SchedulerImplTest] DEBUG: org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [nl.rivm.vubis2warp.task.impl.SchedulerImplTest] DEBUG: org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [nl.rivm.vubis2warp.task.impl.SchedulerImplTest] DEBUG: org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [nl.rivm.vubis2warp.task.impl.SchedulerImplTest] DEBUG: org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [nl.rivm.vubis2warp.task.impl.SchedulerImplTest] DEBUG: org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [nl.rivm.vubis2warp.task.impl.SchedulerImplTest] DEBUG: org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [nl.rivm.vubis2warp.task.impl.SchedulerImplTest] DEBUG: org.springframework.test.context.support.DependencyInjectionTestExecutionListener - Performing dependency injection for test context [[TestContext@13bedc4 testClass = SchedulerImplTest, testInstance = nl.rivm.vubis2warp.task.impl.SchedulerImplTest@176e9c0, testMethod = [null], testException = [null], mergedContextConfiguration = [MergedContextConfiguration@1ec4535 testClass = SchedulerImplTest, locations = '{classpath:/nl/rivm/vubis2warp/task/impl/test-context.xml}', classes = '{}', activeProfiles = '{}', contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader']]]. DEBUG: org.springframework.test.context.support.DelegatingSmartContextLoader - Delegating to GenericXmlContextLoader to load context from [MergedContextConfiguration@1ec4535 testClass = SchedulerImplTest, locations = '{classpath:/nl/rivm/vubis2warp/task/impl/test-context.xml}', classes = '{}', activeProfiles = '{}', contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader']. DEBUG: org.springframework.test.context.support.AbstractGenericContextLoader - Loading ApplicationContext for merged context configuration [[MergedContextConfiguration@1ec4535 testClass = SchedulerImplTest, locations = '{classpath:/nl/rivm/vubis2warp/task/impl/test-context.xml}', classes = '{}', activeProfiles = '{}', contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader']]. ERROR: org.springframework.test.context.TestContextManager - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@5f634c] to prepare test instance [nl.rivm.vubis2warp.task.impl.SchedulerImplTest@176e9c0] java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:157) [...] at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352) Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [nl/rivm/vubis2warp/task/impl/test-context.xml]; nested exception is java.io.FileNotFoundException: class path resource [nl/rivm/vubis2warp/task/impl/test-context.xml] cannot be opened because it does not exist [...] Caused by: java.io.FileNotFoundException: class path resource [nl/rivm/vubis2warp/task/impl/test-context.xml] cannot be opened because it does not exist [...]
Ger-Jan


Reply With Quote