db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb/broker NestedFieldsTest.java ArticleWithNestedStockDetail.java StockDetail.java AllTests.java
Date Mon, 30 Jun 2003 21:16:04 GMT
thma        2003/06/30 14:16:04

  Modified:    src/test/org/apache/ojb/broker StockDetail.java
                        AllTests.java
  Added:       src/test/org/apache/ojb/broker NestedFieldsTest.java
                        ArticleWithNestedStockDetail.java
  Log:
  add testcase for Nested attributes
  
  Revision  Changes    Path
  1.2       +99 -1     db-ojb/src/test/org/apache/ojb/broker/StockDetail.java
  
  Index: StockDetail.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/StockDetail.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StockDetail.java	20 Jun 2002 17:07:50 -0000	1.1
  +++ StockDetail.java	30 Jun 2003 21:16:04 -0000	1.2
  @@ -15,6 +15,11 @@
   
       private ArticleWithStockDetail myArticle;
   
  +	public StockDetail()
  +	{
  +		
  +	}
  +
       public StockDetail(boolean sellout, int minimum, int ordered, int stock, String unit,
ArticleWithStockDetail parent)
       {
           isSelloutArticle = sellout;
  @@ -35,6 +40,99 @@
       {
           stock = newStock;
           // we must keep the detail object in sync with the parent:
  -        myArticle.stock = newStock;
  +        if (myArticle != null)
  +        {
  +        	myArticle.stock = newStock;
  +        }
  +    }
  +    /**
  +     * Returns the isSelloutArticle.
  +     * @return boolean
  +     */
  +    public boolean isSelloutArticle()
  +    {
  +        return isSelloutArticle;
  +    }
  +
  +    /**
  +     * Returns the minimumStock.
  +     * @return int
  +     */
  +    public int getMinimumStock()
  +    {
  +        return minimumStock;
  +    }
  +
  +    /**
  +     * Returns the myArticle.
  +     * @return ArticleWithStockDetail
  +     */
  +    public ArticleWithStockDetail getMyArticle()
  +    {
  +        return myArticle;
  +    }
  +
  +    /**
  +     * Returns the orderedUnits.
  +     * @return int
  +     */
  +    public int getOrderedUnits()
  +    {
  +        return orderedUnits;
  +    }
  +
  +    /**
  +     * Returns the unit.
  +     * @return String
  +     */
  +    public String getUnit()
  +    {
  +        return unit;
  +    }
  +
  +    /**
  +     * Sets the isSelloutArticle.
  +     * @param isSelloutArticle The isSelloutArticle to set
  +     */
  +    public void setIsSelloutArticle(boolean isSelloutArticle)
  +    {
  +        this.isSelloutArticle = isSelloutArticle;
  +    }
  +
  +    /**
  +     * Sets the minimumStock.
  +     * @param minimumStock The minimumStock to set
  +     */
  +    public void setMinimumStock(int minimumStock)
  +    {
  +        this.minimumStock = minimumStock;
  +    }
  +
  +    /**
  +     * Sets the myArticle.
  +     * @param myArticle The myArticle to set
  +     */
  +    public void setMyArticle(ArticleWithStockDetail myArticle)
  +    {
  +        this.myArticle = myArticle;
       }
  +
  +    /**
  +     * Sets the orderedUnits.
  +     * @param orderedUnits The orderedUnits to set
  +     */
  +    public void setOrderedUnits(int orderedUnits)
  +    {
  +        this.orderedUnits = orderedUnits;
  +    }
  +
  +    /**
  +     * Sets the unit.
  +     * @param unit The unit to set
  +     */
  +    public void setUnit(String unit)
  +    {
  +        this.unit = unit;
  +    }
  +
   }
  
  
  
  1.33      +1 -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.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- AllTests.java	19 Jun 2003 20:02:14 -0000	1.32
  +++ AllTests.java	30 Jun 2003 21:16:04 -0000	1.33
  @@ -82,6 +82,7 @@
           suite.addTest(new TestSuite(AnonymousFieldsTest.class));
           suite.addTest(new TestSuite(AbstractExtentClassTest.class));
           suite.addTest(new TestSuite(MtoNTest.class));
  +        suite.addTest(new TestSuite(NestedFieldsTest.class));
           return suite;
       }
   
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/broker/NestedFieldsTest.java
  
  Index: NestedFieldsTest.java
  ===================================================================
  package org.apache.ojb.broker;
  
  import junit.framework.TestCase;
  import org.apache.ojb.broker.metadata.fieldaccess.PersistentNestedFieldMaxPerformanceImpl;
  import org.apache.ojb.broker.util.configuration.impl.OjbConfiguration;
  
  
  /**
   * This TestCase checks the NestedField support
   * @author Thomas Mahler
   */
  public class NestedFieldsTest extends TestCase
  {
  
  	private Class normalPersistentFieldClass;
      PersistenceBroker broker;
      public NestedFieldsTest(String name)
      {
          super(name);
      }
  
      /**
       * launches the TestCase.
       */
      public static void main(String[] args)
      {
  
          String[] arr = {NestedFieldsTest.class.getName()};
          junit.textui.TestRunner.main(arr);
      }
  
      /**
       * Setting up the test fixture.
       */
      public void setUp()
      {
          try
          {
              // obtain broker instance
              broker = PersistenceBrokerFactory.defaultPersistenceBroker();
              // manipulate configuration to use proper field access
              OjbConfiguration conf = (OjbConfiguration) PersistenceBrokerFactory.
                      getConfigurator().getConfigurationFor(null);
              normalPersistentFieldClass = conf.getPersistentFieldClass();
              conf.setPersistentFieldClass(PersistentNestedFieldMaxPerformanceImpl.class);
          }
          catch (PBFactoryException e)
          {
          }
  
      }
  
      /**
       * tearing down the test fixture.
       */
      public void tearDown()
      {
          try
          {            
              // manipulate configuration to reset field access
              OjbConfiguration conf = (OjbConfiguration) PersistenceBrokerFactory.
                      getConfigurator().getConfigurationFor(null);
              conf.setPersistentFieldClass(normalPersistentFieldClass);
          }
          catch (PBFactoryException e)
          {
          }    	
          broker.close();
      }
  
  	public void testLoading()
  	{
  		ArticleWithNestedStockDetail article = new ArticleWithNestedStockDetail();
  		article.setArticleName("an article with a stock detail");
  		article.setPrice(23);
  		article.setProductGroupId(1);
  		
  		StockDetail detail = new StockDetail();
  		detail.setStock(500);
  		detail.setIsSelloutArticle(true);
  		detail.setMinimumStock(100);
  		detail.setOrderedUnits(0);
  		detail.setUnit("bottle");
  		
  		article.setStockDetail(detail);
  		
  		broker.beginTransaction();
  		broker.store(article);
  		Identity oid = new Identity(article, broker);
  		broker.commitTransaction();
  		
  		broker.clearCache();
  		ArticleWithNestedStockDetail copy = null;
  		StockDetail detailCopy = null;
  		broker.beginTransaction();
  		copy = (ArticleWithNestedStockDetail) broker.getObjectByIdentity(oid);
  		detailCopy = copy.getStockDetail();
  		
  		assertEquals(detail.getStock(), detailCopy.getStock());	
  			
  	}
  
  }
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/broker/ArticleWithNestedStockDetail.java
  
  Index: ArticleWithNestedStockDetail.java
  ===================================================================
  package org.apache.ojb.broker;
  
  public class ArticleWithNestedStockDetail implements java.io.Serializable
  {
      /** maps to db-column "Artikel-Nr";INT;PrimaryKey*/
      protected int articleId;
      /** maps to db-column Artikelname;CHAR*/
      protected String articleName;
   
      /** this attribute is not filled through a reference lookup but with a RowReader !*/
      protected StockDetail stockDetail;
  
  
      /** maps to db-column Einzelpreis;DECIMAL*/
      protected double price;
      /** maps to db-column Kategorie-Nr;INT*/
      protected int productGroupId;
      /** maps to db-column Lieferanten-Nr;INT*/
      protected int supplierId;
  
      /** increase the amount of articles in stock by diff*/
      public void addToStock(int diff)
      {
          stockDetail.stock += diff;
      }
  
      /**
       * return an articles unique id.
       * @return int the articles unique id
       */
      public int getArticleId()
      {
          return articleId;
      }
  
      /**
       * return an articles name.
       * @return java.lang.String
       */
      public String getArticleName()
      {
          return articleName;
      }
  
      /** return an articles ProductGroup*/
  
      public double getStockValue()
      {
          return price * stockDetail.getStock();
      }
  
      /**
       * set an articles unique id.
       * @param newArticleId int
       */
      public void setArticleId(int newArticleId)
      {
          articleId = newArticleId;
      }
  
      /**
       * set an articles name.
       * @param newArticleName java.lang.String
       */
      public void setArticleName(String newArticleName)
      {
          articleName = newArticleName;
      }
  
      /**
       * Insert the method's description here.
       * Creation date: (05.01.2001 19:31:04)
       */
      public ArticleWithNestedStockDetail()
      {
      }
  
      /**
       * Insert the method's description here.
       * Creation date: (10.12.2000 14:40:04)
       * @return double
       */
      public double getPrice()
      {
          return price;
      }
  
  
      /**
       * Insert the method's description here.
       * Creation date: (10.12.2000 14:40:04)
       * @return int
       */
      public int getProductGroupId()
      {
          return productGroupId;
      }
  
  
      /**
       * Insert the method's description here.
       * Creation date: (10.12.2000 14:40:04)
       * @return int
       */
      public int getSupplierId()
      {
          return supplierId;
      }
  
  
      /**
       * Insert the method's description here.
       * Creation date: (10.12.2000 14:40:04)
       * @param newPrice double
       */
      public void setPrice(double newPrice)
      {
          price = newPrice;
      }
  
  
      /**
       * Insert the method's description here.
       * Creation date: (10.12.2000 14:40:04)
       * @param newProductGroupId int
       */
      public void setProductGroupId(int newProductGroupId)
      {
          productGroupId = newProductGroupId;
      }
  
  
      /**
       * Insert the method's description here.
       * Creation date: (10.12.2000 14:40:04)
       * @param newSupplierId int
       */
      public void setSupplierId(int newSupplierId)
      {
          supplierId = newSupplierId;
      }
  
  
      public StockDetail getDetail()
      {
          return stockDetail;
      }
  
  
      /**
       * Returns the stockDetail.
       * @return StockDetail
       */
      public StockDetail getStockDetail()
      {
          return stockDetail;
      }
  
      /**
       * Sets the stockDetail.
       * @param stockDetail The stockDetail to set
       */
      public void setStockDetail(StockDetail stockDetail)
      {
          this.stockDetail = stockDetail;
      }
  
  }
  
  
  

Mime
View raw message