2016-05-28 40 views
0

我有IA米嘗試寫測試用例下面簡單的騾子ESB流程:MuleESB簡單的測試用例不工作

<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$1.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$1.evaluate(TestWatcher.java:55) 
at org.junit.internal.runners.statements.FailOnTimeout$StatementThread.run(FailOnTimeout.java:74) 
+0

在調用http端點之前,爲rquestor定義成功代碼驗證程序。 – AnupamBhusari

回答

2

問題是您的偵聽器設置爲只接受POST請求,但默認情況下MuleClient會發送一個GET。要配置MuleClient發送POST,您應該按照說明here定義OperationOptions。

+0

謝謝。就是這樣。 – Klaus