잘 작동하는 camel-sql을 사용하여 코드를 작성했습니다. 이제는 동일한 테스트 케이스를 작성해야합니다. 나는 메모리 데이터베이스 H2를 사용했다. 데이터베이스를 초기화하고 sqlComponent에 데이터 소스를 할당했습니다.메모리 내 데이터베이스에서 결과를 가져 오지 않고 camel-sql 경로를 테스트하십시오.
// Setup code
@Override
protected JndiRegistry createRegistry() throws Exception {
JndiRegistry jndi = super.createRegistry();
// this is the database we create with some initial data for our unit test
database = new EmbeddedDatabaseBuilder()
.setType(EmbeddedDatabaseType.H2).addScript("createTableAndInsert.sql").build();
jndi.bind("myDataSource", database);
return jndi;
}
// Testcase code
@SuppressWarnings("unchecked")
@Test
public void testRoute() throws Exception {
Exchange receivedExchange = template.send("direct:myRoute", ExchangePattern.InOut ,exchange -> {
exchange.getIn().setHeader("ID", new Integer(1));
});
camelContext.start();
MyClass updatedEntity = (MyClass)jdbcTemplate.queryForObject("select * from MY_TABLE where id=?", new Long[] { 1l } ,
new RouteTest.CustomerRowMapper());
// Here I can get the updatedEntity from jdbcTemplate
assertNotNull(receivedExchange);
assertNotNull(updatedEntity);
}
// Main code
from("direct:myRoute")
.routeId("pollDbRoute")
.transacted()
.to("sql:select * from MY_TABLE msg where msg.id = :#"+ID+"?dataSource=#myDataSource&outputType=SelectOne&outputClass=com.entity.MyClass")
.log(LoggingLevel.INFO,"Polled message from DB");
문제는 즉시 테스트 케이스가 시작되면, 그것은
No bean could be found in the registry for: myDataSource of type: javax.sql.DataSource
나는 낙타-SQL 구성 요소 테스트 케이스로보고
말과 같은 일을하고있다,하지만 코드는 할 수 없습니다 데이터 소스를 찾으십시오. 도와주세요. 미리 감사드립니다.
당신이 테스트의 소스 코드를 추가 할 수 있습니까? – ltsallas
테스트 용 메모리 데이터베이스를 사용하므로 camel-sql 자체의 단위 테스트를보십시오. –