KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jbossnet > ejbsimple > EJBEndpointTestCase


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 // $Id: EJBEndpointTestCase.java,v 1.1.2.2 2004/12/01 15:41:51 tdiesler Exp $
9

10 package org.jboss.test.jbossnet.ejbsimple;
11
12 import junit.framework.Test;
13 import org.jboss.test.jbossnet.JBossNetTestBase;
14 import org.w3c.dom.Document JavaDoc;
15 import org.w3c.dom.Element JavaDoc;
16
17 import javax.xml.namespace.QName JavaDoc;
18 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
19 import java.net.URL JavaDoc;
20 import java.util.Arrays JavaDoc;
21
22 /**
23  * Tests remote accessibility of stateless ejb bean
24  * @since 5. Oktober 2001, 12:11
25  * @author <a HREF="mailto:Christoph.Jung@infor.de">Christoph G. Jung</a>
26  * @author Adrian Brock
27  * @author Thomas.Diesler@jboss.org
28  * @version $Revision: 1.1.2.2 $
29  */

30
31 public class EJBEndpointTestCase extends JBossNetTestBase
32 {
33    private QName JavaDoc HELLO_REMOTE_SERVICE = new QName JavaDoc("http://" + getServerHost() + ":8080/jboss-net/services/HelloRemote", "HelloRemoteService");
34    private QName JavaDoc HELLO_LOCAL_SERVICE = new QName JavaDoc("http://" + getServerHost() + ":8080/jboss-net/services/HelloLocal", "HelloLocalService");
35
36    // Constructors --------------------------------------------------
37
public EJBEndpointTestCase(String JavaDoc name)
38    {
39       super(name);
40    }
41
42    /** the session beans with which we interact */
43    HelloRemote hello;
44    HelloRemote helloLocal;
45
46    /** setup the bean */
47    public void setUp() throws Exception JavaDoc
48    {
49       super.setUp();
50       URL JavaDoc wsdlURL = new URL JavaDoc(SERVICES_LOCATION + "/HelloRemote?wsdl");
51       hello = (HelloRemote)createService(wsdlURL, HELLO_REMOTE_SERVICE).getPort(HelloRemote.class);
52       wsdlURL = new URL JavaDoc(SERVICES_LOCATION + "/HelloLocal?wsdl");
53       helloLocal = (HelloRemote)createService(wsdlURL, HELLO_LOCAL_SERVICE).getPort(HelloRemote.class);
54    }
55
56    /** where the config is stored */
57    protected String JavaDoc getAxisConfiguration()
58    {
59       return "jbossnet/ejbsimple/client/client-config.wsdd";
60    }
61
62    /** Make sure we have the xerces parser, otherwise element serialization might fail */
63    public void testClientParser() throws Exception JavaDoc
64    {
65       DocumentBuilderFactory JavaDoc docFactory = DocumentBuilderFactory.newInstance();
66       assertEquals("org.apache.xerces.jaxp.DocumentBuilderFactoryImpl", docFactory.getClass().getName());
67    }
68
69    /** test a simple hello world */
70    public void testHello() throws Exception JavaDoc
71    {
72       assertEquals("Hello World!", hello.hello("World"));
73       assertEquals("Hello World!", helloLocal.hello("World"));
74    }
75
76    /** test some structural parameters */
77    public void testHowdy() throws Exception JavaDoc
78    {
79       HelloData data = new HelloData();
80       data.setName("CGJ");
81       assertEquals("Howdy CGJ!", hello.howdy(data));
82       assertEquals("Howdy CGJ!", helloLocal.howdy(data));
83    }
84
85    /** arrays should be tested too */
86    public void testTypedArrays() throws Exception JavaDoc
87    {
88       HelloData[] values = new HelloData[]{new HelloData(), new HelloData()};
89       assertTrue(Arrays.equals(hello.typedArrays(values), values));
90       assertTrue(Arrays.equals(helloLocal.typedArrays(values), values));
91    }
92
93    /** arrays should be tested too */
94    public void testArrays() throws Exception JavaDoc
95    {
96       Object JavaDoc[] values = new Object JavaDoc[]{new String JavaDoc("Test"), new Integer JavaDoc(1), new HelloData()};
97       assertTrue(Arrays.equals(hello.arrays(values), values));
98       assertTrue(Arrays.equals(helloLocal.arrays(values), values));
99    }
100
101    /** order preservation ok ? */
102    public void testReverse() throws Exception JavaDoc
103    {
104       Object JavaDoc[] values = new Object JavaDoc[]{new String JavaDoc("Test"), new Integer JavaDoc(1), new HelloData()};
105       Object JavaDoc[] expected = new Object JavaDoc[]{new HelloData(), new Integer JavaDoc(1), new String JavaDoc("Test")};
106       assertTrue(Arrays.equals(hello.reverse(values), expected));
107       assertTrue(Arrays.equals(helloLocal.reverse(values), expected));
108    }
109
110    /** order preservation ok ? */
111    public void testElement() throws Exception JavaDoc
112    {
113       DocumentBuilderFactory JavaDoc docFactory = DocumentBuilderFactory.newInstance();
114       Document JavaDoc doc = docFactory.newDocumentBuilder().newDocument();
115       Element JavaDoc testElement = doc.createElement("TestElement");
116       assertEquals(testElement.getNodeName(), hello.element(testElement).getNodeName());
117       assertEquals(testElement.getNodeName(), helloLocal.element(testElement).getNodeName());
118    }
119
120    /** this is to deploy the whole ear */
121    public static Test suite() throws Exception JavaDoc
122    {
123       return getDeploySetup(EJBEndpointTestCase.class, "jbossnet-ejbsimple.ear");
124    }
125
126    /** standalone */
127    public static void main(String JavaDoc[] args)
128    {
129       junit.textui.TestRunner.run(EJBEndpointTestCase.class);
130    }
131
132 }
133
Popular Tags