KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > initial > Tester


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.initial;
23
24 import java.util.Map JavaDoc;
25 import javax.naming.InitialContext JavaDoc;
26
27 /**
28  * Comment
29  *
30  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
31  * @version $Revision: 39547 $
32  */

33 public class Tester implements TesterMBean
34 {
35    public void testSLSBCollocation() throws Exception JavaDoc
36    {
37       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
38       TestLocal local = (TestLocal) ctx.lookup("TestBean/local");
39       TestRemote remote = (TestRemote) ctx.lookup("TestBean/remote");
40
41       if (local.getObject() != TestBean.obj) throw new RuntimeException JavaDoc("Local call not equal");
42       if (local.getObject() == remote.getObject()) throw new RuntimeException JavaDoc("Remote should not be equal");
43       Map JavaDoc map = remote.getObject();
44       map.put("hello", "world");
45
46       Object JavaDoc obj = local.echo(map);
47       if (obj != map) throw new RuntimeException JavaDoc("argument and return should be the same");
48
49       map = (Map JavaDoc)obj;
50       if (!map.containsKey("hello")) throw new RuntimeException JavaDoc("not good return");
51
52       obj = remote.echo(map);
53       if (obj == map) throw new RuntimeException JavaDoc("argument and return should not be the same");
54
55       map = (Map JavaDoc)obj;
56       if (!map.containsKey("hello")) throw new RuntimeException JavaDoc("not good return");
57
58    }
59
60    public void testSFSBCollocation() throws Exception JavaDoc
61    {
62       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
63       StatefulTestLocal local = (StatefulTestLocal) ctx.lookup("StatefulTestBean/local");
64       StatefulTestRemote remote = (StatefulTestRemote) ctx.lookup("StatefulTestBean/remote");
65
66       if (local.getObject() != StatefulTestBean.obj) throw new RuntimeException JavaDoc("Local call not equal");
67       if (local.getObject() == remote.getObject()) throw new RuntimeException JavaDoc("Remote should not be equal");
68       Map JavaDoc map = remote.getObject();
69       map.put("hello", "world");
70
71       Object JavaDoc obj = local.echo(map);
72       if (obj != map) throw new RuntimeException JavaDoc("argument and return should be the same");
73       map = (Map JavaDoc)obj;
74       if (!map.containsKey("hello")) throw new RuntimeException JavaDoc("not good return");
75
76       obj = remote.echo(map);
77       if (obj == map) throw new RuntimeException JavaDoc("argument and return should not be the same");
78
79       map = (Map JavaDoc)obj;
80       if (!map.containsKey("hello")) throw new RuntimeException JavaDoc("not good return");
81    }
82
83
84    public void test() throws Exception JavaDoc
85    {
86       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
87       Test test = (Test) ctx.lookup("TestBean/local");
88       String JavaDoc echo = test.testMe("echo");
89       if (!"echo".equals(echo)) throw new RuntimeException JavaDoc("ECHO FAILED!");
90    }
91
92    public void statefulTest() throws Exception JavaDoc
93    {
94       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
95       StatefulTestLocal test = (StatefulTestLocal) ctx.lookup("StatefulTestBean/local");
96       test.setState("hello world");
97       if (!test.getState().equals("hello world")) throw new Exception JavaDoc("state was not retained");
98    }
99
100    public void testInterceptors() throws Exception JavaDoc
101    {
102       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
103       InterceptedSLTest test = (InterceptedSLTest) ctx.lookup("InterceptedSLTestBean/local");
104       int ret = test.testMethod(5);
105       int expected = 3010;
106
107       if (ret != expected) throw new Exception JavaDoc("return value was not " + expected + ", it was: " + ret);
108
109       boolean exception = false;
110       try
111       {
112          test.throwsThrowable(1);
113       }
114       catch (Throwable JavaDoc e)
115       {
116          exception = true;
117       }
118       if (!exception) throw new Exception JavaDoc("Exception was not thrown");
119    }
120
121    public void testCallbacks() throws Exception JavaDoc
122    {
123       //Check the correct callbacks get invoked
124
InitialContext JavaDoc ctx = new InitialContext JavaDoc();
125       TestStatus status = (TestStatus) ctx.lookup("TestStatusBean/remote");
126       status.clear();
127       InterceptedSLTest test = (InterceptedSLTest) ctx.lookup("InterceptedSLTestBean/local");
128       test.testMethod(5);
129       if (!status.postConstruct()) throw new Exception JavaDoc("PostConstruct should be called for SLSB");
130       if (status.prePassivate()) throw new Exception JavaDoc("PrePassivate should not be called for SLSB");
131       if (status.postActivate()) throw new Exception JavaDoc("PostActivate should not be called for SLSB");
132
133       //TODO: Figure out when destroy gets called
134
//if (!status.preDestroy()) throw new Exception("PreDestroy should be called for SLSB");
135
}
136 }
137
138
139
140
Popular Tags