INT-3834: Upgrade to Smack-4.1.5
JIRA: https://jira.spring.io/browse/INT-3834
This commit is contained in:
committed by
Gary Russell
parent
0fc1f555e7
commit
7da183f8ed
8
spring-integration-xmpp/src/test/java/log4j.properties
Normal file
8
spring-integration-xmpp/src/test/java/log4j.properties
Normal file
@@ -0,0 +1,8 @@
|
||||
log4j.rootCategory=WARN, stdout
|
||||
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss.SSS} %-5p [%t][%c] %m%n
|
||||
|
||||
log4j.category.org.springframework.integration=WARN
|
||||
log4j.category.org.springframework.integration.xmpp=INFO
|
||||
@@ -1,26 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
|
||||
|
||||
<!-- Appenders -->
|
||||
<appender name="console" class="org.apache.log4j.ConsoleAppender">
|
||||
<param name="Target" value="System.out" />
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%-5p: %c - %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
<logger name="org.springframework.integration">
|
||||
<level value="trace" />
|
||||
</logger>
|
||||
|
||||
<!-- <logger name="org.springframework.integration">-->
|
||||
<!-- <level value="debug" />-->
|
||||
<!-- </logger>-->
|
||||
|
||||
<!-- Root Logger -->
|
||||
<root>
|
||||
<priority value="warn" />
|
||||
<appender-ref ref="console" />
|
||||
</root>
|
||||
|
||||
</log4j:configuration>
|
||||
@@ -3,20 +3,11 @@
|
||||
xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xmlns:xmpp="http://www.springframework.org/schema/integration/xmpp"
|
||||
xmlns:tool="http://www.springframework.org/schema/tool"
|
||||
xmlns:lang="http://www.springframework.org/schema/lang"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/integration/xmpp
|
||||
http://www.springframework.org/schema/integration/xmpp/spring-integration-xmpp.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
|
||||
http://www.springframework.org/schema/tool http://www.springframework.org/schema/tool/spring-tool.xsd
|
||||
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd">
|
||||
http://www.springframework.org/schema/integration/xmpp/spring-integration-xmpp.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd">
|
||||
|
||||
<beans:bean id="testConnection" class="org.mockito.Mockito" factory-method="mock">
|
||||
<beans:constructor-arg value="org.jivesoftware.smack.XMPPConnection"/>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,14 +22,15 @@ import static org.junit.Assert.assertSame;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.jivesoftware.smack.PacketListener;
|
||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||
import org.jivesoftware.smack.StanzaListener;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smackx.jiveproperties.JivePropertiesManager;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -51,7 +52,7 @@ import org.springframework.util.ReflectionUtils;
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@DirtiesContext(classMode=ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
public class ChatMessageInboundChannelAdapterParserTests {
|
||||
|
||||
@Autowired
|
||||
@@ -63,18 +64,19 @@ public class ChatMessageInboundChannelAdapterParserTests {
|
||||
@Autowired
|
||||
private MessageChannel autoChannel;
|
||||
|
||||
@Autowired @Qualifier("autoChannel.adapter")
|
||||
@Autowired
|
||||
@Qualifier("autoChannel.adapter")
|
||||
private ChatMessageListeningEndpoint autoChannelAdapter;
|
||||
|
||||
@Test
|
||||
public void testInboundAdapter(){
|
||||
public void testInboundAdapter() {
|
||||
ChatMessageListeningEndpoint adapter = context.getBean("xmppInboundAdapter", ChatMessageListeningEndpoint.class);
|
||||
MessageChannel errorChannel = (MessageChannel) TestUtils.getPropertyValue(adapter, "errorChannel");
|
||||
assertEquals(context.getBean("errorChannel"), errorChannel);
|
||||
assertFalse(adapter.isAutoStartup());
|
||||
QueueChannel channel = (QueueChannel) TestUtils.getPropertyValue(adapter, "outputChannel");
|
||||
assertEquals("xmppInbound", channel.getComponentName());
|
||||
XMPPConnection connection = (XMPPConnection)TestUtils.getPropertyValue(adapter, "xmppConnection");
|
||||
XMPPConnection connection = (XMPPConnection) TestUtils.getPropertyValue(adapter, "xmppConnection");
|
||||
assertEquals(connection, context.getBean("testConnection"));
|
||||
}
|
||||
|
||||
@@ -88,14 +90,14 @@ public class ChatMessageInboundChannelAdapterParserTests {
|
||||
xmppConnectionField.setAccessible(true);
|
||||
ReflectionUtils.setField(xmppConnectionField, adapter, xmppConnection);
|
||||
|
||||
PacketListener packetListener = TestUtils.getPropertyValue(adapter, "packetListener", PacketListener.class);
|
||||
StanzaListener stanzaListener = TestUtils.getPropertyValue(adapter, "stanzaListener", StanzaListener.class);
|
||||
|
||||
Message message = new Message();
|
||||
message.setBody("hello");
|
||||
message.setTo("oleg");
|
||||
JivePropertiesManager.addProperty(message, "foo", "foo");
|
||||
JivePropertiesManager.addProperty(message, "bar", "bar");
|
||||
packetListener.processPacket(message);
|
||||
stanzaListener.processPacket(message);
|
||||
org.springframework.messaging.Message<?> siMessage = xmppInbound.receive(0);
|
||||
assertEquals("foo", siMessage.getHeaders().get("foo"));
|
||||
assertEquals("oleg", siMessage.getHeaders().get("xmpp_to"));
|
||||
@@ -105,4 +107,5 @@ public class ChatMessageInboundChannelAdapterParserTests {
|
||||
public void testAutoChannel() {
|
||||
assertSame(autoChannel, TestUtils.getPropertyValue(autoChannelAdapter, "outputChannel"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,40 +6,40 @@
|
||||
http://www.springframework.org/schema/integration/xmpp http://www.springframework.org/schema/integration/xmpp/spring-integration-xmpp.xsd"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-xmpp="http://www.springframework.org/schema/integration/xmpp">
|
||||
|
||||
|
||||
<bean id="testConnection" class="org.mockito.Mockito" factory-method="mock">
|
||||
<constructor-arg value="org.jivesoftware.smack.XMPPConnection"/>
|
||||
</bean>
|
||||
|
||||
|
||||
<int:channel id="outboundEventChannel"/>
|
||||
|
||||
<int-xmpp:outbound-channel-adapter id="outboundEventAdapter"
|
||||
channel="outboundEventChannel"
|
||||
|
||||
<int-xmpp:outbound-channel-adapter id="outboundEventAdapter"
|
||||
channel="outboundEventChannel"
|
||||
xmpp-connection="testConnection"
|
||||
mapped-request-headers="foo*, bar*"/>
|
||||
|
||||
|
||||
<int:channel id="outboundPollingChannel">
|
||||
<int:queue/>
|
||||
</int:channel>
|
||||
|
||||
<int-xmpp:outbound-channel-adapter id="pollingConsumer"
|
||||
channel="outboundPollingChannel"
|
||||
|
||||
<int-xmpp:outbound-channel-adapter id="pollingConsumer"
|
||||
channel="outboundPollingChannel"
|
||||
xmpp-connection="testConnection">
|
||||
<int:poller fixed-rate="5000" max-messages-per-poll="1"/>
|
||||
</int-xmpp:outbound-channel-adapter>
|
||||
|
||||
<int-xmpp:outbound-channel-adapter id="withHeaderMapper"
|
||||
channel="outboundPollingChannel"
|
||||
|
||||
<int-xmpp:outbound-channel-adapter id="withHeaderMapper"
|
||||
channel="outboundPollingChannel"
|
||||
xmpp-connection="testConnection"
|
||||
header-mapper="headerMapper">
|
||||
<int:poller fixed-rate="5000" max-messages-per-poll="1"/>
|
||||
</int-xmpp:outbound-channel-adapter>
|
||||
|
||||
|
||||
<bean id="headerMapper" class="org.springframework.integration.xmpp.support.DefaultXmppHeaderMapper">
|
||||
<property name="requestHeaderNames" value="foo*"/>
|
||||
</bean>
|
||||
|
||||
<int-xmpp:outbound-channel-adapter id="outboundNoChannelAdapter"
|
||||
|
||||
<int-xmpp:outbound-channel-adapter id="outboundNoChannelAdapter"
|
||||
xmpp-connection="testConnection">
|
||||
</int-xmpp:outbound-channel-adapter>
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,6 +29,7 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.integration.mapping.AbstractHeaderMapper;
|
||||
@@ -110,7 +111,7 @@ public class ChatMessageOutboundChannelAdapterParserTests {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Test
|
||||
public void withHeaderMapper() throws Exception{
|
||||
public void withHeaderMapper() throws Exception {
|
||||
Object pollingConsumer = context.getBean("withHeaderMapper");
|
||||
assertTrue(pollingConsumer instanceof PollingConsumer);
|
||||
assertEquals(headerMapper, TestUtils.getPropertyValue(pollingConsumer, "handler.headerMapper"));
|
||||
@@ -120,40 +121,44 @@ public class ChatMessageOutboundChannelAdapterParserTests {
|
||||
XMPPConnection connection = context.getBean("testConnection", XMPPConnection.class);
|
||||
|
||||
Mockito.doAnswer(new Answer() {
|
||||
public Object answer(InvocationOnMock invocation) {
|
||||
Object[] args = invocation.getArguments();
|
||||
org.jivesoftware.smack.packet.Message xmppMessage = (org.jivesoftware.smack.packet.Message) args[0];
|
||||
assertEquals("oleg", xmppMessage.getTo());
|
||||
assertEquals("foobar", JivePropertiesManager.getProperty(xmppMessage, "foobar"));
|
||||
return null;
|
||||
}})
|
||||
.when(connection).sendPacket(Mockito.any(org.jivesoftware.smack.packet.Message.class));
|
||||
|
||||
public Object answer(InvocationOnMock invocation) {
|
||||
Object[] args = invocation.getArguments();
|
||||
org.jivesoftware.smack.packet.Message xmppMessage = (org.jivesoftware.smack.packet.Message) args[0];
|
||||
assertEquals("oleg", xmppMessage.getTo());
|
||||
assertEquals("foobar", JivePropertiesManager.getProperty(xmppMessage, "foobar"));
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.when(connection).sendStanza(Mockito.any(org.jivesoftware.smack.packet.Message.class));
|
||||
|
||||
channel.send(message);
|
||||
|
||||
verify(connection, times(1)).sendPacket(Mockito.any(org.jivesoftware.smack.packet.Message.class));
|
||||
verify(connection, times(1)).sendStanza(Mockito.any(org.jivesoftware.smack.packet.Message.class));
|
||||
Mockito.reset(connection);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Test //INT-2275
|
||||
public void testOutboundChannelAdapterInsideChain() throws Exception{
|
||||
public void testOutboundChannelAdapterInsideChain() throws Exception {
|
||||
MessageChannel channel = context.getBean("outboundChainChannel", MessageChannel.class);
|
||||
Message<?> message = MessageBuilder.withPayload("hello").setHeader(XmppHeaders.TO, "artem").build();
|
||||
XMPPConnection connection = context.getBean("testConnection", XMPPConnection.class);
|
||||
Mockito.doAnswer(new Answer() {
|
||||
|
||||
public Object answer(InvocationOnMock invocation) {
|
||||
Object[] args = invocation.getArguments();
|
||||
org.jivesoftware.smack.packet.Message xmppMessage = (org.jivesoftware.smack.packet.Message) args[0];
|
||||
assertEquals("artem", xmppMessage.getTo());
|
||||
assertEquals("hello", xmppMessage.getBody());
|
||||
return null;
|
||||
}})
|
||||
.when(connection).sendPacket(Mockito.any(org.jivesoftware.smack.packet.Message.class));
|
||||
}
|
||||
|
||||
}).when(connection).sendStanza(Mockito.any(org.jivesoftware.smack.packet.Message.class));
|
||||
|
||||
channel.send(message);
|
||||
|
||||
verify(connection, times(1)).sendPacket(Mockito.any(org.jivesoftware.smack.packet.Message.class));
|
||||
verify(connection, times(1)).sendStanza(Mockito.any(org.jivesoftware.smack.packet.Message.class));
|
||||
Mockito.reset(connection);
|
||||
}
|
||||
|
||||
@@ -166,4 +171,5 @@ public class ChatMessageOutboundChannelAdapterParserTests {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
http://www.springframework.org/schema/integration/xmpp http://www.springframework.org/schema/integration/xmpp/spring-integration-xmpp.xsd"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-xmpp="http://www.springframework.org/schema/integration/xmpp">
|
||||
|
||||
|
||||
<bean id="testConnection" class="org.mockito.Mockito" factory-method="mock">
|
||||
<constructor-arg value="org.jivesoftware.smack.XMPPConnection"/>
|
||||
</bean>
|
||||
|
||||
<int-xmpp:presence-inbound-channel-adapter channel="outChannel"
|
||||
|
||||
<int-xmpp:presence-inbound-channel-adapter channel="outChannel"
|
||||
xmpp-connection="testConnection" auto-startup="false"/>
|
||||
|
||||
|
||||
<int:channel id="outChannel"/>
|
||||
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,8 +28,8 @@ public class PresenceInboundChannelAdapterParserTests {
|
||||
|
||||
@Test
|
||||
public void testPresenceInboundChannelAdapterParser() {
|
||||
new ClassPathXmlApplicationContext("PresenceInboundChannelAdapterParserTests-context.xml", this.getClass());
|
||||
// no assertion needed. THe fact that no exception was thrown satisfies this test
|
||||
new ClassPathXmlApplicationContext("PresenceInboundChannelAdapterParserTests-context.xml", this.getClass()).close();
|
||||
// no assertion needed. The fact that no exception was thrown satisfies this test
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,43 +6,43 @@
|
||||
http://www.springframework.org/schema/integration/xmpp http://www.springframework.org/schema/integration/xmpp/spring-integration-xmpp.xsd"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-xmpp="http://www.springframework.org/schema/integration/xmpp">
|
||||
|
||||
|
||||
<bean id="testConnection" class="org.mockito.Mockito" factory-method="mock">
|
||||
<constructor-arg value="org.jivesoftware.smack.XMPPConnection"/>
|
||||
</bean>
|
||||
|
||||
|
||||
<int:channel id="pollingChannel">
|
||||
<int:queue/>
|
||||
</int:channel>
|
||||
|
||||
<int-xmpp:presence-outbound-channel-adapter id="pollingOutboundRosterAdapter"
|
||||
xmpp-connection="testConnection"
|
||||
|
||||
<int-xmpp:presence-outbound-channel-adapter id="pollingOutboundRosterAdapter"
|
||||
xmpp-connection="testConnection"
|
||||
channel="pollingChannel"
|
||||
order="23">
|
||||
<int:poller fixed-rate="1000" max-messages-per-poll="1"/>
|
||||
</int-xmpp:presence-outbound-channel-adapter>
|
||||
|
||||
|
||||
|
||||
|
||||
<int:channel id="eventChannel"/>
|
||||
|
||||
<int-xmpp:presence-outbound-channel-adapter id="eventOutboundRosterAdapter"
|
||||
xmpp-connection="testConnection"
|
||||
|
||||
<int-xmpp:presence-outbound-channel-adapter id="eventOutboundRosterAdapter"
|
||||
xmpp-connection="testConnection"
|
||||
channel="eventChannel"
|
||||
order="34"/>
|
||||
|
||||
<int-xmpp:presence-outbound-channel-adapter id="advised"
|
||||
xmpp-connection="testConnection"
|
||||
<int-xmpp:presence-outbound-channel-adapter id="advised"
|
||||
xmpp-connection="testConnection"
|
||||
channel="eventChannel"
|
||||
order="34">
|
||||
<int-xmpp:request-handler-advice-chain>
|
||||
<bean class="org.springframework.integration.xmpp.config.PresenceOutboundChannelAdapterParserTests$FooAdvice" />
|
||||
</int-xmpp:request-handler-advice-chain>
|
||||
</int-xmpp:presence-outbound-channel-adapter>
|
||||
|
||||
|
||||
<int-xmpp:presence-outbound-channel-adapter id="eventOutboundRosterChannel"
|
||||
|
||||
|
||||
<int-xmpp:presence-outbound-channel-adapter id="eventOutboundRosterChannel"
|
||||
xmpp-connection="testConnection"
|
||||
order="45"/>
|
||||
|
||||
|
||||
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -101,4 +101,5 @@ public class PresenceOutboundChannelAdapterParserTests {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,24 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/integration/xmpp http://www.springframework.org/schema/integration/xmpp/spring-integration-xmpp.xsd"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-xmpp="http://www.springframework.org/schema/integration/xmpp">
|
||||
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-xmpp="http://www.springframework.org/schema/integration/xmpp">
|
||||
|
||||
<bean id="xmppConnectionConfigurationBuilder" class="org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration"
|
||||
factory-method="builder">
|
||||
<property name="serviceName" value="myServiceName"/>
|
||||
</bean>
|
||||
|
||||
<bean id="xmppConnection" class="org.springframework.integration.xmpp.config.XmppConnectionFactoryBean">
|
||||
<constructor-arg>
|
||||
<bean class="org.jivesoftware.smack.ConnectionConfiguration">
|
||||
<constructor-arg value="myServiceName"/>
|
||||
</bean>
|
||||
<bean factory-bean="xmppConnectionConfigurationBuilder" factory-method="build"/>
|
||||
</constructor-arg>
|
||||
<property name="autoStartup" value="false"/>
|
||||
</bean>
|
||||
|
||||
|
||||
<int:channel id="outboundEventChannel"/>
|
||||
|
||||
<int-xmpp:outbound-channel-adapter id="outboundEventAdapter"
|
||||
channel="outboundEventChannel"
|
||||
xmpp-connection="xmppConnection"/>
|
||||
|
||||
<int-xmpp:outbound-channel-adapter id="outboundEventAdapter"
|
||||
channel="outboundEventChannel"
|
||||
xmpp-connection="xmppConnection"/>
|
||||
</beans>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,11 +19,11 @@ package org.springframework.integration.xmpp.config;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.jivesoftware.smack.ConnectionConfiguration;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.xmpp.config.XmppConnectionFactoryBean;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
@@ -33,14 +33,15 @@ public class XmppConnectionFactoryBeanTests {
|
||||
|
||||
@Test
|
||||
public void testXmppConnectionFactoryBean() throws Exception {
|
||||
XmppConnectionFactoryBean xmppConnectionFactoryBean = new XmppConnectionFactoryBean(mock(ConnectionConfiguration.class));
|
||||
XmppConnectionFactoryBean xmppConnectionFactoryBean =
|
||||
new XmppConnectionFactoryBean(mock(XMPPTCPConnectionConfiguration.class));
|
||||
XMPPConnection connection = xmppConnectionFactoryBean.createInstance();
|
||||
assertNotNull(connection);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXmppConnectionFactoryBeanViaConfig() throws Exception {
|
||||
new ClassPathXmlApplicationContext("XmppConnectionFactoryBeanTests-context.xml", this.getClass());
|
||||
new ClassPathXmlApplicationContext("XmppConnectionFactoryBeanTests-context.xml", this.getClass()).close();
|
||||
// the fact that no exception was thrown satisfies this test
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-xmpp="http://www.springframework.org/schema/integration/xmpp"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/integration/xmpp http://www.springframework.org/schema/integration/xmpp/spring-integration-xmpp.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
@@ -17,10 +15,10 @@
|
||||
<prop key="sub.mode">reject_all</prop>
|
||||
</util:properties>
|
||||
|
||||
<int-xmpp:xmpp-connection id="connection"
|
||||
user="happy.user"
|
||||
password="blah"
|
||||
host="localhost"
|
||||
<int-xmpp:xmpp-connection id="connection"
|
||||
user="happy.user"
|
||||
password="blah"
|
||||
host="localhost"
|
||||
auto-startup="false"
|
||||
resource="SpringSource"
|
||||
port="6222"
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/integration/xmpp http://www.springframework.org/schema/integration/xmpp/spring-integration-xmpp.xsd"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-xmpp="http://www.springframework.org/schema/integration/xmpp">
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:int-xmpp="http://www.springframework.org/schema/integration/xmpp"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration/xmpp http://www.springframework.org/schema/integration/xmpp/spring-integration-xmpp.xsd">
|
||||
|
||||
<int-xmpp:xmpp-connection id="connection"
|
||||
user="happy.user" password="blah" host="localhost" auto-startup="false"/>
|
||||
|
||||
|
||||
<int-xmpp:xmpp-connection user="happy.user" password="blah" host="localhost" auto-startup="false"/>
|
||||
<int-xmpp:xmpp-connection id="connection"
|
||||
user="happy.user@my.domain" password="blah" host="localhost" auto-startup="false"/>
|
||||
|
||||
<int-xmpp:xmpp-connection id="connectionWithResource" resource="Smack"
|
||||
user="happy.user" password="blah" host="localhost" auto-startup="false"/>
|
||||
|
||||
<int-xmpp:xmpp-connection user="happy.user@my.domain" password="blah" host="localhost" auto-startup="false"/>
|
||||
|
||||
<int-xmpp:xmpp-connection id="connectionWithResource" resource="Smack" service-name="my.domain"
|
||||
user="happy.user" password="blah" host="localhost" auto-startup="false"/>
|
||||
</beans>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,12 +18,13 @@ package org.springframework.integration.xmpp.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
|
||||
@@ -32,36 +33,39 @@ import org.springframework.integration.test.util.TestUtils;
|
||||
* @author Gary Russell
|
||||
* @author Gunnar Hillert
|
||||
* @author Florian Schmaus
|
||||
* @author Artem Bilan
|
||||
*/
|
||||
public class XmppConnectionParserTests {
|
||||
|
||||
@Test
|
||||
public void testSimpleConfiguration() {
|
||||
ApplicationContext ac =
|
||||
ConfigurableApplicationContext ac =
|
||||
new ClassPathXmlApplicationContext("XmppConnectionParserTests-simple.xml", this.getClass());
|
||||
XMPPConnection connection = ac.getBean("connection", XMPPConnection.class);
|
||||
assertEquals("localhost", connection.getServiceName());
|
||||
assertEquals("my.domain", connection.getServiceName());
|
||||
assertFalse(connection.isConnected());
|
||||
XmppConnectionFactoryBean xmppFb = ac.getBean("&connection", XmppConnectionFactoryBean.class);
|
||||
assertEquals("happy.user", TestUtils.getPropertyValue(xmppFb, "user"));
|
||||
assertEquals("happy.user@my.domain", TestUtils.getPropertyValue(xmppFb, "user"));
|
||||
assertEquals("blah", TestUtils.getPropertyValue(xmppFb, "password"));
|
||||
assertNull(TestUtils.getPropertyValue(xmppFb, "resource"));
|
||||
assertEquals("accept_all", TestUtils.getPropertyValue(xmppFb, "subscriptionMode"));
|
||||
assertEquals("accept_all", TestUtils.getPropertyValue(xmppFb, "subscriptionMode").toString());
|
||||
|
||||
xmppFb = ac.getBean("&connectionWithResource", XmppConnectionFactoryBean.class);
|
||||
assertEquals("Smack", TestUtils.getPropertyValue(xmppFb, "resource"));
|
||||
ac.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultConnectionName() {
|
||||
ApplicationContext ac =
|
||||
ConfigurableApplicationContext ac =
|
||||
new ClassPathXmlApplicationContext("XmppConnectionParserTests-simple.xml", this.getClass());
|
||||
assertTrue(ac.containsBean("xmppConnection"));
|
||||
ac.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompleteConfiguration() {
|
||||
ApplicationContext ac =
|
||||
ConfigurableApplicationContext ac =
|
||||
new ClassPathXmlApplicationContext("XmppConnectionParserTests-complete.xml", this.getClass());
|
||||
XMPPConnection connection = ac.getBean("connection", XMPPConnection.class);
|
||||
assertEquals("foogle.com", connection.getServiceName());
|
||||
@@ -70,7 +74,8 @@ public class XmppConnectionParserTests {
|
||||
assertEquals("happy.user", TestUtils.getPropertyValue(xmppFb, "user"));
|
||||
assertEquals("blah", TestUtils.getPropertyValue(xmppFb, "password"));
|
||||
assertEquals("SpringSource", TestUtils.getPropertyValue(xmppFb, "resource"));
|
||||
assertEquals("reject_all", TestUtils.getPropertyValue(xmppFb, "subscriptionMode"));
|
||||
assertEquals("reject_all", TestUtils.getPropertyValue(xmppFb, "subscriptionMode").toString());
|
||||
ac.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,23 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans
|
||||
xmlns="http://www.springframework.org/schema/integration"
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:xmpp="http://www.springframework.org/schema/integration/xmpp"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/integration/xmpp http://www.springframework.org/schema/integration/xmpp/spring-integration-xmpp.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/beans/spring-context.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd">
|
||||
|
||||
<channel id="input"/>
|
||||
<channel id="output"/>
|
||||
|
||||
|
||||
<xmpp:header-enricher input-channel="input" output-channel="output">
|
||||
<xmpp:chat-to value="test1@example.org"/>
|
||||
<xmpp:chat-to value="test1@example.org"/>
|
||||
</xmpp:header-enricher>
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -21,16 +21,14 @@
|
||||
<xmpp:xmpp-connection
|
||||
id="testConnection"
|
||||
user="${user.1.login}"
|
||||
password="${user.1.password}"
|
||||
host="${user.1.host}"
|
||||
service-name="${user.1.service}"/>
|
||||
password="${user.1.password}"/>
|
||||
|
||||
<console:stdout-channel-adapter id="stdout" append-newline="true"/>
|
||||
|
||||
|
||||
<console:stdin-channel-adapter id="stdin">
|
||||
<poller fixed-rate="1000"/>
|
||||
</console:stdin-channel-adapter>
|
||||
|
||||
|
||||
<xmpp:header-enricher input-channel="stdin" output-channel="messagesToSend">
|
||||
<xmpp:chat-to value="${user.2.login}"/>
|
||||
</xmpp:header-enricher>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,17 +19,24 @@ package org.springframework.integration.xmpp.ignore;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Artem Bilan
|
||||
* @since 2.0
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class ConsoleChatTests {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new ClassPathXmlApplicationContext("ConsoleChatTests-context.xml", ConsoleChatTests.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void run() throws Exception {
|
||||
|
||||
@@ -10,11 +10,11 @@
|
||||
xmlns:tool="http://www.springframework.org/schema/tool"
|
||||
xmlns:lang="http://www.springframework.org/schema/lang"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/integration/xmpp
|
||||
http://www.springframework.org/schema/integration/xmpp/spring-integration-xmpp.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration/xmpp/spring-integration-xmpp.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
|
||||
http://www.springframework.org/schema/tool http://www.springframework.org/schema/tool/spring-tool.xsd
|
||||
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd">
|
||||
|
||||
|
||||
@@ -26,14 +26,14 @@
|
||||
service-name="${user.1.service}"/>
|
||||
|
||||
<xmpp:presence-inbound-channel-adapter channel="inboundPresenceChannel" xmpp-connection="testConnection"/>
|
||||
|
||||
|
||||
<channel id="inboundPresenceChannel"/>
|
||||
|
||||
<service-activator input-channel="inboundPresenceChannel" output-channel="stdOutChannel"
|
||||
<service-activator input-channel="inboundPresenceChannel" output-channel="stdOutChannel"
|
||||
expression="'Presence event from: ' + payload.getFrom() + ' - ' + payload.getMode()"/>
|
||||
|
||||
|
||||
<channel id="stdOutChannel"/>
|
||||
|
||||
|
||||
<stream:stdout-channel-adapter channel="stdOutChannel" append-newline="true"/>
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
xmlns:util="http://www.springframework.org/schema/util" xmlns:xmpp="http://www.springframework.org/schema/integration/xmpp"
|
||||
xmlns:tool="http://www.springframework.org/schema/tool" xmlns:lang="http://www.springframework.org/schema/lang"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/integration/xmpp http://www.springframework.org/schema/integration/xmpp/spring-integration-xmpp.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
|
||||
http://www.springframework.org/schema/tool http://www.springframework.org/schema/tool/spring-tool.xsd
|
||||
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd">
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
password="${user.1.password}"
|
||||
host="${user.1.host}"
|
||||
service-name="${user.1.service}"/>
|
||||
|
||||
|
||||
<channel id="outboundPresenceChannel"/>
|
||||
|
||||
<xmpp:presence-outbound-channel-adapter xmpp-connection="testConnection" channel="outboundPresenceChannel"/>
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
password="${user.1.password}"
|
||||
host="${user.1.host}"
|
||||
service-name="${user.1.service}"/>
|
||||
|
||||
|
||||
<int:channel id="xmppInput"/>
|
||||
|
||||
|
||||
<int-xmpp:outbound-channel-adapter channel="xmppInput"/>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -35,14 +35,14 @@ public class SmackMessageSampleTests {
|
||||
public void validateSmackMessageSent(){
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("SmackMessageSampleTest-context.xml", this.getClass());
|
||||
MessageChannel xmppInput = ac.getBean("xmppInput", MessageChannel.class);
|
||||
|
||||
|
||||
|
||||
|
||||
org.jivesoftware.smack.packet.Message smackMessage = new org.jivesoftware.smack.packet.Message("springintegration@gmail.com");
|
||||
smackMessage.setBody("Message sent as Smack Message");
|
||||
|
||||
Message<org.jivesoftware.smack.packet.Message> message =
|
||||
|
||||
Message<org.jivesoftware.smack.packet.Message> message =
|
||||
new GenericMessage<org.jivesoftware.smack.packet.Message>(smackMessage);
|
||||
|
||||
|
||||
xmppInput.send(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,13 +24,12 @@ import static org.mockito.Mockito.mock;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jivesoftware.smack.PacketListener;
|
||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||
import org.jivesoftware.smack.StanzaListener;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.filter.PacketFilter;
|
||||
import org.jivesoftware.smack.filter.StanzaFilter;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
@@ -50,35 +49,39 @@ import org.springframework.messaging.support.ErrorMessage;
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Gunnar Hillert
|
||||
* @author Florian Schmaus
|
||||
*
|
||||
* @author Artem Bilan
|
||||
*/
|
||||
public class ChatMessageListeningEndpointTests {
|
||||
|
||||
|
||||
@Test
|
||||
/**
|
||||
* Should add/remove PacketListener when endpoint started/stopped
|
||||
* Should add/remove StanzaListener when endpoint started/stopped
|
||||
*/
|
||||
public void testLifecycle(){
|
||||
final Set<PacketListener> packetListSet = new HashSet<PacketListener>();
|
||||
public void testLifecycle() {
|
||||
final Set<StanzaListener> packetListSet = new HashSet<StanzaListener>();
|
||||
XMPPConnection connection = mock(XMPPConnection.class);
|
||||
ChatMessageListeningEndpoint endpoint = new ChatMessageListeningEndpoint(connection);
|
||||
|
||||
doAnswer(new Answer<Object>() {
|
||||
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
packetListSet.add((PacketListener) invocation.getArguments()[0]);
|
||||
packetListSet.add((StanzaListener) invocation.getArguments()[0]);
|
||||
return null;
|
||||
}
|
||||
}).when(connection).addPacketListener(Mockito.any(PacketListener.class), (PacketFilter) Mockito.any());
|
||||
|
||||
}).when(connection).addAsyncStanzaListener(Mockito.any(StanzaListener.class), Mockito.any(StanzaFilter.class));
|
||||
|
||||
doAnswer(new Answer<Object>() {
|
||||
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
packetListSet.remove(invocation.getArguments()[0]);
|
||||
packetListSet.remove((StanzaListener) invocation.getArguments()[0]);
|
||||
return null;
|
||||
}
|
||||
}).when(connection).removePacketListener(Mockito.any(PacketListener.class));
|
||||
|
||||
}).when(connection).removeAsyncStanzaListener(Mockito.any(StanzaListener.class));
|
||||
|
||||
assertEquals(0, packetListSet.size());
|
||||
endpoint.setOutputChannel(new QueueChannel());
|
||||
@@ -90,32 +93,32 @@ public class ChatMessageListeningEndpointTests {
|
||||
assertEquals(0, packetListSet.size());
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testNonInitializationFailure(){
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testNonInitializationFailure() {
|
||||
ChatMessageListeningEndpoint endpoint = new ChatMessageListeningEndpoint(mock(XMPPConnection.class));
|
||||
endpoint.start();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithImplicitXmppConnection(){
|
||||
public void testWithImplicitXmppConnection() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.registerSingleton(XmppContextUtils.XMPP_CONNECTION_BEAN_NAME, mock(XMPPConnection.class));
|
||||
ChatMessageListeningEndpoint endpoint = new ChatMessageListeningEndpoint();
|
||||
endpoint.setBeanFactory(bf);
|
||||
endpoint.setOutputChannel(new QueueChannel());
|
||||
endpoint.afterPropertiesSet();
|
||||
assertNotNull(TestUtils.getPropertyValue(endpoint,"xmppConnection"));
|
||||
assertNotNull(TestUtils.getPropertyValue(endpoint, "xmppConnection"));
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testNoXmppConnection(){
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testNoXmppConnection() {
|
||||
ChatMessageListeningEndpoint endpoint = new ChatMessageListeningEndpoint();
|
||||
endpoint.setBeanFactory(mock(BeanFactory.class));
|
||||
endpoint.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithErrorChannel() throws NotConnectedException{
|
||||
public void testWithErrorChannel() throws NotConnectedException {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
XMPPConnection connection = mock(XMPPConnection.class);
|
||||
bf.registerSingleton(XmppContextUtils.XMPP_CONNECTION_BEAN_NAME, connection);
|
||||
@@ -124,25 +127,28 @@ public class ChatMessageListeningEndpointTests {
|
||||
|
||||
DirectChannel outChannel = new DirectChannel();
|
||||
outChannel.subscribe(new MessageHandler() {
|
||||
|
||||
@Override
|
||||
public void handleMessage(org.springframework.messaging.Message<?> message)
|
||||
throws MessagingException {
|
||||
throw new RuntimeException("ooops");
|
||||
}
|
||||
|
||||
});
|
||||
PollableChannel errorChannel = new QueueChannel();
|
||||
endpoint.setBeanFactory(bf);
|
||||
endpoint.setOutputChannel(outChannel);
|
||||
endpoint.setErrorChannel(errorChannel);
|
||||
endpoint.afterPropertiesSet();
|
||||
PacketListener listener = (PacketListener) TestUtils.getPropertyValue(endpoint, "packetListener");
|
||||
StanzaListener listener = (StanzaListener) TestUtils.getPropertyValue(endpoint, "stanzaListener");
|
||||
Message smackMessage = new Message("kermit@frog.com");
|
||||
smackMessage.setBody("hello");
|
||||
smackMessage.setThread("1234");
|
||||
listener.processPacket(smackMessage);
|
||||
|
||||
ErrorMessage msg =
|
||||
(ErrorMessage) errorChannel.receive();
|
||||
assertEquals("hello", ((MessagingException)msg.getPayload()).getFailedMessage().getPayload());
|
||||
(ErrorMessage) errorChannel.receive();
|
||||
assertEquals("hello", ((MessagingException) msg.getPayload()).getFailedMessage().getPayload());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,19 +18,20 @@ package org.springframework.integration.xmpp.inbound;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jivesoftware.smack.Roster;
|
||||
import org.jivesoftware.smack.RosterListener;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.packet.Presence;
|
||||
import org.jivesoftware.smack.packet.Presence.Mode;
|
||||
import org.jivesoftware.smack.packet.Presence.Type;
|
||||
import org.jivesoftware.smack.roster.Roster;
|
||||
import org.jivesoftware.smack.roster.RosterListener;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
@@ -52,30 +53,37 @@ import org.springframework.messaging.support.ErrorMessage;
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Gunnar Hillert
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
*/
|
||||
public class PresenceListeningEndpointTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testEndpointLifecycle() {
|
||||
final Set<RosterListener> rosterSet = new HashSet<RosterListener>();
|
||||
XMPPConnection connection = mock(XMPPConnection.class);
|
||||
Roster roster = mock(Roster.class);
|
||||
when(connection.getRoster()).thenReturn(roster);
|
||||
Map<XMPPConnection, Roster> instances = TestUtils.getPropertyValue(roster, "INSTANCES", Map.class);
|
||||
instances.put(connection, roster);
|
||||
|
||||
doAnswer(new Answer<Object>() {
|
||||
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
rosterSet.add((RosterListener) invocation.getArguments()[0]);
|
||||
return null;
|
||||
}
|
||||
|
||||
}).when(roster).addRosterListener(Mockito.any(RosterListener.class));
|
||||
|
||||
doAnswer(new Answer<Object>() {
|
||||
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
rosterSet.remove(invocation.getArguments()[0]);
|
||||
rosterSet.remove((RosterListener) invocation.getArguments()[0]);
|
||||
return null;
|
||||
}
|
||||
|
||||
}).when(roster).removeRosterListener(Mockito.any(RosterListener.class));
|
||||
PresenceListeningEndpoint rosterEndpoint = new PresenceListeningEndpoint(connection);
|
||||
rosterEndpoint.setOutputChannel(new QueueChannel());
|
||||
@@ -88,17 +96,19 @@ public class PresenceListeningEndpointTests {
|
||||
assertEquals(0, rosterSet.size());
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testNonInitializedFailure() {
|
||||
PresenceListeningEndpoint rosterEndpoint = new PresenceListeningEndpoint(mock(XMPPConnection.class));
|
||||
rosterEndpoint.start();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testRosterPresenceChangeEvent() {
|
||||
XMPPConnection connection = mock(XMPPConnection.class);
|
||||
Roster roster = mock(Roster.class);
|
||||
when(connection.getRoster()).thenReturn(roster);
|
||||
Map<XMPPConnection, Roster> instances = TestUtils.getPropertyValue(roster, "INSTANCES", Map.class);
|
||||
instances.put(connection, roster);
|
||||
PresenceListeningEndpoint rosterEndpoint = new PresenceListeningEndpoint(connection);
|
||||
QueueChannel channel = new QueueChannel();
|
||||
rosterEndpoint.setOutputChannel(channel);
|
||||
@@ -120,10 +130,10 @@ public class PresenceListeningEndpointTests {
|
||||
endpoint.setBeanFactory(bf);
|
||||
endpoint.setOutputChannel(new QueueChannel());
|
||||
endpoint.afterPropertiesSet();
|
||||
assertNotNull(TestUtils.getPropertyValue(endpoint,"xmppConnection"));
|
||||
assertNotNull(TestUtils.getPropertyValue(endpoint, "xmppConnection"));
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testNoXmppConnection() {
|
||||
PresenceListeningEndpoint handler = new PresenceListeningEndpoint();
|
||||
handler.setBeanFactory(mock(BeanFactory.class));
|
||||
@@ -131,7 +141,7 @@ public class PresenceListeningEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithErrorChannel(){
|
||||
public void testWithErrorChannel() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
XMPPConnection connection = mock(XMPPConnection.class);
|
||||
bf.registerSingleton(XmppContextUtils.XMPP_CONNECTION_BEAN_NAME, connection);
|
||||
@@ -140,11 +150,13 @@ public class PresenceListeningEndpointTests {
|
||||
|
||||
DirectChannel outChannel = new DirectChannel();
|
||||
outChannel.subscribe(new MessageHandler() {
|
||||
|
||||
@Override
|
||||
public void handleMessage(org.springframework.messaging.Message<?> message)
|
||||
throws MessagingException {
|
||||
throw new RuntimeException("ooops");
|
||||
}
|
||||
|
||||
});
|
||||
PollableChannel errorChannel = new QueueChannel();
|
||||
endpoint.setBeanFactory(bf);
|
||||
@@ -157,7 +169,10 @@ public class PresenceListeningEndpointTests {
|
||||
listener.presenceChanged(presence);
|
||||
|
||||
ErrorMessage msg =
|
||||
(ErrorMessage) errorChannel.receive();
|
||||
assertEquals(Type.available.toString(), ((MessagingException)msg.getPayload()).getFailedMessage().getPayload().toString());
|
||||
(ErrorMessage) errorChannel.receive();
|
||||
assertSame(presence, ((MessagingException) msg.getPayload())
|
||||
.getFailedMessage()
|
||||
.getPayload());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,60 +40,62 @@ import org.springframework.messaging.support.GenericMessage;
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Gunnar Hillert
|
||||
*
|
||||
* @author Artem Bilan
|
||||
*/
|
||||
public class ChatMessageSendingMessageHandlerTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void validateMessagePostAsString() throws Exception{
|
||||
public void validateMessagePostAsString() throws Exception {
|
||||
XMPPConnection connection = mock(XMPPConnection.class);
|
||||
ChatMessageSendingMessageHandler handler = new ChatMessageSendingMessageHandler(connection);
|
||||
handler.setBeanFactory(mock(BeanFactory.class));
|
||||
handler.afterPropertiesSet();
|
||||
Message<?> message = MessageBuilder.withPayload("Test Message").
|
||||
setHeader(XmppHeaders.TO, "kermit@frog.com").
|
||||
build();
|
||||
setHeader(XmppHeaders.TO, "kermit@frog.com").
|
||||
build();
|
||||
// first Message new
|
||||
handler.handleMessage(message);
|
||||
|
||||
class EqualSmackMessage extends ArgumentMatcher<org.jivesoftware.smack.packet.Message> {
|
||||
@Override
|
||||
|
||||
@Override
|
||||
public boolean matches(Object msg) {
|
||||
org.jivesoftware.smack.packet.Message smackMessage = (org.jivesoftware.smack.packet.Message) msg;
|
||||
boolean bodyMatches = smackMessage.getBody().equals("Test Message");
|
||||
boolean toMatches = smackMessage.getTo().equals("kermit@frog.com");
|
||||
return bodyMatches & toMatches;
|
||||
}
|
||||
org.jivesoftware.smack.packet.Message smackMessage = (org.jivesoftware.smack.packet.Message) msg;
|
||||
boolean bodyMatches = smackMessage.getBody().equals("Test Message");
|
||||
boolean toMatches = smackMessage.getTo().equals("kermit@frog.com");
|
||||
return bodyMatches & toMatches;
|
||||
}
|
||||
}
|
||||
|
||||
verify(connection, times(1)).sendPacket(Mockito.argThat(new EqualSmackMessage()));
|
||||
verify(connection, times(1)).sendStanza(Mockito.argThat(new EqualSmackMessage()));
|
||||
|
||||
// assuming we know thread ID although currently we do not provide this capability
|
||||
message = MessageBuilder.withPayload("Hello Kitty").
|
||||
setHeader(XmppHeaders.TO, "kermit@frog.com").
|
||||
setHeader(XmppHeaders.THREAD, "123").
|
||||
build();
|
||||
setHeader(XmppHeaders.TO, "kermit@frog.com").
|
||||
setHeader(XmppHeaders.THREAD, "123").
|
||||
build();
|
||||
|
||||
class EqualSmackMessageWithThreadId extends ArgumentMatcher<org.jivesoftware.smack.packet.Message> {
|
||||
@Override
|
||||
|
||||
@Override
|
||||
public boolean matches(Object msg) {
|
||||
org.jivesoftware.smack.packet.Message smackMessage = (org.jivesoftware.smack.packet.Message) msg;
|
||||
boolean bodyMatches = smackMessage.getBody().equals("Hello Kitty");
|
||||
boolean toMatches = smackMessage.getTo().equals("kermit@frog.com");
|
||||
boolean threadIdMatches = smackMessage.getThread().equals("123");
|
||||
return bodyMatches & toMatches & threadIdMatches;
|
||||
}
|
||||
org.jivesoftware.smack.packet.Message smackMessage = (org.jivesoftware.smack.packet.Message) msg;
|
||||
boolean bodyMatches = smackMessage.getBody().equals("Hello Kitty");
|
||||
boolean toMatches = smackMessage.getTo().equals("kermit@frog.com");
|
||||
boolean threadIdMatches = smackMessage.getThread().equals("123");
|
||||
return bodyMatches & toMatches & threadIdMatches;
|
||||
}
|
||||
}
|
||||
reset(connection);
|
||||
handler.handleMessage(message);
|
||||
|
||||
// in threaded conversation we need to look for existing chat
|
||||
verify(connection, times(1)).sendPacket(Mockito.argThat(new EqualSmackMessageWithThreadId()));
|
||||
verify(connection, times(1)).sendStanza(Mockito.argThat(new EqualSmackMessageWithThreadId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateMessagePostAsSmackMessage() throws Exception{
|
||||
public void validateMessagePostAsSmackMessage() throws Exception {
|
||||
XMPPConnection connection = mock(XMPPConnection.class);
|
||||
ChatMessageSendingMessageHandler handler = new ChatMessageSendingMessageHandler(connection);
|
||||
handler.setBeanFactory(mock(BeanFactory.class));
|
||||
@@ -107,7 +109,7 @@ public class ChatMessageSendingMessageHandlerTests {
|
||||
// first Message new
|
||||
handler.handleMessage(message);
|
||||
|
||||
verify(connection, times(1)).sendPacket(smackMessage);
|
||||
verify(connection, times(1)).sendStanza(smackMessage);
|
||||
|
||||
// assuming we know thread ID although currently we do not provide this capability
|
||||
smackMessage = new org.jivesoftware.smack.packet.Message("kermit@frog.com");
|
||||
@@ -119,34 +121,36 @@ public class ChatMessageSendingMessageHandlerTests {
|
||||
handler.handleMessage(message);
|
||||
|
||||
// in threaded conversation we need to look for existing chat
|
||||
verify(connection, times(1)).sendPacket(smackMessage);
|
||||
verify(connection, times(1)).sendStanza(smackMessage);
|
||||
}
|
||||
|
||||
@Test(expected=MessageHandlingException.class)
|
||||
public void validateFailureNoChatToUser() throws Exception{
|
||||
@Test(expected = MessageHandlingException.class)
|
||||
public void validateFailureNoChatToUser() throws Exception {
|
||||
ChatMessageSendingMessageHandler handler = new ChatMessageSendingMessageHandler(mock(XMPPConnection.class));
|
||||
handler.handleMessage(new GenericMessage<String>("hello"));
|
||||
}
|
||||
|
||||
@Test(expected=MessageHandlingException.class)
|
||||
public void validateMessageWithUnsupportedPayload() throws Exception{
|
||||
@Test(expected = MessageHandlingException.class)
|
||||
public void validateMessageWithUnsupportedPayload() throws Exception {
|
||||
ChatMessageSendingMessageHandler handler = new ChatMessageSendingMessageHandler(mock(XMPPConnection.class));
|
||||
handler.handleMessage(new GenericMessage<Integer>(123));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithImplicitXmppConnection(){
|
||||
public void testWithImplicitXmppConnection() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.registerSingleton(XmppContextUtils.XMPP_CONNECTION_BEAN_NAME, mock(XMPPConnection.class));
|
||||
ChatMessageSendingMessageHandler handler = new ChatMessageSendingMessageHandler();
|
||||
handler.setBeanFactory(bf);
|
||||
handler.afterPropertiesSet();
|
||||
assertNotNull(TestUtils.getPropertyValue(handler,"xmppConnection"));
|
||||
assertNotNull(TestUtils.getPropertyValue(handler, "xmppConnection"));
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testNoXmppConnection(){
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testNoXmppConnection() {
|
||||
ChatMessageSendingMessageHandler handler = new ChatMessageSendingMessageHandler();
|
||||
handler.setBeanFactory(mock(BeanFactory.class));
|
||||
handler.afterPropertiesSet();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -33,22 +33,22 @@ import org.springframework.messaging.support.GenericMessage;
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Gunnar Hillert
|
||||
*
|
||||
* @author Artem Bilan
|
||||
*/
|
||||
public class PresenceSendingMessageHandlerTests {
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@Test
|
||||
public void testPresencePayload(){
|
||||
public void testPresencePayload() {
|
||||
PresenceSendingMessageHandler handler = new PresenceSendingMessageHandler(mock(XMPPConnection.class));
|
||||
handler.setBeanFactory(mock(BeanFactory.class));
|
||||
handler.afterPropertiesSet();
|
||||
handler.handleMessage(new GenericMessage(mock(Presence.class)));
|
||||
handler.handleMessage(new GenericMessage<Presence>(new Presence(Presence.Type.subscribe)));
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Test(expected=MessageHandlingException.class)
|
||||
public void testWrongPayload(){
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@Test(expected = MessageHandlingException.class)
|
||||
public void testWrongPayload() {
|
||||
PresenceSendingMessageHandler handler = new PresenceSendingMessageHandler(mock(XMPPConnection.class));
|
||||
handler.setBeanFactory(mock(BeanFactory.class));
|
||||
handler.afterPropertiesSet();
|
||||
@@ -56,19 +56,20 @@ public class PresenceSendingMessageHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithImplicitXmppConnection(){
|
||||
public void testWithImplicitXmppConnection() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.registerSingleton(XmppContextUtils.XMPP_CONNECTION_BEAN_NAME, mock(XMPPConnection.class));
|
||||
PresenceSendingMessageHandler handler = new PresenceSendingMessageHandler();
|
||||
handler.setBeanFactory(bf);
|
||||
handler.afterPropertiesSet();
|
||||
assertNotNull(TestUtils.getPropertyValue(handler,"xmppConnection"));
|
||||
assertNotNull(TestUtils.getPropertyValue(handler, "xmppConnection"));
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testNoXmppConnection(){
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testNoXmppConnection() {
|
||||
PresenceSendingMessageHandler handler = new PresenceSendingMessageHandler();
|
||||
handler.setBeanFactory(mock(BeanFactory.class));
|
||||
handler.afterPropertiesSet();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user