How to perform Arquillian Testing with Apache Camel Routes

342 Views Asked by At

I'm new to Apache Camel. I have written simple program to place a file to another Location using camel routes. And I have written Junit and Mock Tests for that.

This is my 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}}");        

 }
}

this is 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());

  }
}

this is my application.yml file

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
 ---

Like the same way I tried with Mock Test through MockEndPoints.

I have Gone through Apache Camel official site: https://camel.apache.org/cdi-testing.html but I didn't understand the flow to test through Camel Arquillian Integration test.

How can I test my project through Arquillian.

0

There are 0 best solutions below