KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > factoryxml > unit > FactoryUnitTestCase


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.ejb3.test.factoryxml.unit;
23
24 import org.jboss.ejb3.test.factoryxml.Entity1;
25 import org.jboss.ejb3.test.factoryxml.Entity2;
26 import org.jboss.ejb3.test.factoryxml.MyService;
27 import org.jboss.ejb3.test.factoryxml.Session1;
28 import org.jboss.ejb3.test.factoryxml.Session2;
29 import org.jboss.ejb3.test.factoryxml.Stateful1;
30 import org.jboss.ejb3.test.factoryxml.Util;
31 import org.jboss.test.JBossTestCase;
32 import junit.framework.Test;
33
34 /**
35  * Sample client for the jboss container.
36  *
37  * @author <a HREF="mailto:bill@burkecentral.com">Bill Burke</a>
38  * @version $Id: FactoryUnitTestCase.java 58110 2006-11-04 08:34:21Z scott.stark@jboss.org $
39  */

40
41 public class FactoryUnitTestCase
42         extends JBossTestCase
43 {
44    org.jboss.logging.Logger log = getLog();
45
46    static boolean deployed = false;
47    static int test = 0;
48
49    public FactoryUnitTestCase(String JavaDoc name)
50    {
51
52       super(name);
53
54    }
55
56    public void testMe() throws Exception JavaDoc
57    {
58       Session1 session1 = (Session1) this.getInitialContext().lookup("factoryxml-test/Session1Bean/remote");
59       Session2 session2 = (Session2) this.getInitialContext().lookup("factoryxml-test/Session2Bean/remote");
60       MyService service = (MyService) this.getInitialContext().lookup("factoryxml-test/MyServiceBean/remote");
61       assertNotNull(service);
62
63       int oneF = session1.create1FromFactory();
64       int oneM = session1.create1FromManager();
65       int twoF = session1.create2FromFactory();
66       int twoM = session1.create2FromManager();
67       session1.doUtil(new Util());
68
69       session2.find1FromFactory(oneF);
70       assertNotNull(session2.find1FromManager(oneM));
71       session2.find2FromFactory(twoF);
72       assertNotNull(session2.find2FromManager(twoM));
73       assertNotNull(service.find2FromManager(twoM));
74       assertNotNull(session2.findUtil1FromManager(1));
75       assertNotNull(session2.findUtil2FromManager(2));
76
77    }
78
79    public void testExtended() throws Exception JavaDoc
80    {
81       Stateful1 stateful1 = (Stateful1) this.getInitialContext().lookup("factoryxml-test/Stateful1Bean/remote");
82       Session2 session2 = (Session2) this.getInitialContext().lookup("factoryxml-test/Session2Bean/remote");
83
84       int oneId = stateful1.create1();
85       int twoId = stateful1.create2();
86
87       stateful1.update1();
88       stateful1.update2();
89
90       {
91          Entity1 one = session2.find1FromManager(oneId);
92          assertEquals(one.getString(), "changed");
93
94          Entity2 two = session2.find2FromManager(twoId);
95          assertEquals(two.getString(), "changed");
96       }
97
98       stateful1.never();
99
100       {
101          Entity1 one = session2.find1FromManager(oneId);
102          assertEquals(one.getString(), "changed");
103
104          Entity2 two = session2.find2FromManager(twoId);
105          assertEquals(two.getString(), "changed");
106       }
107
108       stateful1.checkout();
109
110       {
111          Entity1 one = session2.find1FromManager(oneId);
112          assertEquals(one.getString(), "never");
113
114          Entity2 two = session2.find2FromManager(twoId);
115          assertEquals(two.getString(), "never");
116       }
117    }
118
119    public static Test suite() throws Exception JavaDoc
120    {
121       return getDeploySetup(FactoryUnitTestCase.class, "factoryxml-test.ear");
122    }
123
124 }
125
Popular Tags