KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > client > test > AppClientUnitTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * 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.client.test;
23
24 import java.util.Properties JavaDoc;
25 import java.net.URL JavaDoc;
26 import javax.naming.InitialContext JavaDoc;
27 import javax.naming.Context JavaDoc;
28 import javax.naming.NamingException JavaDoc;
29 import javax.jms.Queue JavaDoc;
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 /** Tests of accessing a j2ee application client deployment
40  *
41  * @author Scott.Stark@jboss.org
42  * @version $Revision: 37406 $
43  */

44 public class AppClientUnitTestCase extends JBossTestCase
45 {
46    public AppClientUnitTestCase(String JavaDoc name)
47    {
48       super(name);
49    }
50
51    /** Test that the client java:comp/env context contains what is expected
52     * @throws Exception
53     */

54    public void testENC() throws Exception JavaDoc
55    {
56       Context JavaDoc enc = getENC();
57       getLog().debug("ENC: "+enc);
58
59       String JavaDoc str0 = (String JavaDoc) enc.lookup("String0");
60       assertTrue("String0 == String0Value", str0.equals("String0Value"));
61
62       Float JavaDoc flt0 = (Float JavaDoc) enc.lookup("Float0");
63       assertTrue("Float0 == 3.14", flt0.equals(new Float JavaDoc("3.14")));
64
65       Long JavaDoc long0 = (Long JavaDoc) enc.lookup("Long0");
66       assertTrue("Long0 == 123456789", long0.equals(new Long JavaDoc(123456789)));
67
68       StatelessSessionHome home = (StatelessSessionHome) enc.lookup("ejb/StatelessSessionBean");
69       assertTrue("ejb/StatelessSessionBean isa StatelessSessionHome", home != null);
70
71       URL JavaDoc jbossHome = (URL JavaDoc) enc.lookup("url/JBossHome");
72       assertTrue("url/JBossHome == http://www.jboss.org",
73          jbossHome.toString().equals("http://www.jboss.org"));
74
75       URL JavaDoc indirectURL = (URL JavaDoc) enc.lookup("url/IndirectURL");
76       assertTrue("url/IndirectURL == http://www.somesite.com",
77          indirectURL.toString().equals("http://www.somesite.com"));
78
79       Queue JavaDoc testQueue = (Queue JavaDoc) enc.lookup("jms/aQueue");
80       assertTrue("jms/aQueue isa Queue", testQueue != null);
81
82       Queue JavaDoc anotherQueue = (Queue JavaDoc) enc.lookup("jms/anotherQueue");
83       assertTrue("jms/anotherQueue isa Queue", anotherQueue != null);
84
85       Queue JavaDoc anotherQueue2 = (Queue JavaDoc) enc.lookup("jms/anotherQueue2");
86       assertTrue("jms/anotherQueue2 isa Queue", anotherQueue != null);
87    }
88
89    /** Test access to EJBs located through the java:comp/env context
90     * @throws Exception
91     */

92    public void testEjbs() throws Exception JavaDoc
93    {
94       Context JavaDoc 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    /** Build the InitialContext factory
102     * @return
103     * @throws NamingException
104     */

105    private Context JavaDoc getENC() throws NamingException JavaDoc
106    {
107       Properties JavaDoc env = new Properties JavaDoc();
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 JavaDoc ctx = new InitialContext JavaDoc(env);
114       Context JavaDoc enc = (Context JavaDoc) ctx.lookup("java:comp/env");
115       return enc;
116    }
117
118    public static Test suite() throws Exception JavaDoc
119    {
120       TestSuite suite = new TestSuite();
121       
122       suite.addTest(new JBossTestSetup(new TestSuite(AppClientUnitTestCase.class))
123       {
124          protected void setUp() throws Exception JavaDoc
125          {
126             super.setUp();
127             ClassLoader JavaDoc 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 JavaDoc
132          {
133             super.tearDown();
134             ClassLoader JavaDoc 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