View Javadoc

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