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 ReadonlyTest.java
Date Fri, 30 May 2003 10:25:10 GMT
arminw      2003/05/30 03:25:09

  Modified:    src/test/org/apache/ojb repository_junit.xml
               src/schema ojbtest-schema.xml
  Added:       src/test/org/apache/ojb/broker ReadonlyTest.java
  Log:
  add test case for 'readonly' fields
  
  Revision  Changes    Path
  1.66      +43 -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.65
  retrieving revision 1.66
  diff -u -r1.65 -r1.66
  --- repository_junit.xml	13 May 2003 15:23:30 -0000	1.65
  +++ repository_junit.xml	30 May 2003 10:25:06 -0000	1.66
  @@ -3681,7 +3681,7 @@
   	<class-descriptor class="org.apache.ojb.broker.BaseQualifierImpl">
   	   <extent-class class-ref="org.apache.ojb.broker.Topic"/>
   	   <extent-class class-ref="org.apache.ojb.broker.Category"/>
  -	   <extent-class class-ref="org.apache.ojb.broker.Area"/>	   
  +	   <extent-class class-ref="org.apache.ojb.broker.Area"/>
   	   <field-descriptor id="1" name="id" column="ID" jdbc-type="INTEGER" primarykey="true"/>
   	</class-descriptor>
   
  @@ -3889,5 +3889,47 @@
                   <foreignkey field-ref="gathererId"/>
           </reference-descriptor>
       </class-descriptor>
  +
  +    <!-- ************************************************* -->
  +    <!--      PB 'readonly' attribute tests                -->
  +    <!-- ************************************************* -->
  +    <!--
  +    private Long objId;
  +    private String name;
  +    private String readonlyString;
  +    private Long readonlyLong;
  +    -->
  +    <class-descriptor
  +        class="org.apache.ojb.broker.ReadonlyTest$TestObject"
  +        table="READONLY_TEST">
  +
  +        <field-descriptor
  +            name="objId"
  +            column="OBJ_ID"
  +            jdbc-type="BIGINT"
  +            primarykey="true"
  +            autoincrement="true"
  +        />
  +
  +        <field-descriptor
  +            name="name"
  +            column="NAME"
  +            jdbc-type="VARCHAR"
  +        />
  +
  +        <field-descriptor
  +            name="readonlyString"
  +            column="RO_STRING"
  +            jdbc-type="VARCHAR"
  +        />
  +
  +        <field-descriptor
  +            name="readonlyLong"
  +            column="RO_LONG"
  +            jdbc-type="BIGINT"
  +        />
  +
  +    </class-descriptor>
  +
   
   <!-- Mapping of classes used in junit tests and tutorials ends here -->
  
  
  
  1.35      +12 -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.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- ojbtest-schema.xml	23 May 2003 20:52:01 -0000	1.34
  +++ ojbtest-schema.xml	30 May 2003 10:25:08 -0000	1.35
  @@ -411,7 +411,7 @@
     <!-- Content -->
     <table name="PAPER">
       <column name="ID" required="true" primaryKey="true" type="INTEGER"/>
  -    <column name="HEADLINE" type="VARCHAR" size="50"/>    
  +    <column name="HEADLINE" type="VARCHAR" size="50"/>
       <column name="ISSUEDATE" type="VARCHAR" size="50"/>
       <column name="AUTHOR" type="VARCHAR" size="50"/>
     </table>
  @@ -689,4 +689,15 @@
           <column name="GAT_ID" type="INTEGER"/>
           <column name="EXTENT_NAME" type="VARCHAR" size="150"/>
       </table>
  +
  +    <!-- =================================================== -->
  +    <!-- PB 'readonly' attribute test                        -->
  +    <!-- =================================================== -->
  +    <table name="READONLY_TEST">
  +        <column name="OBJ_ID" required="true" primaryKey="true" type="DECIMAL"/>
  +        <column name="NAME" type="VARCHAR" size="150"/>
  +        <column name="RO_STRING" type="VARCHAR" size="150"/>
  +        <column name="RO_LONG" type="DECIMAL"/>
  +    </table>
  +
   </database>
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/broker/ReadonlyTest.java
  
  Index: ReadonlyTest.java
  ===================================================================
  package org.apache.ojb.broker;
  
  import junit.framework.TestCase;
  
  /**
   *
   * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
   * @version $Id: ReadonlyTest.java,v 1.1 2003/05/30 10:25:08 arminw Exp $
   */
  public class ReadonlyTest extends TestCase
  {
      private PersistenceBroker broker;
  
      public static void main(String[] args)
      {
          String[] arr = {ReadonlyTest.class.getName()};
          junit.textui.TestRunner.main(arr);
      }
  
      public void setUp() throws PBFactoryException
      {
          broker = PersistenceBrokerFactory.defaultPersistenceBroker();
      }
  
      public void tearDown()
      {
          try
          {
              if(broker != null) broker.close();
          }
          catch (PersistenceBrokerException e)
          {
          }
      }
  
      public void testReadonly() throws Exception
      {
          long timestamp = System.currentTimeMillis();
          TestObject obj = new TestObject(null, "readonly test_"+timestamp, "should not persisted",
new Long(timestamp));
          try
          {
              broker.beginTransaction();
              broker.store(obj);
              broker.commitTransaction();
              broker.clearCache();
  
              broker.beginTransaction();
              Identity oid = new Identity(obj, broker);
              TestObject ret_obj = (TestObject) broker.getObjectByIdentity(oid);
              broker.commitTransaction();
  
              assertNotNull(ret_obj);
              assertNotNull(ret_obj.getName());
              assertNull("Field should not be populated", ret_obj.getReadonlyLong());
              assertNull("Field should not be populated", ret_obj.getReadonlyString());
          }
          finally
          {
              if(broker != null) broker.close();
          }
  
  
      }
  
      public static class TestObject
      {
          private Long objId;
          private String name;
          private String readonlyString;
          private Long readonlyLong;
  
          public TestObject()
          {
          }
  
          public TestObject(Long objId, String name, String readonlyString, Long readonlyLong)
          {
              this.objId = objId;
              this.name = name;
              this.readonlyString = readonlyString;
              this.readonlyLong = readonlyLong;
          }
  
          public Long getObjId()
          {
              return objId;
          }
  
          public void setObjId(Long objId)
          {
              this.objId = objId;
          }
  
          public String getName()
          {
              return name;
          }
  
          public void setName(String name)
          {
              this.name = name;
          }
  
          public String getReadonlyString()
          {
              return readonlyString;
          }
  
          public void setReadonlyString(String readonlyString)
          {
              this.readonlyString = readonlyString;
          }
  
          public Long getReadonlyLong()
          {
              return readonlyLong;
          }
  
          public void setReadonlyLong(Long readonlyLong)
          {
              this.readonlyLong = readonlyLong;
          }
      }
  }
  
  
  

Mime
View raw message