View Javadoc

1   /*
2    * $Id: XSLTWikiDocsTestCase.java 22421 2011-07-15 05:05:06Z 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  
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.AbstractServiceAndFlowTestCase;
16  import org.mule.util.IOUtils;
17  
18  import java.util.Arrays;
19  import java.util.Collection;
20  import java.util.HashMap;
21  import java.util.Map;
22  
23  import org.custommonkey.xmlunit.XMLUnit;
24  import org.junit.Test;
25  import org.junit.runners.Parameterized.Parameters;
26  
27  import static org.junit.Assert.assertNotNull;
28  import static org.junit.Assert.assertNull;
29  import static org.junit.Assert.assertTrue;
30  
31  //START SNIPPET: test-code
32  public class XSLTWikiDocsTestCase extends AbstractServiceAndFlowTestCase
33  {
34      @Parameters
35      public static Collection<Object[]> parameters()
36      {
37          return Arrays.asList(new Object[][]{
38              {ConfigVariant.SERVICE, "org/mule/test/integration/xml/xslt-functional-test-service.xml"},
39              {ConfigVariant.FLOW, "org/mule/test/integration/xml/xslt-functional-test-flow.xml"}
40          });
41      }
42  
43      public XSLTWikiDocsTestCase(ConfigVariant variant, String configResources)
44      {
45          super(variant, configResources);
46      }
47  
48      @Test
49      public void testMessageTransform() throws Exception
50      {
51          //We're using Xml Unit to compare results
52          //Ignore whitespace and comments
53          XMLUnit.setIgnoreWhitespace(true);
54          XMLUnit.setIgnoreComments(true);
55  
56          //Read in src and result data
57          String srcData = IOUtils.getResourceAsString(
58                  "org/mule/test/integration/xml/cd-catalog.xml", getClass());
59          String resultData = IOUtils.getResourceAsString(
60                  "org/mule/test/integration/xml/cd-catalog-result-with-params.xml", getClass());
61  
62          //Create a new Mule Client
63          MuleClient client = new MuleClient(muleContext);
64  
65          //These are the message roperties that will get passed into the XQuery context
66          Map<String, Object> props = new HashMap<String, Object>();
67          props.put("ListTitle", "MyList");
68          props.put("ListRating", new Integer(6));
69  
70          //Invoke the service
71          MuleMessage message = client.send("vm://test.in", srcData, props);
72          assertNotNull(message);
73          assertNull(message.getExceptionPayload());
74          //Compare results
75  
76          assertTrue(XMLUnit.compareXML(message.getPayloadAsString(), resultData).similar());
77  
78      }
79  }
80  //END SNIPPET: test-code