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.test.integration.xml;
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.transport.http.HttpConnector;
13  
14  import java.io.InputStream;
15  
16  import org.junit.Test;
17  
18  import static org.junit.Assert.assertEquals;
19  import static org.junit.Assert.assertNotNull;
20  
21  public class XmlSendTestCase extends FunctionalTestCase
22  {
23  
24      @Override
25      protected String getConfigResources()
26      {
27          return "org/mule/test/integration/xml/xml-conf.xml";
28      }
29  
30      @Test
31      public void testXmlFilter() throws Exception
32      {
33          InputStream xml = getClass().getResourceAsStream("request.xml");
34  
35          assertNotNull(xml);
36  
37          MuleClient client = new MuleClient(muleContext);
38  
39          // this will submit the xml via a POST request
40          MuleMessage message = client.send("http://localhost:63081/xml-parse", xml, null);
41          assertEquals("200", message.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY));
42  
43          // This won't pass the filter
44          xml = getClass().getResourceAsStream("validation1.xml");
45          message = client.send("http://localhost:63081/xml-parse", xml, null);
46          assertEquals("406", message.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY));
47      }
48  
49      @Test
50      public void testXmlFilterAndXslt() throws Exception
51      {
52          InputStream xml = getClass().getResourceAsStream("request.xml");
53  
54          assertNotNull(xml);
55  
56          MuleClient client = new MuleClient(muleContext);
57  
58          // this will submit the xml via a POST request
59          MuleMessage message = client.send("http://localhost:63081/xml-xslt-parse", xml, null);
60          assertEquals("200", message.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY));
61      }
62  
63      @Test
64      public void testXmlValidation() throws Exception
65      {
66          InputStream xml = getClass().getResourceAsStream("validation1.xml");
67  
68          assertNotNull(xml);
69  
70          MuleClient client = new MuleClient(muleContext);
71  
72          // this will submit the xml via a POST request
73          MuleMessage message = client.send("http://localhost:63081/validate", xml, null);
74          assertEquals("200", message.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY));
75  
76          xml = getClass().getResourceAsStream("validation2.xml");
77          message = client.send("http://localhost:63081/validate", xml, null);
78          assertEquals("406", message.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY));
79  
80          xml = getClass().getResourceAsStream("validation3.xml");
81          message = client.send("http://localhost:63081/validate", xml, null);
82          assertEquals("200", message.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY));
83      }
84  
85  }