KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > localcall > ServiceBean


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.ejb3.test.localcall;
24
25 import javax.ejb.Remote JavaDoc;
26 import javax.ejb.Local JavaDoc;
27 import javax.naming.InitialContext JavaDoc;
28
29 import org.jboss.annotation.ejb.Service;
30
31 /**
32  *
33  * @author <a HREF="mailto:kabir.khan@jboss.org">Kabir Khan</a>
34  * @version $Revision: 39547 $
35  */

36 @Service
37 @Remote JavaDoc(ServiceRemote.class)
38 @Local JavaDoc(ServiceLocal.class)
39 public class ServiceBean implements ServiceLocal, ServiceRemote
40 {
41    public void test()
42    {
43       
44    }
45    
46    public void testLocal()throws Exception JavaDoc
47    {
48       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
49       StatefulLocal stateful1 = (StatefulLocal)ctx.lookup("StatefulBean/local");
50       StatefulLocal stateful2 = (StatefulLocal)ctx.lookup("StatefulBean/local");
51       
52       StatefulClustered statefulClustered1 = (StatefulClustered)ctx.lookup("StatefulClusteredBean/remote");
53       StatefulClustered statefulClustered2 = (StatefulClustered)ctx.lookup("StatefulClusteredBean/remote");
54       
55       StatelessLocal stateless1 = (StatelessLocal)ctx.lookup("StatelessBean/local");
56       StatelessLocal stateless2 = (StatelessLocal)ctx.lookup("StatelessBean/local");
57       
58       StatelessClustered statelessClustered1 = (StatelessClustered)ctx.lookup("StatelessClusteredBean/remote");
59       StatelessClustered statelessClustered2 = (StatelessClustered)ctx.lookup("StatelessClusteredBean/remote");
60       
61       ServiceLocal service1 = (ServiceLocal)ctx.lookup("ServiceBean/local");
62       ServiceLocal service2 = (ServiceLocal)ctx.lookup("ServiceBean/local");
63       
64       stateful1.test();
65       stateful2.test();
66       statefulClustered1.test();
67       statefulClustered2.test();
68       stateless1.test();
69       stateless2.test();
70       statelessClustered1.test();
71       statelessClustered2.test();
72       service1.test();
73       service2.test();
74
75       assertFalse(stateful1.hashCode() == stateful2.hashCode());
76       assertFalse(statefulClustered1.hashCode() == statefulClustered2.hashCode());
77       assertTrue(stateless1.hashCode() == stateless2.hashCode());
78       assertTrue(statelessClustered1.hashCode() == statelessClustered2.hashCode());
79       assertTrue(service1.hashCode() == service2.hashCode());
80       
81       assertFalse(stateful1.equals(stateful2));
82       assertFalse(statefulClustered1.equals(statefulClustered2));
83       assertTrue(stateless1.equals(stateless2));
84       assertTrue(statelessClustered1.equals(statelessClustered2));
85       assertTrue(service1.equals(service2));
86    }
87    
88    private void assertFalse(boolean b)
89    {
90       if (b)
91       {
92          throw new RuntimeException JavaDoc("Assertion failed!");
93       }
94    }
95
96    private void assertTrue(boolean b)
97    {
98       if (!b)
99       {
100          throw new RuntimeException JavaDoc("Assertion failed!");
101       }
102    }
103    
104 }
105
Popular Tags