Apache Camel 2.15.3을 사용하여 애플리케이션을 빌드했습니다. 그리고 의존성 주입을 위해 spring-xml을 사용하여 라우트를 연결합니다. 내 경로에 대한 자동 테스트 작성법을 이해하는 데 어려움을 겪고 있습니다. 예를 들어 나는 노선이있을 수 있습니다아파치 낙타 루트 테스트하기
<onException id="Exception">
<exception>java.lang.Exception</exception>
<handled>
<constant>true</constant>
</handled>
<to uri="direct:fear"/>
</onException>
<route id="happyStory">
<from uri="direct:inTheBeginning"/>
<to uri="bean:enchantedKingdom?method=warn" />
<to uri="bean:fluffykins" />
</route>
<route id="scaryStory">
<from uri="direct:fear"/>
<onException>
<exception>java.lang.Exception</exception>
<handled>
<constant>true</constant>
</handled>
</onException>
<to uri="bean:monster"/>
<choice>
<when>
<simple>${header.succesfullywarned}</simple>
<to uri="bean:enchantedKingdom?method=hide"/>
</when>
<otherwise>
<to uri="bean:enchantedKingdom?method=panic" />
</otherwise>
</choice>
</route>
을 그리고 난 때 빈 다음, 빈 메소드가 경고 할 때 다음 헤더가 메시지에 설정해야합니다 "succesfullywarned"라고 말할 수 있도록 wan't 및 fluffykins가 호출되면 메시지가 "scaryStory"로 보내지는 예외가 있어야하며이 경우 bean 메소드 hide가 호출되었다고 주장하지 않습니다.
이 대략 내 테스트 클래스 설정입니다 :
@RunWith(CamelSpringJUnit4ClassRunner.class)
@ContextConfiguration({"/META-INF/spring/route-
stories.xml","/META-INF/spring/beans.xml"})
@MockEndpointsAndSkip("(bean:fluffykins|bean:monster|bean:enchantedKingdom?method=warn|bean:enchantedKingdom?method=hide|bean:enchantedKingdom?method=panic)")
public class StoryHappyRouteTest extends CamelSpringTestSupport {
private String url = "direct:inTheBeginning";
@Autowired
private ApplicationContext applicationContext;
@Override
protected AbstractApplicationContext createApplicationContext() {
return (AbstractApplicationContext)applicationContext;
}
@Test
public void test(){
MockEndpoint warn = getMockEndpoint("mock:bean:enchantedKingdom?method=warn");
MockEndpoint fluffy = getMockEndpoint("mock:bean:fluffykins");
MockEndpoint monster = getMockEndpoint("mock:bean:monster");
MockEndpoint hide = getMockEndpoint("mock:bean:enchantedKingdom?method=hide");
MockEndpoint panic = getMockEndpoint("mock:bean:enchantedKingdom?method=panic");
fluffy.whenAnyExchangeReceived(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
System.out.println("Bunny!");
throw new NullPointerException();
}
});
template.sendBody(url,"");
warn.assertExchangeReceived(0);
fluffy.assertExchangeReceived(0);
monster.assertExchangeReceived(0);
panic.assertExchangeReceived(0);
}
}
내가 행동 낙타의 첫 번째 버전에서 테스트에 장을 읽고 설명서에 주위 (http://camel.apache.org/testing.html)을보고했지만 나는 내 상황에 그것을 적용하는 방법을 이해하지 않습니다. 위의 테스트에서 나는 여러 메소드가있는 bean을 가지고 있지 않으므로 "? method = methodname"을 포함하고있는 uri를 가지고 있으며, 어떤 이유로 이것이 작동하지 않게됩니다. 오류가 발생하지 않거나 모의이 사용되지 않고 대신 실제 콩이 호출됩니다. 내가 할 수없는 일을하는 것이 불가능합니까? 어떤 방법 으로든 테스트 설정을 변경할 수 있지만, 경로와 빈이 spring-xml 파일에 정의되어 있다고 가정합니다.
나는 끝점이 아니라 콩 자체를 조롱하는 법을 배웠다.하지만 내가 생각할 수있는 유일한 방법은 모든 콩이 정의 된 "imposter-beans.xml"파일을 만드는 것인데, 그 점은 stubbclasses를 가리킨다. 경로에 사용 된 모든 클래스를 확장합니다. 그러나 그것은 정교하고 잘못된 접근이라고 느낀다.
예, 이것이 제가 생각한 것 같아요. 전에 그것을 시도했을 때 나는 그것을 작동시키지 못했습니다. 이제 다시 시도하고 조금 더있어하지만 끝점으로 여러 가지 방법으로 콩으로 작동하도록 가져올 수 없습니다. 이 설정을 표시하기 위해 내 게시물을 편집했습니다. 그것은 가능하지 않거나 나는 무엇인가 놓치고 있습니까? – numfar