我是Apache Camel的新手。我编写了一个简单的程序,使用骆驼路线将文件放置到另一个位置。而且我为此编写了Junit和Mock测试。
这是我的simpleCamelRoute.java
@Component
public class SimpleCamelRoute extends RouteBuilder {
@Autowired
Environment environment;
@Override
public void configure() throws Exception {
from("{{startRoute}}").log("Timer Invoked and the body" + environment.getProperty("message"))
.pollEnrich("{{fromRoute}}").to("{{toRoute1}}");
}
}
这是SimpleCamelRouteTest.java
@ActiveProfiles("dev")
@RunWith(CamelSpringBootRunner.class)
@DirtiesContext(classMode =
DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@SpringBootTest
public class SimpleCamelRouteTest {
@Autowired
ProducerTemplate producerTemplate;
@Autowired
Environment environment;
@BeforeClass
public static void startCleanUp() throws IOException {
FileUtils.cleanDirectory(new File("data/input"));
FileUtils.deleteDirectory(new File("data/output"));
}
@Test
public void testMoveFile() throws InterruptedException {
String message = "type,sku#,itemdescription,price\n" + "ADD,100,Samsung TV,500\n" + "ADD,101,LG TV,500";
String fileName = "fileTest.txt";
producerTemplate.sendBodyAndHeader(environment.getProperty("fromRoute"), message, Exchange.FILE_NAME, fileName);
Thread.sleep(3000);
File outFile = new File("data/output/" + fileName);
// File outFile = new File("data/output/"+"abc.txt");
assertTrue(outFile.exists());
}
}
这是我的application.yml文件
spring:
profiles:
active: dev
---
spring:
profiles: mock
startRoute: direct:input
fromRoute : file:data/input?delete=true&readLock=none
toRoute1: mock:output
message: MOCK Environment
---
spring:
profiles: dev
startRoute: timer:hello?period=10s
fromRoute : file:data/input?delete=true&readLock=none
toRoute1: file:data/output
message: DEV Environment
---
就像我尝试通过MockEndPoints进行Mock Test一样。
我已经通过Apache Camel官方网站https://camel.apache.org/cdi-testing.html离开了,但我不理解通过Camel Arquillian Integration测试进行测试的流程。
如何通过Arquillian测试我的项目。