⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testsimplesequencegenerator.java

📁 JAVA做的J2EE下CA认证系统 基于EJB开发
💻 JAVA
字号:
package se.anatom.ejbca.util;import java.util.HashMap;import javax.ejb.EJBException;import javax.ejb.EJBLocalHome;import junit.framework.TestCase;/** * Test for the SimpleSequenceGenerator. * * Make sure that it works...somewhat. :) */public class TestSimpleSequenceGenerator extends TestCase {    private final static int IT = 100000;    /**     * Creates a new TestSimpleSequenceGenerator object.     *     * @param name DOCUMENT ME!     */    public TestSimpleSequenceGenerator(String name) {        super(name);    }    public void testUnableToFindFreeID() throws Exception {        try {            // use a map that always return non null to fake that it always find an existing id            HashMap map = new DummyHashMap();            EJBLocalHome home = new DummyLocalHome(map);            SimpleSequenceGenerator.getNextCount( home );            fail("Should generate an EJBException when no free ID");        } catch (EJBException e){            assertNull("Should be a clean EJBException", e.getCause());        }    }    public void testAbletoFindFreeID() throws Exception {        EJBLocalHome home = new DummyLocalHome(new HashMap()); // will throw a FindExceptionInternally == Free ID        Integer id = SimpleSequenceGenerator.getNextCount( home );        assertNotNull(id);    }    public void testGenerateMultipleConsecutiveIDs() throws Exception {        HashMap db = new HashMap();        EJBLocalHome home = new DummyLocalHome(db);        for (int i = 0; i < IT; i++) {            Integer id = SimpleSequenceGenerator.getNextCount( home );            db.put(id, "dummy"); // simulate a database with stored ids        }        // check that it is really not duplicate ids        assertEquals(IT, db.size());    }    public void testGenerateMultipleFailedConsecutiveIDs() throws Exception {        // use a map that always return non null to fake that it always find an existing id        HashMap db = new DummyHashMap();        EJBLocalHome home = new DummyLocalHome(db);        for (int i = 0; i < IT; i++) {            try {                Integer id = SimpleSequenceGenerator.getNextCount( home );                id.intValue();            } catch (EJBException e){            }        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -