INT-1592 added support for auto-discovery of XmppConnection based on the bean name - 'xmppConnection', added tests
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
package org.springframework.integration.xmpp.messages;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@@ -29,6 +30,9 @@ import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.integration.xmpp.XmppContextUtils;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
@@ -76,4 +80,20 @@ public class XmppMessageDrivenEndpointTests {
|
||||
XmppMessageDrivenEndpoint endpoint = new XmppMessageDrivenEndpoint(mock(XMPPConnection.class));
|
||||
endpoint.start();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithImplicitXmppConnection(){
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.registerSingleton(XmppContextUtils.XMPP_CONNECTION_BEAN_NAME, mock(XMPPConnection.class));
|
||||
XmppMessageDrivenEndpoint endpoint = new XmppMessageDrivenEndpoint();
|
||||
endpoint.setBeanFactory(bf);
|
||||
endpoint.afterPropertiesSet();
|
||||
assertNotNull(TestUtils.getPropertyValue(endpoint,"xmppConnection"));
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testNoXmppConnection(){
|
||||
XmppMessageDrivenEndpoint endpoint = new XmppMessageDrivenEndpoint();
|
||||
endpoint.afterPropertiesSet();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
*/
|
||||
package org.springframework.integration.xmpp.messages;
|
||||
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.times;
|
||||
@@ -15,10 +16,13 @@ import org.jivesoftware.smack.MessageListener;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageHandlingException;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.integration.xmpp.XmppContextUtils;
|
||||
import org.springframework.integration.xmpp.XmppHeaders;
|
||||
|
||||
/**
|
||||
@@ -37,7 +41,7 @@ public class XmppMessageSendingMessageHandlerTests {
|
||||
when(chantManager.createChat(Mockito.any(String.class), Mockito.any(MessageListener.class))).thenReturn(chat);
|
||||
|
||||
XmppMessageSendingMessageHandler handler = new XmppMessageSendingMessageHandler(connection);
|
||||
|
||||
handler.afterPropertiesSet();
|
||||
Message<?> message = MessageBuilder.withPayload("Test Message").
|
||||
setHeader(XmppHeaders.CHAT_TO_USER, "kermit@frog.com").
|
||||
build();
|
||||
@@ -73,4 +77,19 @@ public class XmppMessageSendingMessageHandlerTests {
|
||||
XmppMessageSendingMessageHandler handler = new XmppMessageSendingMessageHandler(mock(XMPPConnection.class));
|
||||
handler.handleMessage(new GenericMessage<Integer>(123));
|
||||
}
|
||||
@Test
|
||||
public void testWithImplicitXmppConnection(){
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.registerSingleton(XmppContextUtils.XMPP_CONNECTION_BEAN_NAME, mock(XMPPConnection.class));
|
||||
XmppMessageSendingMessageHandler handler = new XmppMessageSendingMessageHandler();
|
||||
handler.setBeanFactory(bf);
|
||||
handler.afterPropertiesSet();
|
||||
assertNotNull(TestUtils.getPropertyValue(handler,"xmppConnection"));
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testNoXmppConnection(){
|
||||
XmppMessageSendingMessageHandler handler = new XmppMessageSendingMessageHandler();
|
||||
handler.afterPropertiesSet();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,10 +15,52 @@
|
||||
*/
|
||||
package org.springframework.integration.xmpp.messages;
|
||||
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.packet.Presence;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.integration.MessageHandlingException;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.integration.xmpp.XmppContextUtils;
|
||||
import org.springframework.integration.xmpp.presence.XmppRosterEventMessageSendingHandler;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
*/
|
||||
public class XmppRosterEventMessageSendingHandlerTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void testPresencePayload(){
|
||||
XmppRosterEventMessageSendingHandler handler = new XmppRosterEventMessageSendingHandler(mock(XMPPConnection.class));
|
||||
handler.afterPropertiesSet();
|
||||
handler.handleMessage(new GenericMessage(mock(Presence.class)));
|
||||
}
|
||||
|
||||
@Test(expected=MessageHandlingException.class)
|
||||
public void testWrongPayload(){
|
||||
XmppRosterEventMessageSendingHandler handler = new XmppRosterEventMessageSendingHandler(mock(XMPPConnection.class));
|
||||
handler.afterPropertiesSet();
|
||||
handler.handleMessage(new GenericMessage(new Object()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithImplicitXmppConnection(){
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.registerSingleton(XmppContextUtils.XMPP_CONNECTION_BEAN_NAME, mock(XMPPConnection.class));
|
||||
XmppRosterEventMessageSendingHandler handler = new XmppRosterEventMessageSendingHandler();
|
||||
handler.setBeanFactory(bf);
|
||||
handler.afterPropertiesSet();
|
||||
assertNotNull(TestUtils.getPropertyValue(handler,"xmppConnection"));
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testNoXmppConnection(){
|
||||
XmppRosterEventMessageSendingHandler handler = new XmppRosterEventMessageSendingHandler();
|
||||
handler.afterPropertiesSet();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.integration.xmpp.presence;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -35,9 +36,11 @@ import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.integration.xmpp.XmppContextUtils;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
@@ -115,4 +118,20 @@ public class XmppRosterEventMessageDrivenEndpointTests {
|
||||
Message<?> message = channel.receive(10);
|
||||
assertEquals(entries, message.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithImplicitXmppConnection(){
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.registerSingleton(XmppContextUtils.XMPP_CONNECTION_BEAN_NAME, mock(XMPPConnection.class));
|
||||
XmppRosterEventMessageDrivenEndpoint endpoint = new XmppRosterEventMessageDrivenEndpoint();
|
||||
endpoint.setBeanFactory(bf);
|
||||
endpoint.afterPropertiesSet();
|
||||
assertNotNull(TestUtils.getPropertyValue(endpoint,"xmppConnection"));
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testNoXmppConnection(){
|
||||
XmppRosterEventMessageDrivenEndpoint handler = new XmppRosterEventMessageDrivenEndpoint();
|
||||
handler.afterPropertiesSet();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user