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을 던지고 있음을 확인했습니다. 이 예외가 표시되지 않고 일반 예외 메시지를 받고 있기 때문에 카멜 예외 계층에 아무 것도 나타나지 않았습니다. 다음은 예외입니다.

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