/*
* $Id: HttpStemTestCase.java 20297 2010-11-22 18:49:18Z aperepel $
* --------------------------------------------------------------------------------------
* Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
*
* The software in this package is published under the terms of the CPAL v1.0
* license, a copy of which has been included with this distribution in the
* LICENSE.txt file.
*/
package org.mule.transport.http.functional;
import org.mule.api.MuleEventContext;
import org.mule.api.MuleMessage;
import org.mule.module.client.MuleClient;
import org.mule.tck.DynamicPortTestCase;
import org.mule.tck.functional.EventCallback;
import org.mule.tck.functional.FunctionalTestComponent;
import org.mule.transport.http.HttpConnector;
public class HttpStemTestCase extends DynamicPortTestCase
{
@Override
protected String getConfigResources()
{
return "http-stem-test.xml";
}
public void testStemMatching() throws Exception
{
MuleClient client = new MuleClient(muleContext);
int port = getPorts().get(0);
doTest(client, "http://localhost:" + port + "/foo", "/foo", "/foo");
doTest(client, "http://localhost:" + port + "/foo/baz", "/foo", "/foo/baz");
doTest(client, "http://localhost:" + port + "/bar", "/bar", "/bar");
doTest(client, "http://localhost:" + port + "/bar/baz", "/bar", "/bar/baz");
}
protected void doTest(MuleClient client, final String url, final String contextPath, final String requestPath) throws Exception
{
FunctionalTestComponent testComponent = (FunctionalTestComponent) getComponent(contextPath);
assertNotNull(testComponent);
EventCallback callback = new EventCallback()
{
public void eventReceived(final MuleEventContext context, final Object component) throws Exception
{
MuleMessage msg = context.getMessage();
assertEquals(requestPath, msg.getInboundProperty(HttpConnector.HTTP_REQUEST_PROPERTY));
assertEquals(requestPath, msg.getInboundProperty(HttpConnector.HTTP_REQUEST_PATH_PROPERTY));
assertEquals(contextPath, msg.getInboundProperty(HttpConnector.HTTP_CONTEXT_PATH_PROPERTY));
}
};
testComponent.setEventCallback(callback);
MuleMessage result = client.send(url, "Hello World", null);
assertEquals("Hello World Received", result.getPayloadAsString());
final int status = result.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, 0);
assertEquals(200, status);
}
@Override
protected int getNumPortsToFind()
{
return 1;
}
}