Jestem nowy w Spring Integration. Mam ActiveMQ z powiedzeniem "responseQ". Kiedy nadejdzie wiadomość "responseQ" -> painResponseChannel -> transformer -> processResponseChannel -> beanProcessing. Mam następujące ustawienia:Jak testować 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>
Więc moje pytanie brzmi: jak mogę przetestować zakończyć skończy? Jak mogę potwierdzić wyjście transformatora lub stwierdzić, co jest na tym kanale? Próbowałem, ale nie udało mi się ... Mam nadzieję, że ktoś może pomóc.
Z góry dziękuję. GM
Testowałem w ten sposób: W moim kontekście testowym utworzono adapter kanału wychodzącego, który inicjuje umieszczanie komunikatu na activeMQ za pomocą kanału testJmsQueue. Stworzyła również BRIDGE dla processResponseChannel -> testChannel. Spodziewałem się metody receive(), aby dać mi coś w zamian. Ale myślę, że problem polega na tym, że jest on zbyt szybki i zanim dotrze do metody receive(), potok zakończył się.
Test-context wygląda następująco:
<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>
a następnie w badanej jednostki mam to:
@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
Pierwsze odpowiedź jako zero.
zobaczyć [Basic] (https://github.com/garyrussell/spring-integration-samples/tree/master/basic/testing-examples) i [Advanced] (https://github.com/garyrussell/spring-integration-samples/tree/master/advanced/advanced-testing-examples) Testowanie próbek. Ponadto [Spring Integration in Action] (http://www.manning.com/fisher/) zawiera rozdział poświęcony testowaniu, który jest przykładowym rozdziałem w [Manning] (http://www.manning.com/ rybak/). –
Testowałem w ten sposób, – user2279337
Gary, dzięki za odpowiedź. Zobacz moje zaktualizowane pytanie powyżej. Zawarłem test kontekstowy i test jednostkowy, z których korzystam. Przydałaby się dodatkowa porada lub próbka kodu. – user2279337