1 22 package org.jboss.test.client.test; 23 24 import java.util.Properties ; 25 import java.net.URL ; 26 import javax.naming.InitialContext ; 27 import javax.naming.Context ; 28 import javax.naming.NamingException ; 29 import javax.jms.Queue ; 30 31 import org.jboss.test.cts.interfaces.StatelessSession; 32 import org.jboss.test.cts.interfaces.StatelessSessionHome; 33 import org.jboss.test.JBossTestCase; 34 import org.jboss.test.JBossTestSetup; 35 36 import junit.framework.Test; 37 import junit.framework.TestSuite; 38 39 44 public class AppClientUnitTestCase extends JBossTestCase 45 { 46 public AppClientUnitTestCase(String name) 47 { 48 super(name); 49 } 50 51 54 public void testENC() throws Exception 55 { 56 Context enc = getENC(); 57 getLog().debug("ENC: "+enc); 58 59 String str0 = (String ) enc.lookup("String0"); 60 assertTrue("String0 == String0Value", str0.equals("String0Value")); 61 62 Float flt0 = (Float ) enc.lookup("Float0"); 63 assertTrue("Float0 == 3.14", flt0.equals(new Float ("3.14"))); 64 65 Long long0 = (Long ) enc.lookup("Long0"); 66 assertTrue("Long0 == 123456789", long0.equals(new Long (123456789))); 67 68 StatelessSessionHome home = (StatelessSessionHome) enc.lookup("ejb/StatelessSessionBean"); 69 assertTrue("ejb/StatelessSessionBean isa StatelessSessionHome", home != null); 70 71 URL jbossHome = (URL ) enc.lookup("url/JBossHome"); 72 assertTrue("url/JBossHome == http://www.jboss.org", 73 jbossHome.toString().equals("http://www.jboss.org")); 74 75 URL indirectURL = (URL ) enc.lookup("url/IndirectURL"); 76 assertTrue("url/IndirectURL == http://www.somesite.com", 77 indirectURL.toString().equals("http://www.somesite.com")); 78 79 Queue testQueue = (Queue ) enc.lookup("jms/aQueue"); 80 assertTrue("jms/aQueue isa Queue", testQueue != null); 81 82 Queue anotherQueue = (Queue ) enc.lookup("jms/anotherQueue"); 83 assertTrue("jms/anotherQueue isa Queue", anotherQueue != null); 84 85 Queue anotherQueue2 = (Queue ) enc.lookup("jms/anotherQueue2"); 86 assertTrue("jms/anotherQueue2 isa Queue", anotherQueue != null); 87 } 88 89 92 public void testEjbs() throws Exception 93 { 94 Context enc = getENC(); 95 StatelessSessionHome home = (StatelessSessionHome) enc.lookup("ejb/StatelessSessionBean"); 96 StatelessSession session = home.create(); 97 session.method1("testEjbs"); 98 session.remove(); 99 } 100 101 105 private Context getENC() throws NamingException 106 { 107 Properties env = new Properties (); 108 env.setProperty(Context.INITIAL_CONTEXT_FACTORY, 109 "org.jnp.interfaces.NamingContextFactory"); 110 env.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming.client"); 111 env.setProperty(Context.PROVIDER_URL, "jnp://localhost:1099"); 112 env.setProperty("j2ee.clientName", "test-client"); 113 InitialContext ctx = new InitialContext (env); 114 Context enc = (Context ) ctx.lookup("java:comp/env"); 115 return enc; 116 } 117 118 public static Test suite() throws Exception 119 { 120 TestSuite suite = new TestSuite(); 121 122 suite.addTest(new JBossTestSetup(new TestSuite(AppClientUnitTestCase.class)) 123 { 124 protected void setUp() throws Exception 125 { 126 super.setUp(); 127 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 128 deploy (loader.getResource("messaging/test-destinations-full-service.xml").toString()); 129 deploy ("app-client.ear"); 130 } 131 protected void tearDown() throws Exception 132 { 133 super.tearDown(); 134 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 135 undeploy ("app-client.ear"); 136 undeploy (loader.getResource("messaging/test-destinations-full-service.xml").toString()); 137 } 138 }); 139 140 return suite; 141 } 142 } 143 | Popular Tags |