Announcement Announcement Module
Collapse
No announcement yet.
Problem with Transaction management Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with Transaction management

    Hallo

    Im trying to use rollback for my DAO tests. I wrote my test class like the example in the spring documentation (8.3.7.4.).

    My test class:
    Code:
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration
    @TransactionConfiguration(transactionManager="txMgr")
    @Transactional
    public class KartenManagerTest {
    	private Dao km;
    	private DataSource source;
    	private JdbcTemplate jdbcTemplate;
    	private QueryHelper queryHelper = new QueryHelper();
    
    	 @BeforeTransaction
    	    public void beforeTransaction() {
    	        //some code
    	    } 
    	 
    	 public void setKm(Dao km){
    			this.km=km;
    		}
    	 
    	@Before
    	public void setUp() throws Exception {
    		//some code
    	}
    
    	@After
    	public void tearDown() throws Exception {
    		//some code
    	}
    	
    	@Test
    	public void testSaveKarte(){
    		//some code
    	}
    	
    		
    	@AfterTransaction
    	public void afterTransaction() {
               //some code
            }
    }
    Unfortuanatly I always get following exceptions when I run the test:
    Code:
    26.05.2009 16:11:39 org.springframework.test.context.TestContextManager retrieveTestExecutionListeners
    INFO: @TestExecutionListeners is not present for class [class at.tuwien.sepm.fridolin.dao.KartenManagerTest]: using defaults.
    26.05.2009 16:11:39 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
    INFO: Loading XML bean definitions from class path resource [at/tuwien/sepm/fridolin/dao/KartenManagerTest-context.xml]
    26.05.2009 16:11:39 org.springframework.test.context.TestContextManager prepareTestInstance
    SCHWERWIEGEND: Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@76497934] to prepare test instance [at.tuwien.sepm.fridolin.dao.KartenManagerTest@51b48197]
    java.lang.IllegalStateException: Failed to load ApplicationContext
    	at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:201)
    	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
    	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
    	at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:255)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:111)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:148)
    	at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:59)
    	at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:52)
    	at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
    	at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
    	at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:50)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:97)
    	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
    	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
    Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [at/tuwien/sepm/fridolin/dao/KartenManagerTest-context.xml]; nested exception is java.io.FileNotFoundException: class path resource [at/tuwien/sepm/fridolin/dao/KartenManagerTest-context.xml] cannot be opened because it does not exist
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:349)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212)
    	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:81)
    	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:42)
    	at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:173)
    	at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:197)
    	... 17 more
    Caused by: java.io.FileNotFoundException: class path resource [at/tuwien/sepm/fridolin/dao/KartenManagerTest-context.xml] cannot be opened because it does not exist
    	at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:143)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
    	... 26 more
    java.lang.NoSuchMethodError: org.junit.runner.notification.RunNotifier.testAborted(Lorg/junit/runner/Description;Ljava/lang/Throwable;)V
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:155)
    	at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:59)
    	at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:52)
    	at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
    	at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
    	at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:50)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:97)
    	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
    	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
    The XML configuration file is located in the same directory. The file content is as follows:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
         
    	<bean id="HsqldbServerDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"
       	 destroy-method="close">
     		<property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
     		<property name="url" value="jdbc:hsqldb:file://localhost/fridolinTest"/>
    		<property name="username" value="sa"/>
    	 	<property name="password" value=""/> 	
    	</bean>
    	
    	<bean name="km" class="at.tuwien.sepm.fridolin.dao.KartenDao">  </bean>
    
    	<bean id="txMgr"
    		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    		<property name="dataSource" ref="HsqldbDataSource" />
    	</bean>
    
    
    </beans>
    Im trying to get it working since hours.

    Does anyone know whats the problem?

  • #2
    Hi Apfelsaft,

    the problem is, that it can't find the configuration file!

    Code:
    java.io.FileNotFoundException: class path resource [at/tuwien/sepm/fridolin/dao/KartenManagerTest-context.xml] cannot be opened because it does not exist
    You have to add the KartenManagerTest-context.xml file to your classpath. Or maybe the name of your configuration file ("KartenManagerTest-context.xml") is incorrect?

    Comment

    Working...
    X