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/ejb/org/apache/ojb/ejb CommonTestClient.java VOHelper.java CategoryVO.java ArticleVO.java ArticleManagerPBBean.java AllTests.java
Date Tue, 03 Jun 2003 00:05:37 GMT
arminw      2003/06/02 17:05:37

  Modified:    src/ejb/org/apache/ojb/ejb VOHelper.java CategoryVO.java
                        ArticleVO.java ArticleManagerPBBean.java
                        AllTests.java
  Added:       src/ejb/org/apache/ojb/ejb CommonTestClient.java
  Log:
  add new test case using references
  
  Revision  Changes    Path
  1.6       +12 -2     db-ojb/src/ejb/org/apache/ojb/ejb/VOHelper.java
  
  Index: VOHelper.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/ejb/org/apache/ojb/ejb/VOHelper.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- VOHelper.java	10 Jan 2003 16:52:22 -0000	1.5
  +++ VOHelper.java	3 Jun 2003 00:05:37 -0000	1.6
  @@ -88,11 +88,21 @@
   
       public static ArticleVO createNewArticle(int counter)
       {
  +        return createNewArticle("A simple test article ", counter);
  +    }
  +
  +    public static ArticleVO createNewArticle(String name, int counter)
  +    {
           ArticleVO a = new ArticleVO();
  -        a.setName("New Performance Article " + counter);
  +        a.setName(name);
           a.setPrice(new BigDecimal(0.45d * counter));
  -        a.setDescription("description " + counter);
  +        a.setDescription("test article description " + counter);
           return a;
  +    }
  +
  +    public static CategoryVO createNewCategory(String name)
  +    {
  +        return new CategoryVO(null, name, "this is a test category");
       }
   
       public static PersonVO createNewPerson(int counter)
  
  
  
  1.2       +13 -12    db-ojb/src/ejb/org/apache/ojb/ejb/CategoryVO.java
  
  Index: CategoryVO.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/ejb/org/apache/ojb/ejb/CategoryVO.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CategoryVO.java	10 Jan 2003 16:52:22 -0000	1.1
  +++ CategoryVO.java	3 Jun 2003 00:05:37 -0000	1.2
  @@ -3,6 +3,7 @@
   import org.apache.commons.lang.builder.ToStringBuilder;
   import org.apache.commons.lang.builder.ToStringStyle;
   
  +import java.io.Serializable;
   import java.util.Collection;
   
   /**
  @@ -10,16 +11,16 @@
    * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
    * @version $Id$
    */
  -public class CategoryVO
  +public class CategoryVO implements Serializable
   {
  -    private Integer categoryId;
  +    private Integer objId;
       private String categoryName;
       private String description;
       private Collection assignedArticles;
   
       public CategoryVO(Integer categoryId, String categoryName, String description)
       {
  -        this.categoryId = categoryId;
  +        this.objId = categoryId;
           this.categoryName = categoryName;
           this.description = description;
       }
  @@ -38,14 +39,14 @@
           this.assignedArticles = assignedArticles;
       }
   
  -    public Integer getCategoryId()
  +    public Integer getObjId()
       {
  -        return categoryId;
  +        return objId;
       }
   
  -    public void setCategoryId(Integer categoryId)
  +    public void setObjId(Integer objId)
       {
  -        this.categoryId = categoryId;
  +        this.objId = objId;
       }
   
       public String getCategoryName()
  @@ -71,10 +72,10 @@
       public String toString()
       {
           ToStringBuilder buf = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE);
  -        buf.append("categoryId", categoryId).
  -        append("categoryName", categoryName).
  -        append("description", description).
  -        append("assignedArticles", assignedArticles);
  +        buf.append("objId", objId).
  +                append("categoryName", categoryName).
  +                append("description", description).
  +                append("assignedArticles", assignedArticles);
           return buf.toString();
       }
   }
  
  
  
  1.2       +8 -9      db-ojb/src/ejb/org/apache/ojb/ejb/ArticleVO.java
  
  Index: ArticleVO.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/ejb/org/apache/ojb/ejb/ArticleVO.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ArticleVO.java	10 Jan 2003 16:52:22 -0000	1.1
  +++ ArticleVO.java	3 Jun 2003 00:05:37 -0000	1.2
  @@ -1,10 +1,9 @@
   package org.apache.ojb.ejb;
   
   import org.apache.commons.lang.builder.ToStringBuilder;
  -import org.apache.commons.lang.builder.ToStringStyle;
   
  -import java.math.BigDecimal;
   import java.io.Serializable;
  +import java.math.BigDecimal;
   
   /**
    *
  @@ -95,13 +94,13 @@
   
       public String toString()
       {
  -        ToStringBuilder buf = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE);
  +        ToStringBuilder buf = new ToStringBuilder(this);
           buf.append("articleId", articleId).
  -        append("name", name).
  -        append("description", description).
  -        append("price", price).
  -        append("categoryId", categoryId).
  -        append("category", category);
  +                append("name", name).
  +                append("description", description).
  +                append("price", price).
  +                append("categoryId", categoryId).
  +                append("category", category);
           return buf.toString();
       }
   }
  
  
  
  1.6       +31 -2     db-ojb/src/ejb/org/apache/ojb/ejb/ArticleManagerPBBean.java
  
  Index: ArticleManagerPBBean.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/ejb/org/apache/ojb/ejb/ArticleManagerPBBean.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ArticleManagerPBBean.java	10 Jan 2003 16:52:22 -0000	1.5
  +++ ArticleManagerPBBean.java	3 Jun 2003 00:05:37 -0000	1.6
  @@ -109,6 +109,14 @@
       /**
        * @ejb:interface-method
        */
  +    public CategoryVO storeCategory(CategoryVO category)
  +    {
  +        return (CategoryVO) this.storeObject(category);
  +    }
  +
  +    /**
  +     * @ejb:interface-method
  +     */
       public Collection storeArticles(Collection articles)
       {
           return this.storeObjects(articles);
  @@ -166,9 +174,30 @@
           PersistenceBroker broker = getBroker();
           Criteria criteria = new Criteria();
           if (articleName != null) criteria.addEqualTo("articleName", articleName);
  -        Query q = new QueryByCriteria(ArticleVO.class, null);
  +        Query q = new QueryByCriteria(ArticleVO.class, criteria);
           Collection result = broker.getCollectionByQuery(q);
           broker.close();
  +        return result;
  +    }
  +
  +    /**
  +     * @ejb:interface-method
  +     */
  +    public Collection getCategoryByName(String categoryName)
  +    {
  +        PersistenceBroker broker = getBroker();
  +        Collection result;
  +        try
  +        {
  +            Criteria criteria = new Criteria();
  +            if (categoryName != null) criteria.addEqualTo("categoryName", categoryName);
  +            Query q = new QueryByCriteria(CategoryVO.class, criteria);
  +            result = broker.getCollectionByQuery(q);
  +        }
  +        finally
  +        {
  +            if (broker != null) broker.close();
  +        }
           return result;
       }
   }
  
  
  
  1.4       +2 -1      db-ojb/src/ejb/org/apache/ojb/ejb/AllTests.java
  
  Index: AllTests.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/ejb/org/apache/ojb/ejb/AllTests.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AllTests.java	10 Jan 2003 11:33:09 -0000	1.3
  +++ AllTests.java	3 Jun 2003 00:05:37 -0000	1.4
  @@ -82,6 +82,7 @@
           suite.addTest(new TestSuite(ODMGClient.class));
           suite.addTest(new TestSuite(PersonArticleClient.class));
           suite.addTest(new TestSuite(PersonArticleClientODMG.class));
  +        suite.addTest(new TestSuite(CommonTestClient.class));
           return suite;
       }
   }
  
  
  
  1.1                  db-ojb/src/ejb/org/apache/ojb/ejb/CommonTestClient.java
  
  Index: CommonTestClient.java
  ===================================================================
  package org.apache.ojb.ejb;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache ObjectRelationalBridge" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache ObjectRelationalBridge", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import junit.framework.TestCase;
  
  import javax.ejb.EJBHome;
  import javax.rmi.PortableRemoteObject;
  import java.util.ArrayList;
  import java.util.Collection;
  
  /**
   * Common test client class.
   *
   * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
   * @version $Id: CommonTestClient.java,v 1.1 2003/06/03 00:05:37 arminw Exp $
   */
  public class CommonTestClient extends TestCase
  {
      ArticleManagerPBRemote articleBean;
  
      public CommonTestClient(String s)
      {
          super(s);
      }
  
      public CommonTestClient()
      {
          super(CommonTestClient.class.getName());
      }
  
      public static void main(String[] args)
      {
          String[] arr = {CommonTestClient.class.getName()};
          junit.textui.TestRunner.main(arr);
      }
  
      public void testCollectionRetrieve() throws Exception
      {
          long timestamp = System.currentTimeMillis();
          String name = "collection_test_" + timestamp;
          CategoryVO cat = VOHelper.createNewCategory("category_" + timestamp);
          // store new category
          cat = articleBean.storeCategory(cat);
          ArrayList articles = new ArrayList();
          for (int i = 0; i < 5; i++)
          {
              ArticleVO art = VOHelper.createNewArticle(name, 1);
              // set category
              art.setCategory(cat);
              // store article
              art = articleBean.storeArticle(art);
              articles.add(art);
          }
          // set article collection
          cat.setAssignedArticles(articles);
          // persist updated category
          cat = articleBean.storeCategory(cat);
          assertNotNull(cat.getObjId());
          assertNotNull(cat.getAssignedArticles());
          assertEquals("Wrong number of referenced articles found", 5, cat.getAssignedArticles().size());
  
          Collection result = articleBean.getCategoryByName("category_" + timestamp);
          assertNotNull(result);
          assertEquals(1, result.size());
          cat = (CategoryVO) result.iterator().next();
          Collection articlesCol = cat.getAssignedArticles();
          assertNotNull(articlesCol);
          assertEquals("Wrong number of referenced articles found", 5, articlesCol.size());
      }
  
      protected void setUp() throws Exception
      {
          super.setUp();
          init();
      }
  
      protected void init() throws Exception
      {
          try
          {
              Object object = PortableRemoteObject.narrow(
                      ContextHelper.getContext().lookup(ArticleManagerPBHome.JNDI_NAME), EJBHome.class);
              articleBean = (ArticleManagerPBRemote) ((ArticleManagerPBHome) object).create();
              System.out.println("Bean found: " + articleBean);
          }
          catch (Exception e)
          {
              e.printStackTrace();
              throw e;
          }
      }
  
  }
  
  
  

Mime
View raw message