INT-3383: Update to Smack 4.0.0
JIRA: https://jira.spring.io/browse/INT-3383 The family of Message.(set|get)Properties methods has been factored out of Smack as an extra extension. Use JivePropertiesManager as replacement. It is no longer necessary to supress Smack path warnings. Delete custom smack-config.xml, as all it did was disabling certain (important) SASL mechanisms. Also remove the unit test that verified this. Some unit tests mock ChatManager and Chat for no reason, delete those lines. XMPPConnection.getHost() and .getPort() are only valid after the connection got established, due the fact that those information is often only available after a DNS SRV lookup was performed. Remove the lines in unit tests that verified their value. Remove the truststorePath example in documentation, since Smack 4.0 no longer provides support for providing a custom truststore. Instead ConnectionConfiguration in Smack 4.0 allows to set a custom SSLContext (which then again can provide a TrustManager that uses a custom truststore).
This commit is contained in:
committed by
Artem Bilan
parent
ca2ce6adac
commit
714db85681
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 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,11 +22,11 @@ import static org.junit.Assert.assertSame;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.jivesoftware.smack.Chat;
|
||||
import org.jivesoftware.smack.ChatManager;
|
||||
import org.jivesoftware.smack.PacketListener;
|
||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||
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;
|
||||
@@ -47,6 +47,7 @@ import org.springframework.util.ReflectionUtils;
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Mark Fisher
|
||||
* @author Gunnar Hillert
|
||||
* @author Florian Schmaus
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@@ -78,12 +79,8 @@ public class ChatMessageInboundChannelAdapterParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInboundAdapterUsageWithHeaderMapper() {
|
||||
public void testInboundAdapterUsageWithHeaderMapper() throws NotConnectedException {
|
||||
XMPPConnection xmppConnection = Mockito.mock(XMPPConnection.class);
|
||||
ChatManager chatManager = Mockito.mock(ChatManager.class);
|
||||
Mockito.when(xmppConnection.getChatManager()).thenReturn(chatManager);
|
||||
Chat chat = Mockito.mock(Chat.class);
|
||||
Mockito.when(chatManager.getThreadChat(Mockito.any(String.class))).thenReturn(chat);
|
||||
|
||||
ChatMessageListeningEndpoint adapter = context.getBean("xmppInboundAdapter", ChatMessageListeningEndpoint.class);
|
||||
|
||||
@@ -96,8 +93,8 @@ public class ChatMessageInboundChannelAdapterParserTests {
|
||||
Message message = new Message();
|
||||
message.setBody("hello");
|
||||
message.setTo("oleg");
|
||||
message.setProperty("foo", "foo");
|
||||
message.setProperty("bar", "bar");
|
||||
JivePropertiesManager.addProperty(message, "foo", "foo");
|
||||
JivePropertiesManager.addProperty(message, "bar", "bar");
|
||||
packetListener.processPacket(message);
|
||||
org.springframework.messaging.Message<?> siMessage = xmppInbound.receive(0);
|
||||
assertEquals("foo", siMessage.getHeaders().get("foo"));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 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,6 +24,7 @@ import static org.mockito.Mockito.verify;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smackx.jiveproperties.JivePropertiesManager;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
@@ -53,6 +54,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
* @author Mark Fisher
|
||||
* @author Artem Bilan
|
||||
* @author Gunnar Hillert
|
||||
* @author Florian Schmaus
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@@ -117,7 +119,7 @@ public class ChatMessageOutboundChannelAdapterParserTests {
|
||||
Object[] args = invocation.getArguments();
|
||||
org.jivesoftware.smack.packet.Message xmppMessage = (org.jivesoftware.smack.packet.Message) args[0];
|
||||
assertEquals("oleg", xmppMessage.getTo());
|
||||
assertEquals("foobar", xmppMessage.getProperty("foobar"));
|
||||
assertEquals("foobar", JivePropertiesManager.getProperty(xmppMessage, "foobar"));
|
||||
return null;
|
||||
}})
|
||||
.when(connection).sendPacket(Mockito.any(org.jivesoftware.smack.packet.Message.class));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -21,9 +21,6 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.SmackConfiguration;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -34,28 +31,16 @@ import org.springframework.integration.test.util.TestUtils;
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Gary Russell
|
||||
* @author Gunnar Hillert
|
||||
* @author Florian Schmaus
|
||||
*/
|
||||
public class XmppConnectionParserTests {
|
||||
|
||||
@Test
|
||||
public void testSmackSasl() {
|
||||
/*
|
||||
* Possible SASL mechanisms
|
||||
* EXTERNAL, GSSAPI, DIGEST-MD5, CRAM-MD5, PLAIN, ANONYMOUS
|
||||
*/
|
||||
// values are set in META-INF/smack-config.xml
|
||||
List<String> saslMechNames = SmackConfiguration.getSaslMechs();
|
||||
assertEquals(2, saslMechNames.size());
|
||||
assertEquals("PLAIN", saslMechNames.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleConfiguration() {
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("XmppConnectionParserTests-simple.xml", this.getClass());
|
||||
ApplicationContext ac =
|
||||
new ClassPathXmlApplicationContext("XmppConnectionParserTests-simple.xml", this.getClass());
|
||||
XMPPConnection connection = ac.getBean("connection", XMPPConnection.class);
|
||||
assertEquals("localhost", connection.getServiceName());
|
||||
assertEquals("localhost", connection.getHost());
|
||||
assertEquals(5222, connection.getPort());
|
||||
assertFalse(connection.isConnected());
|
||||
XmppConnectionFactoryBean xmppFb = ac.getBean("&connection", XmppConnectionFactoryBean.class);
|
||||
assertEquals("happy.user", TestUtils.getPropertyValue(xmppFb, "user"));
|
||||
@@ -69,17 +54,17 @@ public class XmppConnectionParserTests {
|
||||
|
||||
@Test
|
||||
public void testDefaultConnectionName() {
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("XmppConnectionParserTests-simple.xml", this.getClass());
|
||||
ApplicationContext ac =
|
||||
new ClassPathXmlApplicationContext("XmppConnectionParserTests-simple.xml", this.getClass());
|
||||
assertTrue(ac.containsBean("xmppConnection"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompleteConfiguration() {
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("XmppConnectionParserTests-complete.xml", this.getClass());
|
||||
ApplicationContext ac =
|
||||
new ClassPathXmlApplicationContext("XmppConnectionParserTests-complete.xml", this.getClass());
|
||||
XMPPConnection connection = ac.getBean("connection", XMPPConnection.class);
|
||||
assertEquals("foogle.com", connection.getServiceName());
|
||||
assertEquals("localhost", connection.getHost());
|
||||
assertEquals(6222, connection.getPort());
|
||||
assertFalse(connection.isConnected());
|
||||
XmppConnectionFactoryBean xmppFb = ac.getBean("&connection", XmppConnectionFactoryBean.class);
|
||||
assertEquals("happy.user", TestUtils.getPropertyValue(xmppFb, "user"));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -13,24 +13,24 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.xmpp.inbound;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
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.Set;
|
||||
|
||||
import org.jivesoftware.smack.Chat;
|
||||
import org.jivesoftware.smack.ChatManager;
|
||||
import org.jivesoftware.smack.PacketListener;
|
||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.filter.PacketFilter;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
@@ -49,6 +49,7 @@ import org.springframework.messaging.support.ErrorMessage;
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Gunnar Hillert
|
||||
* @author Florian Schmaus
|
||||
*
|
||||
*/
|
||||
public class ChatMessageListeningEndpointTests {
|
||||
@@ -114,16 +115,11 @@ public class ChatMessageListeningEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithErrorChannel(){
|
||||
public void testWithErrorChannel() throws NotConnectedException{
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
XMPPConnection connection = mock(XMPPConnection.class);
|
||||
bf.registerSingleton(XmppContextUtils.XMPP_CONNECTION_BEAN_NAME, connection);
|
||||
|
||||
ChatManager cm = mock(ChatManager.class);
|
||||
when(connection.getChatManager()).thenReturn(cm);
|
||||
Chat chat = mock(Chat.class);
|
||||
when(cm.getThreadChat(Mockito.anyString())).thenReturn(chat);
|
||||
|
||||
ChatMessageListeningEndpoint endpoint = new ChatMessageListeningEndpoint();
|
||||
|
||||
DirectChannel outChannel = new DirectChannel();
|
||||
|
||||
@@ -25,8 +25,6 @@ import static org.mockito.Mockito.when;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jivesoftware.smack.Chat;
|
||||
import org.jivesoftware.smack.ChatManager;
|
||||
import org.jivesoftware.smack.Roster;
|
||||
import org.jivesoftware.smack.RosterListener;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
@@ -138,11 +136,6 @@ public class PresenceListeningEndpointTests {
|
||||
XMPPConnection connection = mock(XMPPConnection.class);
|
||||
bf.registerSingleton(XmppContextUtils.XMPP_CONNECTION_BEAN_NAME, connection);
|
||||
|
||||
ChatManager cm = mock(ChatManager.class);
|
||||
when(connection.getChatManager()).thenReturn(cm);
|
||||
Chat chat = mock(Chat.class);
|
||||
when(cm.getThreadChat(Mockito.anyString())).thenReturn(chat);
|
||||
|
||||
PresenceListeningEndpoint endpoint = new PresenceListeningEndpoint();
|
||||
|
||||
DirectChannel outChannel = new DirectChannel();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -23,14 +23,14 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
|
||||
import org.jivesoftware.smackx.jiveproperties.JivePropertiesManager;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.integration.xmpp.XmppHeaders;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Florian Schmaus
|
||||
* @since 2.1
|
||||
*/
|
||||
public class DefaultXmppHeaderMapperTests {
|
||||
@@ -58,12 +58,12 @@ public class DefaultXmppHeaderMapperTests {
|
||||
assertEquals(Message.Type.headline, target.getType());
|
||||
|
||||
// user-defined headers not included by default
|
||||
assertNull(target.getProperty("userDefined1"));
|
||||
assertNull(target.getProperty("userDefined2"));
|
||||
assertNull(JivePropertiesManager.getProperty(target, "userDefined1"));
|
||||
assertNull(JivePropertiesManager.getProperty(target, "userDefined2"));
|
||||
|
||||
// transient headers should not be copied
|
||||
assertNull(target.getProperty("id"));
|
||||
assertNull(target.getProperty("timestamp"));
|
||||
assertNull(JivePropertiesManager.getProperty(target, "id"));
|
||||
assertNull(JivePropertiesManager.getProperty(target, "timestamp"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -91,15 +91,15 @@ public class DefaultXmppHeaderMapperTests {
|
||||
assertEquals(Message.Type.normal, target.getType());
|
||||
|
||||
// user-defined headers are included if in the list
|
||||
assertEquals("foo", target.getProperty("userDefined1"));
|
||||
assertEquals("bar", target.getProperty("userDefined2"));
|
||||
assertEquals("foo", JivePropertiesManager.getProperty(target, "userDefined1"));
|
||||
assertEquals("bar", JivePropertiesManager.getProperty(target, "userDefined2"));
|
||||
|
||||
// user-defined headers are not included if not in the list
|
||||
assertNull(target.getProperty("userDefined3"));
|
||||
assertNull(JivePropertiesManager.getProperty(target, "userDefined3"));
|
||||
|
||||
// transient headers should not be copied
|
||||
assertNull(target.getProperty("id"));
|
||||
assertNull(target.getProperty("timestamp"));
|
||||
assertNull(JivePropertiesManager.getProperty(target, "id"));
|
||||
assertNull(JivePropertiesManager.getProperty(target, "timestamp"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -109,8 +109,8 @@ public class DefaultXmppHeaderMapperTests {
|
||||
source.setFrom("test.from");
|
||||
source.setSubject("test.subject");
|
||||
source.setThread("test.thread");
|
||||
source.setProperty("userDefined1", "foo");
|
||||
source.setProperty("userDefined2", "bar");
|
||||
JivePropertiesManager.addProperty(source, "userDefined1", "foo");
|
||||
JivePropertiesManager.addProperty(source, "userDefined2", "bar");
|
||||
Map<String, Object> headers = mapper.toHeadersFromRequest(source);
|
||||
assertEquals("test.to", headers.get(XmppHeaders.TO));
|
||||
assertEquals("test.from", headers.get(XmppHeaders.FROM));
|
||||
@@ -129,8 +129,8 @@ public class DefaultXmppHeaderMapperTests {
|
||||
source.setFrom("test.from");
|
||||
source.setSubject("test.subject");
|
||||
source.setThread("test.thread");
|
||||
source.setProperty("userDefined1", "foo");
|
||||
source.setProperty("userDefined2", "bar");
|
||||
JivePropertiesManager.addProperty(source, "userDefined1", "foo");
|
||||
JivePropertiesManager.addProperty(source, "userDefined2", "bar");
|
||||
Map<String, Object> headers = mapper.toHeadersFromReply(source);
|
||||
assertNull(headers.get(XmppHeaders.TO));
|
||||
assertNull(headers.get(XmppHeaders.FROM));
|
||||
|
||||
Reference in New Issue
Block a user