MuleESB 简单测试用例不工作

MuleESB Simple Test Case not Working

我有以下简单的 Mule ESB 流程,我正在尝试为其编写测试用例:

<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" basePath="/product-design" doc:name="HTTP Listener Configuration"/>
<jms:activemq-connector name="Active_MQ" brokerURL="tcp://localhost:61616" validateConnections="true" doc:name="Active MQ"/>
<flow name="product-designFlow">
    <http:listener  config-ref="HTTP_Listener_Configuration" path="/" allowedMethods="POST" doc:name="HTTP"/>
    <byte-array-to-string-transformer doc:name="Byte Array to String"/>
    <logger message="We received message: #[message.payload]" level="INFO" doc:name="Logger"/>
    <jms:outbound-endpoint topic="product-design-topic" connector-ref="Active_MQ" doc:name="JMS"/>
</flow>

有问题的测试用例是这样的:

public class SimpleProductRegistrationTestCase extends FunctionalTestCase {

public String getConfigResources(){
    return "src/main/app/product-design.xml";
}

@Test
public void exampleCase() throws MuleException{
    MuleClient client=muleContext.getClient();
    MuleMessage inMessage = new DefaultMuleMessage("loalalal",muleContext);
    MuleMessage outMessage=client.send("http://localhost:8081/product-design", inMessage);
    assertNotNull(outMessage);
}
}

但是,当我尝试 运行 这个测试用例时,出现以下异常。我错过了什么?

org.mule.module.http.internal.request.ResponseValidatorException: Response code 405 mapped as failure.
at org.mule.module.http.internal.request.SuccessStatusCodeValidator.validate(SuccessStatusCodeValidator.java:37)
at org.mule.module.http.internal.request.DefaultHttpRequester.validateResponse(DefaultHttpRequester.java:356)
at org.mule.module.http.internal.request.DefaultHttpRequester.innerProcess(DefaultHttpRequester.java:344)
at org.mule.module.http.internal.request.DefaultHttpRequester.processBlocking(DefaultHttpRequester.java:217)
at org.mule.processor.AbstractNonBlockingMessageProcessor.process(AbstractNonBlockingMessageProcessor.java:43)
at org.mule.client.DefaultLocalMuleClient.send(DefaultLocalMuleClient.java:110)
at SimpleProductRegistrationTestCase.exampleCase(SimpleProductRegistrationTestCase.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.runners.model.FrameworkMethod.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.rules.TestWatcher.evaluate(TestWatcher.java:55)
at org.junit.internal.runners.statements.FailOnTimeout$StatementThread.run(FailOnTimeout.java:74)

问题是您的侦听器设置为仅接受 POST 请求,但默认情况下 MuleClient 将发送 GET。要配置 MuleClient 以发送 POST,您应该按照 .

的说明定义 OperationOptions