You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by we...@apache.org on 2004/05/11 20:23:35 UTC
cvs commit: jakarta-jetspeed-2/components/idgenerator/src/test/org/apache/jetspeed/idgenerator TestIdGenerator.java
weaver 2004/05/11 11:23:35
Modified: components/idgenerator/src/test/org/apache/jetspeed/idgenerator
Tag: NANOCONTAINER_DEPLOYER TestIdGenerator.java
Log:
Revision Changes Path
No revision
No revision
1.1.2.2 +140 -131 jakarta-jetspeed-2/components/idgenerator/src/test/org/apache/jetspeed/idgenerator/Attic/TestIdGenerator.java
Index: TestIdGenerator.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/components/idgenerator/src/test/org/apache/jetspeed/idgenerator/Attic/TestIdGenerator.java,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- TestIdGenerator.java 20 Apr 2004 14:57:07 -0000 1.1.2.1
+++ TestIdGenerator.java 11 May 2004 18:23:35 -0000 1.1.2.2
@@ -1,131 +1,140 @@
-/*
- * Copyright 2000-2004 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.jetspeed.idgenerator;
-
-// Java imports
-import java.util.HashMap;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-import org.apache.jetspeed.components.AbstractComponentAwareTestCase;
-import org.apache.jetspeed.components.ComponentAssemblyTestCase;
-import org.apache.jetspeed.components.NanoDeployerBasedTestSuite;
-
-/**
- * TestIdGenerator
- *
- * @author <a href="paulsp@apache.org">Paul Spencer</a>
- * @version $Id$
- */
-public class TestIdGenerator extends AbstractComponentAwareTestCase
-{
-
- private static int ID_TEST_TRIES = 10000;
-
- /**
- * Defines the testcase name for JUnit.
- *
- * @param name the testcase's name.
- */
- public TestIdGenerator(String name)
- {
- super( name );
- }
-
- public String getBaseProject()
- {
- return "components/jetspeed";
- }
-
- /**
- * Start the tests.
- *
- * @param args the arguments. Not used
- */
- public static void main(String args[])
- {
- junit.awtui.TestRunner.main( new String[] { TestIdGenerator.class.getName() } );
- }
-
- /**
- * Creates the test suite.
- *
- * @return a test suite (<code>TestSuite</code>) that includes all methods
- * starting with "test"
- */
- public static Test suite()
- {
- // All methods starting with "test" will be executed in the test suite.
- // return new TestSuite( TestIdGenerator.class );
- return new NanoDeployerBasedTestSuite(TestIdGenerator.class);
- }
-
- /**
- * Simple test that verify the PEID are unique. This test will generate
- * <CODE>ID_TEST_TRIES<CODE> PEIDs. It will test for a NULL PEID.
- *
- * Granted, passing this test does <B>not</B> guarantee that a duplicate
- * PEID will not be generated.
- *
- * @throws Exception
- */
- public void testVerifyUniquePeid() throws Exception
- {
- IdGenerator generator = (IdGenerator)getContainer().getComponentInstance("IdGenerator");
- assertNotNull("idgenerator is null", generator);
-
- HashMap generatedIds = new HashMap( ID_TEST_TRIES + 1);
- String newId;
-
- // Add a NULL to verify a NULL is not being generated.
- generatedIds.put(null, null);
-
- for (int counter = 1; counter <= ID_TEST_TRIES; counter++)
- {
- newId = generator.getNextPeid();
- assertTrue( "PEID already generated. PEID = " + newId, !generatedIds.containsKey(newId));
- generatedIds.put(newId, null);
- }
- }
-
- /**
- * Simple test that verify the PEIDs are increasing. Although this is not a
- * requirement of the IdGenerator, it is recommended
- *
- * @throws Exception
- */
- public void testVerifyIncreasingPeid() throws Exception
- {
- IdGenerator generator = (IdGenerator)getContainer().getComponentInstance("IdGenerator");
- assertNotNull("idgenerator service is null", generator);
-
- String newId;
- String lastId = null;
-
- for (int counter = 1; counter <= ID_TEST_TRIES; counter++)
- {
- newId = generator.getNextPeid();
- if (lastId == null)
- {
- lastId = newId;
- continue;
- }
- assertTrue( "PEID is not greater then last generated PEID. PEID = " + newId, (lastId.compareTo(newId)<0));
- lastId = newId;
- }
- }
-}
+/*
+ * Copyright 2000-2004 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.jetspeed.idgenerator;
+
+// Java imports
+import java.util.HashMap;
+import java.util.Iterator;
+
+import junit.framework.Test;
+
+import org.apache.jetspeed.components.AbstractComponentAwareTestCase;
+import org.apache.jetspeed.components.ContainerDeployerTestSuite;
+import org.picocontainer.ComponentAdapter;
+
+/**
+ * TestIdGenerator
+ *
+ * @author <a href="paulsp@apache.org">Paul Spencer</a>
+ * @version $Id$
+ */
+public class TestIdGenerator extends AbstractComponentAwareTestCase
+{
+
+ private static int ID_TEST_TRIES = 10000;
+
+ /**
+ * Defines the testcase name for JUnit.
+ *
+ * @param name the testcase's name.
+ */
+ public TestIdGenerator(String name)
+ {
+ super(name );
+ }
+
+ public String getBaseProject()
+ {
+ return "components/jetspeed";
+ }
+
+ /**
+ * Start the tests.
+ *
+ * @param args the arguments. Not used
+ */
+ public static void main(String args[])
+ {
+ junit.awtui.TestRunner.main( new String[] { TestIdGenerator.class.getName() } );
+ }
+
+ /**
+ * Creates the test suite.
+ *
+ * @return a test suite (<code>TestSuite</code>) that includes all methods
+ * starting with "test"
+ */
+ public static Test suite()
+ {
+ // All methods starting with "test" will be executed in the test suite.
+ // return new TestSuite( TestIdGenerator.class );
+ // return new NanoDeployerBasedTestSuite(TestIdGenerator.class);
+ return new ContainerDeployerTestSuite(TestIdGenerator.class);
+ }
+
+ /**
+ * Simple test that verify the PEID are unique. This test will generate
+ * <CODE>ID_TEST_TRIES<CODE> PEIDs. It will test for a NULL PEID.
+ *
+ * Granted, passing this test does <B>not</B> guarantee that a duplicate
+ * PEID will not be generated.
+ *
+ * @throws Exception
+ */
+ public void testVerifyUniquePeid() throws Exception
+ {
+ IdGenerator generator = (IdGenerator)getContainer().getComponentInstance("IdGenerator");
+
+ Iterator itr = getContainer().getComponentAdapters().iterator();
+ System.out.println("Adapter count: "+ getContainer().getComponentAdapters().size());
+ while(itr.hasNext())
+ {
+ ComponentAdapter adapter = (ComponentAdapter)itr.next();
+ System.out.println("Component key: "+adapter.getComponentKey());
+ }
+ assertNotNull("idgenerator is null", generator);
+
+ HashMap generatedIds = new HashMap( ID_TEST_TRIES + 1);
+ String newId;
+
+ // Add a NULL to verify a NULL is not being generated.
+ generatedIds.put(null, null);
+
+ for (int counter = 1; counter <= ID_TEST_TRIES; counter++)
+ {
+ newId = generator.getNextPeid();
+ assertTrue( "PEID already generated. PEID = " + newId, !generatedIds.containsKey(newId));
+ generatedIds.put(newId, null);
+ }
+ }
+
+ /**
+ * Simple test that verify the PEIDs are increasing. Although this is not a
+ * requirement of the IdGenerator, it is recommended
+ *
+ * @throws Exception
+ */
+ public void testVerifyIncreasingPeid() throws Exception
+ {
+ IdGenerator generator = (IdGenerator)getContainer().getComponentInstance("IdGenerator");
+ assertNotNull("idgenerator service is null", generator);
+
+ String newId;
+ String lastId = null;
+
+ for (int counter = 1; counter <= ID_TEST_TRIES; counter++)
+ {
+ newId = generator.getNextPeid();
+ if (lastId == null)
+ {
+ lastId = newId;
+ continue;
+ }
+ assertTrue( "PEID is not greater then last generated PEID. PEID = " + newId, (lastId.compareTo(newId)<0));
+ lastId = newId;
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org