2016-12-14 4 views
-1

@Profileを使用して私は豆を模擬することができますが、模擬方法が呼び出されていないラクダルートです。私はSpringJUnit4ClassRunner.classを使用していて、@ActiveProfileを使用しています 以下は、単体テスト時に私の模擬beanでcancelSubscriptionTransformer、myBeanClient、extendedClient beansを置き換えたいルートです。以下はキャンドルルートの擬似と春の豆を交換することができません

from("{{cancelSubscriptionFromRMQUri}}").routeId("cancelSubscriptionRoute") 
     .unmarshal().json(JsonLibrary.Jackson, Subscription.class) 
      .bean("cancelSubscriptionTransformer", "toKbCancelSubscription") 
      .choice() 
      .when().simple("${body.serviceType} == 'subscriptions'") 
      .bean("myBeanClient", "cancelSubscription(${body.subscriptionId}, ${body.createdBy}, ${body.reason}, ${body.comment})") 
      .bean("extendedClient", "retrieveSubscription(${body.subscriptionId}, ${body.externalKey})") 
      .marshal(json) 
      .to("{{cancelSubscriptionTORMQUri}}") 
      .when().simple("${body.serviceType} == 'usage'") 
      .bean("myBeanClient", "cancelSubscription(${body.subscriptionId}, ${body.dateTime},null, null, -1, ${body.createdBy}, ${body.reason}," + 
        " ${body.comment})") 
      .endChoice(); 

私はモック豆以下

@Profile("test") 
@Primary 
@Repository 
public class ExtendedClientMock extends ExtendedClient { 

public Subscription retrieveSubscription(UUID subscriptionid, String sdpSubscriptionId) throws MyClientException { 
    Subscription subs=new Subscription(); 
    subs.setProductName("test"); 
    return subs; 
} 
} 

の残りの部分と同じアプローチを使用して、私は私のExtendedClientMockを定義する方法であるユニットテストのためのコードです:

@ActiveProfiles({"test", "aop"}) 
    @AutoConfigureTestDatabase(connection = EmbeddedDatabaseConnection.H2) 
    @RunWith(SpringJUnit4ClassRunner.class) 
    @SpringBootTest(classes = CancelSubscriptionRouteTest.class) 
    @EnableAutoConfiguration 
    @ComponentScan 
    @ContextConfiguration(classes = { BillingServicesApplication.class }) 
    @UseAdviceWith 

    public class CancelSubscriptionRouteTest { 

    @Autowired 
    protected CamelContext camelContext; 

    @Autowired 
    private CancelSubscriptionTransformer cancelSubscriptionTransformer; 

    @Autowired 
    private ExtendedClient extendedClient; 

    @Autowired 
    private MyBeanClient myBeanClient; 

    @EndpointInject(uri = "{{cancelSubscriptionTORMQUri}}") 
    private MockEndpoint cancelSubscriptionTORMQUriEndpoint; 

    @EndpointInject(uri = "{{cancelSubscriptionFromRMQUri}}") 
    private ProducerTemplate cancelSubscriptionFromRMQUriEndpoint; 

    @Inject 
    private ObjectMapperContextResolver objectMapperContextResolver; 

    @Test 
    @DirtiesContext 
    public void testCancelSubscriptionRoute() throws Exception { 
    cancelSubscriptionTORMQUriEndpoint.expectedMessageCount(1); 

    ObjectMapper objectMapper= objectMapperContextResolver.getContext(ObjectMapperContextResolver.class); 
    String jsonString=objectMapper.writeValueAsString(subscription); 

CancelSubscription cancelSubscription=cancelSubscriptionTransformer.toKbCancelSubscription(subscription); 

Assert.assertEquals("mock auto created by  amel",cancelSubscription.getComment()); 

cancelSubscriptionFromRMQUriEndpoint.sendBody("   {{cancelSubscriptionFromRMQUri}}",jsonString); 
    cancelSubscriptionTORMQUriEndpoint.assertIsSatisfied(); 
    } 
} 

Assert.assertEquals( "mock auto by amel"、cancelSubscription.getComment());モックBean上で呼び出されるcancelSubscriptionTransformer.toKbCancelSubscriptionを呼び出すことによって統計が取得されます。しかしメッセージがcancelSubscriptionFromRMQUriEndpoint.sendBodyに送信されると、ルートが呼び出され、ルート内の実際のBeanは模擬豆に置き換えられません。

+0

詳細情報(ソースコード、構成、例外など)を提供してください:http://stackoverflow.com/help /尋ねる方法 –

答えて

0

@MickaëlBは正しいBeanを拡張していない私のルートビルダーのSpring Beanで@Injectを使用し、Bean名の文字列形式の代わりにBean名を使用する

関連する問題