001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.idgen.test;
023:
024: import java.lang.reflect.*;
025:
026: import java.util.*;
027: import javax.ejb.*;
028: import javax.naming.*;
029:
030: import junit.framework.Test;
031: import junit.framework.TestCase;
032: import junit.framework.TestSuite;
033:
034: import org.jboss.test.JBossTestCase;
035:
036: import org.jboss.test.idgen.interfaces.*;
037:
038: /**
039: * @author Rickard Oberg
040: * @author Author: d_jencks only added JBossTestCase and logging
041: * @version $Revision: 57211 $
042: */
043: public class IdGenUnitTestCase extends JBossTestCase {
044: // Constants -----------------------------------------------------
045:
046: // Attributes ----------------------------------------------------
047:
048: // Static --------------------------------------------------------
049:
050: // Constructors --------------------------------------------------
051: /**
052: * Constructor for the IdGenUnitTestCase object
053: *
054: * @param name Description of Parameter
055: */
056: public IdGenUnitTestCase(String name) {
057: super (name);
058: }
059:
060: // Public --------------------------------------------------------
061: /**
062: * A unit test for JUnit
063: *
064: * @exception Exception Description of Exception
065: */
066: public void testGenerator() throws Exception {
067: IdGeneratorHome home = (IdGeneratorHome) getInitialContext()
068: .lookup(IdGeneratorHome.JNDI_NAME);
069: IdGenerator generator = home.create();
070:
071: generator.getNewId("Account");
072: generator.getNewId("Account");
073: generator.getNewId("Account");
074:
075: generator.getNewId("Customer");
076: generator.getNewId("Customer");
077: generator.getNewId("Customer");
078:
079: generator.remove();
080: }
081:
082: /**
083: * The JUnit setup method
084: *
085: * @exception Exception Description of Exception
086: */
087: protected void setUp() throws Exception {
088: getLog().debug("Remove id counters");
089: {
090: IdCounterHome home = (IdCounterHome) new InitialContext()
091: .lookup(IdCounterHome.JNDI_NAME);
092: Collection counters = home.findAll();
093: Iterator i = counters.iterator();
094: while (i.hasNext()) {
095: EJBObject obj = (EJBObject) i.next();
096: getLog().debug("Removing " + obj.getPrimaryKey());
097: obj.remove();
098: }
099: }
100: }
101:
102: public static Test suite() throws Exception {
103: return getDeploySetup(IdGenUnitTestCase.class, "idgen.jar");
104: }
105:
106: }
|