KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > webservice > jbws775 > JBWS775TestCase


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.webservice.jbws775;
23
24 import java.io.ByteArrayInputStream JavaDoc;
25
26 import javax.naming.InitialContext JavaDoc;
27 import javax.xml.rpc.Service JavaDoc;
28 import javax.xml.soap.MessageFactory JavaDoc;
29 import javax.xml.soap.SOAPConnection JavaDoc;
30 import javax.xml.soap.SOAPConnectionFactory JavaDoc;
31 import javax.xml.soap.SOAPEnvelope JavaDoc;
32 import javax.xml.soap.SOAPMessage JavaDoc;
33
34 import junit.framework.Test;
35
36 import org.jboss.test.webservice.WebserviceTestBase;
37 import org.jboss.util.xml.DOMWriter;
38
39 /**
40  * Web services deployment can fail when deploying multiple EJB JARs
41  *
42  * http://jira.jboss.com/jira/browse/JBWS-772
43  *
44  * @author Thomas.Diesler@jboss.org
45  * @since 24-Mar-2006
46  */

47 public class JBWS775TestCase extends WebserviceTestBase
48 {
49    public JBWS775TestCase(String JavaDoc name)
50    {
51       super(name);
52    }
53
54    /** Deploy the test */
55    public static Test suite() throws Exception JavaDoc
56    {
57       return getDeploySetup(JBWS775TestCase.class, "ws4ee-jbws775.war, ws4ee-jbws775-client.jar");
58    }
59
60    public void testEndpointAccess() throws Exception JavaDoc
61    {
62       InitialContext JavaDoc iniCtx = getClientContext();
63       Service JavaDoc service = (Service JavaDoc)iniCtx.lookup("java:comp/env/service/DocumentTranslator");
64       DocumentTranslator port = (DocumentTranslator)service.getPort(DocumentTranslator.class);
65       
66       TDocumentHead tDocHead = new TDocumentHead("title", "en");
67       TDocumentBody tDocBody = new TDocumentBody(new String JavaDoc[] {"hi", "bye"});
68       TDocument tDocReq = new TDocument(tDocHead, tDocBody);
69       TTranslationRequest tReq = new TTranslationRequest("es", tDocReq);
70       
71       TDocument tDocRes = port.translate(tReq);
72       assertEquals("en", tDocRes.getHead().getLanguage());
73       assertEquals("title", tDocRes.getHead().getTitle());
74       assertEquals("hi", tDocRes.getBody().getParagraph()[0]);
75       assertEquals("bye", tDocRes.getBody().getParagraph()[1]);
76    }
77    
78    public void testSAAJAccess() throws Exception JavaDoc
79    {
80       String JavaDoc reqStr =
81          "<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" +
82          " <env:Body>" +
83          " <sns:translationRequest targetLanguage='es' xmlns:sns='http://example.com/translator/types' xmlns:vendor='http://jbpm.org/bpel'>" +
84          " <sns:document>" +
85          " <head language='en' title='title'/>" +
86          " <body>" +
87          " <paragraph>hi</paragraph>" +
88          " <paragraph>bye</paragraph>" +
89          " </body>" +
90          " </sns:document>" +
91          " </sns:translationRequest>" +
92          " </env:Body>" +
93          "</env:Envelope>";
94
95       String JavaDoc resStr =
96          "<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" +
97           "<env:Header/>" +
98           "<env:Body>" +
99            "<ns1:document xmlns:ns1='http://example.com/translator/types' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" +
100             "<head language='en' title='title'/>" +
101             "<body>" +
102              "<paragraph>hi</paragraph>" +
103              "<paragraph>bye</paragraph>" +
104             "</body>" +
105            "</ns1:document>" +
106           "</env:Body>" +
107          "</env:Envelope>";
108
109       SOAPMessage JavaDoc reqMsg = MessageFactory.newInstance().createMessage(null, new ByteArrayInputStream JavaDoc(reqStr.getBytes()));
110       SOAPConnection JavaDoc con = SOAPConnectionFactory.newInstance().createConnection();
111       SOAPMessage JavaDoc resMsg = con.call(reqMsg, "http://" + getServerHost() + ":8080/ws4ee-jbws775/document");
112       SOAPEnvelope JavaDoc resEnv = resMsg.getSOAPPart().getEnvelope();
113       
114       assertEquals(resStr, DOMWriter.printNode(resEnv, false));
115    }
116 }
117
Popular Tags