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.module.sxc;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.module.client.MuleClient;
11  import org.mule.tck.junit4.FunctionalTestCase;
12  import org.mule.tck.junit4.rule.DynamicPort;
13  
14  import java.io.ByteArrayOutputStream;
15  
16  import org.apache.commons.io.IOUtils;
17  import org.junit.Rule;
18  import org.junit.Test;
19  
20  import static org.junit.Assert.assertTrue;
21  
22  public class HttpRoutingTestCase extends FunctionalTestCase
23  {
24      private int finished = 0;
25  
26      @Rule
27      public DynamicPort dynamicPort = new DynamicPort("port1");
28  
29      @Override
30      protected String getConfigResources()
31      {
32          return "http-routing-conf.xml";
33      }
34  
35      @Test
36      public void testBasicXPath() throws Exception
37      {
38          final MuleClient client = new MuleClient(muleContext);
39  
40          ByteArrayOutputStream out = new ByteArrayOutputStream();
41          IOUtils.copy(getClass().getResourceAsStream("/purchase-order.xml"), out);
42  
43          String address = "http://localhost:" + dynamicPort.getNumber() + "/proxy";
44          MuleMessage res = client.send(address, out.toByteArray(), null);
45          System.out.println(res.getPayloadAsString());
46          assertTrue(res.getPayloadAsString().contains("purchaseOrder"));
47          assertTrue(res.getPayloadAsString().contains("Alice"));
48  
49          out = new ByteArrayOutputStream();
50          IOUtils.copy(getClass().getResourceAsStream("/namespace-purchase-order.xml"), out);
51  
52          res = client.send(address, out.toByteArray(), null);
53          System.out.println(res.getPayloadAsString());
54          assertTrue(res.getPayloadAsString().contains("purchaseOrder"));
55          assertTrue(res.getPayloadAsString().contains("Alice"));
56      }
57  
58  }