arminw 2005/08/08 06:18:50
Modified: src/test/org/apache/ojb/broker Tag: OJB_1_0_RELEASE
InheritanceMultipleTableTest.java M2NTest.java
QueryTest.java ReferenceTest.java
src/test/org/apache/ojb/odmg Tag: OJB_1_0_RELEASE
FieldConversionTest_4.java
src/test/org/apache/ojb Tag: OJB_1_0_RELEASE
repository_database.xml
repository_junit_reference.xml
Log:
add new tests, improve tests
Revision Changes Path
No revision
No revision
1.7.2.10 +100 -1
db-ojb/src/test/org/apache/ojb/broker/InheritanceMultipleTableTest.java
Index: InheritanceMultipleTableTest.java
===================================================================
RCS file:
/home/cvs/db-ojb/src/test/org/apache/ojb/broker/InheritanceMultipleTableTest.java,v
retrieving revision 1.7.2.9
retrieving revision 1.7.2.10
diff -u -r1.7.2.9 -r1.7.2.10
--- InheritanceMultipleTableTest.java 4 Jun 2005 14:48:04 -0000 1.7.2.9
+++ InheritanceMultipleTableTest.java 8 Aug 2005 13:18:48 -0000 1.7.2.10
@@ -34,6 +34,105 @@
junit.textui.TestRunner.main(new
String[]{InheritanceMultipleTableTest.class.getName()});
}
+ public void testQueryInheritancedObjects()
+ {
+ if(ojbSkipKnownIssueProblem("Classes mapped to multiple joined
tables will always be instantiated " +
+ " with the class type of the query, instead of the real
type"))
+ {
+ return;
+ }
+
+ long timestamp = System.currentTimeMillis();
+ Long id_2 = new Long(timestamp);
+ String name = "testInheritancedObjectsInCollectionReferences_" +
timestamp;
+ // store company with Employee/Executive/Manager
+ Company company = prepareTestDataWithCompany(id_2, name);
+ // add Shareholder too
+ Shareholder shareholder = new Shareholder(id_2, name);
+ shareholder.setShare(77);
+ shareholder.setDepartment("none");
+ AddressIF ad = new Address(name);
+ shareholder.setAddress(ad);
+ broker.beginTransaction();
+ broker.store(shareholder);
+ broker.commitTransaction();
+
+ broker.clearCache();
+ // now we expect 7 objects when query for all Employee (this is the
base class)
+ Criteria crit = new Criteria();
+ crit.addEqualTo("id_2", id_2);
+ crit.addLike("name", "%" + name + "%");
+ Query query = QueryFactory.newQuery(Employee.class, crit);
+ Collection result = broker.getCollectionByQuery(query);
+ assertEquals(7, result.size());
+ int empolyeeCount = 0;
+ int executiveCount = 0;
+ int managerCount = 0;
+ int shareholderCount = 0;
+ for(Iterator iterator = result.iterator(); iterator.hasNext();)
+ {
+ Object obj = iterator.next();
+ if(obj instanceof Employee) ++empolyeeCount;
+ if(obj instanceof Executive) ++executiveCount;
+ if(obj instanceof Manager) ++managerCount;
+ if(obj instanceof Shareholder) ++shareholderCount;
+ }
+ assertEquals(7, empolyeeCount);
+ assertEquals(5, executiveCount);
+ assertEquals(4, managerCount);
+ assertEquals(1, shareholderCount);
+
+ broker.clearCache();
+ // now we expect 4 objects when query for all Manager
+ crit = new Criteria();
+ crit.addEqualTo("id_2", id_2);
+ crit.addLike("name", "%" + name + "%");
+ query = QueryFactory.newQuery(Manager.class, crit);
+ result = broker.getCollectionByQuery(query);
+ assertEquals(4, result.size());
+ empolyeeCount = 0;
+ executiveCount = 0;
+ managerCount = 0;
+ shareholderCount = 0;
+ for(Iterator iterator = result.iterator(); iterator.hasNext();)
+ {
+ Object obj = iterator.next();
+ if(obj instanceof Employee) ++empolyeeCount;
+ if(obj instanceof Executive) ++executiveCount;
+ if(obj instanceof Manager) ++managerCount;
+ if(obj instanceof Shareholder) ++shareholderCount;
+ }
+ assertEquals(4, empolyeeCount);
+ assertEquals(4, executiveCount);
+ assertEquals(4, managerCount);
+ assertEquals(1, shareholderCount);
+
+ broker.clearCache();
+ // now we expect 1 objects when query for all Shareholder
+ crit = new Criteria();
+ crit.addEqualTo("id_2", id_2);
+ crit.addLike("name", "%" + name + "%");
+ query = QueryFactory.newQuery(Shareholder.class, crit);
+ result = broker.getCollectionByQuery(query);
+ assertEquals(1, result.size());
+ empolyeeCount = 0;
+ executiveCount = 0;
+ managerCount = 0;
+ shareholderCount = 0;
+ for(Iterator iterator = result.iterator(); iterator.hasNext();)
+ {
+ Object obj = iterator.next();
+ if(obj instanceof Employee) ++empolyeeCount;
+ if(obj instanceof Executive) ++executiveCount;
+ if(obj instanceof Manager) ++managerCount;
+ if(obj instanceof Shareholder) ++shareholderCount;
+ }
+ assertEquals(1, empolyeeCount);
+ assertEquals(1, executiveCount);
+ assertEquals(1, managerCount);
+ assertEquals(1, shareholderCount);
+ }
+
public void testWithoutJavaInheritance_1()
{
String name = "testWithoutJavaInheritance_1" +
System.currentTimeMillis();
1.7.2.7 +8 -7 db-ojb/src/test/org/apache/ojb/broker/M2NTest.java
Index: M2NTest.java
===================================================================
RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/M2NTest.java,v
retrieving revision 1.7.2.6
retrieving revision 1.7.2.7
diff -u -r1.7.2.6 -r1.7.2.7
--- M2NTest.java 8 May 2005 08:52:29 -0000 1.7.2.6
+++ M2NTest.java 8 Aug 2005 13:18:48 -0000 1.7.2.7
@@ -339,7 +339,7 @@
//============================================================
// test needs refactoring, LINK settings doesn't allow to store
// an object graph
- public void XXXtestStoreAddUpdateDeleteTLLF()
+ public void YYYtestStoreAddUpdateDeleteTLLF()
{
changeMovieCollectionDescriptorTo(true, LINK, LINK, false);
changeActorCollectionDescriptorTo(true, LINK, LINK, false);
@@ -348,7 +348,7 @@
doTestStoreAddUpdateDeleteTLLX(movie, postfix);
}
- public void XXXtestStoreAddUpdateDeleteTLLT()
+ public void YYYtestStoreAddUpdateDeleteTLLT()
{
changeMovieCollectionDescriptorTo(true, LINK, LINK, true);
changeActorCollectionDescriptorTo(true, LINK, LINK, false);
@@ -928,14 +928,14 @@
assertNotNull(loadedActor);
MovieManageableCollection col = loadedActor.getMovies();
assertNotNull(col);
- Movie movie = col.get(0);
+ col.get(0);
}
public void testAddNewEntriesTTTF()
{
changeMovieCollectionDescriptorTo(true, OBJECT, OBJECT, false);
changeActorCollectionDescriptorTo(true, OBJECT, OBJECT, false);
- doTestStoreUpdateTTXX();
+ doTestAddNewEntries();
}
public void testAddNewEntriesTTTT()
@@ -943,12 +943,12 @@
changeMovieCollectionDescriptorTo(true, OBJECT, OBJECT, true);
// default proxy does not work for user defined collection
changeActorCollectionDescriptorTo(true, OBJECT, OBJECT, false);
- doTestStoreUpdateTTXX();
+ doTestAddNewEntries();
}
public void doTestAddNewEntries()
{
- String postfix = "" + System.currentTimeMillis();
+ String postfix = "doTestAddNewEntries_" + System.currentTimeMillis();
/*
Returns 1 movie object with 3 actor objects and one actor object with
@@ -989,6 +989,7 @@
Movie readMovie = (Movie) broker.getObjectByIdentity(oid);
assertNotNull(readMovie);
assertEquals(3, readMovie.getActors().size());
+ assertEquals(0, readMovie.getActors2().size());
/*
we add 2 existing actor an movie object, thus we expect
1.61.2.15 +25 -1 db-ojb/src/test/org/apache/ojb/broker/QueryTest.java
Index: QueryTest.java
===================================================================
RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/QueryTest.java,v
retrieving revision 1.61.2.14
retrieving revision 1.61.2.15
diff -u -r1.61.2.14 -r1.61.2.15
--- QueryTest.java 9 Mar 2005 21:09:34 -0000 1.61.2.14
+++ QueryTest.java 8 Aug 2005 13:18:48 -0000 1.61.2.15
@@ -452,6 +452,30 @@
}
/**
+ * test escaped Like Criteria
+ */
+ public void testLikeEscapedCriteria3()
+ {
+ String name = "testLikeEscapedCriteria3()_" +
System.currentTimeMillis();
+ Person p = new Person();
+ p.setFirstname("123%45");
+ p.setLastname(name);
+ broker.beginTransaction();
+ broker.store(p);
+ broker.commitTransaction();
+
+ LikeCriteria.setEscapeCharacter('/');
+ Criteria crit = new Criteria();
+ crit.addEqualTo("lastname", name);
+ crit.addLike("firstname", "%/%45");
+ Query q = QueryFactory.newQuery(Person.class, crit);
+
+ Collection results = broker.getCollectionByQuery(q);
+ assertNotNull(results);
+ assertEquals(1, results.size());
+ }
+
+ /**
* test Null Criteria
*/
public void testNullCriteria()
1.17.2.3 +23 -1 db-ojb/src/test/org/apache/ojb/broker/ReferenceTest.java
Index: ReferenceTest.java
===================================================================
RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/ReferenceTest.java,v
retrieving revision 1.17.2.2
retrieving revision 1.17.2.3
diff -u -r1.17.2.2 -r1.17.2.3
--- ReferenceTest.java 11 Mar 2005 20:13:01 -0000 1.17.2.2
+++ ReferenceTest.java 8 Aug 2005 13:18:48 -0000 1.17.2.3
@@ -12,6 +12,7 @@
import org.apache.ojb.broker.query.Query;
import org.apache.ojb.broker.query.QueryFactory;
import org.apache.ojb.junit.PBTestCase;
+import org.apache.commons.lang.builder.ToStringBuilder;
/**
* Test case for checking the management of references.
@@ -1775,6 +1776,18 @@
{
this.regionCountry = regionCountry;
}
+
+ public String toString()
+ {
+ return new ToStringBuilder(this)
+ .append("id", id)
+ .append("grape", grape)
+ .append("regionCountry", regionCountry)
+ .append("regionName", regionName)
+ .append("year", year)
+ .append("region", region)
+ .toString();
+ }
}
public static class Region
@@ -1823,6 +1836,15 @@
{
this.description = description;
}
+
+ public String toString()
+ {
+ return new ToStringBuilder(this)
+ .append("country", country)
+ .append("name", name)
+ .append("description", description)
+ .toString();
+ }
}
public static interface RefObject
No revision
No revision
1.1.2.2 +52 -1
db-ojb/src/test/org/apache/ojb/odmg/FieldConversionTest_4.java
Index: FieldConversionTest_4.java
===================================================================
RCS file:
/home/cvs/db-ojb/src/test/org/apache/ojb/odmg/FieldConversionTest_4.java,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- FieldConversionTest_4.java 2 Mar 2005 20:24:12 -0000 1.1.2.1
+++ FieldConversionTest_4.java 8 Aug 2005 13:18:49 -0000 1.1.2.2
@@ -27,6 +27,57 @@
junit.textui.TestRunner.main(arr);
}
+ public void testSelfReferingParent() throws Exception
+ {
+ String strQuery = "select allNodes from " + Node.class.getName();
+ long id = System.currentTimeMillis();
+ Node node = new Node(id, null, true);
+ node.setParent(node);
+
+ List result;
+ int before;
+ TransactionExt tx = (TransactionExt) odmg.newTransaction();
+ try
+ {
+ tx.begin();
+
+ OQLQuery query = odmg.newOQLQuery();
+ query.create(strQuery);
+ result = (List) query.execute();
+ before = result.size();
+
+ database.makePersistent(node);
+ tx.commit();
+
+ tx.begin();
+ tx.getBroker().clearCache();
+ query = odmg.newOQLQuery();
+ query.create(strQuery);
+ result = (List) query.execute();
+ tx.commit();
+ }
+ finally
+ {
+ if (tx != null && tx.isOpen())
+ {
+ tx.abort();
+ }
+ }
+ int after = result.size();
+ assertFalse(after == 0);
+ assertEquals(before + 1, after);
+
+ tx.begin();
+ database.deletePersistent(node);
+ tx.commit();
+
+ OQLQuery query = odmg.newOQLQuery();
+ query.create(strQuery);
+ result = (List) query.execute();
+ after = result.size();
+ assertEquals(before, after);
+ }
+
public void testMakePersistentNode() throws Exception
{
String strQuery = "select allNodes from " + Node.class.getName();
No revision
No revision
1.22.2.11 +13 -20 db-ojb/src/test/org/apache/ojb/repository_database.xml
Index: repository_database.xml
===================================================================
RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/repository_database.xml,v
retrieving revision 1.22.2.10
retrieving revision 1.22.2.11
diff -u -r1.22.2.10 -r1.22.2.11
--- repository_database.xml 30 Apr 2005 20:55:15 -0000 1.22.2.10
+++ repository_database.xml 8 Aug 2005 13:18:49 -0000 1.22.2.11
@@ -48,14 +48,16 @@
ignoreAutoCommitExceptions="false"
>
- <!-- On initialization of connections the ConnectionFactory change
the autoCommit
- state dependent of the used 'useAutoCommit' setting. This
doesn't work in all
- situations/environments, thus this check is deprecated.
- To use the old behavior set this property to 'true', then OJB
try to
- change the autocommit state (if needed) of a new obtained
connections at
- connection initialization.
- If 'false' or this property is removed, OJB don't try to change
connection
- autoCommit state at connection initialization.
+ <!--
+ On initialization of connections the ConnectionFactory change
the 'autoCommit'
+ state dependent of the used 'useAutoCommit' setting. This
doesn't work in all
+ situations/environments, thus for useAutoCommit="1" the
ConnectionFactory does
+ no longer set autoCommit to true on connection creation.
+ To use the old behavior (OJB version 1.0.3 or earlier) set this
property
+ to 'true', then OJB change the autoCommit state (if needed) of
+ new obtained connections at connection initialization to 'true'.
+ If 'false' or this property is removed, OJB don't try to change
connection
+ autoCommit state at connection initialization.
-->
<attribute attribute-name="initializationCheck"
attribute-value="false" />
@@ -105,7 +107,7 @@
<!-- alternative sequence manager implementations, see docs section
"Sequence Manager" -->
<sequence-manager
className="org.apache.ojb.broker.util.sequence.SequenceManagerHighLowImpl">
- <!-- meaning of attributes, please see docs section "Sequence
Manager" -->
+ <!-- attributes of SequenceManagerHighLowImpl, please see docs
section "Sequence Manager" -->
<attribute attribute-name="grabSize" attribute-value="20"/>
<attribute attribute-name="autoNaming" attribute-value="true"/>
<attribute attribute-name="sequenceStart" attribute-value="0"/>
@@ -126,16 +128,7 @@
useAutoCommit="0"
ignoreAutoCommitExceptions="false"
>
- <object-cache
class="org.apache.ojb.broker.cache.ObjectCacheDefaultImpl">
- <attribute attribute-name="cacheExcludes" attribute-value=""/>
- <attribute attribute-name="timeout" attribute-value="900"/>
- <attribute attribute-name="autoSync" attribute-value="true"/>
- <attribute attribute-name="cachingKeyType" attribute-value="0"/>
- </object-cache>
-
- <sequence-manager
className="org.apache.ojb.broker.util.sequence.SequenceManagerNextValImpl">
- <attribute attribute-name="autoNaming" attribute-value="true"/>
- </sequence-manager>
+ Add the other elements like object-cache, connection-pool,
sequence-manager here.
</jdbc-connection-descriptor -->
1.17.2.5 +5 -1
db-ojb/src/test/org/apache/ojb/repository_junit_reference.xml
Index: repository_junit_reference.xml
===================================================================
RCS file:
/home/cvs/db-ojb/src/test/org/apache/ojb/repository_junit_reference.xml,v
retrieving revision 1.17.2.4
retrieving revision 1.17.2.5
diff -u -r1.17.2.4 -r1.17.2.5
--- repository_junit_reference.xml 6 May 2005 18:30:17 -0000 1.17.2.4
+++ repository_junit_reference.xml 8 Aug 2005 13:18:49 -0000 1.17.2.5
@@ -1498,6 +1498,10 @@
auto-delete="false"
indirection-table="M2N_TEST_ROLE"
>
+ <!-- Check the use of order by element for fields and plain
columns -->
+ <orderby name="name" sort="ASC"/>
+ <orderby name="M2N_TEST_ROLE.MOVIE_ID_INT" sort="DESC"/>
+
<fk-pointing-to-this-class column="MOVIE_ID_INT"/>
<fk-pointing-to-this-class column="MOVIE_ID2_INT"/>
<fk-pointing-to-this-class column="MOVIE_ID_STR"/>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]