0

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.

AVINASH M
  • 487
  • 3
  • 7
  • 19
  • Why do you want to use arquillian? And what you posted above are spring boot which tend to be tested with spring boot and junit according to spring boot documents, and with camel-test-spring etc. – Claus Ibsen Jun 06 '19 at 10:47
  • I just wanted to know how can we Perform Real Time Testing with Arquillian in camel @ClausIbsen – AVINASH M Jun 06 '19 at 12:20
  • There is some coverage of using arquillian in the CiA2 book testing chapter. – Claus Ibsen Jun 06 '19 at 13:16

0 Answers0