KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > invokers > test > MultiInvokersUnitTestCase


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.invokers.test;
23
24 import java.util.ArrayList JavaDoc;
25 import javax.naming.InitialContext JavaDoc;
26
27 import junit.framework.Test;
28 import org.jboss.proxy.IClientContainer;
29 import org.jboss.test.JBossTestCase;
30 import org.jboss.test.invokers.interfaces.SimpleBMP;
31 import org.jboss.test.invokers.interfaces.SimpleBMPHome;
32 import org.jboss.test.invokers.interfaces.StatelessSession;
33 import org.jboss.test.invokers.interfaces.StatelessSessionHome;
34 import org.jboss.test.invokers.interfaces.BusinessObjectHome;
35 import org.jboss.test.invokers.interfaces.BusinessObject;
36
37 /**
38  * Test use of multiple invokers per container
39  *
40  * @author bill@burkecentral.com
41  * @version $Revision: 37406 $
42  */

43 public class MultiInvokersUnitTestCase extends JBossTestCase
44 {
45    /**
46     * Constructor for the CustomSocketsUnitTestCase object
47     *
48     * @param name Description of Parameter
49     */

50    public MultiInvokersUnitTestCase(String JavaDoc name)
51    {
52       super(name);
53    }
54
55
56    /**
57     * A unit test for JUnit
58     *
59     * @exception Exception Description of Exception
60     */

61    public void testMultiInvokers() throws Exception JavaDoc
62    {
63       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
64       SimpleBMPHome home1 = (SimpleBMPHome)ctx.lookup("SimpleBMP");
65       SimpleBMPHome home2 = (SimpleBMPHome)ctx.lookup("CompressionSimpleBMP");
66
67       SimpleBMP bmp1 = home1.create(1, "bill");
68       SimpleBMP bmp2 = home2.findByPrimaryKey(new Integer JavaDoc(1)); // should find it.
69

70       getLog().debug("");
71       getLog().debug("bmp1 name: " + bmp1.getName());
72       getLog().debug("bmp2 name: " + bmp2.getName());
73       getLog().debug("setting name to burke");
74       bmp1.setName("burke");
75       getLog().debug("bmp1 name: " + bmp1.getName());
76       getLog().debug("bmp2 name: " + bmp2.getName());
77       assertTrue("bmp1 " + bmp1.getName() + " == bmp2 " + bmp2.getName(), bmp1.getName().equals(bmp2.getName()));
78
79       StatelessSessionHome shome1 = (StatelessSessionHome)ctx.lookup("StatelessSession");
80       StatelessSessionHome shome2 = (StatelessSessionHome)ctx.lookup("CompressionStatelessSession");
81       StatelessSession ss1 = shome1.create();
82       StatelessSession ss2 = shome2.create();
83
84       ss1.getBMP(1);
85       ss2.getBMP(1);
86       
87    }
88
89    /** Use the IClientContainer view of the proxy to install a custom
90     * InvokerInterceptor which routes requests to either the server side
91     * selected transport for the BusinessSession, or an mdb depending
92     * on the method invoked.
93     *
94     * @throws Exception
95     */

96    public void testClientContainer() throws Exception JavaDoc
97    {
98       log.info("+++ testClientContainer");
99       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
100       BusinessObjectHome home = (BusinessObjectHome)ctx.lookup("BusinessSession");
101       // Check the IClientContainer interface
102
IClientContainer container = (IClientContainer) home;
103       ArrayList JavaDoc interceptors = container.getInterceptors();
104       for(int n = 0; n < interceptors.size(); n ++)
105       {
106          log.info(interceptors.get(n));
107       }
108       BusinessObject bean = home.create();
109       container = (IClientContainer) bean;
110       interceptors = container.getInterceptors();
111       for(int n = 0; n < interceptors.size(); n ++)
112       {
113          log.info(interceptors.get(n));
114       }
115       // Replace the default InvokerInterceptor
116
int last = interceptors.size() - 1;
117       interceptors.set(last, new InvokerInterceptor());
118       container.setInterceptors(interceptors);
119
120       // Invoke over the rpc transport
121
bean.doSomething();
122       // Invoker over the jms transport
123
String JavaDoc reply = bean.doSomethingSlowly("arg1", "arg2");
124       assertTrue("Reply is decorated with viaJMSGatewayMDB",
125          reply.indexOf("viaJMSGatewayMDB") > 0 );
126       // Remove the bean to close the jms resources
127
bean.remove();
128    }
129
130    public static Test suite() throws Exception JavaDoc
131    {
132       return getDeploySetup(MultiInvokersUnitTestCase.class, "invokers.jar");
133    }
134
135 }
136
Popular Tags