KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > remoting > marshall > http > metadata > HTTPUnMarshallerMetadataTestCase


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.remoting.marshall.http.metadata;
8
9 import junit.framework.TestCase;
10 import org.apache.log4j.Level;
11 import org.jboss.remoting.Client;
12 import org.jboss.remoting.InvokerLocator;
13
14 import java.util.HashMap JavaDoc;
15 import java.util.List JavaDoc;
16 import java.util.Map JavaDoc;
17 import java.util.Properties JavaDoc;
18
19 /**
20  * Test case that uses the HTTPInvoker client to call on two different public SOAP services (one based
21  * on Axis and the other based on .NET implementations).
22  *
23  * @author <a HREF="mailto:telrod@e2technologies.net">Tom Elrod</a>
24  */

25 public class HTTPUnMarshallerMetadataTestCase extends TestCase
26 {
27    private Client client;
28
29    public void init(String JavaDoc httpTargetURL, HTTPUnMarshallerMock unmarshaller)
30    {
31       try
32       {
33          InvokerLocator locator = new InvokerLocator(httpTargetURL);
34          client = new Client(locator, null);
35          client.setUnMarshaller(unmarshaller);
36          client.connect();
37       }
38       catch(Exception JavaDoc e)
39       {
40          e.printStackTrace();
41       }
42    }
43
44    public String JavaDoc makeInvocationCall(String JavaDoc httpTargetURL, String JavaDoc payload, Map JavaDoc metadata, HTTPUnMarshallerMock unmarshaller) throws Throwable JavaDoc
45    {
46       init(httpTargetURL, unmarshaller);
47
48       Object JavaDoc obj = client.invoke(payload, metadata);
49
50       System.out.println("invoke returned" + obj);
51
52       return (String JavaDoc) obj;
53    }
54
55    public void testWeatherHTTPInvocation() throws Throwable JavaDoc
56    {
57
58       org.apache.log4j.BasicConfigurator.configure();
59       org.apache.log4j.Category.getRoot().setLevel(Level.INFO);
60       org.apache.log4j.Category.getInstance("org.jgroups").setLevel(Level.INFO);
61       org.apache.log4j.Category.getInstance("org.jboss.remoting").setLevel(Level.DEBUG);
62       org.apache.log4j.Category.getInstance("test").setLevel(Level.DEBUG);
63
64
65       String JavaDoc testURL = "http://services.xmethods.net:80/soap/servlet/rpcrouter";
66
67       String JavaDoc xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
68                    "<soap:Envelope xmlns:mrns0=\"urn:xmethods-Temperature\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +
69                    " <soap:Body soap:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n" +
70                    " <mrns0:getTemp>\n" +
71                    " <zipcode xsi:type=\"xs:string\">30106</zipcode>\n" +
72                    " </mrns0:getTemp>\n" +
73                    " </soap:Body>\n" +
74                    "</soap:Envelope>";
75
76       Map JavaDoc metadata = new HashMap JavaDoc();
77       metadata.put(Client.RAW, Boolean.TRUE);
78       metadata.put("TYPE", "POST");
79
80       Properties JavaDoc headerProps = new Properties JavaDoc();
81       headerProps.put("SOAPAction", "");
82       headerProps.put("Content-type", "text/xml; charset=UTF-8");
83
84       metadata.put("HEADER", headerProps);
85
86
87       HTTPUnMarshallerMetadataTestCase client = new HTTPUnMarshallerMetadataTestCase();
88
89       HTTPUnMarshallerMock unmarshaller = new HTTPUnMarshallerMock();
90
91       String JavaDoc result = client.makeInvocationCall(testURL, xml, metadata, unmarshaller);
92
93       // expect to get the following header
94
assertNotNull(unmarshaller.getMetadata());
95       List JavaDoc header = (List JavaDoc)unmarshaller.getMetadata().get("Status");
96       assertEquals("200", header.get(0));
97
98       // don't need to comapre full string. (as actual temp value will change each time run)
99
assertEquals(getExpectedWeatherResult().substring(0, 380), result.substring(0, 380));
100
101    }
102
103    private String JavaDoc getExpectedWeatherResult()
104    {
105       return "<?xml version='1.0' encoding='UTF-8'?>" +
106              "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
107              "<SOAP-ENV:Body>" +
108              "<ns1:getTempResponse xmlns:ns1=\"urn:xmethods-Temperature\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" +
109              "<return xsi:type=\"xsd:float\">60.0</return>" +
110              "</ns1:getTempResponse>" +
111              "\n" +
112              "</SOAP-ENV:Body>\n" +
113              "</SOAP-ENV:Envelope>";
114    }
115
116
117 // public static void main(String[] args)
118
// {
119
// HTTPInvokerClientTest test = new HTTPInvokerClientTest();
120
// test.testHTTPInvocation();
121
// }
122

123 }
Popular Tags