01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * 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.remoting.interceptor;
23:
24: import java.net.MalformedURLException;
25: import org.jboss.aop.advice.Interceptor;
26: import org.jboss.aop.util.PayloadKey;
27: import org.jboss.aspects.remoting.interceptors.invoker.InvokerInterceptor;
28: import org.jboss.aspects.remoting.interceptors.invoker.RemotingInterceptorFactory;
29: import org.jboss.remoting.InvokerLocator;
30: import org.jboss.remoting.marshal.serializable.SerializableMarshaller;
31:
32: import junit.framework.TestCase;
33:
34: /**
35: * @author <a href="mailto:tom@jboss.org">Tom Elrod</a>
36: */
37: public class ClientInterceptorTest extends TestCase {
38: private boolean passed = false;
39:
40: public void runTest() throws MalformedURLException {
41: // Create interceptor stack
42: Interceptor[] interceptorStack = new Interceptor[] { new InvokerInterceptor() };
43:
44: TestInvocation invocation = new TestInvocation(interceptorStack);
45: invocation.setArgument(new TestTarget());
46:
47: int port = 8081;
48: String transport = "socket";
49:
50: InvokerLocator locator = new InvokerLocator(transport
51: + "://localhost:" + port + "/?"
52: + InvokerLocator.DATATYPE + "="
53: + SerializableMarshaller.DATATYPE);
54: invocation.getMetaData().addMetaData(
55: RemotingInterceptorFactory.REMOTING,
56: RemotingInterceptorFactory.INVOKER_LOCATOR, locator,
57: PayloadKey.TRANSIENT);
58:
59: try {
60: Object ret = invocation.invokeNext();
61: if (ret instanceof Boolean
62: && ((Boolean) ret).booleanValue()) {
63: assertTrue(
64: "Simple interceptor test passed. Value returned was not true.",
65: true);
66: System.out.println("Test PASSED.");
67: passed = true;
68: } else {
69: assertTrue(
70: "Simple interceptor test passed. Value returned was not true.",
71: false);
72: System.out.println("Test FAILED!!!");
73: passed = false;
74: }
75: } catch (Throwable throwable) {
76: throwable.printStackTrace();
77: }
78: }
79:
80: public boolean isTestPassing() {
81: return passed;
82: }
83:
84: public static void main(String[] args) {
85: try {
86: new ClientInterceptorTest().runTest();
87: } catch (MalformedURLException e) {
88: e.printStackTrace();
89: }
90: }
91:
92: }
|