首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在内存数据库未提取结果的情况下测试camel-sql路由

在内存数据库未提取结果的情况下测试camel-sql路由
EN

Stack Overflow用户
提问于 2017-10-16 19:20:24
回答 1查看 660关注 0票数 0

我已经使用camel-sql编写了代码,它工作得很好。现在,我必须为同样的问题编写测试用例。我使用了内存中的数据库H2。我已经初始化了数据库并将数据源分配给了sqlComponent。

代码语言:javascript
复制
 // 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");

问题是,一旦测试用例开始,它就会说

代码语言:javascript
复制
No bean could be found in the registry for: myDataSource of type: javax.sql.DataSource 

我查看了camel-SQL组件测试用例,并执行了相同的操作,但代码无法找到dataSource。请帮帮忙。提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2017-10-28 17:33:07

在这个问题上花了很多时间之后,我发现H2数据库正在使用JDBCUtils来获取记录,并且抛出了ClassNotFoundException。我在Camel exception hierarchy中找不到它,因为这个异常被抑制了,所有我都得到了一个通用的异常消息。以下是例外情况:

代码语言:javascript
复制
ClassNotFoundException: com.vividsolutions.jts.geom.Geometry

在搜索这个问题之后,我发现它需要更多的依赖项。所以我添加了它,它解决了这个问题。

问题URL:https://github.com/elastic/elasticsearch/issues/9891

依赖关系:https://mvnrepository.com/artifact/com.vividsolutions/jts-core/1.14.0

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46769120

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档