1
2
3
4
5
6
7
8
9
10
11 package org.mule.issues;
12
13 import org.mule.api.MuleEventContext;
14 import org.mule.api.lifecycle.Callable;
15 import org.mule.module.client.MuleClient;
16 import org.mule.tck.AbstractServiceAndFlowTestCase;
17 import org.mule.tck.junit4.rule.DynamicPort;
18 import org.mule.transformer.simple.ObjectToString;
19
20 import java.util.Arrays;
21 import java.util.Collection;
22
23 import org.junit.Rule;
24 import org.junit.Test;
25 import org.junit.runners.Parameterized.Parameters;
26
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertTrue;
29
30 public class HttpReturnsJaxbObject5531TestCase extends AbstractServiceAndFlowTestCase
31 {
32 private static final String ZIP_RESPONSE = "<?xml version='1.0' encoding='utf-8'?><soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' "
33 + "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>"
34 + "<soap:Body><GetCityWeatherByZIPResponse xmlns='http://ws.cdyne.com/WeatherWS/'><GetCityWeatherByZIPResult>"
35 + "<Success>true</Success><ResponseText>City Found</ResponseText><State>GA</State><City>Roswell</City>"
36 + "<WeatherStationCity>Marietta</WeatherStationCity><WeatherID>1</WeatherID><Description>Thunder Storms</Description>"
37 + "<Temperature>79</Temperature><RelativeHumidity>57</RelativeHumidity><Wind>S8</Wind>"
38 + "<Pressure>29.91R</Pressure><Visibility /><WindChill /><Remarks /></GetCityWeatherByZIPResult>"
39 + "</GetCityWeatherByZIPResponse></soap:Body></soap:Envelope>";
40
41 @Rule
42 public DynamicPort port1 = new DynamicPort("port1");
43
44 @Parameters
45 public static Collection<Object[]> parameters()
46 {
47 return Arrays.asList(new Object[][]{{ConfigVariant.SERVICE,
48 "org/mule/issues/http-returns-jaxb-object-mule-5531-test.xml"}
49
50 });
51 }
52
53 public HttpReturnsJaxbObject5531TestCase(ConfigVariant variant, String configResources)
54 {
55 super(variant, configResources);
56 }
57
58 @Test
59 public void testGetWeather() throws Exception
60 {
61 String testUrl = "http://localhost:" + port1.getNumber() + "/test/weather";
62 MuleClient client = new MuleClient(muleContext);
63 Object response = client.send(testUrl, "hello", null);
64 assertNotNull(response);
65 String stringResponse = (String) new ObjectToString().transform(response, "UTF-8");
66 assertTrue(stringResponse.contains("<Success>true</Success>"));
67 }
68
69 public static class WeatherReport implements Callable
70 {
71 @Override
72 public Object onCall(MuleEventContext eventContext) throws Exception
73 {
74 return ZIP_RESPONSE;
75 }
76 }
77 }