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