You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by jo...@apache.org on 2006/01/14 00:25:02 UTC

svn commit: r368918 - in /jakarta/commons/sandbox/id/trunk: ./ src/java/org/apache/commons/id/ src/java/org/apache/commons/id/random/ src/java/org/apache/commons/id/serial/ src/test/org/apache/commons/id/ src/test/org/apache/commons/id/random/ src/test...

Author: joehni
Date: Fri Jan 13 15:24:41 2006
New Revision: 368918

URL: http://svn.apache.org/viewcvs?rev=368918&view=rev
Log:
Improve coverage.
Improve javadoc and fix typos.

Added:
    jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/random/
    jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/random/SessionIdGeneratorTest.java   (with props)
Modified:
    jakarta/commons/sandbox/id/trunk/   (props changed)
    jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/DefaultIdentifierGeneratorFactory.java
    jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/IdentifierGeneratorFactory.java
    jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/package.html
    jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/random/SessionIdGenerator.java
    jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/serial/LongGenerator.java
    jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/IdentifierUtilsTest.java
    jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/serial/TimeBasedAlphanumericIdentifierGeneratorTest.java
    jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/uuid/UUIDTest.java

Propchange: jakarta/commons/sandbox/id/trunk/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Fri Jan 13 15:24:41 2006
@@ -1,3 +1,4 @@
+
 build.properties
 dist
 .classpath
@@ -7,3 +8,5 @@
 maven.log
 velocity.log
 eclipse_classes
+cobertura.ser
+.clover

Modified: jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/DefaultIdentifierGeneratorFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/DefaultIdentifierGeneratorFactory.java?rev=368918&r1=368917&r2=368918&view=diff
==============================================================================
--- jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/DefaultIdentifierGeneratorFactory.java (original)
+++ jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/DefaultIdentifierGeneratorFactory.java Fri Jan 13 15:24:41 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 2003-2004 The Apache Software Foundation.
+ * Copyright 2003-2006 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -33,7 +33,7 @@
  * commons-uid.
  *
  * @author Commons-Id team
- * @version $id$
+ * @version $Id$
  */
 public class DefaultIdentifierGeneratorFactory extends IdentifierGeneratorFactory implements Serializable  {
     /**

Modified: jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/IdentifierGeneratorFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/IdentifierGeneratorFactory.java?rev=368918&r1=368917&r2=368918&view=diff
==============================================================================
--- jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/IdentifierGeneratorFactory.java (original)
+++ jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/IdentifierGeneratorFactory.java Fri Jan 13 15:24:41 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 2003-2005 The Apache Software Foundation.
+ * Copyright 2003-2006 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -131,6 +131,7 @@
      *  value that can be represented in <code>size</code> base 10 digits
      *  (or throw an exception)
      * @param size the size of the identifier, including prefix length
+     * @return a new StringIdentifierGenerator
      * @throws IllegalArgumentException if prefix is null or size less prefix
      * length is less than 1
      */
@@ -157,6 +158,7 @@
      *  value that can be represented in <code>size</code> base 36 digits
      *  (or throw an exception)
      * @param size the size of the identifier, including prefix length
+     * @return a new StringIdentifierGenerator
      * @throws IllegalArgumentException if prefix is null or size less prefix
      * length is not at least one
      */
@@ -197,7 +199,7 @@
     public abstract StringIdentifierGenerator sessionIdGenerator();
 
     /**
-     * <p>Gets a new {@link IndentifierGenerator} that generates version one UUID objects
+     * <p>Gets a new {@link IdentifierGenerator} that generates version one UUID objects
      * that conform to the <a href="http://www.ietf.org/internet-drafts/draft-mealling-uuid-urn-02.txt">
      * IETF Draft UUID specification</a>.</p>
      *

Modified: jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/package.html
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/package.html?rev=368918&r1=368917&r2=368918&view=diff
==============================================================================
--- jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/package.html (original)
+++ jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/package.html Fri Jan 13 15:24:41 2006
@@ -1,5 +1,5 @@
 <!--
-   Copyright 2003-2004 The Apache Software Foundation
+   Copyright 2003-2006 The Apache Software Foundation
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -24,12 +24,14 @@
      classes for identifier generators, generator factories and an
      IdentifierUtils convenience class that maintains singleton generators and 
      exposes static methods for generating identifiers of the various kinds.</li>
+     
      <li>The <code>random</code> subpackage contains implementations of
      generators that return identifiers that appear to be random.</li>
 
      <li>The <code>serial</code> subpackage contains generators that yield
      sequences of identifiers that follow a regular sequence (e.g., increasing
      numeric values).</li>
+     
      <li>The <code>uuid</code> subpackage contains implementations of the 
      <a href="http://www.ietf.org/internet-drafts/draft-mealling-uuid-urn-01.txt">
      IETF Draft UUID specification</a></li>

Modified: jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/random/SessionIdGenerator.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/random/SessionIdGenerator.java?rev=368918&r1=368917&r2=368918&view=diff
==============================================================================
--- jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/random/SessionIdGenerator.java (original)
+++ jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/random/SessionIdGenerator.java Fri Jan 13 15:24:41 2006
@@ -23,7 +23,8 @@
 /**
  * <p><code>SessionIdGenerator</code> is an identifier generator
  * that generates an alphanumeric 10+ character identifier. The
- * exact length depends on the number of ids requested per time period.</p>
+ * exact length depends on the number of ids requested per time period.
+ * Multiple instances of the class generate still unique ids.</p>
  *
  * <p>Originally designed for JServ sessions. Uses synchronized count and
  * time to ensure uniqueness. Not guaranteed unique across JVMs, but

Modified: jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/serial/LongGenerator.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/serial/LongGenerator.java?rev=368918&r1=368917&r2=368918&view=diff
==============================================================================
--- jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/serial/LongGenerator.java (original)
+++ jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/serial/LongGenerator.java Fri Jan 13 15:24:41 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 2003-2004 The Apache Software Foundation.
+ * Copyright 2003-2006 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.

Modified: jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/IdentifierUtilsTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/IdentifierUtilsTest.java?rev=368918&r1=368917&r2=368918&view=diff
==============================================================================
--- jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/IdentifierUtilsTest.java (original)
+++ jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/IdentifierUtilsTest.java Fri Jan 13 15:24:41 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 2003-2004 The Apache Software Foundation.
+ * Copyright 2003-2006 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -89,9 +89,10 @@
     /** Test LongIdentifier wrapping */
     public void testLongIncrementingWrap() {
         LongIdentifierGenerator f = factory.longGenerator(true, Long.MAX_VALUE - 1);
-        assertEquals(new Long(Long.MAX_VALUE - 1), f.nextLongIdentifier());
-        assertEquals(new Long(Long.MAX_VALUE), f.nextLongIdentifier());
-        assertEquals(new Long(Long.MIN_VALUE), f.nextLongIdentifier());
+        assertEquals(new Long(f.maxValue() - 1), f.nextLongIdentifier());
+        assertEquals(new Long(f.maxValue()), f.nextLongIdentifier());
+        assertEquals(new Long(f.minValue()), f.nextLongIdentifier());
+        assertEquals(new Long(Long.MIN_VALUE + 1), f.nextLongIdentifier());
     }
 
     /** Test LongIdentifier without wrapping */
@@ -99,8 +100,24 @@
         LongIdentifierGenerator f = factory.longGenerator(false, Long.MAX_VALUE);
         try {
             f.nextLongIdentifier();
-            fail();
-        } catch (IllegalStateException ex) {}
+            fail("Thrown " + IllegalStateException.class.getName() + " expected");
+        } catch (final IllegalStateException e) {
+        }
+    }
+    
+    /** Test Long generator with no wrapping is not resetted */
+    public void testLongIncrementingNoWrapIsNotResetted() {
+        LongIdentifierGenerator f = factory.longGenerator(false, Long.MAX_VALUE);
+        try {
+            f.nextLongIdentifier();
+            fail("Thrown " + IllegalStateException.class.getName() + " expected");
+        } catch (final IllegalStateException e) {
+        }
+        try {
+            f.nextLongIdentifier();
+            fail("Thrown " + IllegalStateException.class.getName() + " expected");
+        } catch (final IllegalStateException e) {
+        }
     }
 
     //--------------------------------------------------------------------------
@@ -145,8 +162,24 @@
         StringIdentifierGenerator f = factory.numericGenerator(false, Long.MAX_VALUE);
         try {
             f.nextStringIdentifier();
-            fail();
-        } catch (IllegalStateException ex) { }
+            fail("Thrown " + IllegalStateException.class.getName() + " expected");
+        } catch (final IllegalStateException e) {
+        }
+    }
+    
+    /** Test String Numeric generator with no wrapping is not resetted */
+    public void testStringNumericNoWrapIsNotResetted() {
+        StringIdentifierGenerator f = factory.numericGenerator(false, Long.MAX_VALUE);
+        try {
+            f.nextStringIdentifier();
+            fail("Thrown " + IllegalStateException.class.getName() + " expected");
+        } catch (final IllegalStateException e) {
+        }
+        try {
+            f.nextStringIdentifier();
+            fail("Thrown " + IllegalStateException.class.getName() + " expected");
+        } catch (final IllegalStateException e) {
+        }
     }
 
     //--------------------------------------------------------------------------
@@ -192,6 +225,8 @@
         assertEquals("000000000000011", f.nextStringIdentifier());
         assertEquals("000000000000012", f.nextStringIdentifier());
         assertEquals("000000000000013", f.nextStringIdentifier());
+        
+        assertEquals(f.minLength(), f.maxLength());
     }
 
     /** Test String Numeric identifier no argument */
@@ -216,19 +251,33 @@
     public void testStringAlphanumericWithIllegalInitialValue() {
         try {
             StringIdentifierGenerator f = factory.alphanumericGenerator(true, "1@3");
-            fail("expected an exception");
-        } catch (IllegalArgumentException ex) {
-            // This is expected.
+            fail("Thrown " + IllegalArgumentException.class.getName() + " expected");
+        } catch (final IllegalArgumentException e) {
+        }
+        try {
+            StringIdentifierGenerator f = factory.alphanumericGenerator(false, -1);
+            fail("Thrown " + IllegalArgumentException.class.getName() + " expected");
+        } catch (final IllegalArgumentException e) {
+        }
+        try {
+            StringIdentifierGenerator f = factory.alphanumericGenerator(true, -1);
+            fail("Thrown " + IllegalArgumentException.class.getName() + " expected");
+        } catch (final IllegalArgumentException e) {
+        }
+        try {
+            StringIdentifierGenerator f = factory.alphanumericGenerator(false, 0);
+            fail("Thrown " + IllegalArgumentException.class.getName() + " expected");
+        } catch (final IllegalArgumentException e) {
+        }
+        try {
+            StringIdentifierGenerator f = factory.alphanumericGenerator(true, 0);
+            fail("Thrown " + IllegalArgumentException.class.getName() + " expected");
+        } catch (final IllegalArgumentException e) {
         }
     }
     
     /** Test String Numeric identifier wrapping */
     public void testStringAlphanumericWrap() {
-        try {
-            StringIdentifierGenerator f = factory.alphanumericGenerator(true, -1);
-            fail();
-        } catch (IllegalArgumentException ex) {}
-        
         StringIdentifierGenerator f = factory.alphanumericGenerator(true, 1);
         assertEquals("1", f.nextStringIdentifier());
         assertEquals("2", f.nextStringIdentifier());
@@ -270,11 +319,6 @@
 
     /** Test String Numeric identifier with no wrapping */
     public void testStringAlphanumericNoWrap() {
-        try {
-            StringIdentifierGenerator f = factory.alphanumericGenerator(false, -1);
-            fail();
-        } catch (IllegalArgumentException ex) {}
-
         StringIdentifierGenerator f = factory.alphanumericGenerator(false, 1);
         assertEquals("1", f.nextStringIdentifier());
         assertEquals("2", f.nextStringIdentifier());
@@ -313,8 +357,23 @@
         assertEquals("z", f.nextStringIdentifier());
         try {
             f.nextStringIdentifier();
-            fail();
-        } catch (IllegalStateException ex) {}
+            fail("Thrown " + IllegalStateException.class.getName() + " expected");
+        } catch (final IllegalStateException e) {
+        }
+    }
+    
+    /** Test String Numeric generator with no wrapping is not resetted */
+    public void testStringAlphanumericNoWrapIsNotResetted() {
+        StringIdentifierGenerator f = factory.alphanumericGenerator(false, 1);
+        try {
+            while(true) f.nextStringIdentifier();
+        } catch (final IllegalStateException e) {
+        }
+        try {
+            f.nextStringIdentifier();
+            fail("Thrown " + IllegalStateException.class.getName() + " expected");
+        } catch (final IllegalStateException e) {
+        }
     }
 
     //--------------------------------------------------------------------------
@@ -324,8 +383,8 @@
         StringIdentifierGenerator f = factory.sessionIdGenerator();
         assertTrue(f != IdentifierUtils.STRING_SESSION_IDENTIFIER_GENERATOR);
 
-        String a = (String) f.nextStringIdentifier();
-        String b = (String) IdentifierUtils.nextStringSessionIdentifier();
+        String a = f.nextStringIdentifier();
+        String b = IdentifierUtils.nextStringSessionIdentifier();
         String c = (String) f.nextIdentifier();
         assertTrue(a.length() >= 10);
         assertTrue(b.length() >= 10);
@@ -336,8 +395,8 @@
             assertTrue(a.substring(6, 9).equals(c.substring(6, 9)));
         } catch (AssertionFailedError ex) {
             // try again to make test more robust
-            a = (String) f.nextStringIdentifier();
-            b = (String) IdentifierUtils.nextStringSessionIdentifier();
+            a = f.nextStringIdentifier();
+            b = IdentifierUtils.nextStringSessionIdentifier();
             c = (String) f.nextIdentifier();
             assertTrue(a.substring(6, 9).equals(b.substring(6, 9)));
             assertTrue(a.substring(6, 9).equals(c.substring(6, 9)));

Added: jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/random/SessionIdGeneratorTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/random/SessionIdGeneratorTest.java?rev=368918&view=auto
==============================================================================
--- jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/random/SessionIdGeneratorTest.java (added)
+++ jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/random/SessionIdGeneratorTest.java Fri Jan 13 15:24:41 2006
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.id.random;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.id.StringIdentifierGenerator;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author Commons-Uid team
+ * @version $Id$
+ */
+public class SessionIdGeneratorTest extends TestCase {
+
+    /** Multiple instances generate still unique ids. */
+    public void testMultipleInstancesWillCreateUniqueIds() {
+        Set set = new HashSet();
+        StringIdentifierGenerator[] generators = new StringIdentifierGenerator[100];
+        for (int i = 0; i < generators.length; i++) {
+            generators[i] = new SessionIdGenerator();
+        }
+        for (int i = 0; i < generators.length; i++) {
+            for (int j = 0; j < generators.length; j++) {
+                set.add(generators[j].nextIdentifier());
+            }
+        }
+        assertEquals(generators.length*generators.length, set.size());
+    }
+}

Propchange: jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/random/SessionIdGeneratorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/random/SessionIdGeneratorTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/serial/TimeBasedAlphanumericIdentifierGeneratorTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/serial/TimeBasedAlphanumericIdentifierGeneratorTest.java?rev=368918&r1=368917&r2=368918&view=diff
==============================================================================
--- jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/serial/TimeBasedAlphanumericIdentifierGeneratorTest.java (original)
+++ jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/serial/TimeBasedAlphanumericIdentifierGeneratorTest.java Fri Jan 13 15:24:41 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005 The Apache Software Foundation.
+ * Copyright 2005-2006 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -31,7 +31,8 @@
 
 
 /**
- * @author J&ouml;rg Schaible
+ * @author Commons-Uid team
+ * @version $Id$
  */
 public class TimeBasedAlphanumericIdentifierGeneratorTest extends TestCase {
 
@@ -78,8 +79,8 @@
      */
     public void testIllegalStateWhenTooManyIdentifiersGenerated() {
         final IdentifierGenerator idGenerator = new TimeBasedAlphanumericIdentifierGenerator(0);
-        idGenerator.nextIdentifier();
         try {
+            idGenerator.nextIdentifier();
             idGenerator.nextIdentifier();
             // ensure exception even if a new time slice has been started between the last two calls
             idGenerator.nextIdentifier();

Modified: jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/uuid/UUIDTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/uuid/UUIDTest.java?rev=368918&r1=368917&r2=368918&view=diff
==============================================================================
--- jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/uuid/UUIDTest.java (original)
+++ jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/uuid/UUIDTest.java Fri Jan 13 15:24:41 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 2004 The Apache Software Foundation.
+ * Copyright 2004-2006 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -327,7 +327,6 @@
     	
     	//Sample output from IETF sample code
     	UUID known = UUID.nameUUIDFromString("www.widgets.com", ns);
-    	System.err.println(known);
     	assertEquals("3d813cbb-47fb-32ba-91df-831e1593ac29", known.toString());
     }
 



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