Apache camel 骆驼蓝图测试与黄瓜
是否可以将cucumber与CamelBlueprintTestSupport结合使用?我有跑步课:Apache camel 骆驼蓝图测试与黄瓜,apache-camel,cucumber-jvm,Apache Camel,Cucumber Jvm,是否可以将cucumber与CamelBlueprintTestSupport结合使用?我有跑步课: @RunWith(Cucumber.class) @CucumberOptions(monochrome=true, format={ "pretty", "html:target/cucumber"}, features = "C:/Users/Developer/workspace_camel/SRV002_PatronInformation/src/tes
@RunWith(Cucumber.class)
@CucumberOptions(monochrome=true,
format={ "pretty", "html:target/cucumber"},
features = "C:/Users/Developer/workspace_camel/SRV002_PatronInformation/src/test/resources/cucumber/asynchronousErrorHandling.feature")
public class RunFeature_SRV002_PatronInformationTest {
}
以及我的blueprint测试类和场景:
public class SRV002_PatronInformationScenarioTest extends CamelBlueprintTestSupport {
@Override
protected String getBlueprintDescriptor() {
return "/OSGI-INF/blueprint/blueprint.xml";
}
@Given("^client communicates asynchronous via socket$")
public void client_communicates_asynchronous_via_socket() throws Throwable {
System.out.println("test");
}
@When("^client posts message$")
public void an_error_occurs_inside_the_integration() throws Throwable {
String endpoint = "netty4:tcp://localhost:5000?sync=false&textline=true";
template.sendBody(endpoint, "test");
}
@Then("^the integration should not return response to the client$")
public void the_integration_should_not_return_the_error_to_the_client() throws Throwable {
System.out.println("test");
}
}
现在的问题是,当我运行它时,我在template.sendbody上遇到了nullpointerexception,因为上下文、捆绑包和路由尚未启动。出于某种原因,添加@RunWith(Cucumber)似乎会阻止骆驼路线的启动
有人知道如何解决这个问题吗?谢谢
Souciance好的,所以我设法解决了这个问题。 参考请看这里: 感谢格雷戈·伦茨的帮助 本质上,这里的关键是,在测试方法内部的Camel BlueprintTestSupport类中,启动给定场景,您需要添加这个。setUp()。请参阅下面的代码: 黄瓜
SRVXXX_FileTransferCamelRunner filetransfer = new SRVXXX_FileTransferCamelRunner();
@Given("^an input file$")
public void an_input_file() throws Throwable {
endpoint.append("file:C:/Camel/input?fileName=input.txt");
}
@When("^client puts the file in the input directory$")
public void client_puts_the_file_in_the_input_directory() throws Throwable {
filetransfer.testPutFile(fileData.toString(), endpoint.toString());
}
@Then("^the integration should move the file to the output directory$")
public void the_integration_should_move_the_file_to_the_output_directory() throws Throwable {
String outputPath = "C:/Camel/output/input.txt";
filetransfer.testFileHasMoved(outputPath);
}
骆驼
@Test
public void testPutFile(String body, String endpoint) throws Exception {
this.setUp();
template.sendBody(endpoint,body);
Thread.sleep(2000);
assertFileNotExists(endpoint);
}
好的,所以我设法解决了这个问题。 参考请看这里: 感谢格雷戈·伦茨的帮助 本质上,这里的关键是,在测试方法内部的Camel BlueprintTestSupport类中,启动给定场景,您需要添加这个。setUp()。请参阅下面的代码: 黄瓜
SRVXXX_FileTransferCamelRunner filetransfer = new SRVXXX_FileTransferCamelRunner();
@Given("^an input file$")
public void an_input_file() throws Throwable {
endpoint.append("file:C:/Camel/input?fileName=input.txt");
}
@When("^client puts the file in the input directory$")
public void client_puts_the_file_in_the_input_directory() throws Throwable {
filetransfer.testPutFile(fileData.toString(), endpoint.toString());
}
@Then("^the integration should move the file to the output directory$")
public void the_integration_should_move_the_file_to_the_output_directory() throws Throwable {
String outputPath = "C:/Camel/output/input.txt";
filetransfer.testFileHasMoved(outputPath);
}
骆驼
@Test
public void testPutFile(String body, String endpoint) throws Exception {
this.setUp();
template.sendBody(endpoint,body);
Thread.sleep(2000);
assertFileNotExists(endpoint);
}