복붙노트

[SPRING] 스프링 통합을 테스트하는 방법

SPRING

스프링 통합을 테스트하는 방법

Spring Integration이 처음입니다. 나는 ActiveQ와 함께 'responseQ'라고 말하고있다. 그래서 메시지가 'responseQ'-> painResponseChannel -> transformer -> processResponseChannel -> beanProcessing에 도착할 때. 다음 설정이 있습니다.

    <jms:message-driven-channel-adapter  extract-payload="true"
                                     channel="painResponseChannel"
                                     connection-factory="connectionFactory"
                                     destination-name="responseQ"/>

    <integration:channel id="painResponseChannel" />

    <integration-xml:unmarshalling-transformer
        id="defaultUnmarshaller"
        input-channel="painResponseChannel"
        output-channel="processResponseChannel"
        unmarshaller="marshaller"/>

    <integration:channel id="processResponseChannel" />

    <integration:service-activator
        input-channel="processResponseChannel"
        ref="processResponseActivator"/>

    <bean id="processResponseActivator" class="com.messaging.processor.PainResponseProcessor"/>


    <bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
      <property name="classesToBeBound">
        <list>
            <value>com.domain.pain.Document</value>
        </list>
      </property>
    </bean>

그래서 내 질문은이 끝까지 테스트 할 수 있습니까? 변압기의 출력을 어설 션하거나 채널에 무엇을 어설트 할 수 있습니까? 나는 시도했지만 실패했습니다 ... 누군가가 도울 수 있기를 바랍니다.

미리 감사드립니다. GM

나는 다음과 같이 테스트했다 : 내 테스트 컨텍스트에서 testJmsQueue 채널을 사용하여 activeMQ에 메시지를 넣는 아웃 바운드 채널 어댑터를 만들었다. 또한 processResponseChannel -> testChannel에 대한 BRIDGE를 만들었습니다. 나는 receive () 메소드가 나에게 뭔가 돌려 줄 것을 기대하고 있었다. 하지만 문제는 너무 빨라서 receive () 메소드에 도달 할 때까지 파이프 라인이 끝났다고 생각합니다.

테스트 컨텍스트는 다음과 같습니다.

<integration:bridge input-channel="processResponseChannel" output-channel="testChannel"/>

<jms:outbound-channel-adapter id="jmsOut" destination-name="responseQ" channel="testJmsQueue"/>

<integration:channel id="testJmsQueue"/>

<integration:channel id="testChannel">
    <integration:queue/>
</integration:channel>

다음 단위 테스트에서 나는 이것을 가지고 :

@ContextConfiguration(locations = "classpath*:PainResponseTest-context.xml")
@RunWith(SpringJUnit4ClassRunner.class)
public class PainResponseTest {

private String painResponseXML;

@Autowired
MessageChannel testJmsQueue;
@Autowired
QueueChannel testChannel;

@Before
public void setup() throws Exception {

    ClassPathResource cpr = new ClassPathResource("painResponse.xml");
    InputStream is = cpr.getInputStream();
    StringWriter writer = new StringWriter();
    IOUtils.copy(is, writer, "UTF-8");
    painResponseXML = writer.toString();
}

@Test
@SuppressWarnings("unchecked")
public void shouldDoSomething() throws InterruptedException {

    testJmsQueue.send(MessageBuilder.withPayload(painResponseXML).build());

    Message<String> reply = (Message<String>) testChannel.receive(0);
    Assert.assertNotNull("reply should not be null", reply);
    String out = reply.getPayload();
    System.out.println(out);
}

}

==================== TEST OUTPUT =====================
java.lang.AssertionError: reply should not be null

회신을 null로 설정 중입니다.

해결법

  1. ==============================

    1.종단 간 테스트의 경우 다음을 수행 할 수 있습니다. - 임베디드 구성에서 activemq를 사용하여 JMS 메시지 보내기 - processResponseChannel에 채널 인터셉터 삽입 - DEBUG 레벨 사용 가능 - Spring Integration은 채널 및 서비스 활성기 안팎으로 메시지를 추적하는 매우 유용하고 유용한 로그를 제공합니다.

    종단 간 테스트의 경우 다음을 수행 할 수 있습니다. - 임베디드 구성에서 activemq를 사용하여 JMS 메시지 보내기 - processResponseChannel에 채널 인터셉터 삽입 - DEBUG 레벨 사용 가능 - Spring Integration은 채널 및 서비스 활성기 안팎으로 메시지를 추적하는 매우 유용하고 유용한 로그를 제공합니다.

  2. from https://stackoverflow.com/questions/16219589/how-to-test-spring-integration by cc-by-sa and MIT license