db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb/broker AllTests.java
Date Sun, 10 Oct 2004 15:16:21 GMT
brj         2004/10/10 08:16:21

  Modified:    src/test/org/apache/ojb/broker AllTests.java
  Added:       src/test/org/apache/ojb/broker/accesslayer/sql
                        TableAliasHandlerTest.java
  Log:
  Test-class for TableAliasHandler
  
  Revision  Changes    Path
  1.1                  db-ojb/src/test/org/apache/ojb/broker/accesslayer/sql/TableAliasHandlerTest.java
  
  Index: TableAliasHandlerTest.java
  ===================================================================
  package org.apache.ojb.broker.accesslayer.sql;
  
  import org.apache.ojb.broker.Article;
  import org.apache.ojb.broker.Person;
  import org.apache.ojb.broker.ProductGroup;
  import org.apache.ojb.broker.metadata.ClassDescriptor;
  import org.apache.ojb.broker.query.Criteria;
  import org.apache.ojb.broker.query.QueryByCriteria;
  import org.apache.ojb.broker.query.QueryFactory;
  import org.apache.ojb.junit.PBTestCase;
  
  /**
   * Testing the query API
   */
  public class TableAliasHandlerTest extends PBTestCase
  {
      /**
  	 * BrokerTests constructor comment.
  	 */
      public TableAliasHandlerTest(String name)
      {
          super(name);
      }
  
      public static void main(String[] args)
      {
          String[] arr = {TableAliasHandlerTest.class.getName()};
          junit.textui.TestRunner.main(arr);
      }
  
      private TableAliasHandler createTableAliasHandler(TableAliasHandler parent, QueryByCriteria
query)
      {
          TableAliasHandler ta;
          ClassDescriptor cld;
          
          cld = broker.getDescriptorRepository().getDescriptorFor(query.getSearchClass());
          ta = new TableAliasHandler(parent, query, cld, null);
          
          return ta;
      }
  
      private TableAliasHandler createTableAliasHandler(QueryByCriteria query)
      {
          return createTableAliasHandler(null, query);
      }
  
      
      /**
  	 * test Root Alias
  	 */
      public void testRootAlias()
      {
          Criteria crit = new Criteria();
          QueryByCriteria q = QueryFactory.newQuery(Person.class, crit);
  
          TableAliasHandler ta = createTableAliasHandler(q);
          
          TableAliasHandler.TableAlias root = ta.getRootAlias();
          
          assertNotNull("Root",root);
          assertEquals("DB-Table",root.table,"PERSON");
          assertEquals("Table Alias",root.alias,"A0");
          assertEquals("Search Class", root.cld.getClassOfObject(),Person.class);
          assertTrue("Joins", root.joins.isEmpty());
          assertTrue("Extents", root.extents.isEmpty());
      }
  
      /**
  	 * test Path Root Alias
  	 */
      public void testPathOfRoot()
      {
          Criteria crit = new Criteria();
          QueryByCriteria q = QueryFactory.newQuery(Person.class, crit);
  
          TableAliasHandler ta = createTableAliasHandler(q);
          
          TableAliasHandler.TableAlias root = ta.getTableAlias("",false,null,null,null);
          assertEquals("DB-Table",root.table,"PERSON");
          assertEquals("Table Alias",root.alias,"A0");
          assertEquals("Search Class", root.cld.getClassOfObject(),Person.class);
          assertTrue("Joins", root.joins.isEmpty());
          assertTrue("Extents", root.extents.isEmpty());
          
          assertSame("Root Alias", root, ta.getRootAlias());
      }
  
      /**
  	 * test Joined Alias without extents
  	 */
      public void testJoinedAliasNoExtents()
      {
          Criteria crit = new Criteria();
          crit.addLike("productGroup.groupName","%o%");
          QueryByCriteria q = QueryFactory.newQuery(Article.class, crit);
  
          TableAliasHandler ta = createTableAliasHandler(q);
          
          TableAliasHandler.TableAlias root = ta.getTableAlias("",false,null,null,null);
          assertEquals("DB-Table",root.table,"Artikel");
          assertEquals("Table Alias",root.alias,"A0");
          assertEquals("Search Class", root.cld.getClassOfObject(),Article.class);
          assertEquals("Joins", root.joins.size(),1);
          assertTrue("Extents", root.extents.isEmpty());
  
          TableAliasHandler.TableAlias joined = ta.getTableAlias("productGroup",false,null,null,null);
          assertEquals("DB-Table",joined.table,"Kategorien");
          assertEquals("Table Alias",joined.alias,"A1");
          assertEquals("Search Class", joined.cld.getClassOfObject(),ProductGroup.class);
          assertTrue("Joins", joined.joins.isEmpty());
          assertTrue("Extents", joined.extents.isEmpty());
          
          TableAliasHandler.Join join = (TableAliasHandler.Join)root.joins.get(0);
          assertSame("Left is A0",join.left, root);
          assertSame("Right is A1",join.right, joined);
      }
      
  }
  
  
  
  1.54      +3 -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.53
  retrieving revision 1.54
  diff -u -r1.53 -r1.54
  --- AllTests.java	11 Aug 2004 00:39:45 -0000	1.53
  +++ AllTests.java	10 Oct 2004 15:16:21 -0000	1.54
  @@ -2,6 +2,8 @@
   
   import junit.framework.Test;
   import junit.framework.TestSuite;
  +
  +import org.apache.ojb.broker.accesslayer.sql.TableAliasHandlerTest;
   import org.apache.ojb.broker.cache.LocalCacheTest;
   import org.apache.ojb.broker.cache.ObjectCacheTest;
   import org.apache.ojb.broker.metadata.CustomAttributesTest;
  @@ -37,6 +39,7 @@
       public static Test suite()
       {
           TestSuite suite = new TestSuite();
  +        suite.addTestSuite(TableAliasHandlerTest.class);
           suite.addTestSuite(QueryTest.class);
           suite.addTestSuite(PersistenceBrokerTest.class);
           suite.addTestSuite(BrokerExamples.class);
  
  
  

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