View Javadoc

1   /*
2    * $Id: HttpFunctionalTestCase.java 19817 2010-10-04 18:10:39Z dzapata $
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.api.MuleEventContext;
14  import org.mule.api.MuleMessage;
15  import org.mule.module.client.MuleClient;
16  import org.mule.tck.DynamicPortTestCase;
17  import org.mule.tck.FunctionalTestCase;
18  import org.mule.tck.functional.EventCallback;
19  import org.mule.tck.functional.FunctionalTestComponent;
20  import org.mule.transport.http.HttpConnector;
21  import org.mule.transport.http.HttpConstants;
22  
23  import java.util.HashMap;
24  import java.util.Map;
25  
26  public class HttpFunctionalTestCase extends DynamicPortTestCase
27  {
28      protected static String TEST_MESSAGE = "Test Http Request (R�dgr�d), 57 = \u06f7\u06f5 in Arabic";
29      protected boolean checkPathProperties = true;
30      
31      protected String getConfigResources()
32      {
33          return "http-functional-test.xml";
34      }
35  
36      public void testSend() throws Exception
37      {        
38          FunctionalTestComponent testComponent = getFunctionalTestComponent("testComponent");
39          assertNotNull(testComponent);
40  
41          if (checkPathProperties) 
42          {
43              EventCallback callback = new EventCallback()
44              {
45                  public void eventReceived(final MuleEventContext context, final Object component) throws Exception
46                  {
47                      MuleMessage msg = context.getMessage();
48                      assertEquals("/", msg.getInboundProperty(HttpConnector.HTTP_REQUEST_PROPERTY));
49                      assertEquals("/", msg.getInboundProperty(HttpConnector.HTTP_REQUEST_PATH_PROPERTY));
50                      assertEquals("/", msg.getInboundProperty(HttpConnector.HTTP_CONTEXT_PATH_PROPERTY));
51                  }
52              };
53          
54              testComponent.setEventCallback(callback);
55          }
56  
57          MuleClient client = new MuleClient(muleContext);
58          Map<String, String> props = new HashMap<String, String>();
59          props.put(HttpConstants.HEADER_CONTENT_TYPE, "text/plain;charset=UTF-8");
60          MuleMessage result = client.send("clientEndpoint", TEST_MESSAGE, props);
61          assertEquals(TEST_MESSAGE + " Received", result.getPayloadAsString());
62      }
63  
64      @Override
65      protected int getNumPortsToFind()
66      {
67          return 1;
68      }
69  }