KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > remoting > interceptor > ClientInterceptorTest


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.remoting.interceptor;
8
9 import junit.framework.TestCase;
10 import org.jboss.aop.advice.Interceptor;
11 import org.jboss.aop.util.PayloadKey;
12 import org.jboss.aspects.remoting.interceptors.invoker.InvokerInterceptor;
13 import org.jboss.aspects.remoting.interceptors.invoker.RemotingInterceptorFactory;
14 import org.jboss.remoting.InvokerLocator;
15 import org.jboss.remoting.marshal.serializable.SerializableMarshaller;
16
17 import java.net.MalformedURLException JavaDoc;
18
19 /**
20  * @author <a HREF="mailto:tom@jboss.org">Tom Elrod</a>
21  */

22 public class ClientInterceptorTest extends TestCase
23 {
24    private boolean passed = false;
25
26    public void runTest() throws MalformedURLException JavaDoc
27    {
28       // Create interceptor stack
29
Interceptor[] interceptorStack = new Interceptor[]{new InvokerInterceptor()};
30
31       TestInvocation invocation = new TestInvocation(interceptorStack);
32       invocation.setArgument(new TestTarget());
33
34       int port = 8081;
35       String JavaDoc transport = "socket";
36
37       InvokerLocator locator = new InvokerLocator(transport + "://localhost:" + port + "/?" +
38                                                   InvokerLocator.DATATYPE + "=" + SerializableMarshaller.DATATYPE);
39       invocation.getMetaData().addMetaData(RemotingInterceptorFactory.REMOTING,
40                                            RemotingInterceptorFactory.INVOKER_LOCATOR, locator, PayloadKey.TRANSIENT);
41
42       try
43       {
44          Object JavaDoc ret = invocation.invokeNext();
45          if(ret instanceof Boolean JavaDoc && ((Boolean JavaDoc) ret).booleanValue())
46          {
47             assertTrue("Simple interceptor test passed. Value returned was not true.", true);
48             System.out.println("Test PASSED.");
49             passed = true;
50          }
51          else
52          {
53             assertTrue("Simple interceptor test passed. Value returned was not true.", false);
54             System.out.println("Test FAILED!!!");
55             passed = false;
56          }
57       }
58       catch(Throwable JavaDoc throwable)
59       {
60          throwable.printStackTrace();
61       }
62    }
63
64    public boolean isTestPassing()
65    {
66       return passed;
67    }
68
69    public static void main(String JavaDoc[] args)
70    {
71       try
72       {
73          new ClientInterceptorTest().runTest();
74       }
75       catch(MalformedURLException JavaDoc e)
76       {
77          e.printStackTrace();
78       }
79    }
80
81 }
Popular Tags