KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > aop > test > RemotingUnitTestCase


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.aop.test;
23
24 import javax.management.MBeanServerConnection JavaDoc;
25 import javax.management.ObjectName JavaDoc;
26
27 import junit.framework.Test;
28 import junit.framework.TestSuite;
29
30 import org.jboss.logging.Logger;
31 import org.jboss.mx.util.ObjectNameFactory;
32 import org.jboss.test.JBossTestCase;
33 import org.jboss.test.aop.bean.NonadvisedPOJO;
34 import org.jboss.test.aop.bean.POJO;
35 import org.jboss.aop.proxy.ClassProxy;
36
37 /**
38 * Sample client for the jboss container.
39 *
40 * @author <a HREF="mailto:bill@burkecentral.com">Bill Burke</a>
41 * @version $Id: RemotingUnitTestCase.java 58115 2006-11-04 08:42:14Z scott.stark@jboss.org $
42 */

43
44 public class RemotingUnitTestCase
45    extends JBossTestCase
46 {
47    Logger log = getLog();
48
49    private ObjectName JavaDoc testerName = ObjectNameFactory.create("jboss.aop:name=RemotingTester");
50
51    private Object JavaDoc[] noparams = {};
52    private String JavaDoc[] nosig = {};
53
54    public RemotingUnitTestCase(String JavaDoc name)
55    {
56       super(name);
57    }
58
59    protected void setUp() throws Exception JavaDoc
60    {
61       //load the network registry
62
}
63
64    protected void tearDown() throws Exception JavaDoc
65    {
66    }
67
68    public void testRemoting() throws Exception JavaDoc
69    {
70       MBeanServerConnection JavaDoc server = getServer();
71       POJO pojo = (POJO)server.invoke(testerName, "testRemoting", noparams, nosig);
72       try
73       {
74          ClassProxy proxy = (ClassProxy)pojo;
75          String JavaDoc rtn = pojo.remoteTest(); // invokes remotely
76
if (!rtn.equals("hello"))
77             throw new Exception JavaDoc("DID NOT GET EXPECTED REMOTE VALUE");
78       }
79       finally
80       {
81          unregisterWithOid(server, "myobj");
82       }
83    }
84
85    public void testNonadvisedRemoting() throws Exception JavaDoc
86    {
87       MBeanServerConnection JavaDoc server = getServer();
88       NonadvisedPOJO pojo = (NonadvisedPOJO)server.invoke(testerName, "testNonadvisedRemoting", noparams, nosig);
89       try
90       {
91          String JavaDoc rtn = pojo.remoteTest(); // invokes remotely
92
if (!rtn.equals("hello"))
93             throw new Exception JavaDoc("DID NOT GET EXPECTED REMOTE VALUE");
94       }
95       finally
96       {
97          unregisterWithOid(server, "myobj");
98       }
99    }
100
101    public void testClusteredRemoting() throws Exception JavaDoc
102    {
103       MBeanServerConnection JavaDoc server = getServer();
104       POJO pojo = (POJO)server.invoke(testerName, "testClusteredRemoting", noparams, nosig);
105       try
106       {
107          String JavaDoc rtn = pojo.remoteTest(); // invokes remotely
108
if (!rtn.equals("hello"))
109             throw new Exception JavaDoc("DID NOT GET EXPECTED REMOTE VALUE");
110          pojo.remoteTest();//just make sure we can invoke twice...
111
}
112       finally
113       {
114          unregisterTarget(server, pojo);
115       }
116    }
117
118    public void testClusteredNonadvisedRemoting() throws Exception JavaDoc
119    {
120       MBeanServerConnection JavaDoc server = getServer();
121       NonadvisedPOJO pojo = (NonadvisedPOJO)server.invoke(testerName, "testClusteredNonadvisedRemoting", noparams, nosig);
122       try
123       {
124          String JavaDoc rtn = pojo.remoteTest(); // invokes remotely
125
if (!rtn.equals("hello"))
126             throw new Exception JavaDoc("DID NOT GET EXPECTED REMOTE VALUE");
127       }
128       finally
129       {
130          unregisterTarget(server, pojo);
131       }
132    }
133
134    public static Test suite() throws Exception JavaDoc
135    {
136       TestSuite suite = new TestSuite();
137       suite.addTest(new TestSuite(RemotingUnitTestCase.class));
138
139       AOPTestSetup setup = new AOPTestSetup(suite, "aoptest.sar");
140       return setup;
141    }
142
143    protected void unregisterWithOid(MBeanServerConnection JavaDoc server, String JavaDoc oid) throws Exception JavaDoc
144    {
145       Object JavaDoc[] params = {oid};
146       String JavaDoc[] sig = {"java.lang.String"};
147       server.invoke(testerName, "unregisterNonClusteredObject", params, sig);
148    }
149    
150    protected void unregisterTarget(MBeanServerConnection JavaDoc server, Object JavaDoc proxy)
151       throws Exception JavaDoc
152    {
153       Object JavaDoc[] params = { proxy };
154       String JavaDoc[] sig = { "java.lang.Object" };
155       server.invoke(testerName, "unregisterTarget", params, sig);
156    }
157
158 }
159
Popular Tags