db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mattba...@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb/otm CopyTest.java AllTests.java
Date Mon, 07 Jul 2003 22:54:37 GMT
mattbaird    2003/07/07 15:54:37

  Modified:    src/test/org/apache/ojb/otm AllTests.java
  Added:       src/test/org/apache/ojb/otm CopyTest.java
  Log:
  tests for copy strategies
  
  Revision  Changes    Path
  1.8       +1 -0      db-ojb/src/test/org/apache/ojb/otm/AllTests.java
  
  Index: AllTests.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/otm/AllTests.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- AllTests.java	28 Jun 2003 12:48:52 -0000	1.7
  +++ AllTests.java	7 Jul 2003 22:54:37 -0000	1.8
  @@ -35,6 +35,7 @@
           suite.addTest(new TestSuite(LockTestRepeatableReads.class));
           suite.addTest(new TestSuite(LockTestSerializable.class));
           suite.addTest(new TestSuite(SwizzleTests.class));
  +        suite.addTest(new TestSuite(CopyTest.class));
           return suite;
       }
   
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/otm/CopyTest.java
  
  Index: CopyTest.java
  ===================================================================
  package org.apache.ojb.otm;
  /* ====================================================================
   * 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 org.apache.ojb.otm.copy.MetadataObjectCopyStrategy;
  import org.apache.ojb.otm.copy.ObjectCopyStrategy;
  import org.apache.ojb.otm.copy.SerializeObjectCopyStrategy;
  import org.apache.ojb.otm.copy.ReflectiveObjectCopyStrategy;
  import org.apache.ojb.odmg.TestClassA;
  import org.apache.ojb.odmg.TestClassB;
  import org.apache.ojb.broker.*;
  
  /**
   * Created by IntelliJ IDEA.
   * User: matthew.baird
   * Date: Jul 7, 2003
   * Time: 2:10:49 PM
   */
  public class CopyTest extends TestCase
  {
  	private static Class CLASS = CopyTest.class;
  	private PersistenceBroker m_pb;
  	private static final int ITERATIONS = 10000;
  	private ObjectCopyStrategy m_mdcs = new MetadataObjectCopyStrategy();
  	private ObjectCopyStrategy m_scs = new SerializeObjectCopyStrategy();
  	private ObjectCopyStrategy m_rcs = new ReflectiveObjectCopyStrategy();
  
  	public CopyTest(String name)
  	{
  		super(name);
  	}
  
  	public void setUp()
  	{
  		m_pb = PersistenceBrokerFactory.defaultPersistenceBroker();
  	}
  
  	public void tearDown()
  	{
  		m_pb.close();
  	}
  
  	public static void main(String[] args)
  	{
  		String[] arr = {CLASS.getName()};
  		junit.textui.TestRunner.main(arr);
  	}
  
  	public void testMetadataCopy()
  	{
  		TestClassA tca = generateTestData();
  		TestClassB tcb = tca.getB();
  		internalTest(m_mdcs, tca, tcb);
  	}
  
  	public void testSerializedCopy()
  	{
  		TestClassA tca = generateTestData();
  		TestClassB tcb = tca.getB();
  		internalTest(m_scs, tca, tcb);
  	}
  
  	public void testReflectiveCopy()
  	{
  		TestClassA tca = generateTestData();
  		TestClassB tcb = tca.getB();
  		internalTest(m_rcs, tca, tcb);
  	}
  
  	private void internalTest(ObjectCopyStrategy strategy, TestClassA a, TestClassB b)
  	{
  		TestClassA copy = (TestClassA) strategy.copy(a, m_pb.getDescriptorRepository());
  		assertTrue(a != copy);
  		assertTrue(copy.getOid().equals("someoid"));
  		assertTrue(copy.getValue1().equals("abc"));
  		assertTrue(copy.getValue2().equals("123"));
  		assertTrue(copy.getValue3() == 5);
  		assertTrue(copy.getB() != b);
  		assertTrue(copy.getB().getOid().equals("boid"));
  		assertTrue(copy.getB().getValue1().equals("hi there"));
  	}
  
  	public void testMetadataCopy2()
  	{
  		Zoo zoo = generateZoo();
  		internalTest2(m_mdcs, zoo);
  	}
  
  	public void testSerializeCopy2()
  	{
  		Zoo zoo = generateZoo();
  		internalTest2(m_scs, zoo);
  	}
  
  	public void testReflectiveCopy2()
  	{
  		Zoo zoo = generateZoo();
  		internalTest2(m_rcs, zoo);
  	}
  
  	private void internalTest2(ObjectCopyStrategy strategy, Zoo zoo)
  	{
  		Zoo copy = (Zoo) strategy.copy(zoo, m_pb.getDescriptorRepository());
  		assertTrue(zoo != copy);
  		assertTrue(zoo.getAnimals().size() == copy.getAnimals().size());
  	}
  
  	private Zoo generateZoo()
  	{
  		Zoo zoo = new Zoo();
  		Mammal mammal = new Mammal();
  		mammal.setName("molly");
  		mammal.setNumLegs(4);
  		mammal.setAge(55);
  		zoo.addAnimal(mammal);
  		Reptile reptile = new Reptile();
  		reptile.setColor("green");
  		reptile.setName("hubert");
  		reptile.setAge(51);
  		zoo.addAnimal(reptile);
  		return zoo;
  	}
  
  	public void testPerformance()
  	{
  		long start = System.currentTimeMillis();
  		for (int i = 0; i < ITERATIONS; i++)
  		{
  			TestClassA tca = generateTestData();
  			TestClassB tcb = tca.getB();
  			TestClassA copy = (TestClassA) m_scs.copy(tca, m_pb.getDescriptorRepository());
  		}
  		long stop = System.currentTimeMillis();
  		System.out.println("testSerializedCopy took: " + (stop - start));
  		start = System.currentTimeMillis();
  		for (int i = 0; i < ITERATIONS; i++)
  		{
  			TestClassA tca = generateTestData();
  			TestClassB tcb = tca.getB();
  			TestClassA copy = (TestClassA) m_mdcs.copy(tca, m_pb.getDescriptorRepository());
  		}
  		stop = System.currentTimeMillis();
  		System.out.println("testMetadataCopy took: " + (stop - start));
  		start = System.currentTimeMillis();
  		for (int i = 0; i < ITERATIONS; i++)
  		{
  			TestClassA tca = generateTestData();
  			TestClassB tcb = tca.getB();
  			TestClassA copy = (TestClassA) m_rcs.copy(tca, m_pb.getDescriptorRepository());
  		}
  		stop = System.currentTimeMillis();
  		System.out.println("testReflectiveCopy took: " + (stop - start));
  	}
  
  	private TestClassA generateTestData()
  	{
  		TestClassA tca = new TestClassA();
  		tca.setOid("someoid");
  		tca.setValue1("abc");
  		tca.setValue2("123");
  		tca.setValue3(5);
  		TestClassB tcb = new TestClassB();
  		tcb.setOid("boid");
  		tcb.setValue1("hi there");
  		tca.setB(tcb);
  		return tca;
  	}
  }
  
  

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