View Javadoc

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