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 ; 8 9 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 s) { 26 super(s); 27 factory = new HttpServiceFactory("localhost", 8080, "remoting"); 28 } 30 31 public void testBasicCall() throws Exception { 32 String result = getStatelessTest().upper("word"); 33 assertEquals("WORD",result); 34 } 35 36 public void testException() throws Exception { 37 try { 38 getStatelessTest().throwsException(); 39 } catch (Exception e) { 40 System.out.println(e.getLocalizedMessage()); 41 return; 43 } 44 fail("Exception should have been thrown"); 45 } 46 47 48 public void testEJBException() throws Exception { 49 try { 50 getStatelessTest().throwsSecurityException(); 51 } catch (ServerException e) { 52 53 System.out.println(e.getCause().getLocalizedMessage()); 54 return; 56 } 57 fail("Exception should have been thrown"); 58 } 59 60 61 public void testStatefullCreation() throws Exception { 62 StatelessTest newRemoteObject = getStatelessTest().createOtherBean(); 63 assertNotNull(newRemoteObject); 64 String result = newRemoteObject.upper("call_on_statefull"); 65 assertEquals(result, "CALL_ON_STATEFULL"); 66 } 67 68 public void testAuthentification() throws Exception { 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 { 79 return (StatelessTest) factory.getService(TEST_SESSION); 80 } 81 82 83 84 } 85 | Popular Tags |