2014-07-16 3 views
3

카멜 단위 테스트가 있으며 경로의 첫 번째 지점에서 Exchange에 설정된 헤더 값에 액세스하려고합니다.카멜 테스트 : 경로에 설정된 헤더에 액세스하는 방법

경로 예 ...이 사용되는

<route id="VCM001_incoming"> 
      <from uri="file:{{InLocation}}" /> 
      <convertBodyTo type="java.lang.String"/> 
      <setHeader headerName="FileNameWithoutExtension"> 
       <simple>${file:onlyname.noext}</simple> 
      </setHeader> 
      <to uri="direct:splitFile" /> 
     </route> 

자바 코드 ...이 시점에 따라서 모든 좋은

public List<String> createList(Exchange exchange) { 
     String fileName = (String) exchange.getIn().getHeader("FileNameWithoutExtension"); 

.

이제 내 테스트에서 어떤 헤더 값이 "FileNameWithoutExtension"인지 알고 싶습니다.

@Produce(uri = "file:{{InLocation}}") 
    private ProducerTemplate inputEndpoint; 

    @EndpointInject(uri = "mock:output1") 
    private MockEndpoint outputEndpointRPR; 

@Test 
    public void testCamelRoute() throws Exception 
    { 
    context.addRoutes(new RouteBuilder() { 
     @Override 
     public void configure() throws Exception { 
     from("file:{{OutLocation}}").to(outputEndpoint); 
     } 

    inputEndpoint.sendBody("test-message"); 

    Object[] expectedBodies = new Object[]{"Success: filename=xxx"}; 
    // At this point I need the header 'FileNameWithoutExtension' to setup the correct 'expectedBodies' 

    outputEndpoint.expectedBodiesReceivedInAnyOrder(expectedBodies); 

    assertMockEndpointsSatisfied(); 

    } 

답변

1

를 참조하십시오 :

outputEndpoint.getExchanges().get(0).getIn().getHeader("FileNameWithoutExtension"); 
1

모의 종점을보십시오.

outputEndpointRPR.getExchanges().get(0).getIn().getHeader("FileNameWithoutExtension"); 

당신은 사용하여 매우 쉽게 얻을 수 http://camel.apache.org/mock.html

3

이 매우 늦게 알고 들어, 당신처럼 뭔가를 할 수 있도록 메모리에 각각받은 교환이 저장해야 낙타 2.15.2 다음을 사용할 수 있습니다

outputEndpoint.expectedHeaderReceived("header", "value"); 
관련 문제