db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb/broker/sequence NativeIdentifierTest.java
Date Thu, 24 Jul 2003 10:10:13 GMT
arminw      2003/07/24 03:10:13

  Modified:    src/test/org/apache/ojb/broker/sequence
                        NativeIdentifierTest.java
  Log:
  do more testing
  
  Revision  Changes    Path
  1.5       +89 -11    db-ojb/src/test/org/apache/ojb/broker/sequence/NativeIdentifierTest.java
  
  Index: NativeIdentifierTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/sequence/NativeIdentifierTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- NativeIdentifierTest.java	16 Jul 2003 11:21:38 -0000	1.4
  +++ NativeIdentifierTest.java	24 Jul 2003 10:10:12 -0000	1.5
  @@ -211,11 +211,11 @@
       {
           testSimpleInsert();
           testSimpleInsert();
  -        testReferenceInsert();
  -        testReferenceInsert();
  +        testReferenceInsertUpdate();
  +        testReferenceInsertUpdate();
       }
   
  -    public void testReferenceInsert() throws Exception
  +    public void testReferenceInsertUpdate() throws Exception
       {
           if (skipTest()) return;
           long timestamp = (long) (System.currentTimeMillis() * Math.random());
  @@ -224,44 +224,65 @@
   
           SMNativeObject obj_1 = new SMNativeObject(null, name);
           SMNativeObject obj_2 = new SMNativeObject(null, name);
  +
           SMNativeReference ref_1 = new SMNativeReference(null, nameRef);
           SMNativeReference ref_2 = new SMNativeReference(null, nameRef);
           SMNativeReference ref_3 = new SMNativeReference(null, nameRef);
           SMNativeReference ref_4 = new SMNativeReference(null, nameRef);
  +
           obj_1.addReference(ref_1);
           obj_1.addReference(ref_2);
           obj_1.addReference(ref_3);
           obj_1.addReference(ref_4);
   
           broker.beginTransaction();
  -        // maybe first store a reference
  +        // first store a reference
           broker.store(ref_1);
   //        System.out.println("ref_1: "+ref_1);
  -        // then store main object
  +        // then store main object with other references
           broker.store(obj_1);
   //        System.out.println("obj_1: "+obj_1);
  +        // store second object without references
           broker.store(obj_2);
   //        System.out.println("obj_2: "+obj_2);
           broker.commitTransaction();
   
  +        // try to find both objects
           Criteria crit = new Criteria();
           crit.addEqualTo("name", name);
           QueryByCriteria query = QueryFactory.newQuery(SMNativeObject.class, crit);
           int result = broker.getCount(query);
  -        assertEquals("Not all objects created", 2, result);
  +        assertEquals("Wrong object count", 2, result);
  +
  +        // pk have to set and have to be different
           assertNotNull(obj_1.getIdentifier());
  +        assertNotNull(obj_2.getIdentifier());
  +        assertNotSame(obj_1.getIdentifier(), obj_2.getIdentifier());
  +
  +        // get Identity objects
  +        Identity oid_1 = new Identity(obj_1, broker);
  +        Identity oid_2 = new Identity(obj_2, broker);
  +
           broker.clearCache();
  -        obj_1 = (SMNativeObject) broker.getObjectByIdentity(new Identity(obj_1, broker));
  +
  +        // get object with references
  +        obj_1 = (SMNativeObject) broker.getObjectByIdentity(oid_1);
  +        assertNotNull(obj_1);
           List references = obj_1.getAllReferences();
           assertNotNull(references);
  +        assertEquals("4 references expected for object: "+obj_1, 4, references.size());
           Iterator it = references.iterator();
           while (it.hasNext())
           {
               SMNativeReference ref = (SMNativeReference) it.next();
               assertEquals("Main object fk expected", obj_1.getIdentifier(), ref.fkIdentifier);
  -            assertTrue("Currently we expect a positive value", (ref.getRefIdentifier().longValue()
> 0));
  +            assertTrue("We expect a positive value, identity columns have to start >
0",
  +                    (ref.getRefIdentifier().longValue() > 0));
           }
   
  +        broker.clearCache();
  +
  +        // get references only
           Criteria crit_2 = new Criteria();
           crit_2.addEqualTo("refName", nameRef);
           QueryByCriteria query_2 = QueryFactory.newQuery(SMNativeReference.class, crit_2);
  @@ -270,10 +291,67 @@
           assertNotNull(ref_3.getRefIdentifier());
   
           broker.clearCache();
  -        Identity id = new Identity(obj_1, broker);
  -        SMNativeObject retObj = (SMNativeObject) broker.getObjectByIdentity(id);
  +
  +        // get second object
  +        SMNativeObject retObj = (SMNativeObject) broker.getObjectByIdentity(oid_2);
           List refList = retObj.getAllReferences();
           assertNotNull(refList);
  +        assertEquals("object do not have references", 0, refList.size());
  +
  +        // add new reference to object
  +        SMNativeReference ref_5 = new SMNativeReference(null, nameRef);
  +        SMNativeReference ref_6 = new SMNativeReference(null, nameRef);
  +        obj_1.addReference(ref_5);
  +        obj_2.addReference(ref_6);
  +        broker.beginTransaction();
  +        broker.store(obj_1);
  +        broker.store(obj_2);
  +        broker.commitTransaction();
  +        assertNotNull(ref_5.getRefIdentifier());
  +        assertNotNull(ref_6.getRefIdentifier());
  +
  +        obj_1 = (SMNativeObject) broker.getObjectByIdentity(oid_1);
  +        assertNotNull(obj_1);
  +        references = obj_1.getAllReferences();
  +        assertNotNull(references);
  +        assertEquals("5 references expected for object: "+obj_1, 5, references.size());
  +
  +        obj_2 = (SMNativeObject) broker.getObjectByIdentity(oid_2);
  +        assertNotNull(obj_2);
  +        references = obj_2.getAllReferences();
  +        assertNotNull(references);
  +        assertEquals("1 references expected for object: "+obj_2, 1, references.size());
  +
  +        // now update main objects
  +        obj_1.setName(name+"_update");
  +        obj_2.setName(name+"_update");
  +        broker.beginTransaction();
  +        broker.store(obj_1);
  +        broker.store(obj_2);
  +        broker.commitTransaction();
  +
  +        obj_1 = (SMNativeObject) broker.getObjectByIdentity(oid_1);
  +        obj_2 = (SMNativeObject) broker.getObjectByIdentity(oid_2);
  +
  +        assertNotNull(obj_1);
  +        assertNotNull(obj_2);
  +        assertEquals(obj_1.getName(), name+"_update");
  +        assertEquals(obj_2.getName(), name+"_update");
  +
  +        // now update reference
  +        obj_2 = (SMNativeObject) broker.getObjectByIdentity(oid_2);
  +        assertNotNull(obj_2);
  +        references = obj_2.getAllReferences();
  +        SMNativeReference ref = (SMNativeReference) references.get(0);
  +        ref.setRefName(nameRef+"_update");
  +        broker.beginTransaction();
  +        broker.store(obj_2);
  +        broker.commitTransaction();
  +        obj_2 = (SMNativeObject) broker.getObjectByIdentity(oid_2);
  +        assertNotNull(obj_2);
  +        references = obj_2.getAllReferences();
  +        ref = (SMNativeReference) references.get(0);
  +        assertEquals(nameRef+"_update", ref.getRefName());
       }
   
       public static class SMNativeObject implements Serializable
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message