KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > hibernate > test > ScopedEarsUnitTestCase


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
23 package org.jboss.test.hibernate.test;
24
25 import java.util.Date JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import javax.naming.InitialContext JavaDoc;
29
30 import org.jboss.test.JBossTestCase;
31
32 import junit.framework.Test;
33
34 /**
35  Test of the ejb timers table mapping
36
37  @author Scott.Stark@jboss.org
38  @version $Revision: 41308 $
39  */

40 public class ScopedEarsUnitTestCase extends JBossTestCase
41 {
42    public ScopedEarsUnitTestCase(String JavaDoc name) throws Exception JavaDoc
43    {
44       super(name);
45    }
46
47    /**
48     Setup the test suite.
49     */

50    public static Test suite() throws Exception JavaDoc
51    {
52       return getDeploySetup(ScopedEarsUnitTestCase.class, "hib-ear1.ear,hib-ear2.ear");
53    }
54
55    public void testEAR1Session() throws Throwable JavaDoc
56    {
57       InitialContext JavaDoc ctx = getInitialContext();
58       org.jboss.test.hibernate.model.v1.IPersonHome home =
59          (org.jboss.test.hibernate.model.v1.IPersonHome) ctx.lookup("hibernate/ear1/PersonBean");
60       org.jboss.test.hibernate.model.v1.IPerson bean = null;
61
62       try
63       {
64          bean = home.create();
65          bean.init();
66          bean.sessionInit();
67
68          int initialCount = bean.listPeople().size();
69          assertTrue("People initialCount == 0 ", initialCount == 0 );
70
71          org.jboss.test.hibernate.model.v1.Person jimmy = new org.jboss.test.hibernate.model.v1.Person(197);
72          Date JavaDoc bday = new Date JavaDoc(2003, 6, 13);
73          jimmy.setBDay(bday);
74          jimmy.setName("Jimmy Neutron");
75          jimmy.setAddress("Channel 302, Nicktoons USA");
76          jimmy.setPay(new Float JavaDoc(123456.789));
77          bean.storeUser(jimmy);
78
79          List JavaDoc persons = bean.listPeople();
80          assertNotNull(persons);
81          assertEquals("Incorrect result size", initialCount + 1, persons.size());
82
83          org.jboss.test.hibernate.model.v1.Person found = null;
84          Iterator JavaDoc itr = persons.iterator();
85          while (itr.hasNext())
86          {
87             org.jboss.test.hibernate.model.v1.Person p =
88                (org.jboss.test.hibernate.model.v1.Person) itr.next();
89             if (p.getName().equals(jimmy.getName()))
90             {
91                found = p;
92             }
93          }
94          assertNotNull("Found Jimmy in list", found);
95       }
96       finally
97       {
98          if (bean != null)
99          {
100             try
101             {
102                bean.remove();
103             }
104             catch (Throwable JavaDoc t)
105             {
106                // ignore
107
}
108          }
109       }
110    }
111
112    public void testEAR2Session() throws Throwable JavaDoc
113    {
114       InitialContext JavaDoc ctx = getInitialContext();
115       org.jboss.test.hibernate.model.v2.IPersonHome home =
116          (org.jboss.test.hibernate.model.v2.IPersonHome) ctx.lookup("hibernate/ear2/PersonBean");
117       org.jboss.test.hibernate.model.v2.IPerson bean = null;
118
119       try
120       {
121          bean = home.create();
122          bean.init();
123          bean.sessionInit();
124
125          int initialCount = bean.listPeople().size();
126          assertTrue("People initialCount == 0 ", initialCount == 0 );
127
128          org.jboss.test.hibernate.model.v2.Person jimmy = new org.jboss.test.hibernate.model.v2.Person(197);
129          Date JavaDoc bday = new Date JavaDoc(2003, 6, 13);
130          jimmy.setBDay(bday);
131          jimmy.setName("Jimmy Neutron");
132          jimmy.setAddress("Channel 302, Nicktoons USA");
133          jimmy.setPay(new Float JavaDoc(123456.789));
134          bean.storeUser(jimmy);
135
136          List JavaDoc persons = bean.listPeople();
137          assertNotNull(persons);
138          assertEquals("Incorrect result size", initialCount + 1, persons.size());
139
140          org.jboss.test.hibernate.model.v2.Person found = null;
141          Iterator JavaDoc itr = persons.iterator();
142          while (itr.hasNext())
143          {
144             org.jboss.test.hibernate.model.v2.Person p =
145                (org.jboss.test.hibernate.model.v2.Person) itr.next();
146             if (p.getName().equals(jimmy.getName()))
147             {
148                found = p;
149             }
150          }
151          assertNotNull("Found Jimmy in list", found);
152       }
153       finally
154       {
155          if (bean != null)
156          {
157             try
158             {
159                bean.remove();
160             }
161             catch (Throwable JavaDoc t)
162             {
163                // ignore
164
}
165          }
166       }
167    }
168
169 }
170
Popular Tags