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 repository_junit.xml
Date Wed, 13 Aug 2003 18:05:36 GMT
arminw      2003/08/13 11:05:36

  Modified:    src/schema ojbtest-schema.xml
               src/test/org/apache/ojb/broker/metadata MetadataTest.java
               src/test/org/apache/ojb/broker/sequence
                        SequenceManagerTest.java
               src/test/org/apache/ojb repository_junit.xml
  Log:
  update test cases
  
  Revision  Changes    Path
  1.46      +7 -1      db-ojb/src/schema/ojbtest-schema.xml
  
  Index: ojbtest-schema.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/schema/ojbtest-schema.xml,v
  retrieving revision 1.45
  retrieving revision 1.46
  diff -u -r1.45 -r1.46
  --- ojbtest-schema.xml	9 Aug 2003 10:04:34 -0000	1.45
  +++ ojbtest-schema.xml	13 Aug 2003 18:05:35 -0000	1.46
  @@ -487,6 +487,12 @@
           <column name="NAME" type="VARCHAR" size="250" javaName="name"/>
       </table>
   
  +    <table name="SM_AUTO_NAMING">
  +        <column name="SM_ID" required="true" primaryKey="true" type="INTEGER"
  +        javaName="id"/>
  +        <column name="NAME" type="VARCHAR" size="250" javaName="name"/>
  +    </table>
  +
       <table name="SM_TAB_MAX_A" javaName="SMMaxA">
           <column name="SM_ID" required="true" primaryKey="true" type="INTEGER"
           javaName="id"/>
  @@ -747,7 +753,7 @@
        <column name="SOMEVALUE" type="INTEGER" />
      </table>
      <!-- Used in tests AbstractExtentClassTest -->
  -   <table name="ABSTRACT_COLLECTION_CONTAINER">
  +   <table name="XCONTAINER">
        <column name="OBJ_ID" required="true" primaryKey="true" type="INTEGER"/>
      </table>
   
  
  
  
  1.11      +13 -12    db-ojb/src/test/org/apache/ojb/broker/metadata/MetadataTest.java
  
  Index: MetadataTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/metadata/MetadataTest.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- MetadataTest.java	2 Jun 2003 12:52:28 -0000	1.10
  +++ MetadataTest.java	13 Aug 2003 18:05:35 -0000	1.11
  @@ -3,15 +3,15 @@
   import junit.framework.TestCase;
   import org.apache.ojb.broker.PBKey;
   import org.apache.ojb.broker.PersistenceBroker;
  +import org.apache.ojb.broker.PersistenceBrokerException;
   import org.apache.ojb.broker.PersistenceBrokerFactory;
   import org.apache.ojb.broker.TestHelper;
  -import org.apache.ojb.broker.PersistenceBrokerException;
   import org.apache.ojb.broker.query.Criteria;
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.query.QueryFactory;
  +import org.apache.ojb.broker.sequence.Repository;
   import org.apache.ojb.broker.util.sequence.SequenceManagerHighLowImpl;
   import org.apache.ojb.odmg.OJB;
  -import org.apache.ojb.odmg.collections.DListImpl;
   import org.odmg.Database;
   import org.odmg.Implementation;
   import org.odmg.OQLQuery;
  @@ -32,7 +32,7 @@
       /**
        * A persistent object class
        */
  -    private Class testClass = DListImpl.class;
  +    private static final Class TEST_CLASS = Repository.SMKey.class;
   
       public static void main(String[] args)
       {
  @@ -84,11 +84,12 @@
                   {
                       // try to find persistent object, only available in global
                       // repository profile
  -                    Class clazz = broker.getClassDescriptor(testClass).getClassOfObject();
  -                    fail("We should not found this class-descriptor in profile");
  +                    Class clazz = broker.getClassDescriptor(TEST_CLASS).getClassOfObject();
  +                    assertNull("We should not found this class-descriptor in profile",
clazz);
                   }
                   catch (PersistenceBrokerException e)
                   {
  +                    assertTrue(true);
                   }
               }
               finally
  @@ -109,9 +110,9 @@
               // now we load copy of global DescriptorRepository
               mm.loadProfile("global");
               broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  -            Class clazz = broker.getClassDescriptor(testClass).getClassOfObject();
  +            Class clazz = broker.getClassDescriptor(TEST_CLASS).getClassOfObject();
               broker.close();
  -            assertEquals(testClass, clazz);
  +            assertEquals(TEST_CLASS, clazz);
               mm.removeAllProfiles();
               try
               {
  @@ -123,9 +124,9 @@
               }
   
               broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  -            clazz = broker.getClassDescriptor(testClass).getClassOfObject();
  +            clazz = broker.getClassDescriptor(TEST_CLASS).getClassOfObject();
               broker.close();
  -            assertEquals(testClass, clazz);
  +            assertEquals(TEST_CLASS, clazz);
           }
           finally
           {
  @@ -167,7 +168,7 @@
           PBKey key1 = new PBKey(TestHelper.DEF_JCD_ALIAS);
           PBKey key2 = new PBKey(TestHelper.DEF_JCD_ALIAS, TestHelper.DEF_USER, TestHelper.DEF_PASSWORD);
           PBKey key3 = new PBKey(TestHelper.FAR_AWAY_JCD_ALIAS);
  -        Query query = QueryFactory.newQuery(testClass, new Criteria());
  +        Query query = QueryFactory.newQuery(TEST_CLASS, new Criteria());
   
           PersistenceBroker broker = PersistenceBrokerFactory.createPersistenceBroker(key1);
           broker.getCount(query);
  @@ -188,7 +189,7 @@
       public void testLookupPB2()
       {
           PBKey key1 = new PBKey(TestHelper.DEF_JCD_ALIAS, "!!TestCase: This should fail!!",
"nothing");
  -        Query query = QueryFactory.newQuery(testClass, new Criteria());
  +        Query query = QueryFactory.newQuery(TEST_CLASS, new Criteria());
           PersistenceBroker broker = PersistenceBrokerFactory.createPersistenceBroker(key1);
           // hsql is not very strict in user handling
           try
  @@ -208,7 +209,7 @@
        */
       public void testLookupDatabase() throws Exception
       {
  -        String queryStr = "select allArticle from " + testClass.getName();
  +        String queryStr = "select allArticle from " + TEST_CLASS.getName();
           Implementation odmg = OJB.getInstance();
           Transaction tx;
           Database db = odmg.newDatabase();
  
  
  
  1.24      +55 -21    db-ojb/src/test/org/apache/ojb/broker/sequence/SequenceManagerTest.java
  
  Index: SequenceManagerTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/sequence/SequenceManagerTest.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- SequenceManagerTest.java	9 Aug 2003 13:23:40 -0000	1.23
  +++ SequenceManagerTest.java	13 Aug 2003 18:05:35 -0000	1.24
  @@ -41,7 +41,7 @@
   {
       private static final String TEST_SEQUENCE_NAME = "TEST_SEQUENCE";
       /**
  -     * Max PK value for {@link SMMax} test class prepared
  +     * Max PK value for {@link Repository.SMMax} test class prepared
        * in database.
        */
       private static final int SMMAX_MAX_PK_VALUE = 131;
  @@ -137,7 +137,7 @@
   
       /**
        * Test support for classes with multiple autoincrement
  -     * fields - e.g. see repository for {@link SMKey}
  +     * fields - e.g. see repository for {@link Repository.SMKey}
        */
       public void testMultipleAutoincrement()
       {
  @@ -209,8 +209,9 @@
               // allow per thread changes of persistent object data
               mm.setEnablePerThreadChanges(true);
               DescriptorRepository dr = mm.copyOfGlobalRepository();
  -            ClassDescriptor cld = dr.getDescriptorFor(SMObjectTwo.class);
  +            ClassDescriptor cld = dr.getDescriptorFor(SMAutoNaming.class);
               FieldDescriptor field = cld.getAutoIncrementField();
  +
               // set sequence name for persistent object to null
               field.setSequenceName(null);
               mm.setDescriptor(dr);
  @@ -222,11 +223,15 @@
                   persistent object descriptor doesn't has a sequence name
                   and autoNaming is false --> expect an exception
                   */
  -                SMObjectTwo obj = new SMObjectTwo("testAutoNaming");
  +                SMAutoNaming obj = new SMAutoNaming("testAutoNaming_1");
  +                sd = broker.serviceConnectionManager().getConnectionDescriptor().getSequenceDescriptor();
  +                assertTrue("false".equals(sd.getAttribute("autoNaming")));
  +
                   broker.beginTransaction();
                   broker.store(obj);
                   broker.commitTransaction();
  -                fail("This test should cause an exception");
  +                fail("If sequence manager implementation supports 'autoNaming' feature,"
  +                        +" this test should cause an exception (else ignore this failure).");
               }
               catch (PersistenceBrokerException e)
               {
  @@ -236,31 +241,37 @@
   
               try
               {
  -                // now we set a sequence name for autoincrement field
  -                // should pass
  -                field.setSequenceName("SEQ_testAutoNaming");
  -                SMObjectTwo obj = new SMObjectTwo("testAutoNaming");
  +                /* attribute 'auto-naming' is still false,
  +                but now we set a sequence name for autoincrement field
  +                --> should pass
  +                */
  +                field.setSequenceName("AA_testAutoNaming_user_set");
  +                SMAutoNaming obj = new SMAutoNaming("testAutoNaming_2");
                   broker.beginTransaction();
                   broker.store(obj);
                   broker.commitTransaction();
  -                broker.close();
               }
               catch (PersistenceBrokerException e)
               {
  -                fail("Sequence key generation failed");
  +                e.printStackTrace();
  +                broker.close();
  +                throw e;
               }
   
               try
               {
  +                // let OJB re-initialize sequence-manager
  +                broker.close();
  +                PersistenceBrokerFactory.releaseAllInstances();
                   /*
                   remove sequence name of autoincrement field
  -                and enable automatic sequence name generation
  +                but enable automatic sequence name generation
  +                --> should pass
                   */
                   field.setSequenceName(null);
                   sd.addAttribute("autoNaming", "true");
  -                PersistenceBrokerFactory.releaseAllInstances();
                   broker = PersistenceBrokerFactory.createPersistenceBroker(tempKey);
  -                SMObjectTwo obj = new SMObjectTwo("testAutoNaming");
  +                SMAutoNaming obj = new SMAutoNaming("testAutoNaming_3");
                   broker.beginTransaction();
                   broker.store(obj);
                   broker.commitTransaction();
  @@ -486,8 +497,8 @@
           FieldDescriptor fieldOne = broker.getClassDescriptor(classOne).getAutoIncrementField();
           FieldDescriptor fieldTwo = broker.getClassDescriptor(classOne).getAutoIncrementField();
   
  -        List listOne = createKeyList(broker, classOne, fieldOne, numberOfKeys);
  -        List listTwo = createKeyList(broker, classTwo, fieldTwo, numberOfKeys);
  +        List listOne = createKeyList(broker, fieldOne, numberOfKeys);
  +        List listTwo = createKeyList(broker, fieldTwo, numberOfKeys);
           for (int i = 0; i < listOne.size(); i++)
           {
               if (listTwo.contains(listOne.get(i)))
  @@ -500,8 +511,7 @@
           broker.close();
       }
   
  -    private List createKeyList(PersistenceBroker broker, Class objectClass,
  -                               FieldDescriptor field, int number)
  +    private List createKeyList(PersistenceBroker broker, FieldDescriptor field, int number)
               throws SequenceManagerException
       {
           SequenceManager sm = SequenceManagerFactory.getSequenceManager(broker);
  @@ -786,14 +796,14 @@
               Criteria cr = new Criteria();
               cr.addEqualTo("name", objectName_One);
               Query query = new QueryByCriteria(SMObjectOne.class, cr);
  -            Collection result = (Collection) broker.getCollectionByQuery(query);
  +            Collection result = broker.getCollectionByQuery(query);
   
               broker.clearCache();
   
               Criteria cr_2 = new Criteria();
               cr_2.addEqualTo("name", objectName_Two);
               Query query_2 = new QueryByCriteria(SMObjectTwo.class, cr_2);
  -            Collection result_2 = (Collection) broker.getCollectionByQuery(query_2);
  +            Collection result_2 = broker.getCollectionByQuery(query_2);
   
               assertEquals("We have to found 2 SMObjectOne objects", 2, result.size());
               assertEquals("We have to found 2 SMObjectTwo objects", 2, result_2.size());
  @@ -856,6 +866,30 @@
           }
   
           public SMObjectTwo(String name)
  +        {
  +            this.name = name;
  +        }
  +
  +        public String getName()
  +        {
  +            return name;
  +        }
  +
  +        public void setName(String name)
  +        {
  +            this.name = name;
  +        }
  +    }
  +
  +    public static class SMAutoNaming extends AbstractSMObject
  +    {
  +        private String name;
  +
  +        public SMAutoNaming()
  +        {
  +        }
  +
  +        public SMAutoNaming(String name)
           {
               this.name = name;
           }
  
  
  
  1.85      +23 -1     db-ojb/src/test/org/apache/ojb/repository_junit.xml
  
  Index: repository_junit.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/repository_junit.xml,v
  retrieving revision 1.84
  retrieving revision 1.85
  diff -u -r1.84 -r1.85
  --- repository_junit.xml	9 Aug 2003 13:23:40 -0000	1.84
  +++ repository_junit.xml	13 Aug 2003 18:05:35 -0000	1.85
  @@ -3244,6 +3244,28 @@
           />
       </class-descriptor>
   
  +
  +    <class-descriptor
  +      class="org.apache.ojb.broker.sequence.SequenceManagerTest$SMAutoNaming"
  +      table="SM_AUTO_NAMING"
  +    >
  +        <field-descriptor
  +         name="objectId"
  +         column="SM_ID"
  +         jdbc-type="INTEGER"
  +         primarykey="true"
  +         autoincrement="true"
  +
  +        />
  +
  +        <field-descriptor
  +         name="name"
  +         column="NAME"
  +         jdbc-type="VARCHAR"
  +        />
  +    </class-descriptor>
  +
  +
       <!-- NOTE: This test class is specific for hsql, the database table was
       generated at runtime
       -->
  @@ -4439,7 +4461,7 @@
   
       <class-descriptor
       class="org.apache.ojb.broker.AbstractExtentClassTest$XContainer"
  -    table="ABSTRACT_COLLECTION_CONTAINER">
  +    table="XCONTAINER">
           <field-descriptor
           name="id"
           column="OBJ_ID"
  
  
  

---------------------------------------------------------------------
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