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.util.IOUtils;
13  
14  import java.util.HashMap;
15  import java.util.Map;
16  
17  import org.custommonkey.xmlunit.XMLUnit;
18  import org.junit.Test;
19  
20  import static org.junit.Assert.assertNotNull;
21  import static org.junit.Assert.assertNull;
22  import static org.junit.Assert.assertTrue;
23  
24  public class XSLTWikiDocsTestCase extends FunctionalTestCase
25  {
26  
27      @Override
28      protected String getConfigResources()
29      {
30          return "org/mule/test/integration/xml/xslt-functional-test.xml";
31      }
32  
33      @Test
34      public void testMessageTransform() throws Exception
35          {
36              //We're using Xml Unit to compare results
37              //Ignore whitespace and comments
38              XMLUnit.setIgnoreWhitespace(true);
39              XMLUnit.setIgnoreComments(true);
40  
41              //Read in src and result data
42              String srcData = IOUtils.getResourceAsString(
43                      "org/mule/test/integration/xml/cd-catalog.xml", getClass());
44              String resultData = IOUtils.getResourceAsString(
45                      "org/mule/test/integration/xml/cd-catalog-result-with-params.xml", getClass());
46  
47              //Create a new Mule Client
48              MuleClient client = new MuleClient(muleContext);
49  
50              //These are the message roperties that will get passed into the XQuery context
51              Map<String, Object> props = new HashMap<String, Object>();
52              props.put("ListTitle", "MyList");
53              props.put("ListRating", new Integer(6));
54  
55              //Invoke the service
56              MuleMessage message = client.send("vm://test.in", srcData, props);
57              assertNotNull(message);
58              assertNull(message.getExceptionPayload());
59              //Compare results
60              assertTrue(XMLUnit.compareXML(message.getPayloadAsString(), resultData).similar());
61          }
62      }