View Javadoc

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