2013-01-15 13 views
8

私はCamelから出発していますが、テストを書く上で問題があります。私のユースケースは、cfx proxy exampleとまったく同じです。私は "RealWebservice"は必要ではないことを除いて。今私は、アノテーションのアプローチを使用して、ユニットテスト(ない例に含まれているとして、統合テスト)を書き込むしようとしている:模擬エンドポイントを使ったCamelテストのルートの開始方法

@RunWith(CamelSpringJUnit4ClassRunner.class) 
@ContextConfiguration(locations = { "classpath:application-context.xml" }) 
@MockEndpointsAndSkip 
public class RoutesTest { 

@Autowired 
CamelContext camelContext; 

@EndpointInject(uri = "mock:cxf:bean:cxfEndpoint", context = "camelContext") 
MockEndpoint cxfEndpoint; 

@EndpointInject(uri = "mock:log:input", context = "camelContext") 
MockEndpoint logInputEndpoint; 

@EndpointInject(uri = "mock:http:realhostname:8211/service", context = "camelContext") 
MockEndpoint realEndpoint; 

@EndpointInject(uri = "mock:cxf:bean:cxfEndpoint") 
ProducerTemplate producer; 

@Test 
public void testLeleuxMifidRoute() throws InterruptedException { 
    String body = "<blah/>"; 

    cxfEndpoint.expectedBodiesReceived(body); 
    logInputEndpoint.expectedBodiesReceived(body); 
    realEndpoint.expectedBodiesReceived(body); 

    producer.sendBody(body); 

    MockEndpoint.assertIsSatisfied(camelContext); 
} 
} 

cxfEndpointはメッセージを受信するが、他のエンドポイントにはありません。

ルートはこのようになります(私はそれを実行したときにそれが動作してSOAPUIとのメッセージを送って、明らかに私は、この例では、IPSとbeannamesを難読化):私は間違って

<endpoint id="callRealWebService" uri="http://realhostname:8211/service?throwExceptionOnFailure=true" /> 
<route> 
    <from uri="cxf:bean:cxfEndpoint?dataFormat=MESSAGE"/> 
    <to uri="log:input?showStreams=true"/> 
    <to ref="callRealWebService"/> 
    <to uri="log:output"/> 
</route> 

何をしているのですか?私が見つけたすべての例と他の質問は、「直接的なもの:スタート」を使うか、生産ルートを変更するように見えます。

答えて

4

私たちが成功裏に使用したアプローチの1つは、テスト実行とメインコード用に異なるプロパティファイルを用意することです。

は、我々は我々がテスト実行のためのuri.propertiesを持っているメインコードと/src/test/resources/META-INF/ためuri.propertiesファイルを持っているフォルダ/src/main/resources/META-INF/では、ラクダのコンテキスト内で、プロパティ

<propertyPlaceholder id="properties" 
      location="classpath:META-INF/uri.properties" xmlns="http://camel.apache.org/schema/spring" /> 

を定義します。

主uri.propertiesが

cxf.bean.cxfEndpoint=cxf:bean:cxfEndpoint?dataFormat=MESSAGE 

試験uri.propertiesであろうあなたの経路は、表記{{properties.name}}

<route> 
    <from uri="{{cxf.bean.cxfEndpoint}}"/> 
</route> 

を使用して、代わりに実際のURI値のプロパティのプレースホルダを使用して書き換えなければなりませんは

cxf.bean.cxfEndpoint=direct:start 

この設定を使用します。あなたのルートを簡単にテストすることができます。

関連する問題