Tôi mới vào Spring Integration. Tôi có ActiveMQ với câu trả lời là 'responseQ'. Vì vậy, khi một tin nhắn đến 'responseQ' -> painResponseChannel -> transformer -> processResponseChannel -> beanProcessing. Tôi có thiết lập sau:Làm thế nào để kiểm tra Spring Integration
<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>
Vì vậy, câu hỏi của tôi là TÔI CÓ THỂ THỬ NGHIỆM KẾT THÚC NÀY END? Làm thế nào tôi có thể khẳng định đầu ra của máy biến áp hoặc khẳng định whats trên kênh? Tôi đã thử nhưng thất bại ... Hy vọng ai đó có thể giúp đỡ.
Xin cảm ơn trước. GM
Tôi đã thử nghiệm như thế này: Trong ngữ cảnh thử nghiệm của tôi đã tạo bộ chuyển đổi kênh đi, khởi tạo việc đặt thông báo trên activeMQ bằng cách sử dụng kênh testJmsQueue. Và cũng đã tạo một BRIDGE cho processResponseChannel -> testChannel. Tôi đã mong đợi phương thức receive() trả lại cho tôi một cái gì đó. Nhưng tôi nghĩ vấn đề là nó quá nhanh và vào thời điểm nó nhận được phương thức receive() mà đường ống đã kết thúc.
Các thử bối cảnh trông như thế này:
<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>
và sau đó trong các thử nghiệm đơn vị tôi có điều này:
@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
Bắt bài trả lời là null.
Xem [Cơ bản] (https://github.com/garyrussell/spring-integration-samples/tree/master/basic/testing-examples) và [Nâng cao] (https://github.com/garyrussell/spring-integration-samples/tree/master/advanced/advanced-testing-examples) Các mẫu thử. Ngoài ra, [Spring Integration in Action] (http://www.manning.com/fisher/) có một chương về thử nghiệm, đó là một chương mẫu tại [Manning] (http://www.manning.com/ người câu cá/). –
Tôi đã thử nghiệm như thế này – user2279337
Gary, cảm ơn bạn đã trả lời. Vui lòng xem câu hỏi được cập nhật của tôi ở trên. Tôi đã bao gồm bối cảnh thử nghiệm và thử nghiệm đơn vị mà tôi đang sử dụng. Tư vấn thêm hoặc mẫu mã sẽ hữu ích. – user2279337