1 16 17 18 package org.apache.jetspeed.services.idgenerator; 19 20 import java.util.HashMap ; 22 23 import junit.framework.Test; 25 import junit.framework.TestSuite; 26 27 import org.apache.jetspeed.test.JetspeedTestCase; 29 import org.apache.jetspeed.services.idgenerator.JetspeedIdGenerator; 30 31 import org.apache.turbine.util.TurbineConfig; 32 import org.apache.turbine.util.StringUtils; 33 34 40 public class TestIdGenerator extends JetspeedTestCase { 41 42 private static int ID_TEST_TRIES = 10000; 43 44 48 private static TurbineConfig config = null; 49 50 54 static 55 { 56 try 57 { 58 config = new TurbineConfig( "webapp", 59 "/WEB-INF/conf/TurbineResources.properties"); 60 config.init(); 61 } 62 catch (Exception e) 63 { 64 fail(StringUtils.stackTrace(e)); 65 } 66 } 67 68 73 public TestIdGenerator(String name) { 74 super( name ); 75 } 76 77 82 public static void main(String args[]) { 83 junit.awtui.TestRunner.main( new String [] { TestIdGenerator.class.getName() } ); 84 } 85 86 public void setup() { 87 } 88 94 public static Test suite() { 95 return new TestSuite( TestIdGenerator.class ); 97 } 98 99 108 public void testVerifyUniquePeid() throws Exception 109 { 110 HashMap generatedIds = new HashMap ( ID_TEST_TRIES + 1); 111 String newId; 112 113 generatedIds.put(null, null); 115 116 for (int counter = 1; counter <= ID_TEST_TRIES; counter++) 117 { 118 newId = JetspeedIdGenerator.getNextPeid(); 119 assertTrue( "PEID already generated. PEID = " + newId, !generatedIds.containsKey(newId)); 120 generatedIds.put(newId, null); 121 } 122 } 123 124 130 public void testVerifyIncreasingPeid() throws Exception 131 { 132 String newId; 133 String lastId = null; 134 135 for (int counter = 1; counter <= ID_TEST_TRIES; counter++) 136 { 137 newId = JetspeedIdGenerator.getNextPeid(); 138 if (lastId == null) 139 { 140 lastId = newId; 141 continue; 142 } 143 assertTrue( "PEID is not greater then last generated PEID. PEID = " + newId, (lastId.compareTo(newId)<0)); 144 lastId = newId; 145 } 146 } 147 } 148 | Popular Tags |