0

我是 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 尝试使用模拟测试一样。

我已经浏览了 Apache Camel 官方网站:https : //camel.apache.org/cdi-testing.html 但我不明白通过 Camel Arquillian 集成测试进行测试的流程。

如何通过 Arquillian 测试我的项目。

4

0 回答 0