commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From froehl...@apache.org
Subject cvs commit: jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore TestStore.java TestSoftRefMemoryStore.java TestSample.java TestPersistent.java TestObject.java TestAll.java
Date Sat, 09 Feb 2002 18:57:05 GMT
froehlich    02/02/09 10:57:05

  Modified:    simplestore/src/test/org/apache/commons/simplestore
                        TestStore.java TestSoftRefMemoryStore.java
                        TestSample.java TestPersistent.java TestObject.java
                        TestAll.java
  Log:
  added full license and reformated with jedit's JavaStyle
  
  Revision  Changes    Path
  1.2       +79 -27    jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore/TestStore.java
  
  Index: TestStore.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore/TestStore.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestStore.java	21 Jan 2002 22:02:25 -0000	1.1
  +++ TestStore.java	9 Feb 2002 18:57:05 -0000	1.2
  @@ -1,59 +1,111 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -
  +/*
  + * 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 Cocoon" and "Apache Software Foundation" 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",
  + *    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/>.
  + */
  + 
   package org.apache.commons.simplestore;
   
  -import junit.framework.*;
  -import java.util.Map;
   import java.util.Collection;
  +import java.util.Map;
  +import junit.framework.*;
   
   /**
  - * @author Gerhard Froehlich <a href="mailto:g-froehlich@gmx.de">
  + *@author     Gerhard Froehlich <a href="mailto:g-froehlich@gmx.de">
    *      g-froehlich@gmx.de</a>
  - *
  - * @version $Id: TestStore.java,v 1.1 2002/01/21 22:02:25 froehlich Exp $
  + *@version    $Id: TestStore.java,v 1.2 2002/02/09 18:57:05 froehlich Exp $
    */
   public abstract class TestStore extends TestObject {
  -  
  +
  +    protected Store store = null;
  +
       public TestStore(String testName) {
           super(testName);
       }
  -    
  -    protected Store store = null;
   
       /**
        * Return a new, empty {@link Map} to used for testing.
  +     *
  +     *@return
        */
       public abstract Store makeStore();
   
       public Object makeObject() {
           return makeStore();
       }
  - 
  +
       /**
        * Try to put the given pair into the given Collection.
        *
        * Fails any Throwable except UnsupportedOperationException,
        * ClassCastException, or IllegalArgumentException
        * or NullPointerException is thrown.
  +     *
  +     *@param  store
  +     *@param  key
  +     *@param  val
        */
       protected void tryToPut(Store store, Object key, Object val) {
           try {
  -            store.put(key,val);
  -        } catch(UnsupportedOperationException e) {
  -            
  -        } catch(ClassCastException e) {
  -            
  -        } catch(IllegalArgumentException e) {
  -            
  -        } catch(NullPointerException e) {
  -            
  -        } catch(Throwable t) {
  +            store.put(key, val);
  +        } catch (UnsupportedOperationException e) {
  +
  +        } catch (ClassCastException e) {
  +
  +        } catch (IllegalArgumentException e) {
  +
  +        } catch (NullPointerException e) {
  +
  +        } catch (Throwable t) {
               t.printStackTrace();
               fail("Store.put should only throw UnsupportedOperationException, ClassCastException,
IllegalArgumentException or NullPointerException. Found " + t.toString());
           }
  
  
  
  1.8       +145 -91   jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore/TestSoftRefMemoryStore.java
  
  Index: TestSoftRefMemoryStore.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore/TestSoftRefMemoryStore.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- TestSoftRefMemoryStore.java	27 Jan 2002 17:42:00 -0000	1.7
  +++ TestSoftRefMemoryStore.java	9 Feb 2002 18:57:05 -0000	1.8
  @@ -1,131 +1,185 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -
  +/*
  + * 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 Cocoon" and "Apache Software Foundation" 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",
  + *    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/>.
  + */
   package org.apache.commons.simplestore;
   
  +import java.util.HashMap;
  +import java.util.Map;
   import junit.framework.Test;
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
  -import java.util.Map;
  -import java.util.HashMap;
   
   /**
  - * @author Gerhard Froehlich <a href="mailto:g-froehlich@gmx.de">
  + *@author     Gerhard Froehlich <a href="mailto:g-froehlich@gmx.de">
    *      g-froehlich@gmx.de</a>
  - * @author Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
  + *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - * @version $Id: TestSoftRefMemoryStore.java,v 1.7 2002/01/27 17:42:00 froehlich Exp $
  + *@version    $Id: TestSoftRefMemoryStore.java,v 1.8 2002/02/09 18:57:05 froehlich Exp
$
    */
   public class TestSoftRefMemoryStore extends TestStore {
  -    
  +
       private final int ITERATIONS = 200;
       private final int MAX_STRONG_REFS = 10;
       private final int ITEM_SIZE = 0xFFFF;
  -    
  -    
  +
  +
       public TestSoftRefMemoryStore(String testName) {
           super(testName);
       }
  -    
  +
       public static Test suite() {
           return new TestSuite(TestSoftRefMemoryStore.class);
       }
  -    
  +
       public static void main(String args[]) {
  -        String[] testCaseName = { TestSoftRefMemoryStore.class.getName() };
  +        String[] testCaseName = {TestSoftRefMemoryStore.class.getName()};
           junit.textui.TestRunner.main(testCaseName);
       }
  -    
  +
       public Store makeStore() {
  -        Swap swap = new Swap(){
  -             // this means GC decided memory is low and
  -            // SoftRefMemoryStore decided object is "old"
  -            // value wrapper calls this method from finalize
  -            // Queue implementation can write object to swap here
  -            // It can use JMS to send Object Message
  -            public void add(Object key , Reachable object ){
  -                System.out.println( key + " Object added to swap " + object.toString().substring(0,20));
  -            }
  -            // do nothing at this time, becouse we added no object to Qeue at this time
  -            // Queue implementation can add objects to Batch, then this method can be usd
to test Queue
  -            // It can use Thread in stand alone application to execute Batch
  -            
  -         
  -        };
  -        SoftRefMemoryStore store = new SoftRefMemoryStore(new MRUMap(ITERATIONS),swap,MAX_STRONG_REFS
);
  +        Swap swap =
  +            new Swap() {
  +                // this means GC decided memory is low and
  +                // SoftRefMemoryStore decided object is "old"
  +                // value wrapper calls this method from finalize
  +                // Queue implementation can write object to swap here
  +                // It can use JMS to send Object Message
  +                public void add(Object key, Reachable object) {
  +                    System.out.println(key + " Object added to swap " + object.toString().substring(0,
20));
  +                }
  +                // do nothing at this time, becouse we added no object to Qeue at this
time
  +                // Queue implementation can add objects to Batch, then this method can
be usd to test Queue
  +                // It can use Thread in stand alone application to execute Batch
  +
  +
  +            };
  +        SoftRefMemoryStore store = new SoftRefMemoryStore(new MRUMap(ITERATIONS), swap,
MAX_STRONG_REFS);
           return store;
       }
  -    
  -    public void testSwaping(){
  -        
  -        assertTrue("try to set ITERATIONS > MAX_STRONG_REFS ", ITERATIONS > MAX_STRONG_REFS
);
  -        
  -        char[] testObject = new char[ ITEM_SIZE/2 + 1  ];
  -        java.util.Arrays.fill(testObject,'.');
  +
  +    public void testSwaping() {
  +
  +        assertTrue("try to set ITERATIONS > MAX_STRONG_REFS ", ITERATIONS > MAX_STRONG_REFS);
  +
  +        char[] testObject = new char[ITEM_SIZE / 2 + 1];
  +        java.util.Arrays.fill(testObject, '.');
           Object key = new Integer(0);
  -        Object value =  new String(testObject);
  +        Object value = new String(testObject);
           ValueObject valueObj = new ValueObject(value);
  -        store.put(key, valueObj );
  -        for(int i = 1; i < ITERATIONS; i++) {
  -            Object obj =  new String(testObject);
  +        store.put(key, valueObj);
  +        for (int i = 1; i < ITERATIONS; i++) {
  +            Object obj = new String(testObject);
               obj = new ValueObject(obj);
  -            store.put(new Integer(i),obj );
  +            store.put(new Integer(i), obj);
  +            _testGet(i);
  +        }
  +        // get something
  +        for (int i = ITERATIONS / (MAX_STRONG_REFS == 0 ? 10 : MAX_STRONG_REFS);
  +                i < ITERATIONS / 2; i++) {
               _testGet(i);
           }
  -       // get something  
  -        for( int i = ITERATIONS / ( MAX_STRONG_REFS == 0 ? 10 : MAX_STRONG_REFS );
  -                i < ITERATIONS / 2 ; i++) {
  -              _testGet(i);
  -        }
  -        assertEquals("Lost Strong Referense in cache", store.get(key), valueObj );
  -        
  -        
  +        assertEquals("Lost Strong Referense in cache", store.get(key), valueObj);
  +
       }
  -    
  -    public static class ValueObject implements Reachable{
  -        Object reference;
  -        Object value;
  -        public ValueObject( Object value){
  -          this.value = value;
  -         }
  -        Object getValue(){
  -        return value;
  -      }
  -      public String toString(){ return value != null ? value.toString() : null; }
  -      public void setReference(Object reference) {
  -               this.reference = reference;
  -      }
  -      
  -      }
  -    private void _testGet(int lastKey){
  -        
  -       if( lastKey >= MAX_STRONG_REFS)
  -           System.out.println("GET ... ");
  -       
  -        for( int i = lastKey - MAX_STRONG_REFS ; 
  -               ( i < lastKey ) && ( i > 0 ); 
  -                 i += ( MAX_STRONG_REFS / 2 + 1 ) ) {
  -                     
  +
  +
  +    protected void setUp() throws java.lang.Exception {
  +        super.setUp();
  +        store = makeStore();
  +    }
  +
  +    private void _testGet(int lastKey) {
  +
  +        if (lastKey >= MAX_STRONG_REFS) {
  +            System.out.println("GET ... ");
  +        }
  +
  +        for (int i = lastKey - MAX_STRONG_REFS;
  +                (i < lastKey) && (i > 0);
  +                i += (MAX_STRONG_REFS / 2 + 1)) {
  +
               Object key = new Integer(i);
               Object object = store.get(key);
  -            
  -            if(object == null){
  -                System.out.println( key + " removed from memory ");
  -            }else{
  -                System.out.println( object.toString().substring(0,20) );
  +
  +            if (object == null) {
  +                System.out.println(key + " removed from memory ");
  +            } else {
  +                System.out.println(object.toString().substring(0, 20));
               }
           }
       }
  -    
  -    
  -    protected void setUp() throws java.lang.Exception {
  -        super.setUp();
  -        store = makeStore();
  +
  +    public static class ValueObject implements Reachable {
  +        Object reference;
  +        Object value;
  +
  +        public ValueObject(Object value) {
  +            this.value = value;
  +        }
  +
  +        public void setReference(Object reference) {
  +            this.reference = reference;
  +        }
  +
  +        public String toString() {
  +            return value != null ? value.toString() : null;
  +        }
  +
  +        Object getValue() {
  +            return value;
  +        }
  +
       }
   }
   
  
  
  
  1.2       +137 -92   jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore/TestSample.java
  
  Index: TestSample.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore/TestSample.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestSample.java	9 Feb 2002 13:49:47 -0000	1.1
  +++ TestSample.java	9 Feb 2002 18:57:05 -0000	1.2
  @@ -1,101 +1,147 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -
  +/*
  + * 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 Cocoon" and "Apache Software Foundation" 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",
  + *    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/>.
  + */
   package org.apache.commons.simplestore;
   
  +import java.util.HashMap;
  +import java.util.Map;
   import junit.framework.Test;
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
  -import java.util.Map;
  -import java.util.HashMap;
  -import org.apache.commons.simplestore.persistence.*;
   import org.apache.commons.simplestore.jdbc.*;
  +import org.apache.commons.simplestore.persistence.*;
   
   /**
  - * @author Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
  + *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - * @version $Id: TestSample.java,v 1.1 2002/02/09 13:49:47 baliuka Exp $
  + *@version    $Id: TestSample.java,v 1.2 2002/02/09 18:57:05 froehlich Exp $
    */
   public class TestSample extends TestCase {
  -   
  -  PersistenceManager pm; 
  -  
  +
  +    PersistenceManager pm;
  +
       public TestSample(String testName) {
           super(testName);
       }
  -    
  +
       public static Test suite() {
           return new TestSuite(TestSample.class);
       }
  -    
  +
       public static void main(String args[]) {
  -        String[] testCaseName = { TestSample.class.getName() };
  +        String[] testCaseName = {TestSample.class.getName()};
           junit.textui.TestRunner.main(testCaseName);
       }
  -    
  -    public void testCreate()throws java.lang.Exception{
  -     for(int i = 0 ; i < 10; i++ ){
  -         
  -        Transaction transaction =  pm.getTransaction();
  -        
  -        transaction.begin();
  -        TestPersistent object1 = (TestPersistent)pm.createInstance(TestPersistent.class);
  -        Object oid = pm.getOID(object1);
  -        transaction.commit();
  -                
  -        transaction.begin();
  -        TestPersistent object2 = (TestPersistent)pm.findInstance(TestPersistent.class,oid);
  -        transaction.commit();
  -        
  -        transaction.begin();
  -         TestPersistent object3 = (TestPersistent)pm.createInstance(TestPersistent.class);
  -         object3.setDateVal(new java.util.Date());
  -         object3.setIntVal(i);
  -         object3.setFloatVal(i/2);
  -         object3.setStrVal("" + i);
  -         object3.setBoolVal(true);
  -        transaction.commit();
  -        
  -        assertEquals("Equals " + oid, object2 , object1 );
  -        assertTrue(" == " + oid , object2 == object1 );
  -        
  -     }
  -    
  -    }
  -    
  -    public void testRetrieve()throws java.lang.Exception{
  -    
  -       Transaction transaction =  pm.getTransaction();
  -        
  +
  +    public void testCreate() throws java.lang.Exception {
  +        for (int i = 0; i < 10; i++) {
  +
  +            Transaction transaction = pm.getTransaction();
  +
  +            transaction.begin();
  +            TestPersistent object1 = (TestPersistent) pm.createInstance(TestPersistent.class);
  +            Object oid = pm.getOID(object1);
  +            transaction.commit();
  +
  +            transaction.begin();
  +            TestPersistent object2 = (TestPersistent) pm.findInstance(TestPersistent.class,
oid);
  +            transaction.commit();
  +
  +            transaction.begin();
  +            TestPersistent object3 = (TestPersistent) pm.createInstance(TestPersistent.class);
  +            object3.setDateVal(new java.util.Date());
  +            object3.setIntVal(i);
  +            object3.setFloatVal(i / 2);
  +            object3.setStrVal("" + i);
  +            object3.setBoolVal(true);
  +            transaction.commit();
  +
  +            assertEquals("Equals " + oid, object2, object1);
  +            assertTrue(" == " + oid, object2 == object1);
  +
  +        }
  +
  +    }
  +
  +    public void testRetrieve() throws java.lang.Exception {
  +
  +        Transaction transaction = pm.getTransaction();
  +
           transaction.begin();
  -         java.util.Set objects = pm.findAll( TestPersistent.class );
  -         System.out.println("retrieved " + objects.size() );
  -         java.util.Iterator i = objects.iterator();
  -         
  -         while(i.hasNext()){
  -              
  -           TestPersistent object = (TestPersistent)i.next();
  -           System.out.println("ID       =" + object);
  -           System.out.println("BoolVal  = " + object.getBoolVal());
  -           System.out.println("DateVal  = "+ object.getDateVal());
  -           System.out.println("IntVal   = " + object.getIntVal());
  -           System.out.println("FloatVal =" + object.getFloatVal());
  -           System.out.println("StrVal   =" + object.getStrVal());
  -          
  -         }
  -        
  +        java.util.Set objects = pm.findAll(TestPersistent.class);
  +        System.out.println("retrieved " + objects.size());
  +        java.util.Iterator i = objects.iterator();
  +
  +        while (i.hasNext()) {
  +
  +            TestPersistent object = (TestPersistent) i.next();
  +            System.out.println("ID       =" + object);
  +            System.out.println("BoolVal  = " + object.getBoolVal());
  +            System.out.println("DateVal  = " + object.getDateVal());
  +            System.out.println("IntVal   = " + object.getIntVal());
  +            System.out.println("FloatVal =" + object.getFloatVal());
  +            System.out.println("StrVal   =" + object.getStrVal());
  +
  +        }
  +
           transaction.commit();
  -     
  -    
  +
       }
  +
       protected void setUp() throws java.lang.Exception {
           super.setUp();
  -        
  +
           // this datasource is for reentrant connections only !!!
           DriverDataSource ds = new DriverDataSource();
           ds.setDriver("org.hsqldb.jdbcDriver");
  @@ -103,26 +149,25 @@
           ds.setUrl("jdbc:hsqldb:sample");
           ds.setUser("sa");
           ds.setPassword("");
  -        String sql = "CREATE TABLE TEST_PERSISTENT ( ID bigint not null primary key, Bool_Val
smallint," + 
  -         " Int_Val integer, Float_Val float, Date_Val date, Str_Val longVarChar )  ";
  -        
  -        java.sql.Connection con  = ds.getConnection();
  -        try{
  -          java.sql.Statement  stmt = con.createStatement();
  -         try{ 
  -          stmt.executeUpdate(sql);
  -         }catch(java.sql.SQLException e){
  -             System.out.println(e.getMessage());// exists ? 
  -         }
  -          stmt.close();
  -        }finally {
  -          con.close();
  -        } 
  -        
  +        String sql = "CREATE TABLE TEST_PERSISTENT ( ID bigint not null primary key, Bool_Val
smallint," +
  +                " Int_Val integer, Float_Val float, Date_Val date, Str_Val longVarChar
)  ";
  +
  +        java.sql.Connection con = ds.getConnection();
  +        try {
  +            java.sql.Statement stmt = con.createStatement();
  +            try {
  +                stmt.executeUpdate(sql);
  +            } catch (java.sql.SQLException e) {
  +                System.out.println(e.getMessage());// exists ?
  +            }
  +            stmt.close();
  +        } finally {
  +            con.close();
  +        }
  +
           DBStorage storage = new DBStorage(ds);
  -        pm = PersistenceManager.getPersistenceManager(storage,storage);  
  +        pm = PersistenceManager.getPersistenceManager(storage, storage);
       }
  -    
  -    
  +
   }
   
  
  
  
  1.2       +79 -32    jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore/TestPersistent.java
  
  Index: TestPersistent.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore/TestPersistent.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestPersistent.java	9 Feb 2002 13:49:47 -0000	1.1
  +++ TestPersistent.java	9 Feb 2002 18:57:05 -0000	1.2
  @@ -1,40 +1,87 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -
  +/*
  + * 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 Cocoon" and "Apache Software Foundation" 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",
  + *    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/>.
  + */
   package org.apache.commons.simplestore;
  +
   /**
  - * @author Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
  + *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *      baliuka@mwm.lt</a>
  - * @version $Id: TestPersistent.java,v 1.1 2002/02/09 13:49:47 baliuka Exp $
  + *@version    $Id: TestPersistent.java,v 1.2 2002/02/09 18:57:05 froehlich Exp $
    */
   public interface TestPersistent {
  -    
  -  public boolean getBoolVal();
  -  
  -  public void setBoolVal(boolean val);
  -  
  -  public void setIntVal(int val);
  -  
  -  public int getIntVal();
  -  
  -  public void setFloatVal( float val);
  -  
  -  public float getFloatVal();
  -  
  -  public java.util.Date getDateVal();
  -  
  -  public void setDateVal( java.util.Date val );
  -  
  -  public void setStrVal( String val );
  -  
  -  public String getStrVal( );
   
  -  //TODO : PesistentObjectVal and unknown SerializableObjectVal
  -  
  +    public boolean getBoolVal();
  +
  +    public void setBoolVal(boolean val);
  +
  +    public void setIntVal(int val);
  +
  +    public int getIntVal();
  +
  +    public void setFloatVal(float val);
  +
  +    public float getFloatVal();
  +
  +    public java.util.Date getDateVal();
  +
  +    public void setDateVal(java.util.Date val);
  +
  +    public void setStrVal(String val);
  +
  +    public String getStrVal();
  +
  +    //TODO : PesistentObjectVal and unknown SerializableObjectVal
  +
   }
   
  
  
  
  1.2       +66 -19    jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore/TestObject.java
  
  Index: TestObject.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore/TestObject.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestObject.java	20 Jan 2002 13:59:36 -0000	1.1
  +++ TestObject.java	9 Feb 2002 18:57:05 -0000	1.2
  @@ -1,24 +1,69 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -
  +/*
  + * 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 Cocoon" and "Apache Software Foundation" 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",
  + *    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/>.
  + */
   package org.apache.commons.simplestore;
   
  -import junit.framework.*;
  -import java.util.Collection;
   import java.util.ArrayList;
  +import java.util.Collection;
   import java.util.Iterator;
   import java.util.NoSuchElementException;
  +import junit.framework.*;
   
   /**
  - * @author Gerhard Froehlich <a href="mailto:g-froehlich@gmx.de">
  + *@author     Gerhard Froehlich <a href="mailto:g-froehlich@gmx.de">
    *      g-froehlich@gmx.de</a>
  - *
  - * @version $Id: TestObject.java,v 1.1 2002/01/20 13:59:36 froehlich Exp $
  + *@version    $Id: TestObject.java,v 1.2 2002/02/09 18:57:05 froehlich Exp $
    */
   public abstract class TestObject extends TestCase {
       public TestObject(String testName) {
  @@ -27,27 +72,29 @@
   
       /**
        * Return a new, empty {@link Object} to used for testing.
  +     *
  +     *@return
        */
       public abstract Object makeObject();
   
       public void testObjectEqualsSelf() {
           Object obj = makeObject();
  -        assertEquals("A Object should equal itself",obj,obj);
  +        assertEquals("A Object should equal itself", obj, obj);
       }
   
       public void testObjectHashCodeEqualsSelfHashCode() {
           Object obj = makeObject();
  -        assertEquals("hashCode should be repeatable",obj.hashCode(),obj.hashCode());
  +        assertEquals("hashCode should be repeatable", obj.hashCode(), obj.hashCode());
       }
   
       public void testObjectHashCodeEqualsContract() {
           Object obj1 = makeObject();
  -        if(obj1.equals(obj1)) {
  -            assertEquals("[1] When two objects are equal, their hashCodes should be also.",obj1.hashCode(),obj1.hashCode());
  +        if (obj1.equals(obj1)) {
  +            assertEquals("[1] When two objects are equal, their hashCodes should be also.",
obj1.hashCode(), obj1.hashCode());
           }
           Object obj2 = makeObject();
  -        if(obj1.equals(obj2)) {
  -            assertEquals("[2] When two objects are equal, their hashCodes should be also.",obj1.hashCode(),obj2.hashCode());
  +        if (obj1.equals(obj2)) {
  +            assertEquals("[2] When two objects are equal, their hashCodes should be also.",
obj1.hashCode(), obj2.hashCode());
           }
       }
   }
  
  
  
  1.7       +59 -12    jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore/TestAll.java
  
  Index: TestAll.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/test/org/apache/commons/simplestore/TestAll.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestAll.java	9 Feb 2002 17:01:39 -0000	1.6
  +++ TestAll.java	9 Feb 2002 18:57:05 -0000	1.7
  @@ -1,19 +1,65 @@
  -/*****************************************************************************
  - * Copyright (C) The Apache Software Foundation. All rights reserved.        *
  - * ------------------------------------------------------------------------- *
  - * This software is published under the terms of the Apache Software License *
  - * version 1.1, a copy of which has been included  with this distribution in *
  - * the LICENSE file.                                                         *
  - *****************************************************************************/
  -
  +/*
  + * 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 Cocoon" and "Apache Software Foundation" 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",
  + *    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/>.
  + */
   package org.apache.commons.simplestore;
   
   import junit.framework.*;
   
   /**
  - * @author Gerhard Froehlich <a href="mailto:g-froehlich@gmx.de">
  + *@author     Gerhard Froehlich <a href="mailto:g-froehlich@gmx.de">
    *      g-froehlich@gmx.de</a>
  - * @version $Id: TestAll.java,v 1.6 2002/02/09 17:01:39 froehlich Exp $
  + *@version    $Id: TestAll.java,v 1.7 2002/02/09 18:57:05 froehlich Exp $
    */
   public class TestAll extends TestCase {
       public TestAll(String testName) {
  @@ -27,9 +73,10 @@
           suite.addTest(TestSample.suite());
           return suite;
       }
  -        
  +
       public static void main(String args[]) {
  -        String[] testCaseName = { TestAll.class.getName() };
  +        String[] testCaseName = {TestAll.class.getName()};
           junit.textui.TestRunner.main(testCaseName);
       }
   }
  +
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message