Ошибка при модульном тестировании пружины интеграции DSL - PullRequest
0 голосов
/ 08 июня 2018

При выполнении модульного тестирования моего кода интеграции пружины я вижу следующую ошибку.А также я не был уверен, как смоделировать мой сервис и другие зависимости при использовании mockIntegrationContext.

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'orderInputEndPoint' available

    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:686)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1210)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:204)

Основной программный код

@EnableIntegration
public class OrderPersistFlow {

    @Autowired
    private ActiveMQConnectionFactory activeMQConnectionFactory;

    @Autowired
    private OrderTransformer orderTransformer;

    @Autowired
    private OrderService orderService;


    @Bean
    public IntegrationFlow persistFlow() {
        return IntegrationFlows
                .from(Jms.messageDrivenChannelAdapter(activeMQConnectionFactory)
                        .id("orderInputEndPoint")
                        .destination("order.queue")
                        .jmsMessageConverter(new MarshallingMessageConverter(jaxbMarshaller())))
                .filter(OrderVO.class, p -> p.getOrderStatus().equals("OPEN")
                .transform(orderTransformer)
                .handle(orderService, "save")
                .get();
    }
}

Тестовый код

RunWith(SpringRunner.class)
@SpringIntegrationTest(noAutoStartup = "orderInputEndPoint")
public class OrderPersistFlowTest {

    @Autowired
    private MockIntegrationContext mockIntegrationContext;

    @Test
    public void persistFlowTest(){
        OrderVO orderVO = new OrderVO();
        orderVO.setId("1234");
        orderVO.setName("TestOrder");
        orderVO.setDescription("order desc");

        MessageSource<OrderVO> messageSource = () -> new GenericMessage<>(orderVO);

        this.mockIntegrationContext.substituteMessageSourceFor("orderInputEndPoint", messageSource);

        Message<?> receive = messageSource.receive();
    }
}

1 Ответ

0 голосов
/ 08 июня 2018

Я не вижу @ContextConfiguration(classes = OrderPersistFlow.class) в вашем тестовом классе: https://docs.spring.io/spring/docs/5.0.6.RELEASE/spring-framework-reference/testing.html#integration-testing-annotations-spring

Полностью не ясно, что вы собираетесь тестировать, если нет контекста приложения для загрузки ...

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...