View Javadoc

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