1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-15 03:59:38 +02:00

Use Jid (and subclasses) from jxmpp-jid

Fixes SMACK-634
This commit is contained in:
Florian Schmaus 2015-02-14 17:15:02 +01:00
parent 0ee2d9ed1e
commit 5bb4727c57
180 changed files with 1510 additions and 1032 deletions

View file

@ -25,6 +25,8 @@ import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smackx.bytestreams.ibb.packet.Close;
import org.junit.Test;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.JidTestUtil;
import org.mockito.ArgumentCaptor;
import org.powermock.reflect.Whitebox;
@ -35,8 +37,8 @@ import org.powermock.reflect.Whitebox;
*/
public class CloseListenerTest {
String initiatorJID = "initiator@xmpp-server/Smack";
String targetJID = "target@xmpp-server/Smack";
static final Jid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
static final Jid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1;
/**
* If a close request to an unknown session is received it should be replied

View file

@ -26,6 +26,8 @@ import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smackx.bytestreams.ibb.packet.Data;
import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension;
import org.junit.Test;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.JidTestUtil;
import org.mockito.ArgumentCaptor;
import org.powermock.reflect.Whitebox;
@ -36,8 +38,8 @@ import org.powermock.reflect.Whitebox;
*/
public class DataListenerTest {
String initiatorJID = "initiator@xmpp-server/Smack";
String targetJID = "target@xmpp-server/Smack";
static final Jid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
static final Jid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1;
/**
* If a data packet of an unknown session is received it should be replied

View file

@ -20,6 +20,7 @@ import org.jivesoftware.smack.packet.EmptyResultIQ;
import org.jivesoftware.smack.packet.ErrorIQ;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.XMPPError;
import org.jxmpp.jid.Jid;
/**
* Utility methods to create packets.
@ -36,7 +37,7 @@ public class IBBPacketUtils {
* @param xmppError the XMPP error
* @return an error IQ
*/
public static IQ createErrorIQ(String from, String to, XMPPError xmppError) {
public static IQ createErrorIQ(Jid from, Jid to, XMPPError xmppError) {
IQ errorIQ = new ErrorIQ(xmppError);
errorIQ.setType(IQ.Type.error);
errorIQ.setFrom(from);
@ -51,7 +52,7 @@ public class IBBPacketUtils {
* @param to the recipients JID
* @return a result IQ
*/
public static IQ createResultIQ(String from, String to) {
public static IQ createResultIQ(Jid from, Jid to) {
IQ result = new EmptyResultIQ();
result.setType(IQ.Type.result);
result.setFrom(from);

View file

@ -35,6 +35,9 @@ import org.jivesoftware.util.Protocol;
import org.jivesoftware.util.Verification;
import org.junit.Before;
import org.junit.Test;
import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.FullJid;
import org.jxmpp.jid.JidTestUtil;
/**
* Test for InBandBytestreamManager.
@ -44,9 +47,9 @@ import org.junit.Test;
public class InBandBytestreamManagerTest {
// settings
String initiatorJID = "initiator@xmpp-server/Smack";
String targetJID = "target@xmpp-server/Smack";
String xmppServer = "xmpp-server";
static final FullJid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
static final FullJid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1;
static final DomainBareJid xmppServer = JidTestUtil.DOMAIN_BARE_JID_1;
String sessionID = "session_id";
// protocol verifier
@ -99,7 +102,7 @@ public class InBandBytestreamManagerTest {
}
/**
* Invoking {@link InBandBytestreamManager#establishSession(String)} should
* Invoking {@link InBandBytestreamManager#establishSession(org.jxmpp.jid.Jid)} should
* throw an exception if the given target does not support in-band
* bytestream.
* @throws SmackException

View file

@ -28,6 +28,8 @@ import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smackx.bytestreams.ibb.packet.Open;
import org.junit.Before;
import org.junit.Test;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.JidTestUtil;
import org.mockito.ArgumentCaptor;
/**
@ -37,8 +39,8 @@ import org.mockito.ArgumentCaptor;
*/
public class InBandBytestreamRequestTest {
String initiatorJID = "initiator@xmpp-server/Smack";
String targetJID = "target@xmpp-server/Smack";
static final Jid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
static final Jid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1;
String sessionID = "session_id";
XMPPConnection connection;

View file

@ -40,6 +40,9 @@ import org.jivesoftware.util.Protocol;
import org.jivesoftware.util.Verification;
import org.junit.Before;
import org.junit.Test;
import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.FullJid;
import org.jxmpp.jid.JidTestUtil;
import org.powermock.reflect.Whitebox;
/**
@ -52,9 +55,9 @@ import org.powermock.reflect.Whitebox;
public class InBandBytestreamSessionMessageTest {
// settings
String initiatorJID = "initiator@xmpp-server/Smack";
String targetJID = "target@xmpp-server/Smack";
String xmppServer = "xmpp-server";
static final FullJid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
static final FullJid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1;
static final DomainBareJid xmppServer = JidTestUtil.DOMAIN_BARE_JID_1;
String sessionID = "session_id";
int blockSize = 10;

View file

@ -40,6 +40,9 @@ import org.jivesoftware.util.Protocol;
import org.jivesoftware.util.Verification;
import org.junit.Before;
import org.junit.Test;
import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.FullJid;
import org.jxmpp.jid.JidTestUtil;
import org.powermock.reflect.Whitebox;
/**
@ -53,9 +56,9 @@ import org.powermock.reflect.Whitebox;
public class InBandBytestreamSessionTest {
// settings
String initiatorJID = "initiator@xmpp-server/Smack";
String targetJID = "target@xmpp-server/Smack";
String xmppServer = "xmpp-server";
static final FullJid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
static final FullJid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1;
static final DomainBareJid xmppServer = JidTestUtil.DOMAIN_BARE_JID_1;
String sessionID = "session_id";
int blockSize = 10;

View file

@ -28,6 +28,9 @@ import org.jivesoftware.smackx.bytestreams.BytestreamRequest;
import org.jivesoftware.smackx.bytestreams.ibb.packet.Open;
import org.junit.Before;
import org.junit.Test;
import org.jxmpp.jid.FullJid;
import org.jxmpp.jid.JidTestUtil;
import org.jxmpp.jid.impl.JidCreate;
import org.mockito.ArgumentCaptor;
import org.powermock.reflect.Whitebox;
@ -38,8 +41,8 @@ import org.powermock.reflect.Whitebox;
*/
public class InitiationListenerTest {
String initiatorJID = "initiator@xmpp-server/Smack";
String targetJID = "target@xmpp-server/Smack";
static final FullJid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
static final FullJid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1;
String sessionID = "session_id";
XMPPConnection connection;
@ -190,7 +193,7 @@ public class InitiationListenerTest {
// add listener for request of user "other_initiator"
InBandBytestreamListener listener = mock(InBandBytestreamListener.class);
byteStreamManager.addIncomingBytestreamListener(listener, "other_" + initiatorJID);
byteStreamManager.addIncomingBytestreamListener(listener, JidCreate.from("other_" + initiatorJID));
// run the listener with the initiation packet
initiationListener.handleIQRequest(initBytestream);
@ -261,8 +264,8 @@ public class InitiationListenerTest {
// add listener for request of user "other_initiator"
InBandBytestreamListener userRequestsListener = mock(InBandBytestreamListener.class);
byteStreamManager.addIncomingBytestreamListener(userRequestsListener, "other_"
+ initiatorJID);
byteStreamManager.addIncomingBytestreamListener(userRequestsListener, JidCreate.from("other_"
+ initiatorJID));
// run the listener with the initiation packet
initiationListener.handleIQRequest(initBytestream);

View file

@ -17,13 +17,13 @@
package org.jivesoftware.smackx.bytestreams.ibb.packet;
import static org.junit.Assert.assertEquals;
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
import java.util.Properties;
import org.jivesoftware.smack.packet.IQ;
import org.junit.Test;
import org.jxmpp.jid.impl.JidCreate;
import com.jamesmurty.utils.XMLBuilder;
@ -74,8 +74,8 @@ public class CloseTest {
.asString(outputProperties);
Close close = new Close("i781hf64");
close.setFrom("romeo@montague.lit/orchard");
close.setTo("juliet@capulet.lit/balcony");
close.setFrom(JidCreate.from("romeo@montague.lit/orchard"));
close.setTo(JidCreate.from("juliet@capulet.lit/balcony"));
close.setStanzaId("us71g45j");
assertXMLEqual(control, close.toXML().toString());

View file

@ -25,6 +25,7 @@ import java.util.Properties;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.util.stringencoder.Base64;
import org.junit.Test;
import org.jxmpp.jid.impl.JidCreate;
import com.jamesmurty.utils.XMLBuilder;
@ -70,8 +71,8 @@ public class DataTest {
DataPacketExtension dpe = new DataPacketExtension("i781hf64", 0, encodedData);
Data data = new Data(dpe);
data.setFrom("romeo@montague.lit/orchard");
data.setTo("juliet@capulet.lit/balcony");
data.setFrom(JidCreate.from("romeo@montague.lit/orchard"));
data.setTo(JidCreate.from("juliet@capulet.lit/balcony"));
data.setStanzaId("kr91n475");
assertXMLEqual(control, data.toXML().toString());

View file

@ -24,6 +24,7 @@ import java.util.Properties;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager.StanzaType;
import org.junit.Test;
import org.jxmpp.jid.impl.JidCreate;
import com.jamesmurty.utils.XMLBuilder;
@ -95,8 +96,8 @@ public class OpenTest {
.asString(outputProperties);
Open open = new Open("i781hf64", 4096, StanzaType.IQ);
open.setFrom("romeo@montague.lit/orchard");
open.setTo("juliet@capulet.lit/balcony");
open.setFrom(JidCreate.from("romeo@montague.lit/orchard"));
open.setTo(JidCreate.from("juliet@capulet.lit/balcony"));
open.setStanzaId("jn3h8g65");
assertXMLEqual(control, open.toXML().toString());

View file

@ -29,6 +29,10 @@ import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.junit.Before;
import org.junit.Test;
import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.FullJid;
import org.jxmpp.jid.JidTestUtil;
import org.jxmpp.jid.impl.JidCreate;
import org.mockito.ArgumentCaptor;
import org.powermock.reflect.Whitebox;
@ -39,10 +43,10 @@ import org.powermock.reflect.Whitebox;
*/
public class InitiationListenerTest {
String initiatorJID = "initiator@xmpp-server/Smack";
String targetJID = "target@xmpp-server/Smack";
String xmppServer = "xmpp-server";
String proxyJID = "proxy.xmpp-server";
static final FullJid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
static final FullJid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1;
static final DomainBareJid xmppServer = JidTestUtil.DOMAIN_BARE_JID_1;
static final DomainBareJid proxyJID = JidTestUtil.MUC_EXAMPLE_ORG;
String proxyAddress = "127.0.0.1";
String sessionID = "session_id";
@ -169,7 +173,7 @@ public class InitiationListenerTest {
// add listener for request of user "other_initiator"
Socks5BytestreamListener listener = mock(Socks5BytestreamListener.class);
byteStreamManager.addIncomingBytestreamListener(listener, "other_" + initiatorJID);
byteStreamManager.addIncomingBytestreamListener(listener, JidCreate.from("other_" + initiatorJID));
// run the listener with the initiation packet
initiationListener.handleIQRequest(initBytestream);
@ -240,8 +244,8 @@ public class InitiationListenerTest {
// add listener for request of user "other_initiator"
Socks5BytestreamListener userRequestsListener = mock(Socks5BytestreamListener.class);
byteStreamManager.addIncomingBytestreamListener(userRequestsListener, "other_"
+ initiatorJID);
byteStreamManager.addIncomingBytestreamListener(userRequestsListener, JidCreate.from("other_"
+ initiatorJID));
// run the listener with the initiation packet
initiationListener.handleIQRequest(initBytestream);

View file

@ -50,6 +50,11 @@ import org.jivesoftware.util.Verification;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.FullJid;
import org.jxmpp.jid.JidTestUtil;
import org.jxmpp.jid.impl.JidCreate;
import org.jxmpp.stringprep.XmppStringprepException;
/**
* Test for Socks5BytestreamManager.
@ -59,10 +64,10 @@ import org.junit.Test;
public class Socks5ByteStreamManagerTest {
// settings
String initiatorJID = "initiator@xmpp-server/Smack";
String targetJID = "target@xmpp-server/Smack";
String xmppServer = "xmpp-server";
String proxyJID = "proxy.xmpp-server";
static final FullJid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
static final FullJid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1;
static final DomainBareJid xmppServer = JidTestUtil.DOMAIN_BARE_JID_1;
static final DomainBareJid proxyJID = JidTestUtil.MUC_EXAMPLE_ORG;
String proxyAddress = "127.0.0.1";
String sessionID = "session_id";
@ -137,7 +142,7 @@ public class Socks5ByteStreamManagerTest {
}
/**
* Invoking {@link Socks5BytestreamManager#establishSession(String)} should throw an exception
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid)} should throw an exception
* if the given target does not support SOCKS5 Bytestream.
* @throws XMPPException
*/
@ -165,7 +170,7 @@ public class Socks5ByteStreamManagerTest {
}
/**
* Invoking {@link Socks5BytestreamManager#establishSession(String, String)} should fail if XMPP
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if XMPP
* server doesn't return any proxies.
*/
@Test
@ -216,7 +221,7 @@ public class Socks5ByteStreamManagerTest {
}
/**
* Invoking {@link Socks5BytestreamManager#establishSession(String, String)} should fail if no
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if no
* proxy is a SOCKS5 proxy.
*/
@Test
@ -254,7 +259,7 @@ public class Socks5ByteStreamManagerTest {
// build discover info for proxy containing information about NOT being a Socks5
// proxy
DiscoverInfo proxyInfo = Socks5PacketUtils.createDiscoverInfo(proxyJID, initiatorJID);
Identity identity = new Identity("noproxy", proxyJID, "bytestreams");
Identity identity = new Identity("noproxy", proxyJID.toString(), "bytestreams");
proxyInfo.addIdentity(identity);
// return the proxy identity if proxy is queried
@ -279,7 +284,7 @@ public class Socks5ByteStreamManagerTest {
}
/**
* Invoking {@link Socks5BytestreamManager#establishSession(String, String)} should fail if no
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if no
* SOCKS5 proxy can be found. If it turns out that a proxy is not a SOCKS5 proxy it should not
* be queried again.
*/
@ -318,7 +323,7 @@ public class Socks5ByteStreamManagerTest {
// build discover info for proxy containing information about NOT being a Socks5
// proxy
DiscoverInfo proxyInfo = Socks5PacketUtils.createDiscoverInfo(proxyJID, initiatorJID);
Identity identity = new Identity("noproxy", proxyJID, "bytestreams");
Identity identity = new Identity("noproxy", proxyJID.toString(), "bytestreams");
proxyInfo.addIdentity(identity);
// return the proxy identity if proxy is queried
@ -370,7 +375,7 @@ public class Socks5ByteStreamManagerTest {
}
/**
* Invoking {@link Socks5BytestreamManager#establishSession(String, String)} should fail if the
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if the
* target does not accept a SOCKS5 Bytestream. See <a
* href="http://xmpp.org/extensions/xep-0065.html#usecase-alternate">XEP-0065 Section 5.2 A2</a>
*/
@ -408,7 +413,7 @@ public class Socks5ByteStreamManagerTest {
// build discover info for proxy containing information about being a SOCKS5 proxy
DiscoverInfo proxyInfo = Socks5PacketUtils.createDiscoverInfo(proxyJID, initiatorJID);
Identity identity = new Identity("proxy", proxyJID, "bytestreams");
Identity identity = new Identity("proxy", proxyJID.toString(), "bytestreams");
proxyInfo.addIdentity(identity);
// return the socks5 bytestream proxy identity if proxy is queried
@ -454,11 +459,12 @@ public class Socks5ByteStreamManagerTest {
}
/**
* Invoking {@link Socks5BytestreamManager#establishSession(String, String)} should fail if the
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if the
* proxy used by target is invalid.
* @throws XmppStringprepException
*/
@Test
public void shouldFailIfTargetUsesInvalidSocks5Proxy() {
public void shouldFailIfTargetUsesInvalidSocks5Proxy() throws XmppStringprepException {
// disable clients local SOCKS5 proxy
Socks5Proxy.setLocalSocks5ProxyEnabled(false);
@ -491,7 +497,7 @@ public class Socks5ByteStreamManagerTest {
// build discover info for proxy containing information about being a SOCKS5 proxy
DiscoverInfo proxyInfo = Socks5PacketUtils.createDiscoverInfo(proxyJID, initiatorJID);
Identity identity = new Identity("proxy", proxyJID, "bytestreams");
Identity identity = new Identity("proxy", proxyJID.toString(), "bytestreams");
proxyInfo.addIdentity(identity);
// return the socks5 bytestream proxy identity if proxy is queried
@ -512,7 +518,7 @@ public class Socks5ByteStreamManagerTest {
Bytestream streamHostUsedPacket = Socks5PacketUtils.createBytestreamResponse(targetJID,
initiatorJID);
streamHostUsedPacket.setSessionID(sessionID);
streamHostUsedPacket.setUsedHost("invalid.proxy");
streamHostUsedPacket.setUsedHost(JidCreate.from("invalid.proxy"));
// return used stream host info as response to the bytestream initiation
protocol.addResponse(streamHostUsedPacket, Verification.correspondingSenderReceiver,
@ -536,7 +542,7 @@ public class Socks5ByteStreamManagerTest {
}
/**
* Invoking {@link Socks5BytestreamManager#establishSession(String, String)} should fail if
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if
* initiator can not connect to the SOCKS5 proxy used by target.
*/
@Test
@ -573,7 +579,7 @@ public class Socks5ByteStreamManagerTest {
// build discover info for proxy containing information about being a SOCKS5 proxy
DiscoverInfo proxyInfo = Socks5PacketUtils.createDiscoverInfo(proxyJID, initiatorJID);
Identity identity = new Identity("proxy", proxyJID, "bytestreams");
Identity identity = new Identity("proxy", proxyJID.toString(), "bytestreams");
proxyInfo.addIdentity(identity);
// return the socks5 bytestream proxy identity if proxy is queried
@ -628,7 +634,7 @@ public class Socks5ByteStreamManagerTest {
}
/**
* Invoking {@link Socks5BytestreamManager#establishSession(String, String)} should successfully
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should successfully
* negotiate and return a SOCKS5 Bytestream connection.
*
* @throws Exception should not happen
@ -667,7 +673,7 @@ public class Socks5ByteStreamManagerTest {
// build discover info for proxy containing information about being a SOCKS5 proxy
DiscoverInfo proxyInfo = Socks5PacketUtils.createDiscoverInfo(proxyJID, initiatorJID);
Identity identity = new Identity("proxy", proxyJID, "bytestreams");
Identity identity = new Identity("proxy", proxyJID.toString(), "bytestreams");
proxyInfo.addIdentity(identity);
// return the socks5 bytestream proxy identity if proxy is queried
@ -838,7 +844,7 @@ public class Socks5ByteStreamManagerTest {
}
/**
* Invoking {@link Socks5BytestreamManager#establishSession(String, String)} the first time
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} the first time
* should successfully negotiate a SOCKS5 Bytestream via the second SOCKS5 proxy and should
* prioritize this proxy for a second SOCKS5 Bytestream negotiation.
*
@ -921,7 +927,7 @@ public class Socks5ByteStreamManagerTest {
}
/**
* Invoking {@link Socks5BytestreamManager#establishSession(String, String)} the first time
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} the first time
* should successfully negotiate a SOCKS5 Bytestream via the second SOCKS5 proxy. The second
* negotiation should run in the same manner if prioritization is disabled.
*
@ -995,7 +1001,7 @@ public class Socks5ByteStreamManagerTest {
}
private void createResponses(Verification<Bytestream, Bytestream> streamHostUsedVerification) {
private void createResponses(Verification<Bytestream, Bytestream> streamHostUsedVerification) throws XmppStringprepException {
// build discover info that supports the SOCKS5 feature
DiscoverInfo discoverInfo = Socks5PacketUtils.createDiscoverInfo(targetJID, initiatorJID);
discoverInfo.addFeature(Bytestream.NAMESPACE);
@ -1007,7 +1013,7 @@ public class Socks5ByteStreamManagerTest {
// build discover items containing a proxy item
DiscoverItems discoverItems = Socks5PacketUtils.createDiscoverItems(xmppServer,
initiatorJID);
discoverItems.addItem(new Item("proxy2.xmpp-server"));
discoverItems.addItem(new Item(JidCreate.from("proxy2.xmpp-server")));
discoverItems.addItem(new Item(proxyJID));
// return the proxy item if XMPP server is queried
@ -1018,7 +1024,7 @@ public class Socks5ByteStreamManagerTest {
* build discover info for proxy "proxy2.xmpp-server" containing information about being a
* SOCKS5 proxy
*/
DiscoverInfo proxyInfo1 = Socks5PacketUtils.createDiscoverInfo("proxy2.xmpp-server",
DiscoverInfo proxyInfo1 = Socks5PacketUtils.createDiscoverInfo(JidCreate.from("proxy2.xmpp-server"),
initiatorJID);
Identity identity1 = new Identity("proxy", "proxy2.xmpp-server", "bytestreams");
proxyInfo1.addIdentity(identity1);
@ -1029,7 +1035,7 @@ public class Socks5ByteStreamManagerTest {
// build discover info for proxy containing information about being a SOCKS5 proxy
DiscoverInfo proxyInfo2 = Socks5PacketUtils.createDiscoverInfo(proxyJID, initiatorJID);
Identity identity2 = new Identity("proxy", proxyJID, "bytestreams");
Identity identity2 = new Identity("proxy", proxyJID.toString(), "bytestreams");
proxyInfo2.addIdentity(identity2);
// return the SOCKS5 bytestream proxy identity if proxy is queried
@ -1041,8 +1047,8 @@ public class Socks5ByteStreamManagerTest {
* port of the proxy
*/
Bytestream streamHostInfo1 = Socks5PacketUtils.createBytestreamResponse(
"proxy2.xmpp-server", initiatorJID);
streamHostInfo1.addStreamHost("proxy2.xmpp-server", proxyAddress, 7778);
JidCreate.from("proxy2.xmpp-server"), initiatorJID);
streamHostInfo1.addStreamHost(JidCreate.from("proxy2.xmpp-server"), proxyAddress, 7778);
// return stream host info if it is queried
protocol.addResponse(streamHostInfo1, Verification.correspondingSenderReceiver,

View file

@ -40,6 +40,10 @@ import org.jivesoftware.util.Protocol;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.FullJid;
import org.jxmpp.jid.JidTestUtil;
import org.jxmpp.jid.impl.JidCreate;
/**
* Tests for the Socks5BytestreamRequest class.
@ -49,10 +53,10 @@ import org.junit.Test;
public class Socks5ByteStreamRequestTest {
// settings
String initiatorJID = "initiator@xmpp-server/Smack";
String targetJID = "target@xmpp-server/Smack";
String xmppServer = "xmpp-server";
String proxyJID = "proxy.xmpp-server";
static final FullJid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
static final FullJid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1;
static final DomainBareJid xmppServer = JidTestUtil.DOMAIN_BARE_JID_1;
static final DomainBareJid proxyJID = JidTestUtil.MUC_EXAMPLE_ORG;
String proxyAddress = "127.0.0.1";
String sessionID = "session_id";
@ -174,7 +178,7 @@ public class Socks5ByteStreamRequestTest {
// build SOCKS5 Bytestream initialization request
Bytestream bytestreamInitialization = Socks5PacketUtils.createBytestreamInitiation(
initiatorJID, targetJID, sessionID);
bytestreamInitialization.addStreamHost("invalid." + proxyJID, "127.0.0.2", 7778);
bytestreamInitialization.addStreamHost(JidCreate.from("invalid." + proxyJID), "127.0.0.2", 7778);
// get SOCKS5 Bytestream manager for connection
Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);
@ -266,7 +270,7 @@ public class Socks5ByteStreamRequestTest {
// build SOCKS5 Bytestream initialization request
Bytestream bytestreamInitialization = Socks5PacketUtils.createBytestreamInitiation(
initiatorJID, targetJID, sessionID);
bytestreamInitialization.addStreamHost("invalid." + proxyJID, "127.0.0.2", 7778);
bytestreamInitialization.addStreamHost(JidCreate.from("invalid." + proxyJID), "127.0.0.2", 7778);
// get SOCKS5 Bytestream manager for connection
Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);

View file

@ -42,6 +42,9 @@ import org.jivesoftware.util.Verification;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.FullJid;
import org.jxmpp.jid.JidTestUtil;
/**
* Test for Socks5ClientForInitiator class.
@ -51,10 +54,10 @@ import org.junit.Test;
public class Socks5ClientForInitiatorTest {
// settings
String initiatorJID = "initiator@xmpp-server/Smack";
String targetJID = "target@xmpp-server/Smack";
String xmppServer = "xmpp-server";
String proxyJID = "proxy.xmpp-server";
static final FullJid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
static final FullJid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1;
static final DomainBareJid xmppServer = JidTestUtil.DOMAIN_BARE_JID_1;
static final DomainBareJid proxyJID = JidTestUtil.MUC_EXAMPLE_ORG;
String proxyAddress = "127.0.0.1";
int proxyPort = 7890;
String sessionID = "session_id";

View file

@ -32,6 +32,8 @@ import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.JidTestUtil;
/**
* Test for Socks5Client class.
@ -43,7 +45,7 @@ public class Socks5ClientTest {
// settings
private String serverAddress = "127.0.0.1";
private int serverPort = 7890;
private String proxyJID = "proxy.xmpp-server";
private DomainBareJid proxyJID = JidTestUtil.MUC_EXAMPLE_ORG;
private String digest = "digest";
private ServerSocket serverSocket;

View file

@ -21,6 +21,7 @@ import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
import org.jivesoftware.smackx.disco.packet.DiscoverItems;
import org.jxmpp.jid.Jid;
/**
* A collection of utility methods to create XMPP packets.
@ -38,7 +39,7 @@ public class Socks5PacketUtils {
* @param sessionID the session ID
* @return SOCKS5 Bytestream initialization request packet
*/
public static Bytestream createBytestreamInitiation(String from, String to, String sessionID) {
public static Bytestream createBytestreamInitiation(Jid from, Jid to, String sessionID) {
Bytestream bytestream = new Bytestream();
bytestream.setFrom(from);
bytestream.setTo(to);
@ -55,7 +56,7 @@ public class Socks5PacketUtils {
* @param to the initiator
* @return response to a SOCKS5 Bytestream initialization request
*/
public static Bytestream createBytestreamResponse(String from, String to) {
public static Bytestream createBytestreamResponse(Jid from, Jid to) {
Bytestream streamHostInfo = new Bytestream();
streamHostInfo.setFrom(from);
streamHostInfo.setTo(to);
@ -70,7 +71,7 @@ public class Socks5PacketUtils {
* @param to the XMPP client
* @return response to an item discovery request
*/
public static DiscoverItems createDiscoverItems(String from, String to) {
public static DiscoverItems createDiscoverItems(Jid from, Jid to) {
DiscoverItems discoverItems = new DiscoverItems();
discoverItems.setFrom(from);
discoverItems.setTo(to);
@ -85,7 +86,7 @@ public class Socks5PacketUtils {
* @param to the initiator
* @return response to an info discovery request
*/
public static DiscoverInfo createDiscoverInfo(String from, String to) {
public static DiscoverInfo createDiscoverInfo(Jid from, Jid to) {
DiscoverInfo discoverInfo = new DiscoverInfo();
discoverInfo.setFrom(from);
discoverInfo.setTo(to);
@ -100,7 +101,7 @@ public class Socks5PacketUtils {
* @param to JID of the client who wants to activate the SOCKS5 Bytestream
* @return response IQ for a activation request to the proxy
*/
public static IQ createActivationConfirmation(String from, String to) {
public static IQ createActivationConfirmation(Jid from, Jid to) {
IQ response = new EmptyResultIQ();
response.setFrom(from);
response.setTo(to);

View file

@ -38,6 +38,8 @@ import org.jivesoftware.smackx.xdata.FormField;
import org.jivesoftware.smackx.xdata.packet.DataForm;
import org.junit.Before;
import org.junit.Test;
import org.jxmpp.jid.impl.JidCreate;
import org.jxmpp.stringprep.XmppStringprepException;
public class EntityCapsManagerTest extends InitExtensions {
@ -50,9 +52,10 @@ public class EntityCapsManagerTest extends InitExtensions {
/**
* <a href="http://xmpp.org/extensions/xep-0115.html#ver-gen-complex">XEP-
* 0115 Complex Generation Example</a>
* @throws XmppStringprepException
*/
@Test
public void testComplexGenerationExample() {
public void testComplexGenerationExample() throws XmppStringprepException {
DiscoverInfo di = createComplexSamplePacket();
CapsVersionAndHash versionAndHash = EntityCapsManager.generateVerificationString(di, StringUtils.SHA1);
@ -66,13 +69,13 @@ public class EntityCapsManagerTest extends InitExtensions {
}
@Test
public void testVerificationDuplicateFeatures() {
public void testVerificationDuplicateFeatures() throws XmppStringprepException {
DiscoverInfo di = createMalformedDiscoverInfo();
assertTrue(di.containsDuplicateFeatures());
}
@Test
public void testVerificationDuplicateIdentities() {
public void testVerificationDuplicateIdentities() throws XmppStringprepException {
DiscoverInfo di = createMalformedDiscoverInfo();
assertTrue(di.containsDuplicateIdentities());
}
@ -97,11 +100,11 @@ public class EntityCapsManagerTest extends InitExtensions {
assertEquals(di.toXML().toString(), restored_di.toXML().toString());
}
private static DiscoverInfo createComplexSamplePacket() {
private static DiscoverInfo createComplexSamplePacket() throws XmppStringprepException {
DiscoverInfo di = new DiscoverInfo();
di.setFrom("benvolio@capulet.lit/230193");
di.setFrom(JidCreate.from("benvolio@capulet.lit/230193"));
di.setStanzaId("disco1");
di.setTo("juliet@capulet.lit/chamber");
di.setTo(JidCreate.from("juliet@capulet.lit/chamber"));
di.setType(IQ.Type.result);
Collection<DiscoverInfo.Identity> identities = new LinkedList<DiscoverInfo.Identity>();
@ -148,11 +151,11 @@ public class EntityCapsManagerTest extends InitExtensions {
return di;
}
private static DiscoverInfo createMalformedDiscoverInfo() {
private static DiscoverInfo createMalformedDiscoverInfo() throws XmppStringprepException {
DiscoverInfo di = new DiscoverInfo();
di.setFrom("benvolio@capulet.lit/230193");
di.setFrom(JidCreate.from("benvolio@capulet.lit/230193"));
di.setStanzaId("disco1");
di.setTo(")juliet@capulet.lit/chamber");
di.setTo(JidCreate.from(")juliet@capulet.lit/chamber"));
di.setType(IQ.Type.result);
Collection<DiscoverInfo.Identity> identities = new LinkedList<DiscoverInfo.Identity>();

View file

@ -25,6 +25,7 @@ import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.jxmpp.jid.JidTestUtil;
public class FileTransferNegotiatorTest {
private DummyConnection connection;
@ -50,7 +51,7 @@ public class FileTransferNegotiatorTest {
public void verifyForm() throws Exception {
FileTransferNegotiator fileNeg = FileTransferNegotiator.getInstanceFor(connection);
try {
fileNeg.negotiateOutgoingTransfer("me", "streamid", "file", 1024, null, 10);
fileNeg.negotiateOutgoingTransfer(JidTestUtil.DUMMY_AT_EXAMPLE_ORG, "streamid", "file", 1024, null, 10);
} catch (NoResponseException e) {
// Ignore
}

View file

@ -16,8 +16,10 @@
*/
package org.jivesoftware.smackx.forward;
import static org.jivesoftware.smack.test.util.CharsequenceEquals.equalsCharSequence;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import java.util.Properties;
@ -56,7 +58,7 @@ public class ForwardedTest {
assertEquals(null, fwd.getDelayInformation());
// check message
assertEquals("romeo@montague.com", fwd.getForwardedPacket().getFrom());
assertThat("romeo@montague.com", equalsCharSequence(fwd.getForwardedPacket().getFrom()));
// check end of tag
assertEquals(XmlPullParser.END_TAG, parser.getEventType());
@ -84,7 +86,7 @@ public class ForwardedTest {
assertNotNull(delay);
// check message
assertEquals("romeo@montague.com", fwd.getForwardedPacket().getFrom());
assertThat("romeo@montague.com", equalsCharSequence(fwd.getForwardedPacket().getFrom()));
// check end of tag
assertEquals(XmlPullParser.END_TAG, parser.getEventType());

View file

@ -16,7 +16,9 @@
*/
package org.jivesoftware.smackx.iqversion;
import static org.jivesoftware.smack.test.util.CharsequenceEquals.equalsCharSequence;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import org.jivesoftware.smack.DummyConnection;
@ -52,7 +54,7 @@ public class VersionTest {
Version reply = (Version) replyPacket;
//getFrom check is pending for SMACK-547
//assertEquals("juliet@capulet.lit/balcony", reply.getFrom());
assertEquals("capulet.lit", reply.getTo());
assertThat("capulet.lit", equalsCharSequence(reply.getTo()));
assertEquals("s2c1", reply.getStanzaId());
assertEquals(IQ.Type.result, reply.getType());
assertEquals("Test", reply.getName());

View file

@ -16,10 +16,13 @@
*/
package org.jivesoftware.smackx.ping;
import static org.jivesoftware.smack.test.util.CharsequenceEquals.equalsCharSequence;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.jxmpp.jid.JidTestUtil.DUMMY_AT_EXAMPLE_ORG;
import java.io.IOException;
@ -66,7 +69,7 @@ public class PingTest extends InitExtensions {
assertTrue(pongPacket instanceof IQ);
IQ pong = (IQ) pongPacket;
assertEquals("capulet.lit", pong.getTo());
assertThat("capulet.lit", equalsCharSequence(pong.getTo()));
assertEquals("s2c1", pong.getStanzaId());
assertEquals(IQ.Type.result, pong.getType());
}
@ -76,7 +79,7 @@ public class PingTest extends InitExtensions {
DummyConnection dummyCon = getAuthentiactedDummyConnection();
PingManager pinger = PingManager.getInstanceFor(dummyCon);
try {
pinger.ping("test@myserver.com");
pinger.ping(DUMMY_AT_EXAMPLE_ORG);
}
catch (SmackException e) {
// Ignore the fact the server won't answer for this unit test.
@ -92,7 +95,7 @@ public class PingTest extends InitExtensions {
PingManager pinger = PingManager.getInstanceFor(threadedCon);
boolean pingSuccess = pinger.ping("test@myserver.com");
boolean pingSuccess = pinger.ping(DUMMY_AT_EXAMPLE_ORG);
assertTrue(pingSuccess);
@ -111,7 +114,7 @@ public class PingTest extends InitExtensions {
PingManager pinger = PingManager.getInstanceFor(dummyCon);
try {
pinger.ping("test@myserver.com");
pinger.ping(DUMMY_AT_EXAMPLE_ORG);
}
catch (NoResponseException e) {
return;
@ -140,7 +143,7 @@ public class PingTest extends InitExtensions {
PingManager pinger = PingManager.getInstanceFor(threadedCon);
boolean pingSuccess = pinger.ping("test@myserver.com");
boolean pingSuccess = pinger.ping(DUMMY_AT_EXAMPLE_ORG);
assertFalse(pingSuccess);
}
@ -207,7 +210,7 @@ public class PingTest extends InitExtensions {
con.addIQReply(discoReply);
PingManager pinger = PingManager.getInstanceFor(con);
boolean pingSupported = pinger.isPingSupported("test@myserver.com");
boolean pingSupported = pinger.isPingSupported(DUMMY_AT_EXAMPLE_ORG);
assertTrue(pingSupported);
}
@ -229,7 +232,7 @@ public class PingTest extends InitExtensions {
con.addIQReply(discoReply);
PingManager pinger = PingManager.getInstanceFor(con);
boolean pingSupported = pinger.isPingSupported("test@myserver.com");
boolean pingSupported = pinger.isPingSupported(DUMMY_AT_EXAMPLE_ORG);
assertFalse(pingSupported);
}

View file

@ -33,6 +33,7 @@ import org.jivesoftware.smackx.pubsub.packet.PubSub;
import org.jivesoftware.smackx.xdata.packet.DataForm;
import org.junit.Assert;
import org.junit.Test;
import org.jxmpp.stringprep.XmppStringprepException;
/**
*
@ -77,7 +78,7 @@ public class ConfigureFormTest
}
@Test (expected=SmackException.class)
public void getConfigFormWithTimeout() throws XMPPException, SmackException, InterruptedException
public void getConfigFormWithTimeout() throws XMPPException, SmackException, InterruptedException, XmppStringprepException
{
ThreadedDummyConnection con = new ThreadedDummyConnection();
PubSubManager mgr = new PubSubManager(con);

View file

@ -19,7 +19,9 @@ package org.jivesoftware.smackx.receipts;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.jivesoftware.smack.test.util.CharsequenceEquals.equalsCharSequence;
import java.util.Properties;
@ -31,6 +33,8 @@ import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.InitExtensions;
import org.jivesoftware.smackx.receipts.DeliveryReceiptManager.AutoReceiptMode;
import org.junit.Test;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.impl.JidCreate;
import org.xmlpull.v1.XmlPullParser;
import com.jamesmurty.utils.XMLBuilder;
@ -62,7 +66,7 @@ public class DeliveryReceiptTest extends InitExtensions {
assertTrue(DeliveryReceiptManager.hasDeliveryReceiptRequest(p));
Message m = new Message("romeo@montague.com", Message.Type.normal);
Message m = new Message(JidCreate.from("romeo@montague.com"), Message.Type.normal);
assertFalse(DeliveryReceiptManager.hasDeliveryReceiptRequest(m));
DeliveryReceiptRequest.addTo(m);
assertTrue(DeliveryReceiptManager.hasDeliveryReceiptRequest(m));
@ -77,8 +81,8 @@ public class DeliveryReceiptTest extends InitExtensions {
TestReceiptReceivedListener rrl = new TestReceiptReceivedListener();
drm.addReceiptReceivedListener(rrl);
Message m = new Message("romeo@montague.com", Message.Type.normal);
m.setFrom("julia@capulet.com");
Message m = new Message(JidCreate.from("romeo@montague.com"), Message.Type.normal);
m.setFrom(JidCreate.from("julia@capulet.com"));
m.setStanzaId("reply-id");
m.addExtension(new DeliveryReceipt("original-test-id"));
c.processPacket(m);
@ -88,9 +92,9 @@ public class DeliveryReceiptTest extends InitExtensions {
private static class TestReceiptReceivedListener extends WaitForPacketListener implements ReceiptReceivedListener {
@Override
public void onReceiptReceived(String fromJid, String toJid, String receiptId, Stanza receipt) {
assertEquals("julia@capulet.com", fromJid);
assertEquals("romeo@montague.com", toJid);
public void onReceiptReceived(Jid fromJid, Jid toJid, String receiptId, Stanza receipt) {
assertThat("julia@capulet.com", equalsCharSequence(fromJid));
assertThat("romeo@montague.com", equalsCharSequence(toJid));
assertEquals("original-test-id", receiptId);
reportInvoked();
}
@ -106,8 +110,8 @@ public class DeliveryReceiptTest extends InitExtensions {
assertEquals(AutoReceiptMode.always, drm.getAutoReceiptMode());
// test auto-receipts
Message m = new Message("julia@capulet.com", Message.Type.normal);
m.setFrom("romeo@montague.com");
Message m = new Message(JidCreate.from("julia@capulet.com"), Message.Type.normal);
m.setFrom(JidCreate.from("romeo@montague.com"));
m.setStanzaId("test-receipt-request");
DeliveryReceiptRequest.addTo(m);
@ -116,7 +120,7 @@ public class DeliveryReceiptTest extends InitExtensions {
Stanza reply = c.getSentPacket();
DeliveryReceipt r = DeliveryReceipt.from(reply);
assertEquals("romeo@montague.com", reply.getTo());
assertThat("romeo@montague.com", equalsCharSequence(reply.getTo()));
assertEquals("test-receipt-request", r.getId());
}
}

View file

@ -32,6 +32,8 @@ import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.FullJid;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
@ -67,7 +69,7 @@ public class ConnectionUtils {
* @throws InterruptedException
*/
public static XMPPConnection createMockedConnection(final Protocol protocol,
String initiatorJID, String xmppServer) throws SmackException, XMPPErrorException, InterruptedException {
FullJid initiatorJID, DomainBareJid xmppServer) throws SmackException, XMPPErrorException, InterruptedException {
// mock XMPP connection
XMPPConnection connection = mock(XMPPConnection.class);