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.transport.http.functional;
8   
9   import org.mule.DefaultMuleMessage;
10  import org.mule.api.MuleMessage;
11  import org.mule.api.endpoint.InboundEndpoint;
12  import org.mule.module.client.MuleClient;
13  import org.mule.module.xml.transformer.XsltTransformer;
14  import org.mule.tck.junit4.FunctionalTestCase;
15  import org.mule.util.IOUtils;
16  
17  import java.io.InputStream;
18  
19  import org.junit.Test;
20  
21  import static org.junit.Assert.assertEquals;
22  import static org.junit.Assert.assertNotNull;
23  
24  public class HttpContentLengthPropagationTestCase extends FunctionalTestCase
25  {
26  
27      private static final String NAME_PAYLOAD = "test-xml-payload.xml";
28      private static final String NAME_STYLESHEET = "stylesheet.xsl";
29  
30      @Override
31      protected String getConfigResources()
32      {
33          return "http-content-length-propagation-conf.xml";
34      }
35  
36      @Test
37      public void testContentLengthPropagation() throws Exception
38      {
39          InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(NAME_PAYLOAD);
40          assertNotNull("Payload test file not found.", is);
41          byte[] fileContents = IOUtils.toByteArray(is);
42  
43          MuleClient client = new MuleClient(muleContext);
44          MuleMessage result = client.send(((InboundEndpoint) client.getMuleContext().getRegistry().lookupObject("httpEndpoint")).getAddress(),
45              new DefaultMuleMessage(fileContents, muleContext));
46  
47          XsltTransformer trans = new XsltTransformer();
48          trans.setMuleContext(muleContext);
49          trans.setXslFile(NAME_STYLESHEET);
50          trans.initialise();
51          final byte[] locallyTransformedBytes = (byte[]) trans.doTransform(fileContents, "UTF-8");
52  
53          assertEquals(new String(locallyTransformedBytes), result.getPayloadAsString());
54      }
55  }