Skip to content

Instantly share code, notes, and snippets.

@cjmamo
Created May 28, 2012 16:47
Show Gist options
  • Save cjmamo/2820059 to your computer and use it in GitHub Desktop.
Save cjmamo/2820059 to your computer and use it in GitHub Desktop.
Revisiting Dynamic Ports in Mule 3
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:test="http://www.mulesoft.org/schema/mule/test"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/test http://www.mulesoft.org/schema/mule/test/current/mule-test.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
<flow name="main">
<http:inbound-endpoint host="localhost" port="${foo}"/>
<test:component appendString=" Received"/>
</flow>
</mule>
import org.junit.Rule;
import org.junit.Test;
import org.mule.api.MuleMessage;
import org.mule.api.client.MuleClient;
import org.mule.tck.junit4.FunctionalTestCase;
import org.mule.tck.junit4.rule.DynamicPort;
import org.mule.transport.NullPayload;
import static org.junit.Assert.*;
public class DynamicPortJunit4TestCase extends FunctionalTestCase
{
@Rule
public DynamicPort port = new DynamicPort("foo");
protected String getConfigResources()
{
return "dynamic-port-junit4-functional-test-config.xml";
}
@Test
public void DynamicPortJunit4() throws Exception
{
MuleClient client = muleContext.getClient();
MuleMessage result = client.send("http://localhost:" + port.getNumber() , "some data", null);
assertNotNull(result);
assertNull(result.getExceptionPayload());
assertFalse(result.getPayload() instanceof NullPayload);
assertEquals("some data Received", result.getPayloadAsString());
}
}
<http:inbound-endpoint host="localhost" port="${port23}"/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment