Я новичок в интеграции Spring. У меня ActiveMQ с ответом «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
Я тестировал следующее: В моем тестовом контексте создан адаптер исходящего канала, который инициирует отправку сообщения на activeMQ с использованием канала testJmsQueue. А также создал МОСТ для процессаResponseChannel -> testChannel. Я ожидал, что метод 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.
ВИДЕТЬ [Основные] (https://github.com/garyrussell/spring-integration-samples/tree/master/basic/testing-examples) и [Дополнительно] (https://github.com/garyrussell/spring-integration-samples/tree/master/advanced/advanced-testing-examples) Тестирование образцов. Кроме того, [Spring Integration in Action] (http://www.manning.com/fisher/) имеет главу о тестировании, которая, как представляется, является образцовой главой в [Manning] (http://www.manning.com/ рыболов /). –
Я так тестировал – user2279337
Гэри, спасибо за ответ. См. Мой обновленный вопрос выше. Я включил тест-контекст и модульный тест, который я использую. Дальнейшая рекомендация или образец кода были бы полезны. – user2279337