1 13 14 package se.anatom.ejbca.ca.sign; 15 16 import java.math.BigInteger ; 17 import java.util.Date ; 18 import java.util.HashMap ; 19 20 import junit.framework.TestCase; 21 22 import org.apache.log4j.Logger; 23 import org.ejbca.core.ejb.ca.sign.ISernoGenerator; 24 import org.ejbca.core.ejb.ca.sign.SernoGenerator; 25 26 27 32 public class TestSernoGenerator extends TestCase { 33 private static Logger log = Logger.getLogger(TestSernoGenerator.class); 34 35 40 public TestSernoGenerator(String name) { 41 super(name); 42 } 43 44 protected void setUp() throws Exception { 45 } 46 47 protected void tearDown() throws Exception { 48 } 49 50 52 public void test01GenerateSernos() throws Exception { 53 log.debug(">test01GenerateSernos()"); 54 55 ISernoGenerator gen = SernoGenerator.instance(); 56 HashMap map = new HashMap (300000); 57 String hex = null; 58 59 for (int j = 0; j < 300; j++) { 60 for (int i = 0; i < 1000; i++) { 61 BigInteger bi = gen.getSerno(); 62 63 hex = bi.toString(); 65 66 if (map.put(hex, hex) != null) { 67 System.out.println("Duplicate serno produced: " + hex); 68 } 69 } 70 71 System.out.println(((j + 1) * 1000) + " sernos produced: " + hex); 72 73 long seed = Math.abs((new Date ().getTime()) + this.hashCode()); 74 gen.setSeed(seed); 75 System.out.println("Reseeding: " + seed); 76 } 77 78 System.out.println("Map now contains " + map.size() + " serial numbers."); 79 log.debug("<test01GenerateSernos()"); 80 } 81 } 82 | Popular Tags |