KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jbossnet > document > ObjectElementTestCase


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

7 package org.jboss.test.jbossnet.document;
8
9 // $Id: ObjectElementTestCase.java,v 1.1.2.4 2005/03/02 14:51:02 tdiesler Exp $
10

11 import junit.framework.Test;
12 import org.jboss.axis.utils.DOM2Utils;
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.DocumentBuilder JavaDoc;
19 import javax.xml.rpc.Call JavaDoc;
20 import javax.xml.rpc.Service JavaDoc;
21 import java.io.ByteArrayInputStream JavaDoc;
22 import java.net.URL JavaDoc;
23
24 /** An endpoint test for document centric message exchange
25  *
26  * It uses the the jva:RPC provider with xsd:anyType
27  *
28  * @author Thomas.Diesler@jboss.org
29  */

30 public class ObjectElementTestCase extends JBossNetTestBase
31 {
32    public static final String JavaDoc xmlstr = "<root><child>Hello</child><child>World</child></root>";
33
34    private String JavaDoc namespaceURI = "http://jboss.net/document";
35    private Service JavaDoc service;
36
37    public ObjectElementTestCase(String JavaDoc name)
38    {
39       super(name);
40    }
41
42    protected void setUp() throws Exception JavaDoc
43    {
44       super.setUp();
45       URL JavaDoc wsdlURL = new URL JavaDoc(SERVICES_LOCATION + "/ObjectElementServer?wsdl");
46       service = createService(wsdlURL, new QName JavaDoc(namespaceURI, "ObjectElementServerService"));
47    }
48
49    /** Process an Element at the endpoint
50     */

51    public void testProcessElement() throws Exception JavaDoc
52    {
53       DocumentBuilder JavaDoc builder = DOM2Utils.getDocumentBuilder();
54       Document JavaDoc doc = builder.parse(new ByteArrayInputStream JavaDoc(xmlstr.getBytes()));
55       Element JavaDoc rootEl = doc.getDocumentElement();
56
57       Call JavaDoc call = service.createCall(new QName JavaDoc(namespaceURI, "ObjectElementServer"), "processElement");
58
59       Object JavaDoc retObj = call.invoke(new Object JavaDoc[]{rootEl});
60       assertNotNull("Return obj is null", retObj);
61       assertTrue("Return obj is not an Element: " + retObj.getClass().getName(), retObj instanceof Element JavaDoc);
62    }
63
64    /** Process an Object at the endpoint
65     */

66    public void testProcessObject() throws Exception JavaDoc
67    {
68       DocumentBuilder JavaDoc builder = DOM2Utils.getDocumentBuilder();
69       Document JavaDoc doc = builder.parse(new ByteArrayInputStream JavaDoc(xmlstr.getBytes()));
70       Element JavaDoc rootEl = doc.getDocumentElement();
71
72       Call JavaDoc call = service.createCall(new QName JavaDoc(namespaceURI, "ObjectElementServer"), "processObject");
73
74       Object JavaDoc retObj = call.invoke(new Object JavaDoc[]{rootEl});
75       assertNotNull("Return obj is null", retObj);
76       assertTrue("Return obj is not an Element: " + retObj.getClass().getName(), retObj instanceof Element JavaDoc);
77    }
78
79    /** Deploy the test ear */
80    public static Test suite() throws Exception JavaDoc
81    {
82       return getDeploySetup(ObjectElementTestCase.class, "jbossnet-document.wsr");
83    }
84
85 }
86
Popular Tags