View Javadoc

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