KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > idgen > test > IdGenUnitTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.idgen.test;
23 import java.lang.reflect.*;
24
25 import java.util.*;
26 import javax.ejb.*;
27 import javax.naming.*;
28
29 import junit.framework.Test;
30 import junit.framework.TestCase;
31 import junit.framework.TestSuite;
32
33 import org.jboss.test.JBossTestCase;
34
35 import org.jboss.test.idgen.interfaces.*;
36
37 /**
38  * @see <related>
39  * @author Author: d_jencks only added JBossTestCase and logging
40  * @version $Revision: 58390 $
41  */

42 public class IdGenUnitTestCase
43        extends JBossTestCase
44 {
45    // Constants -----------------------------------------------------
46

47    // Attributes ----------------------------------------------------
48

49    // Static --------------------------------------------------------
50

51
52    // Constructors --------------------------------------------------
53
/**
54     * Constructor for the IdGenUnitTestCase object
55     *
56     * @param name Description of Parameter
57     */

58    public IdGenUnitTestCase(String JavaDoc name)
59    {
60       super(name);
61    }
62
63    // Public --------------------------------------------------------
64
/**
65     * A unit test for JUnit
66     *
67     * @exception Exception Description of Exception
68     */

69    public void testGenerator()
70           throws Exception JavaDoc
71    {
72       IdGeneratorHome home = (IdGeneratorHome)getInitialContext().lookup(IdGeneratorHome.JNDI_NAME);
73       IdGenerator generator = home.create();
74
75       generator.getNewId("Account");
76       generator.getNewId("Account");
77       generator.getNewId("Account");
78
79       generator.getNewId("Customer");
80       generator.getNewId("Customer");
81       generator.getNewId("Customer");
82
83       generator.remove();
84    }
85
86    /**
87     * The JUnit setup method
88     *
89     * @exception Exception Description of Exception
90     */

91    protected void setUp()
92           throws Exception JavaDoc
93    {
94       super.setUp();
95       getLog().debug("Remove id counters");
96       {
97          IdCounterHome home = (IdCounterHome)new InitialContext().lookup(IdCounterHome.JNDI_NAME);
98          Collection counters = home.findAll();
99          Iterator i = counters.iterator();
100          while (i.hasNext())
101          {
102             EJBObject obj = (EJBObject)i.next();
103             getLog().debug("Removing " + obj.getPrimaryKey());
104             obj.remove();
105          }
106       }
107    }
108
109    public static Test suite() throws Exception JavaDoc
110    {
111       return getDeploySetup(IdGenUnitTestCase.class, "idgen.jar");
112    }
113
114 }
115
Popular Tags