Author: tv Date: Sun Jan 8 12:00:03 2006 New Revision: 367079 URL: http://svn.apache.org/viewcvs?rev=367079&view=rev Log: - Added tests for managers and caching. - Made CopyTest, BeanTest and ManagerTest conditional depending on the settings in project.properties Note: For the ManagerTest to succeed you need to add "torque.manager.useCache = true" to your Torque.properties.
Added: db/torque/test/trunk/profile/tv/ db/torque/test/trunk/profile/tv/Torque.properties db/torque/test/trunk/profile/tv/project.properties db/torque/test/trunk/profile/tv/project.xml db/torque/test/trunk/test-project/src/java/cache.ccf db/torque/test/trunk/test-project/src/java/org/apache/torque/BeanTestConditional.java - copied, changed from r367053, db/torque/test/trunk/test-project/src/java/org/apache/torque/BeanTest.java db/torque/test/trunk/test-project/src/java/org/apache/torque/ManagerTestConditional.java db/torque/test/trunk/test-project/src/java/org/apache/torque/util/CopyTestConditional.java - copied, changed from r367053, db/torque/test/trunk/test-project/src/java/org/apache/torque/util/CopyTest.java Removed: db/torque/test/trunk/test-project/src/java/org/apache/torque/BeanTest.java db/torque/test/trunk/test-project/src/java/org/apache/torque/util/CopyTest.java Modified: db/torque/test/trunk/test-project/maven.xml db/torque/test/trunk/test-project/src/logging/log4j.properties Added: db/torque/test/trunk/profile/tv/Torque.properties URL: http://svn.apache.org/viewcvs/db/torque/test/trunk/profile/tv/Torque.properties?rev=367079&view=auto ============================================================================== --- db/torque/test/trunk/profile/tv/Torque.properties (added) +++ db/torque/test/trunk/profile/tv/Torque.properties Sun Jan 8 12:00:03 2006 @@ -0,0 +1,36 @@ +# Copyright 2005 The Apache Software Foundation. +# +# 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. + +# +# Runtime settings for the mysql test profile +# +# $Id: Torque.properties 279964 2005-09-10 07:07:23Z tfischer $ +# + +torque.database.default = bookstore +torque.database.bookstore.adapter = mysql + +#Using commons-dbcp +torque.dsfactory.bookstore.factory = org.apache.torque.dsfactory.SharedPoolDataSourceFactory +torque.dsfactory.bookstore.connection.driver = org.gjt.mm.mysql.Driver +torque.dsfactory.bookstore.connection.url = jdbc:mysql://gatekeeper.home.lan:3306/bookstore +torque.dsfactory.bookstore.connection.user = torque +torque.dsfactory.bookstore.connection.password = torque + +torque.dsfactory.bookstore.pool.validationQuery = SELECT 1 + +# Determines whether the managers cache instances of the business objects. +# And also whether the MethodResultCache will really cache results. + +torque.manager.useCache = true Added: db/torque/test/trunk/profile/tv/project.properties URL: http://svn.apache.org/viewcvs/db/torque/test/trunk/profile/tv/project.properties?rev=367079&view=auto ============================================================================== --- db/torque/test/trunk/profile/tv/project.properties (added) +++ db/torque/test/trunk/profile/tv/project.properties Sun Jan 8 12:00:03 2006 @@ -0,0 +1,36 @@ +# Copyright 2005 The Apache Software Foundation. +# +# 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. + +# +# Generator and build settings for the mysql test profile +# +# $Id: project.properties 359291 2005-12-27 21:45:04Z tfischer $ +# + +#build settings for replacing tokens in the schema files +torque.test.base.idMethod = idbroker + +#settings for the generator +torque.generateBeans = true +torque.useManagers = true + +torque.database = mysql +torque.database.createUrl = jdbc:mysql://gatekeeper.home.lan:3306/mysql +torque.database.buildUrl = jdbc:mysql://gatekeeper.home.lan:3306/bookstore +torque.database.driver = org.gjt.mm.mysql.Driver +torque.database.user = torque +torque.database.password = torque + +#settings for the datadump and jdbc task +torque.database.url = jdbc:mysql://gatekeeper.home.lan:3306/bookstore \ No newline at end of file Added: db/torque/test/trunk/profile/tv/project.xml URL: http://svn.apache.org/viewcvs/db/torque/test/trunk/profile/tv/project.xml?rev=367079&view=auto ============================================================================== --- db/torque/test/trunk/profile/tv/project.xml (added) +++ db/torque/test/trunk/profile/tv/project.xml Sun Jan 8 12:00:03 2006 @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright 2001-2005 The Apache Software Foundation. + + 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. + + =========================================================================== + + project descriptor for the mysql test profile + $Id: project.xml 359291 2005-12-27 21:45:04Z tfischer $ + +--> + +<project> + <extend>../../../runtime/project.xml</extend> + <artifactId>torque-mysql-test</artifactId> + <name>Torque-mysql-test</name> + <dependencies> + <dependency> + <artifactId>mysql-connector-java</artifactId> + <groupId>mm.mysql</groupId> + <version>3.1.12-bin</version> + </dependency> + </dependencies> +</project> \ No newline at end of file Modified: db/torque/test/trunk/test-project/maven.xml URL: http://svn.apache.org/viewcvs/db/torque/test/trunk/test-project/maven.xml?rev=367079&r1=367078&r2=367079&view=diff ============================================================================== --- db/torque/test/trunk/test-project/maven.xml (original) +++ db/torque/test/trunk/test-project/maven.xml Sun Jan 8 12:00:03 2006 @@ -85,6 +85,23 @@ destdir="${torque.test.compile.dir}" optimize="${torque.compile.optimize}" srcdir="${torque.test.junit.src.dir}"> + <include name="**/*Test.java" /> + + <j:set var="managers" value="${torque.useManagers}"/> + <j:if test="${managers == 'true'}"> + <include name="**/ManagerTestConditional.java"/> + </j:if> + <j:set var="beans" value="${torque.generateBeans}"/> + <j:if test="${beans == 'true'}"> + <include name="**/BeanTestConditional.java"/> + </j:if> + <j:set var="complex" value="${torque.complexObjectModel}"/> + <j:if test="${complex == 'true'}"> + <j:set var="caching" value="${torque.objectIsCaching}"/> + <j:if test="${caching == 'true'}"> + <include name="**/CopyTestConditional.java"/> + </j:if> + </j:if> <classpath> <pathelement location="${torque.test.compile.dir}"/> <path refid="maven.dependency.classpath"/> @@ -92,6 +109,22 @@ </javac> </goal> + <postGoal name="torque-test:pre-test"> + <j:set var="managers" value="${torque.useManagers}"/> + <j:if test="${managers == 'true'}"> + <copy todir="${torque.test.compile.dir}"> + <fileset dir="${torque.test.junit.src.dir}"> + <include name="cache.ccf"/> + </fileset> + </copy> + </j:if> + + <copy todir="${torque.test.compile.dir}"> + <fileset dir="src/logging"> + <include name="*"/> + </fileset> + </copy> + </postGoal> <goal name="torque-test:test" prereqs="torque-test:pre-test" @@ -102,6 +135,12 @@ <mkdir dir="${torque.test.log.dir}" /> <mkdir dir="${torque.test.junit.report.dir}" /> + + <echo>UseManagers is ${torque.useManagers}</echo> + <echo>GenerateBeans is ${torque.generateBeans}</echo> + <echo>ComplexObjectModel is ${torque.complexObjectModel}</echo> + <echo>ObjectIsCaching is ${torque.objectIsCaching}</echo> + <junit printsummary="no" haltonfailure="yes" fork="true"> <sysproperty key="torque.configuration.file" @@ -116,6 +155,21 @@ <batchtest todir="${torque.test.junit.report.dir}"> <fileset dir="${torque.test.junit.src.dir}"> + <j:set var="managers" value="${torque.useManagers}"/> + <j:if test="${managers == 'true'}"> + <include name="**/ManagerTestConditional.java"/> + </j:if> + <j:set var="beans" value="${torque.generateBeans}"/> + <j:if test="${beans == 'true'}"> + <include name="**/BeanTestConditional.java"/> + </j:if> + <j:set var="complex" value="${torque.complexObjectModel}"/> + <j:if test="${complex == 'true'}"> + <j:set var="caching" value="${torque.objectIsCaching}"/> + <j:if test="${caching == 'true'}"> + <include name="**/CopyTestConditional.java"/> + </j:if> + </j:if> <include name="**/*Test.java"/> <exclude name="**/test/**/*.java"/> </fileset> Added: db/torque/test/trunk/test-project/src/java/cache.ccf URL: http://svn.apache.org/viewcvs/db/torque/test/trunk/test-project/src/java/cache.ccf?rev=367079&view=auto ============================================================================== --- db/torque/test/trunk/test-project/src/java/cache.ccf (added) +++ db/torque/test/trunk/test-project/src/java/cache.ccf Sun Jan 8 12:00:03 2006 @@ -0,0 +1,16 @@ +# Java Caching System configuration + +jcs.default= +jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes +jcs.default.cacheattributes.MaxObjects=100 +jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache + +jcs.region.aloe_om_Author= +jcs.region.aloe_om_Author.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes +jcs.region.aloe_om_Author.cacheattributes.MaxObjects=100 +jcs.region.aloe_om_Author.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache + +jcs.region.aloe_om_Book= +jcs.region.aloe_om_Book.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes +jcs.region.aloe_om_Book.cacheattributes.MaxObjects=100 +jcs.region.aloe_om_Book.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache Copied: db/torque/test/trunk/test-project/src/java/org/apache/torque/BeanTestConditional.java (from r367053, db/torque/test/trunk/test-project/src/java/org/apache/torque/BeanTest.java) URL: http://svn.apache.org/viewcvs/db/torque/test/trunk/test-project/src/java/org/apache/torque/BeanTestConditional.java?p2=db/torque/test/trunk/test-project/src/java/org/apache/torque/BeanTestConditional.java&p1=db/torque/test/trunk/test-project/src/java/org/apache/torque/BeanTest.java&r1=367053&r2=367079&rev=367079&view=diff ============================================================================== --- db/torque/test/trunk/test-project/src/java/org/apache/torque/BeanTest.java (original) +++ db/torque/test/trunk/test-project/src/java/org/apache/torque/BeanTestConditional.java Sun Jan 8 12:00:03 2006 @@ -37,7 +37,7 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Thomas Fischer</a> * @version $Id$ */ -public class BeanTest extends BaseRuntimeTestCase +public class BeanTestConditional extends BaseRuntimeTestCase { public static final String AUTHOR_1_NAME = "Joshua Bloch"; @@ -54,7 +54,7 @@ /** * Creates a new instance. */ - public BeanTest(String name) + public BeanTestConditional(String name) { super(name); } Added: db/torque/test/trunk/test-project/src/java/org/apache/torque/ManagerTestConditional.java URL: http://svn.apache.org/viewcvs/db/torque/test/trunk/test-project/src/java/org/apache/torque/ManagerTestConditional.java?rev=367079&view=auto ============================================================================== --- db/torque/test/trunk/test-project/src/java/org/apache/torque/ManagerTestConditional.java (added) +++ db/torque/test/trunk/test-project/src/java/org/apache/torque/ManagerTestConditional.java Sun Jan 8 12:00:03 2006 @@ -0,0 +1,98 @@ +package org.apache.torque; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * 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. + */ + +import org.apache.torque.test.Author; +import org.apache.torque.test.AuthorManager; +import org.apache.torque.test.AuthorPeer; +import org.apache.torque.test.Book; +import org.apache.torque.test.BookManager; +import org.apache.torque.test.BookPeer; +import org.apache.torque.util.Criteria; + +/** + * Runtime tests for managers and caching. + * + * @author <a href="mailto:[EMAIL PROTECTED]">Thomas Vandahl</a> + * @version $Id:$ + */ +public class ManagerTestConditional extends BaseRuntimeTestCase +{ + /** + * Creates a new instance. + */ + public ManagerTestConditional(String name) + { + super(name); + } + + public void setUp() + { + super.setUp(); + } + + + /** + * Tests whether managers and caching work + * @throws Exception if the test fails + */ + public void testManagers() throws Exception + { + cleanBookstore(); + AuthorManager.getManager().setRegion("test_om_Author"); + BookManager.getManager().setRegion("test_om_Book"); + + Author author1 = new Author(); + author1.setName("author1"); + author1.save(); + Author author2 = new Author(); + author2.setName("author2"); + author2.save(); + + Author myauthor = AuthorManager.getCachedInstance(author1.getPrimaryKey()); + assertNotNull("Primary key of Author1 should not be null", author1.getPrimaryKey()); + assertNotNull("MyAuthor should not be null", myauthor); + assertTrue("Author1 and MyAuthor should point to the same cache instance", author1 == myauthor); + + Book book = new Book(); + book.setAuthor(author1); + book.setTitle("Book 1"); + book.setIsbn("unknown"); + book.save(); + + Book mybook = BookManager.getInstance(book.getPrimaryKey()); + assertTrue("Author1 and the author of MyBook should point to the same cache instance", author1 == mybook.getAuthor()); + } + + + /** + * Deletes all authors and books in the bookstore tables + * @throws Exception if the bookstore could not be cleaned + */ + protected void cleanBookstore() throws Exception + { + Criteria criteria = new Criteria(); + criteria.add(BookPeer.BOOK_ID, (Long) null, Criteria.NOT_EQUAL); + BookPeer.doDelete(criteria); + + criteria.clear(); + criteria.add( + AuthorPeer.AUTHOR_ID, + (Long) null, Criteria.NOT_EQUAL); + AuthorPeer.doDelete(criteria); + } +} Copied: db/torque/test/trunk/test-project/src/java/org/apache/torque/util/CopyTestConditional.java (from r367053, db/torque/test/trunk/test-project/src/java/org/apache/torque/util/CopyTest.java) URL: http://svn.apache.org/viewcvs/db/torque/test/trunk/test-project/src/java/org/apache/torque/util/CopyTestConditional.java?p2=db/torque/test/trunk/test-project/src/java/org/apache/torque/util/CopyTestConditional.java&p1=db/torque/test/trunk/test-project/src/java/org/apache/torque/util/CopyTest.java&r1=367053&r2=367079&rev=367079&view=diff ============================================================================== --- db/torque/test/trunk/test-project/src/java/org/apache/torque/util/CopyTest.java (original) +++ db/torque/test/trunk/test-project/src/java/org/apache/torque/util/CopyTestConditional.java Sun Jan 8 12:00:03 2006 @@ -27,12 +27,12 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Rafal Maczewski</a> * @version $Id$ */ -public class CopyTest extends BaseRuntimeTestCase +public class CopyTestConditional extends BaseRuntimeTestCase { /** * Creates a new instance. */ - public CopyTest(String name) + public CopyTestConditional(String name) { super(name); } Modified: db/torque/test/trunk/test-project/src/logging/log4j.properties URL: http://svn.apache.org/viewcvs/db/torque/test/trunk/test-project/src/logging/log4j.properties?rev=367079&r1=367078&r2=367079&view=diff ============================================================================== --- db/torque/test/trunk/test-project/src/logging/log4j.properties (original) +++ db/torque/test/trunk/test-project/src/logging/log4j.properties Sun Jan 8 12:00:03 2006 @@ -22,8 +22,14 @@ log4j.rootLogger = DEBUG, torque +log4j.logger.org.apache.torque = DEBUG, torque +log4j.additivity.org.apache.torque = false + +log4j.logger.org.apache.jcs = DEBUG, torque +log4j.additivity.org.apache.jcs = false + log4j.appender.torque = org.apache.log4j.FileAppender -log4j.appender.torque.file = target/tests/base/target/logs/base-test.log -log4j.appender.torque.append = false +log4j.appender.torque.file = target/logs/base-test.log +log4j.appender.torque.append = true log4j.appender.torque.layout = org.apache.log4j.PatternLayout log4j.appender.torque.layout.conversionPattern = %d [%t] %-5p %c - %m%n --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]