org.apache.ojb.broker
Class ReferenceTest

java.lang.Object
  extended byjunit.framework.Assert
      extended byjunit.framework.TestCase
          extended byorg.apache.ojb.broker.ReferenceTest
All Implemented Interfaces:
junit.framework.Test

public class ReferenceTest
extends junit.framework.TestCase

Test case for checking the management of references.

Version:
$Id: ReferenceTest.java,v 1.11 2004/02/06 12:27:02 arminw Exp $
Author:
Armin Waibel

Nested Class Summary
static class ReferenceTest.Animal
           
static class ReferenceTest.Bird
           
static class ReferenceTest.Fish
           
static class ReferenceTest.Mammal
           
static class ReferenceTest.Reference
           
static class ReferenceTest.ReferenceA
           
static interface ReferenceTest.ReferenceAIF
           
static class ReferenceTest.ReferenceB
           
static interface ReferenceTest.ReferenceBIF
           
static interface ReferenceTest.ReferenceIF
           
static class ReferenceTest.Region
           
static class ReferenceTest.Repository
           
static class ReferenceTest.RepositoryFK
           
static class ReferenceTest.Wine
           
 
Constructor Summary
ReferenceTest()
           
 
Method Summary
static void main(java.lang.String[] args)
           
 void setUp()
           
 void tearDown()
           
 void testAbstractReferenceDelete()
          this test case use an abstract class as reference
 void testAbstractReferenceQuery()
           
 void testAbstractReferenceStore()
          this test case use an abstract class as reference
 void testDeleteReferencesMappedToSameTable()
           
 void testGetReferencesByIdentityMappedToSameTable()
           
 void testHandlingOfMultiplePKFields()
          not really a reference test, here we check handling of objects with multiple PK fields.
 void testQueryReferencesMappedToSameTable()
           
 void testRepositoryFKStore()
          This test does the same as the testRepositoryFKStore(), but the used mapping data differ.
 void testStoreReferencesMappedToSameTable()
           
 void testStoreWithMultiplePK_1()
           
 void testStoreWithMultiplePK_2()
           
 void testStoreWithMultiplePK_3()
           
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ReferenceTest

public ReferenceTest()
Method Detail

main

public static void main(java.lang.String[] args)

setUp

public void setUp()
           throws PBFactoryException
Throws:
PBFactoryException

tearDown

public void tearDown()

testHandlingOfMultiplePKFields

public void testHandlingOfMultiplePKFields()
                                    throws java.lang.Exception
not really a reference test, here we check handling of objects with multiple PK fields. Such an object was used in following reference tests.

Throws:
java.lang.Exception

testStoreWithMultiplePK_1

public void testStoreWithMultiplePK_1()
                               throws java.lang.Exception
Throws:
java.lang.Exception

testStoreWithMultiplePK_2

public void testStoreWithMultiplePK_2()
                               throws java.lang.Exception
Throws:
java.lang.Exception

testStoreWithMultiplePK_3

public void testStoreWithMultiplePK_3()
                               throws java.lang.Exception
Throws:
java.lang.Exception

testStoreReferencesMappedToSameTable

public void testStoreReferencesMappedToSameTable()

testGetReferencesByIdentityMappedToSameTable

public void testGetReferencesByIdentityMappedToSameTable()

testQueryReferencesMappedToSameTable

public void testQueryReferencesMappedToSameTable()

testDeleteReferencesMappedToSameTable

public void testDeleteReferencesMappedToSameTable()

testRepositoryFKStore

public void testRepositoryFKStore()
This test does the same as the testRepositoryFKStore(), but the used mapping data differ. ReferenceTest.RepositoryFK defines all the reference fields as primary key in field-descriptors. Further on the used database table declares the reference fields as PK too. Based on a user post: > The following fails to be stored by PersistenceBroker: > > I have a class ACL which has two primary keys: objectId and userFK, and > userFK is also a foreign key tied to a reference of type User. If I do this: > > persistentBroker.beginTransaction(); > ACL acl = new ACL(); > acl.setObjectId( 100 ); > acl.setUser( currentUser ); > persistentBroker.store(acl); > persistentBroker.commitTransaction(); > > Acl will not be saved. The reason seems to be because in the storeToDb() > method of the PersistentBroker, there first comes an assertion of the > PrimaryKeys and afterwards comes the assignment of all the foreign keys. In > the scenario above the assertion of the primary keys will fail, because the > userFK has not been assigned yet, so we have an incomplete set of primary > keys. This does work with the ODMG layer, probably because of a different > sequence of events during the storing of the object. > > I wonder if there should be a check whether a primary key is shared by the > foreign key and allow that assignment before the assertion of the primary > keys is performed. Any ideas? > > Cheers, > --Bill.


testAbstractReferenceStore

public void testAbstractReferenceStore()
                                throws java.lang.Exception
this test case use an abstract class as reference

Throws:
java.lang.Exception

testAbstractReferenceQuery

public void testAbstractReferenceQuery()
                                throws java.lang.Exception
Throws:
java.lang.Exception

testAbstractReferenceDelete

public void testAbstractReferenceDelete()
                                 throws java.lang.Exception
this test case use an abstract class as reference

Throws:
java.lang.Exception


Authors: Thomas Mahler and others. (C) 2000 - 2003 Apache Software Foundation
All rights reserved. Published under the Apache License.
http://db.apache.org/ojb
Version: 1.0.rc5, 2003-12-14