0

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コンポーネントのテストケースに見て、同じことをやってますが、コードはすることができませんデータソースを見つける。助けてください。前もって感謝します。

+0

あなたのテストのソースコードを追加することはできますか? – ltsallas

+0

camel-sqlの単体テストを調べて、テスト用のメモリ内のデータベースを使用するようにしてください –

答えて

0

この問題で多くの時間を費やした結果、H2データベースがJDBCUtilsを使用してレコードを取得していたことが判明し、ClassNotFoundExceptionがスローされました。この例外は抑制されていて、私が一般的な例外メッセージを受け取っていたので、私はCamelの例外階層のどこにもいなかった。ここに例外があります:

ClassNotFoundException: com.vividsolutions.jts.geom.Geometry 

問題を検索した後、もう1つの依存関係が必要です。だから私はそれを追加し、問題を解決しました。

発行URL:https://github.com/elastic/elasticsearch/issues/9891

依存関係:https://mvnrepository.com/artifact/com.vividsolutions/jts-core/1.14.0

関連する問題