2012-12-04 8 views
1

구성 요소 (끝점)가 기록 된 낙타 프로젝트가 있습니다. 경로 (mycomponent : somename)에서 사용됩니다. 구성 요소가 완료된 후 경로에 대한 단위 테스트가 실패하기 시작했습니다. (자체 클라이언트가 작성된 일부 http 통신을 사용함) "서버에 연결할 수 없습니다 ...", "속성을 읽을 수 없습니다 ..."에 따라 오류가 표시됩니다.낙타 단위 테스트 맞춤 구성 요소를 방문하십시오

엔드 포인트가이 용도로 직접 사용되지는 않습니다. 경로에 대한 실제 단위 테스트가 필요합니다. 일부 테스트를 실행하기 위해 웹 서비스를 시작할 필요가 없습니다. 단지 경로 테스트 여야합니다.

샘플 코드 :

public class MyTest extends CamelTestSupport { 

@Override 
public String isMockEndpoints() { 
    return "*"; 
} 

@Override 
protected RouteBuilder createRouteBuilder() throws Exception { 
    return new RouteBuilder() { 
     @Override 
     public void configure() throws Exception { 
      includeRoutes(new MyRoute()); 
     } 
    }; 
} 

@Test 
public void testRouteToRd() throws Exception { 
    context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() { 

     @Override 
     public void configure() throws Exception { 
      replaceFromWith("direct:incomponent"); // replacing from 
     } 
    }); 

    getMockEndpoint("mock:myconnector:outcomponent").expectedMessageCount(1); 
    template.sendBody("direct:incomponent", OK_MESSAGE); // and sending to direct 
    assertMockEndpointsSatisfied(); 
} 
} 

나는이 구성 실제 구성 요소를 타격하기 시작 이유는 무엇 (이 구성 요소가 끝난 훨씬 전에 일하고 있었다) 누군가가 도와 줄 수, 감사합니다.

정말 미안하지만 복사 붙여 넣기와 구성으로 "재생"하면 도움이되었습니다.

@Override 
public String isMockEndpointsAndSkip() { 
    return "*"; 
} 

그리고 내 모든 테스트는 지금 좋은 것 :

@Override 
public String isMockEndpoints() { 
    return "*"; 
} 

대체되었습니다. 하지만 아직도 이런 일이 일어나지 않는 이유를 이해하지 못한다. 나는 끝점에서 직결로 직접 메시지를 보낸다. (실제가 아님)

매우 유감스럽게도, 좋은 질문이 아닌 경우 닫으십시오. 당신이 낙타 시험에 adviceWith을 사용하는 경우

답변

0

, 당신은 방법 isUseAdviceWith을 무시하고 당신이 당신의 데이터를 전송하기 전에 다음 context.start() 전화를해야

예 :.

@Override 
public boolean isUseAdviceWith() { 
    // tell we are using advice with, which allows us to advice the route 
    // before Camel is being started 
    return true; 
} 

@Test 
public void testRouteToRd() throws Exception { 
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() { 

    @Override 
    public void configure() throws Exception { 
     replaceFromWith("direct:incomponent"); // replacing from 
    } 
}); 

context.start(); // NECESSARY IF USING ADVICEWITH 

getMockEndpoint("mock:myconnector:outcomponent").expectedMessageCount(1); 
template.sendBody("direct:incomponent", OK_MESSAGE); // and sending to direct 
assertMockEndpointsSatisfied(); 

}

참조 : Camel AdviceWith documentation