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の単体テストを調べて、テスト用のメモリ内のデータベースを使用するようにしてください –