KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > appclient > unit > SimpleResourceUnitTestCase


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2005, Red Hat Middleware LLC, 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.ejb3.test.appclient.unit;
23
24 import java.net.URL JavaDoc;
25
26 import javax.naming.Context JavaDoc;
27 import javax.naming.NameNotFoundException JavaDoc;
28
29 import junit.framework.Test;
30
31 import org.jboss.ejb3.client.ClientLauncher;
32 import org.jboss.ejb3.metamodel.ApplicationClientDD;
33 import org.jboss.ejb3.test.appclient.client.SimpleResourceClient;
34 import org.jboss.test.JBossTestCase;
35
36 /**
37  * Comment
38  *
39  * @author <a HREF="mailto:carlo.dewolf@jboss.com">Carlo de Wolf</a>
40  * @version $Revision: $
41  */

42 public class SimpleResourceUnitTestCase extends JBossTestCase
43 {
44
45    public SimpleResourceUnitTestCase(String JavaDoc name)
46    {
47       super(name);
48    }
49
50    /**
51     * Test to see if the client deployer has setup enc env correctly.
52     *
53     * @throws Exception
54     */

55    public void testJNDI() throws Exception JavaDoc
56    {
57       String JavaDoc clientName = "appclient-simpleresource-client";
58       Context JavaDoc ctx = getInitialContext();
59       try
60       {
61          ctx = (Context JavaDoc) ctx.lookup(clientName);
62       }
63       catch(NameNotFoundException JavaDoc e)
64       {
65          fail(clientName + " not bound");
66       }
67       
68       try
69       {
70          String JavaDoc value = (String JavaDoc) ctx.lookup("env/msg");
71          assertEquals("Hello world", value);
72       }
73       catch(NameNotFoundException JavaDoc e)
74       {
75          fail("env/msg not bound");
76       }
77       
78       // TODO: shouldn't org.jboss.ejb3.test.appclient.client.SimpleResourceClient/msg be bound?
79

80 // NamingEnumeration<NameClassPair> e = ctx.list("env");
81
// while(e.hasMore())
82
// {
83
// NameClassPair ncp = e.next();
84
// System.out.println(ncp.getName());
85
// }
86
// try
87
// {
88
//
89
// }
90
// catch(NameNotFoundException e)
91
// {
92
//
93
// }
94
}
95    
96    public void testClientLauncher() throws Exception JavaDoc
97    {
98       URL JavaDoc url = Thread.currentThread().getContextClassLoader().getResource("appclient/simpleresource/application-client.xml");
99       //URL jbossClientURL = Thread.currentThread().getContextClassLoader().getResource("appclient/jboss-client.xml");
100
URL JavaDoc jbossClientURL = null;
101       ApplicationClientDD xml = ClientLauncher.loadXML(url, jbossClientURL);
102       
103       String JavaDoc mainClassName = SimpleResourceClient.class.getName();
104       String JavaDoc applicationClientName = "appclient-simpleresource-client"; // must match JNDI name in jboss-client.xml or display-name in application-client.xml
105
String JavaDoc args[] = { };
106       
107       ClientLauncher.launch(xml, mainClassName, applicationClientName, args);
108    }
109    
110    public static Test suite() throws Exception JavaDoc
111    {
112       return getDeploySetup(SimpleResourceUnitTestCase.class, "appclient-simpleresource-client.jar");
113    }
114
115 }
116
Popular Tags