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 AllTests.java
Date Sat, 26 Jun 2004 00:22:25 GMT
arminw      2004/06/25 17:22:25

  Modified:    src/test/org/apache/ojb/broker AllTests.java
  Added:       src/test/org/apache/ojb/broker/metadata
                        PersistentFieldTest.java
  Log:
  - add new test case for Persistentfield implementations
  
  Revision  Changes    Path
  1.1                  db-ojb/src/test/org/apache/ojb/broker/metadata/PersistentFieldTest.java
  
  Index: PersistentFieldTest.java
  ===================================================================
  package org.apache.ojb.broker.metadata;
  
  import java.util.Collection;
  
  import org.apache.commons.lang.builder.ToStringBuilder;
  import org.apache.commons.lang.builder.ToStringStyle;
  import org.apache.ojb.broker.metadata.fieldaccess.PersistentField;
  import org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldAutoProxyImpl;
  import org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldDirectAccessImpl;
  import org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldDirectAccessImplNew;
  import org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldIntrospectorImpl;
  import org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldPrivilegedImpl;
  import org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldPrivilegedImplNew;
  import org.apache.ojb.broker.util.ClassHelper;
  import org.apache.ojb.junit.OJBTestCase;
  
  /* 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.
   */
  
  /**
   * Test to check the capability of the {@link org.apache.ojb.broker.metadata.fieldaccess.PersistentField}
   * implementations.
   *
   * @author <a href="mailto:arminw@apache.org">Armin Waibel</a>
   * @version $Id: PersistentFieldTest.java,v 1.1 2004/06/26 00:22:25 arminw Exp $
   */
  public class PersistentFieldTest extends OJBTestCase
  {
      Class[] persistentFieldClasses = new Class[]{
          PersistentFieldDirectAccessImpl.class
          , PersistentFieldDirectAccessImplNew.class
          , PersistentFieldIntrospectorImpl.class
          , PersistentFieldPrivilegedImpl.class
          , PersistentFieldPrivilegedImplNew.class
          , PersistentFieldAutoProxyImpl.class};
  
      public static void main(String[] args)
      {
          String[] arr = {PersistentFieldTest.class.getName()};
          junit.textui.TestRunner.main(arr);
      }
  
      public void testDirectAccess() throws Exception
      {
          Class targetClass = PersistentFieldDirectAccessImpl.class;
          PersistentField pfNM_Name = newInstance(targetClass, NestedMain.class, NESTED_MAIN_NAME);
          PersistentField pfNDD_RD = newInstance(targetClass, NestedMain.class, NESTED_DETAIL_DETAIL_REAL_DETAIL);
          // PersistentField pfND_MJB = newInstance(targetClass, NestedMain.class, NESTED_DETAIL_MORE_JAVA_BEAN);
          // PersistentField pfNE_Name = newInstance(targetClass, NestedMain.class, NESTED_ENTRY_NAME);
  
          // test getter
          NestedMain nm = createNestedObject();
          Object result = pfNM_Name.get(nm);
          assertEquals(NESTED_MAIN_NAME_VALUE, result);
          result = pfNDD_RD.get(nm);
          assertEquals(NESTED_DETAIL_DETAIL_REAL_DETAIL_VALUE, result);
  
          NestedMain newNM = new NestedMain();
          // test setter
          pfNM_Name.set(newNM, NESTED_MAIN_NAME_VALUE);
          pfNDD_RD.set(newNM, NESTED_DETAIL_DETAIL_REAL_DETAIL_VALUE);
          result = pfNM_Name.get(newNM);
          assertEquals(NESTED_MAIN_NAME_VALUE, result);
          result = pfNDD_RD.get(newNM);
          assertEquals(NESTED_DETAIL_DETAIL_REAL_DETAIL_VALUE , result);
  
      }
  
      public void testDirectAccessNew() throws Exception
      {
          Class targetClass = PersistentFieldDirectAccessImplNew.class;
          PersistentField pfNM_Name = newInstance(targetClass, NestedMain.class, NESTED_MAIN_NAME);
          PersistentField pfNDD_RD = newInstance(targetClass, NestedMain.class, NESTED_DETAIL_DETAIL_REAL_DETAIL);
          // PersistentField pfND_MJB = newInstance(targetClass, NestedMain.class, NESTED_DETAIL_MORE_JAVA_BEAN);
          // PersistentField pfNE_Name = newInstance(targetClass, NestedMain.class, NESTED_ENTRY_NAME);
  
          // test getter
          NestedMain nm = createNestedObject();
          Object result = pfNM_Name.get(nm);
          assertEquals(NESTED_MAIN_NAME_VALUE, result);
          result = pfNDD_RD.get(nm);
          assertEquals(NESTED_DETAIL_DETAIL_REAL_DETAIL_VALUE, result);
  
          NestedMain newNM = new NestedMain();
          // test setter
          pfNM_Name.set(newNM, NESTED_MAIN_NAME_VALUE);
          pfNDD_RD.set(newNM, NESTED_DETAIL_DETAIL_REAL_DETAIL_VALUE);
          result = pfNM_Name.get(newNM);
          assertEquals(NESTED_MAIN_NAME_VALUE, result);
          result = pfNDD_RD.get(newNM);
          assertEquals(NESTED_DETAIL_DETAIL_REAL_DETAIL_VALUE , result);
  
      }
  
      public void testPrivileged() throws Exception
      {
          Class targetClass = PersistentFieldPrivilegedImpl.class;
          PersistentField pfNM_Name = newInstance(targetClass, NestedMain.class, NESTED_MAIN_NAME);
          PersistentField pfNDD_RD = newInstance(targetClass, NestedMain.class, NESTED_DETAIL_DETAIL_REAL_DETAIL);
          // PersistentField pfND_MJB = newInstance(targetClass, NestedMain.class, NESTED_DETAIL_MORE_JAVA_BEAN);
          // PersistentField pfNE_Name = newInstance(targetClass, NestedMain.class, NESTED_ENTRY_NAME);
  
          // test getter
          NestedMain nm = createNestedObject();
          Object result = pfNM_Name.get(nm);
          assertEquals(NESTED_MAIN_NAME_VALUE, result);
          result = pfNDD_RD.get(nm);
          assertEquals(NESTED_DETAIL_DETAIL_REAL_DETAIL_VALUE, result);
  
          NestedMain newNM = new NestedMain();
          // test setter
          pfNM_Name.set(newNM, NESTED_MAIN_NAME_VALUE);
          pfNDD_RD.set(newNM, NESTED_DETAIL_DETAIL_REAL_DETAIL_VALUE);
          result = pfNM_Name.get(newNM);
          assertEquals(NESTED_MAIN_NAME_VALUE, result);
          result = pfNDD_RD.get(newNM);
          assertEquals(NESTED_DETAIL_DETAIL_REAL_DETAIL_VALUE , result);
  
      }
  
      public void testPrivilegedNew() throws Exception
      {
          Class targetClass = PersistentFieldPrivilegedImplNew.class;
          PersistentField pfNM_Name = newInstance(targetClass, NestedMain.class, NESTED_MAIN_NAME);
          PersistentField pfNDD_RD = newInstance(targetClass, NestedMain.class, NESTED_DETAIL_DETAIL_REAL_DETAIL);
          // PersistentField pfND_MJB = newInstance(targetClass, NestedMain.class, NESTED_DETAIL_MORE_JAVA_BEAN);
          // PersistentField pfNE_Name = newInstance(targetClass, NestedMain.class, NESTED_ENTRY_NAME);
  
          // test getter
          NestedMain nm = createNestedObject();
          Object result = pfNM_Name.get(nm);
          assertEquals(NESTED_MAIN_NAME_VALUE, result);
          result = pfNDD_RD.get(nm);
          assertEquals(NESTED_DETAIL_DETAIL_REAL_DETAIL_VALUE, result);
  
          NestedMain newNM = new NestedMain();
          // test setter
          pfNM_Name.set(newNM, NESTED_MAIN_NAME_VALUE);
          pfNDD_RD.set(newNM, NESTED_DETAIL_DETAIL_REAL_DETAIL_VALUE);
          result = pfNM_Name.get(newNM);
          assertEquals(NESTED_MAIN_NAME_VALUE, result);
          result = pfNDD_RD.get(newNM);
          assertEquals(NESTED_DETAIL_DETAIL_REAL_DETAIL_VALUE , result);
  
      }
  
      public void testIntrospector() throws Exception
      {
          Class targetClass = PersistentFieldIntrospectorImpl.class;
          PersistentField pfNM_Name = newInstance(targetClass, NestedMain.class, NESTED_MAIN_NAME);
          PersistentField pfNDD_RD = newInstance(targetClass, NestedMain.class, NESTED_DETAIL_DETAIL_REAL_DETAIL);
          PersistentField pfND_MJB = newInstance(targetClass, NestedMain.class, NESTED_DETAIL_MORE_JAVA_BEAN);
          PersistentField pfNE_Name = newInstance(targetClass, NestedMain.class, NESTED_ENTRY_NAME);
  
          // test getter
          NestedMain nm = createNestedObject();
          Object result = pfNM_Name.get(nm);
          assertEquals(NESTED_MAIN_NAME_VALUE, result);
          result = pfNDD_RD.get(nm);
          assertEquals(NESTED_DETAIL_DETAIL_REAL_DETAIL_VALUE, result);
  
          result = pfND_MJB.get(nm);
          assertEquals(NESTED_DETAIL_MORE_JAVA_BEAN_VALUE, result);
          result = pfNE_Name.get(nm);
          assertEquals(NESTED_ENTRY_NAME_VALUE, result);
  
          NestedMain newNM = new NestedMain();
          // test setter
          pfNM_Name.set(newNM, NESTED_MAIN_NAME_VALUE);
          pfNDD_RD.set(newNM, NESTED_DETAIL_DETAIL_REAL_DETAIL_VALUE);
          pfND_MJB.set(newNM, NESTED_DETAIL_MORE_JAVA_BEAN_VALUE);
          pfNE_Name.set(newNM, NESTED_ENTRY_NAME_VALUE);
          result = pfNM_Name.get(newNM);
          assertEquals(NESTED_MAIN_NAME_VALUE, result);
          result = pfNDD_RD.get(newNM);
          assertEquals(NESTED_DETAIL_DETAIL_REAL_DETAIL_VALUE , result);
          result = pfND_MJB.get(newNM);
          assertEquals(NESTED_DETAIL_MORE_JAVA_BEAN_VALUE, result);
          result = pfNE_Name.get(newNM);
          assertEquals(NESTED_ENTRY_NAME_VALUE, result);
      }
  
      public void testAutoProxy() throws Exception
      {
          // TODO: fix problem with nested fields
          if(ojbSkipKnownIssueProblem()) return;
          Class targetClass = PersistentFieldAutoProxyImpl.class;
          PersistentField pfNM_Name = newInstance(targetClass, NestedMain.class, NESTED_MAIN_NAME);
          PersistentField pfNDD_RD = newInstance(targetClass, NestedMain.class, NESTED_DETAIL_DETAIL_REAL_DETAIL);
          PersistentField pfND_MJB = newInstance(targetClass, NestedMain.class, NESTED_DETAIL_MORE_JAVA_BEAN);
          PersistentField pfNE_Name = newInstance(targetClass, NestedMain.class, NESTED_ENTRY_NAME);
  
          // test getter
          NestedMain nm = createNestedObject();
          Object result = pfNM_Name.get(nm);
          assertEquals(NESTED_MAIN_NAME_VALUE, result);
          result = pfNDD_RD.get(nm);
          assertEquals(NESTED_DETAIL_DETAIL_REAL_DETAIL_VALUE, result);
  
          result = pfND_MJB.get(nm);
          assertEquals(NESTED_DETAIL_MORE_JAVA_BEAN_VALUE, result);
          result = pfNE_Name.get(nm);
          assertEquals(NESTED_ENTRY_NAME_VALUE, result);
  
          NestedMain newNM = new NestedMain();
          // test setter
          pfNM_Name.set(newNM, NESTED_MAIN_NAME_VALUE);
          pfNDD_RD.set(newNM, NESTED_DETAIL_DETAIL_REAL_DETAIL_VALUE);
          pfND_MJB.set(newNM, NESTED_DETAIL_MORE_JAVA_BEAN_VALUE);
          pfNE_Name.set(newNM, NESTED_ENTRY_NAME_VALUE);
          result = pfNM_Name.get(newNM);
          assertEquals(NESTED_MAIN_NAME_VALUE, result);
          result = pfNDD_RD.get(newNM);
          assertEquals(NESTED_DETAIL_DETAIL_REAL_DETAIL_VALUE , result);
          result = pfND_MJB.get(newNM);
          assertEquals(NESTED_DETAIL_MORE_JAVA_BEAN_VALUE, result);
          result = pfNE_Name.get(newNM);
          assertEquals(NESTED_ENTRY_NAME_VALUE, result);
      }
  
  
  
      private NestedMain createNestedObject()
      {
          NestedEntry ne = new NestedEntry(NESTED_ENTRY_NAME_VALUE);
          NestedDetailDetail ndd = new NestedDetailDetail(NESTED_DETAIL_DETAIL_REAL_DETAIL_VALUE,
null);
          NestedDetail nd = new NestedDetail(ndd);
          nd.setMoreJavaBeans(NESTED_DETAIL_MORE_JAVA_BEAN_VALUE);
          NestedMain main = new NestedMain(NESTED_MAIN_NAME_VALUE, nd);
          main.setNestedEntry(ne);
          main.setJavaBeansField(NESTED_MAIN_JAVA_BEAN_VALUE);
  
          return main;
      }
  
      private PersistentField newInstance(Class pfClass, Class testClass, String fieldName)
throws Exception
      {
          Class[] types = new Class[]{Class.class, String.class};
          Object[] args = new Object[]{testClass, fieldName};
          return (PersistentField) ClassHelper.newInstance(pfClass, types, args);
      }
  
  
      //************************************************************************
      // inner classes - used test classes
      //************************************************************************
  
      static String NESTED_MAIN_NAME = "name";
      static String NESTED_MAIN_NAME_VALUE = "name_value";
  
      static String NESTED_MAIN_JAVA_BEAN = "javaBeansField";
      static String NESTED_MAIN_JAVA_BEAN_VALUE = "javaBeansField_value";
  
      static String NESTED_MAIN_NESTED_ENTRY = "nestedEntry::name";
      static String NESTED_MAIN_NESTED_ENTRY_VALUE = "nestedEntry_value";
  
      static String NESTED_DETAIL_MORE_JAVA_BEAN = "nestedDetail::moreJavaBeans";
      static String NESTED_DETAIL_MORE_JAVA_BEAN_VALUE = "moreJavaBeans_value";
  
      static String NESTED_DETAIL_DETAIL_REAL_DETAIL = "nestedDetail::nestedDetailDetail::realDetailName";
      static String NESTED_DETAIL_DETAIL_REAL_DETAIL_VALUE = "realDetailName_value";
  
      static String NESTED_ENTRY_NAME = "nestedEntry::name";
      static String NESTED_ENTRY_NAME_VALUE = "nestedEntryName_value";
  
  
      public static class NestedMain
      {
          private Long objId;
          private String name;
          private NestedDetail nestedDetail;
          // getter/setter don't have to match field name
          private String javaBeansFieldXXX;
          // getter/setter don't have to match field name
          private NestedEntry nestedEntryXXX;
  
          public NestedMain()
          {
          }
  
          public NestedMain(String name, NestedDetail detail)
          {
              this.name = name;
              this.nestedDetail = detail;
          }
  
          public NestedEntry getNestedEntry()
          {
              return nestedEntryXXX;
          }
  
          public void setNestedEntry(NestedEntry nestedEntry)
          {
              this.nestedEntryXXX = nestedEntry;
          }
  
          public String getJavaBeansField()
          {
              return javaBeansFieldXXX;
          }
  
          public void setJavaBeansField(String javaBeansField)
          {
              this.javaBeansFieldXXX = javaBeansField;
          }
  
          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 NestedDetail getNestedDetail()
          {
              return nestedDetail;
          }
  
          public void setNestedDetail(NestedDetail nestedDetail)
          {
              this.nestedDetail = nestedDetail;
          }
  
          public String toString()
          {
              ToStringBuilder buf = new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE);
              buf.append("objId", objId).
                      append("name", name).
                      append("detail", nestedDetail);
              return buf.toString();
          }
      }
  
      public static class NestedDetail
      {
          private NestedDetailDetail nestedDetailDetail;
          private Collection nestedEntryCollection;
          // getter/setter don't have to match field name
          private String moreJavaBeansXXX;
  
          public NestedDetail()
          {
          }
  
          public String getMoreJavaBeans()
          {
              return moreJavaBeansXXX;
          }
  
          public void setMoreJavaBeans(String moreJavaBeans)
          {
              this.moreJavaBeansXXX = moreJavaBeans;
          }
  
          public Collection getNestedEntryCollection()
          {
              return nestedEntryCollection;
          }
  
          public void setNestedEntryCollection(Collection nestedEntryCollection)
          {
              this.nestedEntryCollection = nestedEntryCollection;
          }
  
          public NestedDetail(NestedDetailDetail detail)
          {
              this.nestedDetailDetail = detail;
          }
  
          public NestedDetailDetail getNestedDetailDetail()
          {
              return nestedDetailDetail;
          }
  
          public void setNestedDetailDetail(NestedDetailDetail nestedDetailDetail)
          {
              this.nestedDetailDetail = nestedDetailDetail;
          }
  
          public String toString()
          {
              ToStringBuilder buf = new ToStringBuilder(this, ToStringStyle.SIMPLE_STYLE);
              buf.append("detail", nestedDetailDetail);
              return buf.toString();
          }
      }
  
      public static class NestedDetailDetail
      {
          private String realDetailName;
          private String realDetailDescription;
  
          public NestedDetailDetail()
          {
          }
  
          public NestedDetailDetail(String realDetailName, String realDetailDescription)
          {
              this.realDetailName = realDetailName;
              this.realDetailDescription = realDetailDescription;
          }
  
          public String getRealDetailName()
          {
              return realDetailName;
          }
  
          public void setRealDetailName(String realDetailName)
          {
              this.realDetailName = realDetailName;
          }
  
          public String getRealDetailDescription()
          {
              return realDetailDescription;
          }
  
          public void setRealDetailDescription(String realDetailDescription)
          {
              this.realDetailDescription = realDetailDescription;
          }
  
          public String toString()
          {
              ToStringBuilder buf = new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE);
              buf.append("realDetailName", realDetailName).
                      append("realDetailDescription", realDetailDescription);
              return buf.toString();
          }
      }
  
      public static class NestedEntry
      {
          private Integer id;
          private Long fkId;
          private String name;
  
          public NestedEntry()
          {
          }
  
          public NestedEntry(String name)
          {
              this.name = name;
          }
  
          public Integer getId()
          {
              return id;
          }
  
          public void setId(Integer id)
          {
              this.id = id;
          }
  
          public Long getFkId()
          {
              return fkId;
          }
  
          public void setFkId(Long fkId)
          {
              this.fkId = fkId;
          }
  
          public String getName()
          {
              return name;
          }
  
          public void setName(String name)
          {
              this.name = name;
          }
      }
  }
  
  
  
  1.49      +2 -0      db-ojb/src/test/org/apache/ojb/broker/AllTests.java
  
  Index: AllTests.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/AllTests.java,v
  retrieving revision 1.48
  retrieving revision 1.49
  diff -u -r1.48 -r1.49
  --- AllTests.java	23 Jun 2004 18:24:17 -0000	1.48
  +++ AllTests.java	26 Jun 2004 00:22:25 -0000	1.49
  @@ -7,6 +7,7 @@
   import org.apache.ojb.broker.metadata.CustomAttributesTest;
   import org.apache.ojb.broker.metadata.MetadataMultithreadedTest;
   import org.apache.ojb.broker.metadata.MetadataTest;
  +import org.apache.ojb.broker.metadata.PersistentFieldTest;
   import org.apache.ojb.broker.metadata.ReadonlyTest;
   import org.apache.ojb.broker.metadata.ReferenceMapTest;
   import org.apache.ojb.broker.metadata.RepositoryElementsTest;
  @@ -97,6 +98,7 @@
           suite.addTestSuite(PathTest.class);
           suite.addTestSuite(PrimaryKeyForeignKeyTest.class);
           suite.addTestSuite(M2NGraphTest.class);
  +        suite.addTestSuite(PersistentFieldTest.class);
           return suite;
       }
   
  
  
  

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