View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.issues;
8   
9   import org.mule.api.MuleEventContext;
10  import org.mule.api.lifecycle.Callable;
11  import org.mule.module.client.MuleClient;
12  import org.mule.tck.junit4.FunctionalTestCase;
13  import org.mule.tck.junit4.rule.DynamicPort;
14  import org.mule.transformer.simple.ObjectToString;
15  
16  import org.junit.Rule;
17  import org.junit.Test;
18  
19  import static org.junit.Assert.assertNotNull;
20  import static org.junit.Assert.assertTrue;
21  
22  
23  public class HttpReturnsJaxbObject5531TestCase extends FunctionalTestCase
24  {
25      private static final String ZIP_RESPONSE =
26          "<?xml version='1.0' encoding='utf-8'?><soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' " +
27              "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" +
28              "<soap:Body><GetCityWeatherByZIPResponse xmlns='http://ws.cdyne.com/WeatherWS/'><GetCityWeatherByZIPResult>" +
29              "<Success>true</Success><ResponseText>City Found</ResponseText><State>GA</State><City>Roswell</City>" +
30              "<WeatherStationCity>Marietta</WeatherStationCity><WeatherID>1</WeatherID><Description>Thunder Storms</Description>" +
31              "<Temperature>79</Temperature><RelativeHumidity>57</RelativeHumidity><Wind>S8</Wind>" +
32              "<Pressure>29.91R</Pressure><Visibility /><WindChill /><Remarks /></GetCityWeatherByZIPResult>" +
33              "</GetCityWeatherByZIPResponse></soap:Body></soap:Envelope>";
34  
35      @Rule
36      public DynamicPort dynamicPort = new DynamicPort("port1");
37  
38      @Override
39      protected String getConfigResources()
40      {
41          return "org/mule/issues/http-returns-jaxb-object-mule-5531-test.xml";
42      }
43  
44      @Test
45      public void testGetWeather() throws Exception
46      {
47          String testUrl = "http://localhost:" + dynamicPort.getNumber() + "/test/weather";
48          MuleClient client = new MuleClient(muleContext);
49          Object response = client.send(testUrl, "hello", null);
50          assertNotNull(response);
51          String stringResponse = (String) new ObjectToString().transform(response, "UTF-8");
52          assertTrue(stringResponse.contains("<Success>true</Success>"));
53      }
54  
55      public static class WeatherReport implements Callable
56      {
57          public Object onCall(MuleEventContext eventContext) throws Exception
58          {
59              return ZIP_RESPONSE;
60          }
61      }
62  }