View Javadoc

1   /*
2    * $Id: XQueryFunctionalTestCase.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.transformers;
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  public class XQueryFunctionalTestCase extends FunctionalTestCase
24  {
25      protected String getConfigResources()
26      {
27          //Our Mule configuration file
28          return "org/mule/test/integration/xml/xquery-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("cd-catalog.xml", getClass());
40          String resultData = IOUtils.getResourceAsString("cd-catalog-result-with-params.xml", getClass());
41  
42          //Create a new Mule Client
43          MuleClient client = new MuleClient(muleContext);
44  
45          //These are the message roperties that will get passed into the XQuery context
46          Map props = new HashMap();
47          props.put("ListTitle", "MyList");
48          props.put("ListRating", new Integer(6));
49  
50          //Invoke the service
51          MuleMessage message = client.send("vm://test.in", srcData, props);
52          assertNotNull(message);
53          assertNull(message.getExceptionPayload());
54          //Compare results
55          assertTrue(XMLUnit.compareXML(message.getPayloadAsString(), resultData).similar());
56      }
57  }