KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > bsf > remoting > TestHttpSession


1 package org.bsf.remoting;
2
3 import org.bsf.remoting.EJBDefinition;
4 import org.bsf.remoting.http.HttpServiceFactory;
5 import junit.framework.TestCase;
6
7 import java.rmi.ServerException JavaDoc;
8
9 /**
10  * Test the basic functionnalities of the HTTP invocation.
11  * User: gaetan
12  * Date: Dec 12, 2002
13  * Time: 10:12:37 AM
14  */

15 public class TestHttpSession extends TestCase{
16
17     HttpServiceFactory factory;
18
19     private static final EJBDefinition TEST_SESSION = new EJBDefinition(
20         "ejb/TestSession",
21             "org.bsf.remoting.StatelessTestHome",
22             "org.bsf.remoting.StatelessTest"
23     );
24
25     public TestHttpSession(String JavaDoc s) {
26         super(s);
27         factory = new HttpServiceFactory("localhost", 8080, "remoting");
28 // factory = new HttpServiceFactory("https","www.bs-factory.com", 443,"remoting");
29
}
30
31     public void testBasicCall() throws Exception JavaDoc {
32         String JavaDoc result = getStatelessTest().upper("word");
33         assertEquals("WORD",result);
34     }
35
36     public void testException() throws Exception JavaDoc{
37         try {
38             getStatelessTest().throwsException();
39         } catch (Exception JavaDoc e) {
40             System.out.println(e.getLocalizedMessage());
41             //OK normal
42
return;
43         }
44         fail("Exception should have been thrown");
45     }
46
47
48     public void testEJBException() throws Exception JavaDoc{
49         try {
50             getStatelessTest().throwsSecurityException();
51         } catch (ServerException JavaDoc e) {
52
53             System.out.println(e.getCause().getLocalizedMessage());
54             //OK
55
return;
56         }
57         fail("Exception should have been thrown");
58     }
59
60
61     public void testStatefullCreation() throws Exception JavaDoc {
62         StatelessTest newRemoteObject = getStatelessTest().createOtherBean();
63         assertNotNull(newRemoteObject);
64         String JavaDoc result = newRemoteObject.upper("call_on_statefull");
65         assertEquals(result, "CALL_ON_STATEFULL");
66     }
67
68     public void testAuthentification() throws Exception JavaDoc {
69         factory.setLogin("titi");
70         factory.setPassword("toto");
71
72         long time = System.currentTimeMillis();
73         assertEquals("titi", getStatelessTest().getCallerPrincipal());
74         time = System.currentTimeMillis() - time;
75         System.out.println("Call to getCurrentTimeMillis in " + time + " ms");
76     }
77
78     public StatelessTest getStatelessTest() throws Exception JavaDoc{
79         return (StatelessTest) factory.getService(TEST_SESSION);
80     }
81
82
83
84 }
85
Popular Tags