db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From baser...@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb/broker ExtentAwarePathExpressionsTest.java
Date Fri, 23 May 2003 19:44:25 GMT
baserose    2003/05/23 12:44:25

  Modified:    src/test/org/apache/ojb/broker
                        ExtentAwarePathExpressionsTest.java
  Log:
  Addind test to point out that the wehre clause is not correct when using
  extent aware path expressions. See javadoc .
  
  Revision  Changes    Path
  1.5       +54 -4     db-ojb/src/test/org/apache/ojb/broker/ExtentAwarePathExpressionsTest.java
  
  Index: ExtentAwarePathExpressionsTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/ExtentAwarePathExpressionsTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ExtentAwarePathExpressionsTest.java	13 May 2003 15:23:31 -0000	1.4
  +++ ExtentAwarePathExpressionsTest.java	23 May 2003 19:44:24 -0000	1.5
  @@ -1,13 +1,18 @@
   package org.apache.ojb.broker;
   
  +import java.net.URL;
   import java.util.Iterator;
   import java.util.List;
   
  +import junit.framework.Test;
   import junit.framework.TestCase;
  +import junit.framework.TestSuite;
  +
   import org.apache.ojb.broker.query.Criteria;
   import org.apache.ojb.broker.query.QueryByCriteria;
   
   /**
  + * Tests for extent aware path expressions
    * 
    * @author <a href="leandro@ibnetwork.com.br">Leandro Rodrigo Saad Cruz</a>
    * 
  @@ -15,10 +20,11 @@
    */
   public class ExtentAwarePathExpressionsTest extends TestCase
   {
  -	private static Class CLASS = ExtentAwarePathExpressionsTest.class;
   
  +    /** */
   	private PersistenceBroker broker;
  -	/**
  +	
  +    /**
   	 * 
   	 */
   	public ExtentAwarePathExpressionsTest()
  @@ -26,9 +32,16 @@
   		super();
   	}
   
  +    /**
  +     * You can run the test like a java app 
  +     */
   	public static void main(String[] args)
   	{
  -		String[] arr = { CLASS.getName()};
  +        //OBS: when running this test from eclipse, one must copy the database file to
the directory where 
  +        //u checked out ojb from cvs
  +        URL url = Thread.currentThread().getContextClassLoader().getResource("DB.script");
  +        System.out.println("Hsql database @ :" + url);
  +		String[] arr = {ExtentAwarePathExpressionsTest.class.getName()};
   		junit.textui.TestRunner.main(arr);
   	}
   
  @@ -40,6 +53,19 @@
   		super(testName);
   	}
   
  +    public static Test suite()
  +    {
  +        TestSuite suite = new TestSuite();
  +        suite.addTest(new ExtentAwarePathExpressionsTest("testAddPathClass"));
  +        suite.addTest(new ExtentAwarePathExpressionsTest("testAddPathClasses"));
  +        suite.addTest(new ExtentAwarePathExpressionsTest("testNotNullPathElement"));
  +        suite.addTest(new ExtentAwarePathExpressionsTest("testSetPathClass"));
  +        suite.addTest(new ExtentAwarePathExpressionsTest("testWithoutHintClass1"));
  +        suite.addTest(new ExtentAwarePathExpressionsTest("testWithoutHintClass2"));
  +        return suite;
  +        
  +    }
  +
   	public void setUp() throws PBFactoryException
   	{
   		broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  @@ -108,4 +134,28 @@
           assertEquals(1,content.size());
           assertEquals(10,((Paper)content.get(0)).getId());
       }
  +
  +
  +    /**
  +     * Right query 
  +     * SELECT DISTINCT A0.HEADLINE,A0.ID FROM NEWS A0 
  +     * INNER JOIN CONTENT_QUALIFIER A1 ON A0.ID=A1.CONTENT_ID 
  +     * LEFT OUTER JOIN TOPIC A2 ON A1.QUALIFIER_ID=A2.ID 
  +     * LEFT OUTER JOIN CATEGORY A2E1 ON A1.QUALIFIER_ID=A2E1.ID 
  +     * WHERE (A0.HEADLINE LIKE  'Bra%' ) AND (A2.NAME IS NOT NULL  OR A2E1.NAME IS NOT
NULL) 
  +     */
  +    public void testAddPathClasses()
  +    {
  +        Criteria criteria = new Criteria();
  +        criteria.addLike("headline","Bra%");
  +        criteria.addNotNull("qualifiers.name");
  +        QueryByCriteria query = new QueryByCriteria(BaseContentImpl.class, criteria, true);
  +        query.addPathClass("qualifiers",Qualifier.class);
  +        query.addPathClass("qualifiers",Topic.class);
  +        query.addPathClass("qualifiers",Category.class);
  +        List content = (List) broker.getCollectionByQuery(query);
  +        assertEquals(1,content.size());
  +        assertEquals(3,((News)content.get(0)).getId());
  +    }
  +
   }
  
  
  

Mime
View raw message