단위 테스트에서 Exception
이 발생한다는 것을 시뮬레이트하고 싶습니다.인터셉터를 사용할 때 카멜 예외 처리 동작
doTry/doCatch
-block 때문에 "mock : count"엔드 포인트에서 하나의 메시지를 수신 할 것으로 예상됩니다. 왜 이런 일이 일어나지 않고 왜 Exception
은 일반 onException
- 블록으로 처리됩니까?
import org.apache.camel.LoggingLevel;
import org.apache.camel.builder.AdviceWithRouteBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.apache.cxf.binding.soap.SoapFault;
import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;
public class TestClass extends CamelTestSupport {
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
onException(Exception.class)
.log(LoggingLevel.INFO, "outer catch")
.handled(true);
from("direct:start")
.doTry()
.to("mock:exception")
.doCatch(Exception.class)
.log(LoggingLevel.INFO, "inner catch")
.to("mock:count")
.end();
}
};
}
@Test
public void testBlaat() throws Exception {
final SoapFault soapFault = new SoapFault("Something clearly went wrong", SoapFault.FAULT_CODE_CLIENT);
Element detail = soapFault.getOrCreateDetail();
Document doc = detail.getOwnerDocument();
Text tn = doc.createTextNode("Fault details");
detail.appendChild(tn);
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("mock:exception").throwException(new Exception("test"));
}
});
template.sendBody("direct:start", "start");
MockEndpoint endpoint = getMockEndpoint("mock:count");
endpoint.expectedMessageCount(1);
assertMockEndpointsSatisfied();
}
}
isUseRouteBuilder 재정의를 추가하지 않은 경우에만 작동합니다. –
나는 그 방법을 무시하는 것이 필요하다고 생각했다. – hveiga
불행히도 여전히 작동하지 않습니다. .markRollBackOnly() 및 .handled (true)를 주석 처리하면 작동하지만 모든 예외가 먼저 해당 블록을 통과 한 것처럼 보입니다. –