db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb repository_junit.xml
Date Fri, 30 Sep 2005 21:48:47 GMT
tomdz       2005/09/30 14:48:47

  Modified:    src/schema ojbtest-schema.xml
               src/test/org/apache/ojb/broker RowReaderTestImpl.java
                        PersistenceBrokerTest.java FactoryTest.java
               src/xdoclet/test/xdoclet/modules/ojb/tests
                        TestRowReader.java
               src/test/org/apache/ojb repository_junit.xml
  Added:       src/test/org/apache/ojb/broker ComplexEnclosingClass.java
                        OuterClass.java InnerClassTest.java
  Log:
  Added tests for the inner class support
  Adapted existing tests to the API changes
  
  Revision  Changes    Path
  1.101     +30 -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.100
  retrieving revision 1.101
  diff -u -r1.100 -r1.101
  --- ojbtest-schema.xml	9 Sep 2005 00:40:09 -0000	1.100
  +++ ojbtest-schema.xml	30 Sep 2005 21:48:37 -0000	1.101
  @@ -1796,4 +1796,33 @@
         	<reference local="superid" foreign="id"/>
       </foreign-key>
     </table>
  +
  +  <table name="OuterClass">
  +    <column name="id" required="true" primaryKey="true" type="INTEGER"/>
  +    <column name="value" type="VARCHAR" size="150"/>
  +  </table>
  +
  +  <table name="InnerClass">
  +    <column name="id" required="true" primaryKey="true" type="INTEGER"/>
  +    <column name="outerid" required="true" type="INTEGER"/>
  +    <column name="value" type="DOUBLE"/>
  +    <foreign-key foreignTable="OuterClass">
  +      	<reference local="outerid" foreign="id"/>
  +    </foreign-key>
  +  </table>
  +
  +  <table name="Level1InnerClass">
  +    <column name="id" required="true" primaryKey="true" type="INTEGER"/>
  +    <column name="value" type="DOUBLE"/>
  +  </table>
  +
  +  <table name="Level3InnerClass">
  +    <column name="id" required="true" primaryKey="true" type="INTEGER"/>
  +    <column name="level1id" required="true" type="INTEGER"/>
  +    <column name="value" type="VARCHAR"/>
  +    <foreign-key foreignTable="Level1InnerClass">
  +      	<reference local="level1id" foreign="id"/>
  +    </foreign-key>
  +  </table>
  +
   </database>
  \ No newline at end of file
  
  
  
  1.6       +2 -2      db-ojb/src/test/org/apache/ojb/broker/RowReaderTestImpl.java
  
  Index: RowReaderTestImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/RowReaderTestImpl.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- RowReaderTestImpl.java	18 Dec 2004 14:01:17 -0000	1.5
  +++ RowReaderTestImpl.java	30 Sep 2005 21:48:39 -0000	1.6
  @@ -27,9 +27,9 @@
        * the implementor of this class must not care for materialiing
        *  references or collection attributes, this is done later!
        */
  -    public Object readObjectFrom(Map row)
  +    public Object readObjectFrom(Map row, Object enclosingObj)
       {
  -        Object result = super.readObjectFrom(row);
  +        Object result = super.readObjectFrom(row, enclosingObj);
           if (result instanceof ArticleWithStockDetail)
           {
               ArticleWithStockDetail art = (ArticleWithStockDetail) result;
  
  
  
  1.53      +0 -31     db-ojb/src/test/org/apache/ojb/broker/PersistenceBrokerTest.java
  
  Index: PersistenceBrokerTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/PersistenceBrokerTest.java,v
  retrieving revision 1.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- PersistenceBrokerTest.java	17 Apr 2005 13:05:04 -0000	1.52
  +++ PersistenceBrokerTest.java	30 Sep 2005 21:48:40 -0000	1.53
  @@ -1514,37 +1514,6 @@
                   d.getArticleName());
       }
   
  -    public void testGetPKEnumerationByConstraints() throws Exception
  -    {
  -        String name = "testGetPKEnumerationByConstraints_" + System.currentTimeMillis();
  -        // 1. ensure there are 0 items matching the query
  -        Criteria criteria = new Criteria();
  -        criteria.addEqualTo("articleName", name);
  -        Query query = QueryFactory.newQuery(Article.class, criteria);
  -        Enumeration en = broker.getPKEnumerationByQuery(ArticlePrimaryKey.class, query);
  -        assertTrue("size of collection should be zero", !en.hasMoreElements());
  -
  -        //2. insert 3 matching items
  -        broker.beginTransaction();
  -        Article a1 = createArticle(null, name);
  -        broker.store(a1);
  -        Article a2 = createArticle(null, name);
  -        broker.store(a2);
  -        Article a3 = createArticle(null, name);
  -        broker.store(a3);
  -        broker.commitTransaction();
  -        // 3. check if all items are found
  -        en = broker.getPKEnumerationByQuery(ArticlePrimaryKey.class, query);
  -        int count = 0;
  -        while (en.hasMoreElements())
  -        {
  -            count++;
  -            Article tmp = readArticleByIdentity(new Integer(((ArticlePrimaryKey) en.nextElement()).id));
  -            assertEquals("should be same value", name, tmp.getArticleName());
  -        }
  -        assertEquals("Iterator should produce 3 items", 3, count);
  -    }
  -
       public void testInsert() throws Exception
       {
           String name = "testInsert_" + System.currentTimeMillis();
  
  
  
  1.6       +2 -2      db-ojb/src/test/org/apache/ojb/broker/FactoryTest.java
  
  Index: FactoryTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/FactoryTest.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- FactoryTest.java	3 Sep 2005 15:28:13 -0000	1.5
  +++ FactoryTest.java	30 Sep 2005 21:48:42 -0000	1.6
  @@ -82,11 +82,11 @@
   
   class TestFactory implements ObjectCreator
   {
  -    public Object newInstance(ClassDescriptor classDesc, Object[] args)
  +    public Object newInstance(ClassDescriptor classDesc, Object[] args, Object enclosingObj)
       {
           return new InitializableObject();
       }
  -    public Object newIdentityInstance(ClassDescriptor classDesc, Object[] args)
  +    public Object newIdentityInstance(ClassDescriptor classDesc, Object[] args, Object
enclosingObj)
       {
           return new InitializableObject();
       }
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/broker/ComplexEnclosingClass.java
  
  Index: ComplexEnclosingClass.java
  ===================================================================
  package org.apache.ojb.broker;
  
  /**
   * Class for testing of the persistence of more complex inner classes structures.
   * This outermost class is not persistent
   */
  public class ComplexEnclosingClass
  {
      // This inner class is persistent
      public class Level1InnerClass
      {
          // This inner class is is not persistent
          public class Level2InnerClass
          {
              // This inner class is persistent
              public class Level3InnerClass
              {
                  private Integer level3Id;
                  private String  value;
  
                  public Level3InnerClass(String value)
                  {
                      this.value = value;
                  }
                  
                  public Level2InnerClass getEnclosing()
                  {
                      return Level2InnerClass.this;
                  }
  
                  public Integer getLevel3Id()
                  {
                      return level3Id;
                  }
  
                  public String getValue()
                  {
                      return value;
                  }
  
                  public void setValue(String value)
                  {
                      this.value = value;
                  }
              }
  
              public Level1InnerClass getEnclosing()
              {
                  return Level1InnerClass.this;
              }
          }
  
          private Integer level1Id;
          private double  value;
  
          public ComplexEnclosingClass getEnclosing()
          {
              return ComplexEnclosingClass.this;
          }
  
          public Integer getLevel1Id()
          {
              return level1Id;
          }
  
          public double getValue()
          {
              return value;
          }
  
          public void setValue(double value)
          {
              this.value = value;
          }
          
      }
  }
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/broker/OuterClass.java
  
  Index: OuterClass.java
  ===================================================================
  package org.apache.ojb.broker;
  
  /**
   * Class for testing of the persistence of inner classes.
   */
  public class OuterClass
  {
      public class InnerClass
      {
          private Integer innerId;
          private double innerValue;
  
          public OuterClass getOuter()
          {
              return OuterClass.this;
          }
  
          public double getInnerValue()
          {
              return innerValue;
          }
  
          public void setInnerValue(double innerValue)
          {
              this.innerValue = innerValue;
          }
  
          public Integer getInnerId()
          {
              return innerId;
          }
          
      }
  
      private Integer outerId;
      private String outerValue;
  
      public String getOuterValue()
      {
          return outerValue;
      }
  
      public void setOuterValue(String outerValue)
      {
          this.outerValue = outerValue;
      }
  
      public Integer getOuterId()
      {
          return outerId;
      }
  }
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/broker/InnerClassTest.java
  
  Index: InnerClassTest.java
  ===================================================================
  package org.apache.ojb.broker;
  
  /* Copyright 2002-2004 The Apache Software Foundation
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  import org.apache.ojb.broker.query.Criteria;
  import org.apache.ojb.junit.PBTestCase;
  
  /**
   * Tests persistence of inner (non-static) classes.
   */
  public class InnerClassTest extends PBTestCase 
  {
      /**
       * Helper method that retrieves the single inner class object from the database.
       * 
       * @return The inner class instance if any
       */
      private OuterClass.InnerClass readInner()
      {
          return (OuterClass.InnerClass)broker.getObjectByQuery(ojb.getQueryFactory().newQuery(OuterClass.InnerClass.class,
(Criteria)null));
      }
  
      /**
       * Helper method that retrieves the single outer class object from the database.
       * 
       * @return The outer class instance if any
       */
      private OuterClass readOuter()
      {
          return (OuterClass)broker.getObjectByQuery(ojb.getQueryFactory().newQuery(OuterClass.class,
(Criteria)null));
      }
  
      /**
       * Tests persistence of a simple inner-outer class model.
       */
      public void _testSimpleModel()
      {
          OuterClass            outer = new OuterClass();
          OuterClass.InnerClass inner = outer.new InnerClass();
  
          outer.setOuterValue("outer");
          inner.setInnerValue(1.0);
  
          // first we test storing
          broker.beginTransaction();
          broker.store(inner);
          broker.commitTransaction();
  
          inner = null;
          outer = null;
          broker.clearCache();
  
          inner = readInner();
          outer = inner.getOuter();
  
          assertEquals("outer",
                       outer.getOuterValue());
          assertEquals(1.0,
                       inner.getInnerValue(),
                       0.0);
  
          // next we test updating
          outer.setOuterValue("new outer");
          inner.setInnerValue(2.0);
          
          broker.beginTransaction();
          broker.store(inner);
          broker.commitTransaction();
  
          inner = null;
          outer = null;
          broker.clearCache();
  
          inner = readInner();
          outer = inner.getOuter();
  
          assertEquals("new outer",
                       outer.getOuterValue());
          assertEquals(2.0,
                       inner.getInnerValue(),
                       0.0);
          
          inner = null;
          outer = null;
          broker.clearCache();
  
          // same query as above, but now we retrieve the outer class first to check for caching
          outer = readOuter();
          inner = readInner();
  
          assertTrue(outer == inner.getOuter());
  
          // lets delete the inner -> this won't delete the outer
          broker.beginTransaction();
          broker.delete(inner);
          broker.commitTransaction();
  
          inner = null;
          outer = null;
          broker.clearCache();
  
          inner = readInner();
          outer = readOuter();
  
          assertNull(inner);
          assertNotNull(outer);
  
          // finally delete the outer
          broker.beginTransaction();
          broker.delete(outer);
          broker.commitTransaction();
      }
  
      /**
       * Helper method that retrieves the single innermost class object from the database.
       * 
       * @return The innermost class instance if any
       */
      private ComplexEnclosingClass.Level1InnerClass.Level2InnerClass.Level3InnerClass readLevel3Inner()
      {
          return (ComplexEnclosingClass.Level1InnerClass.Level2InnerClass.Level3InnerClass)
                      broker.getObjectByQuery(ojb.getQueryFactory().newQuery(
                              ComplexEnclosingClass.Level1InnerClass.Level2InnerClass.Level3InnerClass.class,
                              (Criteria)null));
      }
      
      /**
       * Helper method that retrieves the single level1-inner class object from the database.
       * 
       * @return The class instance if any
       */
      private ComplexEnclosingClass.Level1InnerClass readLevel1Inner()
      {
          return (ComplexEnclosingClass.Level1InnerClass)
                      broker.getObjectByQuery(ojb.getQueryFactory().newQuery(
                              ComplexEnclosingClass.Level1InnerClass.class,
                              (Criteria)null));
      }
  
      /**
       * Tests a more complex inner-outer class model.
       */
      public void testComplexModel()
      {
          ComplexEnclosingClass                                                    rootObj
  = new ComplexEnclosingClass();
          ComplexEnclosingClass.Level1InnerClass                                   level1Obj
= rootObj.new Level1InnerClass();
          ComplexEnclosingClass.Level1InnerClass.Level2InnerClass                  level2Obj
= level1Obj.new Level2InnerClass();
          ComplexEnclosingClass.Level1InnerClass.Level2InnerClass.Level3InnerClass level3Obj
= level2Obj.new Level3InnerClass("deepest");
  
          level1Obj.setValue(-1.5);
  
          // first we test storing
          broker.beginTransaction();
          broker.store(level3Obj);
          broker.commitTransaction();
  
          rootObj   = null;
          level1Obj = null;
          level2Obj = null;
          level3Obj = null;
          broker.clearCache();
          
          level3Obj = readLevel3Inner();
          level1Obj = level3Obj.getEnclosing().getEnclosing();
  
          assertEquals("deepest",
                       level3Obj.getValue());
          assertEquals(-1.5,
                       level1Obj.getValue(),
                       0.0);
  
          // next we test updating
          level3Obj.setValue("really, really deep");
          level1Obj.setValue(10.01);
  
          broker.beginTransaction();
          broker.store(level3Obj);
          broker.commitTransaction();
  
          level3Obj = null;
          broker.clearCache();
  
          level3Obj = readLevel3Inner();
          level1Obj = readLevel1Inner();
  
          assertEquals("really, really deep",
                       level3Obj.getValue());
          assertEquals(10.01,
                       level1Obj.getValue(),
                       0.0);
          assertTrue(level1Obj == level3Obj.getEnclosing().getEnclosing());
  
          // and finally deletion, first of the deepest
          broker.beginTransaction();
          broker.delete(level3Obj);
          broker.commitTransaction();
  
          level1Obj = null;
          level3Obj = null;
          broker.clearCache();
  
          level3Obj = readLevel3Inner();
          level1Obj = readLevel1Inner();
  
          assertNull(level3Obj);
          assertNotNull(level1Obj);
      }
  }
  
  
  
  1.6       +46 -68    db-ojb/src/xdoclet/test/xdoclet/modules/ojb/tests/TestRowReader.java
  
  Index: TestRowReader.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/xdoclet/test/xdoclet/modules/ojb/tests/TestRowReader.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TestRowReader.java	29 Sep 2005 20:36:44 -0000	1.5
  +++ TestRowReader.java	30 Sep 2005 21:48:46 -0000	1.6
  @@ -1,68 +1,46 @@
  -package xdoclet.modules.ojb.tests;
  -
  -/* Copyright 2003-2004 The Apache Software Foundation
  - *
  - * Licensed under the Apache License, Version 2.0 (the "License");
  - * you may not use this file except in compliance with the License.
  - * You may obtain a copy of the License at
  - *
  - *     http://www.apache.org/licenses/LICENSE-2.0
  - *
  - * Unless required by applicable law or agreed to in writing, software
  - * distributed under the License is distributed on an "AS IS" BASIS,
  - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  - * See the License for the specific language governing permissions and
  - * limitations under the License.
  - */
  -
  -import java.sql.ResultSet;
  -import java.util.Map;
  -
  -import org.apache.ojb.broker.accesslayer.ResultSetAndStatement;
  -import org.apache.ojb.broker.accesslayer.RowReader;
  -import org.apache.ojb.broker.core.factory.ObjectCreator;
  -import org.apache.ojb.broker.metadata.ClassDescriptor;
  -
  -/**
  - * Row reader class used in some of the unit tests.
  - */
  -public class TestRowReader implements RowReader
  -{
  -    public ClassDescriptor getClassDescriptor()
  -    {
  -        return null;
  -    }
  -
  -    public void readObjectArrayFrom(ResultSet rs, Map row)
  -    {
  -    }
  -
  -    public Object readObjectFrom(Map row)
  -    {
  -        return null;
  -    }
  -
  -    public void readPkValuesFrom(ResultSet rs, Map row)
  -    {
  -    }
  -
  -    public void refreshObject(Object instance, Map row)
  -    {
  -    }
  -
  -    public void setClassDescriptor(ClassDescriptor cld)
  -    {
  -    }
  -
  -    public void setObjectFactory(ObjectCreator factory)
  -    {
  -    }
  -
  -    public void readObjectArrayFrom(ResultSetAndStatement rs, Map row)
  -    {
  -    }
  -
  -    public void readPkValuesFrom(ResultSetAndStatement rs, Map row)
  -    {
  -    }
  -}
  +package xdoclet.modules.ojb.tests;
  +
  +/* Copyright 2003-2004 The Apache Software Foundation
  + *
  + * Licensed under the Apache License, Version 2.0 (the "License");
  + * you may not use this file except in compliance with the License.
  + * You may obtain a copy of the License at
  + *
  + *     http://www.apache.org/licenses/LICENSE-2.0
  + *
  + * Unless required by applicable law or agreed to in writing, software
  + * distributed under the License is distributed on an "AS IS" BASIS,
  + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  + * See the License for the specific language governing permissions and
  + * limitations under the License.
  + */
  +
  +import java.util.Map;
  +
  +import org.apache.ojb.broker.accesslayer.ResultSetAndStatement;
  +import org.apache.ojb.broker.accesslayer.RowReader;
  +
  +/**
  + * Row reader class used in some of the unit tests.
  + */
  +public class TestRowReader implements RowReader
  +{
  +    private static final long serialVersionUID = -8911480237456496599L;
  +
  +    public void readObjectArrayFrom(ResultSetAndStatement rs, Map row)
  +    {
  +    }
  +
  +    public Object readObjectFrom(Map row, Object enclosingObj)
  +    {
  +        return null;
  +    }
  +
  +    public void readPkValuesFrom(ResultSetAndStatement rs, Map row)
  +    {
  +    }
  +
  +    public void refreshObject(Object instance, Map row)
  +    {
  +    }
  +}
  
  
  
  1.138     +99 -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.137
  retrieving revision 1.138
  diff -u -r1.137 -r1.138
  --- repository_junit.xml	9 Sep 2005 00:40:09 -0000	1.137
  +++ repository_junit.xml	30 Sep 2005 21:48:46 -0000	1.138
  @@ -635,6 +635,104 @@
     		</reference-descriptor>
      </class-descriptor>
   
  +   <class-descriptor
  +   	  class="org.apache.ojb.broker.OuterClass"
  +   	  table="OuterClass"
  +   >
  +      <field-descriptor
  +         name="outerId"
  +         column="id"
  +         jdbc-type="INTEGER"
  +         primarykey="true"
  +         autoincrement="true"
  +      />
  +      <field-descriptor
  +         name="outerValue"
  +         column="value"
  +         jdbc-type="VARCHAR"
  +      />
  +   </class-descriptor>
  +   <class-descriptor
  +   	  class="org.apache.ojb.broker.OuterClass$InnerClass"
  +   	  table="InnerClass"
  +   >
  +      <field-descriptor
  +         name="innerId"
  +         column="id"
  +         jdbc-type="INTEGER"
  +         primarykey="true"
  +         autoincrement="true"
  +      />
  +      <field-descriptor
  +         name="innerValue"
  +         column="value"
  +         jdbc-type="DOUBLE"
  +      />
  +      <field-descriptor
  +         name="outerId"
  +         column="outerid"
  +         jdbc-type="INTEGER"
  +         access="anonymous"
  +      />
  +      <reference-descriptor
  +         name="OuterClass.this"
  +         class-ref="org.apache.ojb.broker.OuterClass"
  +      >
  +         <foreignkey field-ref="outerId"/>
  +      </reference-descriptor>
  +   </class-descriptor>
  +
  +   <class-descriptor
  +   	  class="org.apache.ojb.broker.ComplexEnclosingClass$Level1InnerClass"
  +   	  table="Level1InnerClass"
  +   >
  +      <field-descriptor
  +         name="level1Id"
  +         column="id"
  +         jdbc-type="INTEGER"
  +         primarykey="true"
  +         autoincrement="true"
  +      />
  +      <field-descriptor
  +         name="value"
  +         column="value"
  +         jdbc-type="DOUBLE"
  +      />
  +   </class-descriptor>
  +   <class-descriptor
  +   	  class="org.apache.ojb.broker.ComplexEnclosingClass$Level1InnerClass$Level2InnerClass$Level3InnerClass"
  +   	  table="Level3InnerClass"
  +   >
  +      <creation-descriptor type="constructor">
  +        <parameter field-ref="value" type="java.lang.String"/>
  +      </creation-descriptor>
  +      <field-descriptor
  +         name="level3Id"
  +         column="id"
  +         jdbc-type="INTEGER"
  +         primarykey="true"
  +         autoincrement="true"
  +      />
  +      <field-descriptor
  +         name="value"
  +         column="value"
  +         jdbc-type="VARCHAR"
  +      />
  +      <field-descriptor
  +         name="level1Id"
  +         column="level1id"
  +         jdbc-type="INTEGER"
  +         access="anonymous"
  +      />
  +      <reference-descriptor
  +         name="Level1InnerClass.this"
  +         class-ref="org.apache.ojb.broker.ComplexEnclosingClass$Level1InnerClass"
  +      >
  +         <foreignkey field-ref="level1Id"/>
  +      </reference-descriptor>
  +   </class-descriptor>
  +
  +
   <!-- ===================================================================== -->
   <!-- inner classes of ObjectRepository, e.g. used in AnonymousField tests  -->
   <!-- ===================================================================== -->
  
  
  

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