Ok, the cascading-it tests now run in Eclipse (setting the working directory did the trick) but I'm still having troubles with @Transactional:
I've added a propertyConfigurer to spring-config-create.xml (plus the corresponding db.properties file) and added the dataSource to the transactionManager. This seems to work: If I access the db directly via SimpleJdbcTemplate, transactional now rolls back as expected. But with castor: no chance. I think this is because the jdoManager and the transactionManager use a different dataSource (the one defined in jdo-conf.xml and myDataSource, respectively), so I kind of understand why it doesn't work. What do I need to do, to set that whole thing up properly? Also, it was my understanding that, as long as I don't specify a dataSource for the transactionManager explicitly, it would just use the one of the jdoManager... but that's apperently not the case, otherwise this would have worked already. (note: attached patch only includes the new changes) On Sat, Jan 16, 2010 at 13:50, Lukas Lang <lukas.l...@inode.at> wrote: > Hey Michael, > > first of all I must state that it's great to see you making progress! > As Ralph already said in his previous response, it would be nice if you > could provide more information. However, I will try to spot possible > mistakes (see comments inline). > > Am 15.01.2010 um 23:38 schrieb Michael Schröder: > > > Using "mvn clean test" all tests should and do finish successfully, > > but here are the problems: > > > > 1) It doesn't seem to use the current state of it's parent castor > > source, so the changes we've made to our trunk aren't there. (That's > > why autostore is set to true, so the tests can run without making use > > of our cascading feature.) I guess you can configure that in the > > pom.xml? > > Maven itself always loads dependencies from the local repository (.m2). > Your POM depends on castor-jdo, which should contain changes made by you > recently. I think this is where castor-orm comes in. Unfortunately, this is > a dependency cycle because castor-orm depends on a previous version of > Castor (this has become a real pain since the last two years). You could try > to exclude transitive dependencies of castor-orm using the <exclusions> > element. > > > > > 2) @Transactional doesn't work. The tests run because all ids are > > different, but if you were to e.g. make create2() use the same ids as > > create() you'll get an error. The test classes are all > > AbstractTransactionalJUnit4SpringContextTests and I'm pretty sure the > > transactionManager gets injected correctly (at least everything's done > > exactly like in jpa-extension-it). I've got to be missing something > > here... > > Several Spring application context files in your patch declare a > "myDataSource" bean, being configured by property replacement without > declaring a "propertyPlaceholderConfigurer". If you want to use environment > variables (from your shell) you should do so. > To verify correct behavior of your transactional test environment, could > you try accessing the database within a transactional test using the > SimpleJdbcTemplate? > > > > > 3) It doesn't work with JUnit in Eclipse. It can't find the database. > > (I used to get something along the lines of "schema TEST doesn't > > exist" but now all I'm getting is "Database target/test not found") > > > > I think this could be either a problem with "Working Directories" and > relative paths in Eclipse/POM, or simply the database has not yet been > created by Maven (the maven-sql-plugin more precisely). In the second case, > just run a "mvn clean install -Dmaven.test.skip=true" to execute the > maven-sql-plugin resulting in a clean Derby instance in the target folder. > Maven, however, does not allow the execution of a single plugin...this could > be fixed using profiles. > > Unfortunately, the combination of Eclipse/Maven/Castor is not able to > handle paths correctly as I mentioned above. You can fix that by setting the > Working Directory of your Eclipse test execution (Tab "Arguments") to the > module your test is located (e.g. > "${workspace_loc:castor/jpa-extensions-it}"). > > Hope that helps. If not, let us know! > > Regards, > Lukas > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > >
Index: cascading-it/src/test/java/org/castor/cascading/one_to_one/CreateTest.java =================================================================== --- cascading-it/src/test/java/org/castor/cascading/one_to_one/CreateTest.java (revision 0) +++ cascading-it/src/test/java/org/castor/cascading/one_to_one/CreateTest.java (revision 0) @@ -0,0 +1,119 @@ +/* + * Copyright 2009 Werner Guttmann + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.castor.cascading.one_to_one; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +import org.castor.spring.orm.CastorObjectRetrievalFailureException; +import org.exolab.castor.jdo.Database; +import org.exolab.castor.jdo.JDOManager; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests; +import org.springframework.test.context.transaction.TransactionConfiguration; +import org.springframework.transaction.annotation.Transactional; + +/** + * This class is part of the functional test suite for Castor JDO + * and assists in testing JPA annotation support. + * + * @author Werner Guttmann + * @since 1.3.1 + */ +...@contextconfiguration(locations = { "spring-config-create.xml" }) +...@transactionconfiguration(transactionManager = "transactionManager", defaultRollback = true) +public class CreateTest extends AbstractTransactionalJUnit4SpringContextTests { + + @Autowired + private JDOManager jdoManager; + + @Test + @Transactional + public void create() throws Exception { + + this.simpleJdbcTemplate.update("INSERT INTO OneToOne_Author (id, time_stamp, name) VALUES (?, ?, ?)", 1, 0, "hans"); + + + /* + + Database _db = jdoManager.getDatabase(); + // cascading must be independent of autostore + _db.setAutoStore(true); // TODO: set back to false + + Author author = new Author(); + author.setId(2); + + Book book = new Book(); + book.setId(1); + book.setAuthor(author); + + // persist book and therefore author + // (because cascading=true for the relation book --> author) + _db.begin(); + _db.create(book); + _db.commit(); + + // now let's see if book & author were properly commited/created + _db.begin(); + Book db_book = _db.load(Book.class, 1); + Author db_author = _db.load(Author.class, 2); + _db.commit(); + + assertEquals(1, db_book.getId()); + assertEquals(2, db_author.getId()); + _db.close();*/ + } + + @Test + @Transactional + public void create2() throws Exception { + + this.simpleJdbcTemplate.update("INSERT INTO OneToOne_Author (id, time_stamp, name) VALUES (?, ?, ?)", 1, 0, "hans"); + + /* + + Database _db = jdoManager.getDatabase(); + // cascading must be independent of autostore + _db.setAutoStore(true); // TODO: set back to false + + Author author = new Author(); + author.setId(2); + + Book book = new Book(); + book.setId(1); + book.setAuthor(author); + + // persist book and therefore author + // (because cascading=true for the relation book --> author) + _db.begin(); + _db.create(book); + _db.commit(); + + // now let's see if book & author were properly commited/created + _db.begin(); + Book db_book = _db.load(Book.class, 1); + Author db_author = _db.load(Author.class, 2); + _db.commit(); + + assertEquals(1, db_book.getId()); + assertEquals(2, db_author.getId()); + _db.close();*/ + } + +} Index: cascading-it/src/test/resources/org/castor/cascading/db.properties =================================================================== --- cascading-it/src/test/resources/org/castor/cascading/db.properties (revision 0) +++ cascading-it/src/test/resources/org/castor/cascading/db.properties (revision 0) @@ -0,0 +1,4 @@ +url=jdbc:derby:target/test +driver=org.apache.derby.jdbc.EmbeddedDriver +user=test +password=test \ No newline at end of file Index: cascading-it/src/test/resources/org/castor/cascading/one_to_one/spring-config-create.xml =================================================================== --- cascading-it/src/test/resources/org/castor/cascading/one_to_one/spring-config-create.xml (revision 0) +++ cascading-it/src/test/resources/org/castor/cascading/one_to_one/spring-config-create.xml (revision 0) @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="UTF-8"?> +<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:tx="http://www.springframework.org/schema/tx" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd + http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> + + <!-- Enable transaction support using Annotations --> + <tx:annotation-driven transaction-manager="transactionManager" /> + + <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> + <property name="location"> + <value>classpath:org/castor/cascading/db.properties</value> + </property> + </bean> + + <bean id="myDataSource" + class="org.apache.commons.dbcp.BasicDataSource" + destroy-method="close"> + <property name="driverClassName" value="${driver}" /> + <property name="url" value="${url}" /> + <property name="username" value="${user}" /> + <property name="password" value="${password}" /> + </bean> + + <bean id="transactionManager" + class="org.castor.spring.orm.CastorTransactionManager"> + <property name="JDOManager" ref="jdoManager" /> + <property name="dataSource" ref="myDataSource" /> + </bean> + + <bean id="jdoManager" + class="org.castor.spring.orm.LocalCastorFactoryBean"> + <property name="databaseName" value="testOneToOne" /> + <property name="configLocation" + value="classpath:org/castor/cascading/one_to_one/create/jdo-conf.xml" /> + </bean> + +</beans>
--------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email