View Javadoc

1   /*
2    * $Id: HttpRoutingTestCase.java 20320 2010-11-24 15:03:31Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.module.sxc;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.module.client.MuleClient;
15  import org.mule.tck.DynamicPortTestCase;
16  
17  import java.io.ByteArrayOutputStream;
18  
19  import org.apache.commons.io.IOUtils;
20  
21  public class HttpRoutingTestCase extends DynamicPortTestCase 
22  {
23      int finished = 0;
24  
25      public void testBasicXPath() throws Exception
26      {
27          final MuleClient client = new MuleClient(muleContext);
28  
29          ByteArrayOutputStream out = new ByteArrayOutputStream();
30          IOUtils.copy(getClass().getResourceAsStream("/purchase-order.xml"), out);
31  
32          String address = "http://localhost:" + getPorts().get(0) + "/proxy";
33          MuleMessage res = client.send(address, out.toByteArray(), null);
34          System.out.println(res.getPayloadAsString());
35          assertTrue(res.getPayloadAsString().contains("purchaseOrder"));
36          assertTrue(res.getPayloadAsString().contains("Alice"));
37          
38          out = new ByteArrayOutputStream();
39          IOUtils.copy(getClass().getResourceAsStream("/namespace-purchase-order.xml"), out);
40          
41          res = client.send(address, out.toByteArray(), null);
42          System.out.println(res.getPayloadAsString());
43          assertTrue(res.getPayloadAsString().contains("purchaseOrder"));
44          assertTrue(res.getPayloadAsString().contains("Alice"));
45      }
46  
47      @Override
48      protected String getConfigResources()
49      {
50          return "http-routing-conf.xml";
51      }
52  
53      protected int getNumPortsToFind()
54      {
55          return 1;
56      }
57  
58  }