KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > webservice > attachmentstepbystep > MyServiceClientTestCase


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.attachmentstepbystep;
23
24 import java.io.BufferedReader JavaDoc;
25 import java.io.InputStreamReader JavaDoc;
26 import javax.activation.DataHandler JavaDoc;
27 import javax.activation.FileDataSource JavaDoc;
28 import javax.xml.namespace.QName JavaDoc;
29 import javax.xml.rpc.Call JavaDoc;
30 import javax.xml.rpc.ParameterMode JavaDoc;
31 import javax.xml.rpc.Service JavaDoc;
32 import javax.xml.rpc.ServiceFactory JavaDoc;
33 import junit.framework.Test;
34 import org.jboss.test.JBossTestCase;
35 import org.jboss.test.webservice.WebserviceTestBase;
36 import org.jboss.test.webservice.attachment.AttachmentDIITestCase;
37
38 public class MyServiceClientTestCase extends WebserviceTestBase
39 {
40    public MyServiceClientTestCase(String JavaDoc name)
41    {
42       super(name);
43    }
44
45    /** Deploy the test */
46    public static Test suite() throws Exception JavaDoc
47    {
48       return getDeploySetup(MyServiceClientTestCase.class, "myservice.war");
49    }
50
51    public void testMyService() throws Exception JavaDoc
52    {
53       String JavaDoc NS_URI = "http://org.jboss.test.webservice.attachmentstepbystep/MyService";
54       QName JavaDoc ATTACHMENT_TYPE;
55
56       if (isWS4EEAvailable())
57          ATTACHMENT_TYPE = new QName JavaDoc("http://xml.apache.org/xml-soap", "DataHandler");
58       else
59          ATTACHMENT_TYPE = new QName JavaDoc("http://www.jboss.org/jbossws/attachment/mimetype", "text_plain");
60
61       ServiceFactory JavaDoc factory = ServiceFactory.newInstance();
62       Service JavaDoc service = factory.createService(new QName JavaDoc(NS_URI, "MyService"));
63       Call JavaDoc call = service.createCall(new QName JavaDoc(NS_URI, "MyService"));
64       call.setTargetEndpointAddress("http://" + getServerHost() + ":8080/myservice/MyService");
65
66       // send the text file
67
call.setOperationName(new QName JavaDoc(NS_URI, "myService"));
68       call.addParameter("mimepart", ATTACHMENT_TYPE, DataHandler JavaDoc.class, ParameterMode.IN);
69       call.setReturnType(ATTACHMENT_TYPE, DataHandler JavaDoc.class);
70       DataHandler JavaDoc dh = (DataHandler JavaDoc)call.invoke(new Object JavaDoc[] { new DataHandler JavaDoc(new FileDataSource JavaDoc(
71             "resources/webservice/attachmentstepbystep/attachment_client2server.txt")) });
72
73       assertNotNull(dh);
74
75       if (dh != null)
76       {
77          BufferedReader JavaDoc in = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(dh.getInputStream()));
78          String JavaDoc line = "";
79          String JavaDoc result = "";
80          line = in.readLine();
81          result = "" + line;
82          while (line != null)
83          {
84             line = in.readLine();
85             result = result + line;
86          }
87          in.close();
88          assertEquals(192, result.length());
89       }
90    }
91 }
92
Popular Tags