1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-10 01:29:38 +02:00

Merge from 3.3 branch

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@13663 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
rcollier 2013-05-18 16:56:52 +00:00
commit dac68c64a9
163 changed files with 2304 additions and 2366 deletions

View file

@ -49,6 +49,7 @@ public class DummyConnection extends Connection {
private boolean authenticated = false;
private boolean anonymous = false;
private boolean reconnect = false;
private String user;
private String connectionID;
@ -57,16 +58,26 @@ public class DummyConnection extends Connection {
private final BlockingQueue<Packet> queue = new LinkedBlockingQueue<Packet>();
public DummyConnection() {
super(new ConnectionConfiguration("example.com"));
this(new ConnectionConfiguration("example.com"));
}
public DummyConnection(ConnectionConfiguration configuration) {
super(configuration);
for (ConnectionCreationListener listener : getConnectionCreationListeners()) {
listener.connectionCreated(this);
}
}
@Override
public void connect() throws XMPPException {
connectionID = "dummy-" + new Random(new Date().getTime()).nextInt();
if (reconnect) {
for (ConnectionListener listener : getConnectionListeners()) {
listener.reconnectionSuccessful();
}
}
}
@Override
@ -76,6 +87,11 @@ public class DummyConnection extends Connection {
roster = null;
authenticated = false;
anonymous = false;
for (ConnectionListener listener : getConnectionListeners()) {
listener.connectionClosed();
}
reconnect = true;
}
@Override
@ -191,15 +207,27 @@ public class DummyConnection extends Connection {
}
/**
* Returns the first packet that's sent through {@link #sendPacket(Packet)} and
* that has not been returned by earlier calls to this method. This method
* will block for up to two seconds if no packets have been sent yet.
* Returns the first packet that's sent through {@link #sendPacket(Packet)}
* and that has not been returned by earlier calls to this method.
*
* @return a sent packet.
* @throws InterruptedException
*/
public Packet getSentPacket() throws InterruptedException {
return queue.poll(2, TimeUnit.SECONDS);
return queue.poll();
}
/**
* Returns the first packet that's sent through {@link #sendPacket(Packet)}
* and that has not been returned by earlier calls to this method. This
* method will block for up to the specified number of seconds if no packets
* have been sent yet.
*
* @return a sent packet.
* @throws InterruptedException
*/
public Packet getSentPacket(int wait) throws InterruptedException {
return queue.poll(wait, TimeUnit.SECONDS);
}
/**

View file

@ -3,8 +3,6 @@
* $Revision$
* $Date$
*
* Copyright 2003-2007 Jive Software.
*
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at

View file

@ -3,7 +3,7 @@
* $Revision$
* $Date$
*
* Copyright 2003-2007 Jive Software.
* Copyright 2013 Robin Collier
*
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -17,61 +17,52 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smack;
import java.io.IOException;
import java.io.StringReader;
import org.xmlpull.mxp1.MXParser;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
final public class TestUtils
{
private TestUtils() {}
public static XmlPullParser getIQParser(String stanza)
{
return getParser(stanza, "iq");
}
public static XmlPullParser getMessageParser(String stanza)
{
return getParser(stanza, "message");
}
public static XmlPullParser getPresenceParser(String stanza)
{
return getParser(stanza, "presence");
}
public static XmlPullParser getParser(String stanza, String startTag)
{
XmlPullParser parser = new MXParser();
try
{
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
parser.setInput(new StringReader(stanza));
boolean found = false;
while (!found)
{
if ((parser.next() == XmlPullParser.START_TAG) && parser.getName().equals(startTag))
found = true;
}
if (!found)
throw new IllegalArgumentException("Cannot parse start tag [" + startTag + "] from stanze [" + stanza + "]");
}
catch (XmlPullParserException e)
{
throw new RuntimeException(e);
}
catch (IOException e)
{
throw new RuntimeException(e);
}
return parser;
}
}
package org.jivesoftware.smack;
import java.io.IOException;
import java.io.StringReader;
import org.xmlpull.mxp1.MXParser;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
final public class TestUtils {
private TestUtils() {
}
public static XmlPullParser getIQParser(String stanza) {
return getParser(stanza, "iq");
}
public static XmlPullParser getMessageParser(String stanza) {
return getParser(stanza, "message");
}
public static XmlPullParser getPresenceParser(String stanza) {
return getParser(stanza, "presence");
}
public static XmlPullParser getParser(String stanza, String startTag) {
XmlPullParser parser = new MXParser();
try {
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
parser.setInput(new StringReader(stanza));
boolean found = false;
while (!found) {
if ((parser.next() == XmlPullParser.START_TAG) && parser.getName().equals(startTag))
found = true;
}
if (!found)
throw new IllegalArgumentException("Cannot parse start tag [" + startTag + "] from stanza [" + stanza
+ "]");
} catch (XmlPullParserException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
return parser;
}
}

View file

@ -3,8 +3,6 @@
* $Revision$
* $Date$
*
* Copyright 2003-2007 Jive Software.
*
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -17,80 +15,90 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smack;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.IQ.Type;
public class ThreadedDummyConnection extends DummyConnection
{
private BlockingQueue<IQ> replyQ = new ArrayBlockingQueue<IQ>(1);
private BlockingQueue<Packet> messageQ = new LinkedBlockingQueue<Packet>(5);
@Override
public void sendPacket(Packet packet)
{
super.sendPacket(packet);
if ((packet instanceof IQ) && !replyQ.isEmpty())
{
// Set reply packet to match one being sent. We haven't started the
// other thread yet so this is still safe.
IQ replyPacket = replyQ.peek();
replyPacket.setPacketID(packet.getPacketID());
replyPacket.setFrom(packet.getTo());
replyPacket.setTo(packet.getFrom());
replyPacket.setType(Type.RESULT);
new ProcessQueue(replyQ).start();
}
}
public void addMessage(Message msgToProcess)
{
messageQ.add(msgToProcess);
}
public void addIQReply(IQ reply)
{
replyQ.add(reply);
}
public void processMessages()
{
if (!messageQ.isEmpty())
new ProcessQueue(messageQ).start();
else
System.out.println("No messages to process");
}
class ProcessQueue extends Thread
{
private BlockingQueue<? extends Packet> processQ;
ProcessQueue(BlockingQueue<? extends Packet> queue)
{
processQ = queue;
}
@Override
public void run()
{
try
{
processPacket(processQ.take());
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
};
}
package org.jivesoftware.smack;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.IQ.Type;
/**
*
* @author Robin Collier
*
*/
public class ThreadedDummyConnection extends DummyConnection {
private BlockingQueue<IQ> replyQ = new ArrayBlockingQueue<IQ>(1);
private BlockingQueue<Packet> messageQ = new LinkedBlockingQueue<Packet>(5);
private volatile boolean timeout = false;
@Override
public void sendPacket(Packet packet) {
super.sendPacket(packet);
if (packet instanceof IQ && !timeout) {
timeout = false;
// Set reply packet to match one being sent. We haven't started the
// other thread yet so this is still safe.
IQ replyPacket = replyQ.peek();
// If no reply has been set via addIQReply, then we create a simple reply
if (replyPacket == null) {
replyPacket = IQ.createResultIQ((IQ) packet);
replyQ.add(replyPacket);
}
replyPacket.setPacketID(packet.getPacketID());
replyPacket.setFrom(packet.getTo());
replyPacket.setTo(packet.getFrom());
replyPacket.setType(Type.RESULT);
new ProcessQueue(replyQ).start();
}
}
/**
* Calling this method will cause the next sendPacket call with an IQ packet to timeout.
* This is accomplished by simply stopping the auto creating of the reply packet
* or processing one that was entered via {@link #processPacket(Packet)}.
*/
public void setTimeout() {
timeout = true;
}
public void addMessage(Message msgToProcess) {
messageQ.add(msgToProcess);
}
public void addIQReply(IQ reply) {
replyQ.add(reply);
}
public void processMessages() {
if (!messageQ.isEmpty())
new ProcessQueue(messageQ).start();
else
System.out.println("No messages to process");
}
class ProcessQueue extends Thread {
private BlockingQueue<? extends Packet> processQ;
ProcessQueue(BlockingQueue<? extends Packet> queue) {
processQ = queue;
}
@Override
public void run() {
try {
processPacket(processQ.take());
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
}

View file

@ -3,7 +3,7 @@
* $Revision$
* $Date$
*
* Copyright 2003-2007 Jive Software.
* Copyright 2011 Robin Collier
*
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -25,7 +25,12 @@ import static org.junit.Assert.assertFalse;
import org.jivesoftware.smack.filter.FromMatchesFilter;
import org.jivesoftware.smack.packet.Packet;
import org.junit.Test;
/**
*
* @author Robin Collier
*
*/
public class FromMatchesFilterTest {
private static final String BASE_JID1 = "ss@muc.myserver.com";
private static final String FULL_JID1_R1 = BASE_JID1 + "/resource";

View file

@ -0,0 +1,159 @@
package org.jivesoftware.smack.keepalive;
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Properties;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.DummyConnection;
import org.jivesoftware.smack.PacketInterceptor;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.TestUtils;
import org.jivesoftware.smack.ThreadedDummyConnection;
import org.jivesoftware.smack.filter.IQTypeFilter;
import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.keepalive.KeepAliveManager;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.ping.PingFailedListener;
import org.jivesoftware.smack.ping.packet.Ping;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class KeepaliveTest {
private static final long PING_MINIMUM = 1000;
private static String TO = "juliet@capulet.lit/balcony";
private static String ID = "s2c1";
private static Properties outputProperties = new Properties();
{
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
}
private int originalTimeout;
@Before
public void resetProperties()
{
SmackConfiguration.setKeepAliveInterval(-1);
originalTimeout = SmackConfiguration.getPacketReplyTimeout();
SmackConfiguration.setPacketReplyTimeout(1000);
}
@After
public void restoreProperties()
{
SmackConfiguration.setPacketReplyTimeout(originalTimeout);
}
/*
* Stanza copied from spec
*/
@Test
public void validatePingStanzaXML() throws Exception {
// @formatter:off
String control = "<iq to='juliet@capulet.lit/balcony' id='s2c1' type='get'>"
+ "<ping xmlns='urn:xmpp:ping'/></iq>";
// @formatter:on
Ping ping = new Ping(TO);
ping.setPacketID(ID);
assertXMLEqual(control, ping.toXML());
}
@Test
public void serverPingFailSingleConnection() throws Exception {
DummyConnection connection = getConnection();
CountDownLatch latch = new CountDownLatch(2);
addInterceptor(connection, latch);
addPingFailedListener(connection, latch);
// Time based testing kind of sucks, but this should be reliable on a DummyConnection since there
// is no actual server involved. This will provide enough time to ping and wait for the lack of response.
assertTrue(latch.await(getWaitTime(), TimeUnit.MILLISECONDS));
}
@Test
public void serverPingSuccessfulSingleConnection() throws Exception {
ThreadedDummyConnection connection = getThreadedConnection();
final CountDownLatch latch = new CountDownLatch(1);
connection.addPacketListener(new PacketListener() {
@Override
public void processPacket(Packet packet) {
latch.countDown();
}
}, new IQTypeFilter(IQ.Type.RESULT));
// Time based testing kind of sucks, but this should be reliable on a DummyConnection since there
// is no actual server involved. This will provide enough time to ping and wait for the lack of response.
assertTrue(latch.await(getWaitTime(), TimeUnit.MILLISECONDS));
}
@Test
public void serverPingFailMultipleConnection() throws Exception {
CountDownLatch latch = new CountDownLatch(6);
SmackConfiguration.setPacketReplyTimeout(15000);
DummyConnection con1 = getConnection();
addInterceptor(con1, latch);
addPingFailedListener(con1, latch);
DummyConnection con2 = getConnection();
addInterceptor(con2, latch);
addPingFailedListener(con2, latch);
DummyConnection con3 = getConnection();
addInterceptor(con3, latch);
addPingFailedListener(con2, latch);
assertTrue(latch.await(getWaitTime(), TimeUnit.MILLISECONDS));
}
private void addPingFailedListener(DummyConnection con, final CountDownLatch latch) {
KeepAliveManager manager = KeepAliveManager.getInstanceFor(con);
manager.addPingFailedListener(new PingFailedListener() {
@Override
public void pingFailed() {
latch.countDown();
}
});
}
private DummyConnection getConnection() {
DummyConnection con = new DummyConnection();
KeepAliveManager mgr = KeepAliveManager.getInstanceFor(con);
mgr.setPingInterval(PING_MINIMUM);
return con;
}
private ThreadedDummyConnection getThreadedConnection() {
ThreadedDummyConnection con = new ThreadedDummyConnection();
KeepAliveManager mgr = KeepAliveManager.getInstanceFor(con);
mgr.setPingInterval(PING_MINIMUM);
return con;
}
private void addInterceptor(final Connection con, final CountDownLatch latch) {
con.addPacketInterceptor(new PacketInterceptor() {
@Override
public void interceptPacket(Packet packet) {
con.removePacketInterceptor(this);
latch.countDown();
}
}, new PacketTypeFilter(Ping.class));
}
private long getWaitTime() {
return PING_MINIMUM + SmackConfiguration.getPacketReplyTimeout() + 3000;
}
}

View file

@ -24,7 +24,7 @@ public class DNSUtilTest {
@Test
public void xmppClientDomainJavaXTest() {
DNSResolver resolver = JavaxResolver.maybeGetInstance();
DNSResolver resolver = JavaxResolver.getInstance();
assertNotNull(resolver);
DNSUtil.setDNSResolver(resolver);
xmppClientDomainTest();
@ -32,7 +32,7 @@ public class DNSUtilTest {
@Test
public void xmppServerDomainJavaXTest() {
DNSResolver resolver = JavaxResolver.maybeGetInstance();
DNSResolver resolver = JavaxResolver.getInstance();
assertNotNull(resolver);
DNSUtil.setDNSResolver(resolver);
xmppServerDomainTest();

View file

@ -3,8 +3,6 @@
* $Revision$
* $Date$
*
* Copyright 2003-2007 Jive Software.
*
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at

View file

@ -3,8 +3,6 @@
* $Revision$
* $Date$
*
* Copyright 2003-2007 Jive Software.
*
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at

View file

@ -3,8 +3,6 @@
* $Revision$
* $Date$
*
* Copyright 2003-2007 Jive Software.
*
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at

View file

@ -3,8 +3,6 @@
* $Revision$
* $Date$
*
* Copyright 2003-2007 Jive Software.
*
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at

View file

@ -3,8 +3,6 @@
* $Revision$
* $Date$
*
* Copyright 2003-2007 Jive Software.
*
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at

View file

@ -1,168 +0,0 @@
/**
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.carbons;
import static org.junit.Assert.*;
import java.io.IOException;
import java.io.StringReader;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Properties;
import java.util.TimeZone;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smackx.packet.DelayInfo;
import org.jivesoftware.smackx.packet.DelayInformation;
import org.jivesoftware.smackx.forward.Forwarded;
import org.junit.Test;
import org.xmlpull.mxp1.MXParser;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import com.jamesmurty.utils.XMLBuilder;
public class CarbonForwardedTest {
private static Properties outputProperties = new Properties();
static {
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
}
@Test
public void forwardedTest() throws Exception {
XmlPullParser parser;
String control;
Forwarded fwd;
control = XMLBuilder.create("forwarded")
.a("xmlns", "urn:xmpp:forwarded:0")
.e("message")
.a("from", "romeo@montague.com")
.asString(outputProperties);
parser = getParser(control, "forwarded");
fwd = (Forwarded) new Forwarded.Provider().parseExtension(parser);
// no delay in packet
assertEquals(null, fwd.getDelayInfo());
// check message
assertEquals("romeo@montague.com", fwd.getForwardedPacket().getFrom());
// check end of tag
assertEquals(XmlPullParser.END_TAG, parser.getEventType());
assertEquals("forwarded", parser.getName());
}
@Test(expected=Exception.class)
public void forwardedEmptyTest() throws Exception {
XmlPullParser parser;
String control;
control = XMLBuilder.create("forwarded")
.a("xmlns", "urn:xmpp:forwarded:0")
.asString(outputProperties);
parser = getParser(control, "forwarded");
new Forwarded.Provider().parseExtension(parser);
}
@Test
public void carbonSentTest() throws Exception {
XmlPullParser parser;
String control;
Carbon cc;
Forwarded fwd;
control = XMLBuilder.create("sent")
.e("forwarded")
.a("xmlns", "urn:xmpp:forwarded:0")
.e("message")
.a("from", "romeo@montague.com")
.asString(outputProperties);
parser = getParser(control, "sent");
cc = (Carbon) new Carbon.Provider().parseExtension(parser);
fwd = cc.getForwarded();
// meta
assertEquals(Carbon.Direction.sent, cc.getDirection());
// no delay in packet
assertEquals(null, fwd.getDelayInfo());
// check message
assertEquals("romeo@montague.com", fwd.getForwardedPacket().getFrom());
// check end of tag
assertEquals(XmlPullParser.END_TAG, parser.getEventType());
assertEquals("sent", parser.getName());
}
@Test
public void carbonReceivedTest() throws Exception {
XmlPullParser parser;
String control;
Carbon cc;
control = XMLBuilder.create("received")
.e("forwarded")
.a("xmlns", "urn:xmpp:forwarded:0")
.e("message")
.a("from", "romeo@montague.com")
.asString(outputProperties);
parser = getParser(control, "received");
cc = (Carbon) new Carbon.Provider().parseExtension(parser);
assertEquals(Carbon.Direction.received, cc.getDirection());
// check end of tag
assertEquals(XmlPullParser.END_TAG, parser.getEventType());
assertEquals("received", parser.getName());
}
@Test(expected=Exception.class)
public void carbonEmptyTest() throws Exception {
XmlPullParser parser;
String control;
control = XMLBuilder.create("sent")
.a("xmlns", "urn:xmpp:forwarded:0")
.asString(outputProperties);
parser = getParser(control, "sent");
new Carbon.Provider().parseExtension(parser);
}
private XmlPullParser getParser(String control, String startTag)
throws XmlPullParserException, IOException {
XmlPullParser parser = new MXParser();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
parser.setInput(new StringReader(control));
while (true) {
if (parser.next() == XmlPullParser.START_TAG
&& parser.getName().equals(startTag)) {
break;
}
}
return parser;
}
}

View file

@ -1,6 +1,8 @@
package org.jivesoftware.smackx.entitycaps;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
@ -9,10 +11,9 @@ import java.util.LinkedList;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.util.Base32Encoder;
import org.jivesoftware.smack.util.Base64Encoder;
import org.jivesoftware.smack.util.Base64FileUrlEncoder;
import org.jivesoftware.smack.util.StringEncoder;
import org.jivesoftware.smackx.FormField;
import org.jivesoftware.smackx.entitycaps.EntityCapsManager;
import org.jivesoftware.smackx.entitycaps.cache.EntityCapsPersistentCache;
import org.jivesoftware.smackx.entitycaps.cache.SimpleDirectoryPersistentCache;
import org.jivesoftware.smackx.packet.DataForm;
@ -37,7 +38,7 @@ public class EntityCapsManagerTest {
@Test
public void testSimpleDirectoryCacheBase64() throws IOException {
EntityCapsManager.persistentCache = null;
testSimpleDirectoryCache(Base64Encoder.getInstance());
testSimpleDirectoryCache(Base64FileUrlEncoder.getInstance());
}
@Test
@ -216,9 +217,7 @@ public class EntityCapsManagerTest {
}
public static File createTempDirectory() throws IOException {
String tmpdir = System.getProperty("java.io.tmpdir");
File tmp;
tmp = File.createTempFile(tmpdir, "entityCaps");
File tmp = File.createTempFile("entity", "caps");
tmp.delete();
tmp.mkdir();
return tmp;

View file

@ -3,7 +3,7 @@
* $Revision$
* $Date$
*
* Copyright 2003-2007 Jive Software.
* Copyright 2011 Robin Collier
*
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -17,44 +17,42 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.filetransfer;
import static org.junit.Assert.*;
import org.jivesoftware.smack.DummyConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smackx.ServiceDiscoveryManager;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class FileTransferNegotiatorTest {
private DummyConnection connection;
@Before
public void setUp() throws Exception {
// Uncomment this to enable debug output
//Connection.DEBUG_ENABLED = true;
connection = new DummyConnection();
connection.connect();
connection.login("me", "secret");
new ServiceDiscoveryManager(connection);
}
@After
public void tearDown() throws Exception {
if (connection != null)
connection.disconnect();
}
@Test
public void verifyForm() throws Exception
{
FileTransferNegotiator fileNeg = FileTransferNegotiator.getInstanceFor(connection);
fileNeg.negotiateOutgoingTransfer("me", "streamid", "file", 1024, null, 10);
Packet packet = connection.getSentPacket();
assertTrue(packet.toXML().indexOf("\"stream-method\" type=\"list-single\"") != -1);
}
}
package org.jivesoftware.smackx.filetransfer;
import static org.junit.Assert.assertTrue;
import org.jivesoftware.smack.DummyConnection;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smackx.ServiceDiscoveryManager;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class FileTransferNegotiatorTest {
private DummyConnection connection;
@Before
public void setUp() throws Exception {
// Uncomment this to enable debug output
// Connection.DEBUG_ENABLED = true;
connection = new DummyConnection();
connection.connect();
connection.login("me", "secret");
new ServiceDiscoveryManager(connection);
}
@After
public void tearDown() throws Exception {
if (connection != null)
connection.disconnect();
}
@Test
public void verifyForm() throws Exception {
FileTransferNegotiator fileNeg = FileTransferNegotiator.getInstanceFor(connection);
fileNeg.negotiateOutgoingTransfer("me", "streamid", "file", 1024, null, 10);
Packet packet = connection.getSentPacket();
assertTrue(packet.toXML().indexOf("\"stream-method\" type=\"list-single\"") != -1);
}
}

View file

@ -3,7 +3,7 @@
* $Revision$
* $Date$
*
* Copyright 2003-2007 Jive Software.
* Copyright 2011 Robin Collier
*
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -17,53 +17,50 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.muc;
import org.jivesoftware.smackx.FormField;
import org.jivesoftware.smackx.muc.RoomInfo;
import org.jivesoftware.smackx.packet.DataForm;
import org.jivesoftware.smackx.packet.DiscoverInfo;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class RoomInfoTest
{
@Test
public void validateRoomWithEmptyForm()
{
DataForm dataForm = new DataForm("result");
DiscoverInfo discoInfo = new DiscoverInfo();
discoInfo.addExtension(dataForm);
RoomInfo roomInfo = new RoomInfo(discoInfo);
assertTrue(roomInfo.getDescription().isEmpty());
assertTrue(roomInfo.getSubject().isEmpty());
assertEquals(-1, roomInfo.getOccupantsCount());
}
@Test
public void validateRoomWithForm()
{
DataForm dataForm = new DataForm("result");
FormField desc = new FormField("muc#roominfo_description");
desc.addValue("The place for all good witches!");
dataForm.addField(desc);
FormField subject = new FormField("muc#roominfo_subject");
subject.addValue("Spells");
dataForm.addField(subject);
FormField occupants = new FormField("muc#roominfo_occupants");
occupants.addValue("3");
dataForm.addField(occupants);
DiscoverInfo discoInfo = new DiscoverInfo();
discoInfo.addExtension(dataForm);
RoomInfo roomInfo = new RoomInfo(discoInfo);
assertEquals("The place for all good witches!", roomInfo.getDescription());
assertEquals("Spells", roomInfo.getSubject());
assertEquals(3, roomInfo.getOccupantsCount());
}
}
package org.jivesoftware.smackx.muc;
import org.jivesoftware.smackx.FormField;
import org.jivesoftware.smackx.muc.RoomInfo;
import org.jivesoftware.smackx.packet.DataForm;
import org.jivesoftware.smackx.packet.DiscoverInfo;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class RoomInfoTest {
@Test
public void validateRoomWithEmptyForm() {
DataForm dataForm = new DataForm("result");
DiscoverInfo discoInfo = new DiscoverInfo();
discoInfo.addExtension(dataForm);
RoomInfo roomInfo = new RoomInfo(discoInfo);
assertTrue(roomInfo.getDescription().isEmpty());
assertTrue(roomInfo.getSubject().isEmpty());
assertEquals(-1, roomInfo.getOccupantsCount());
}
@Test
public void validateRoomWithForm() {
DataForm dataForm = new DataForm("result");
FormField desc = new FormField("muc#roominfo_description");
desc.addValue("The place for all good witches!");
dataForm.addField(desc);
FormField subject = new FormField("muc#roominfo_subject");
subject.addValue("Spells");
dataForm.addField(subject);
FormField occupants = new FormField("muc#roominfo_occupants");
occupants.addValue("3");
dataForm.addField(occupants);
DiscoverInfo discoInfo = new DiscoverInfo();
discoInfo.addExtension(dataForm);
RoomInfo roomInfo = new RoomInfo(discoInfo);
assertEquals("The place for all good witches!", roomInfo.getDescription());
assertEquals("Spells", roomInfo.getSubject());
assertEquals(3, roomInfo.getOccupantsCount());
}
}

View file

@ -1,38 +0,0 @@
/**
* Copyright 2012 Florian Schmaus
*
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.ping;
import static org.junit.Assert.assertEquals;
import org.jivesoftware.smackx.ping.packet.Ping;
import org.jivesoftware.smackx.ping.packet.Pong;
import org.junit.Test;
public class PingPongTest {
@Test
public void createPongfromPingTest() {
Ping ping = new Ping("from@sender.local/resourceFrom", "to@receiver.local/resourceTo");
// create a pong from a ping
Pong pong = new Pong(ping);
assertEquals(pong.getFrom(), ping.getTo());
assertEquals(pong.getTo(), ping.getFrom());
assertEquals(pong.getPacketID(), ping.getPacketID());
}
}

View file

@ -0,0 +1,222 @@
/**
* Copyright 2012 Florian Schmaus
*
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.ping;
import org.jivesoftware.smack.DummyConnection;
import org.jivesoftware.smack.TestUtils;
import org.jivesoftware.smack.ThreadedDummyConnection;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.ping.packet.Ping;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.packet.DiscoverInfo;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
public class PingTest {
private DummyConnection dummyCon;
private ThreadedDummyConnection threadedCon;
@Before
public void setup() {
dummyCon = new DummyConnection();
threadedCon = new ThreadedDummyConnection();
}
@Test
public void checkProvider() throws Exception {
// @formatter:off
String control = "<iq from='capulet.lit' to='juliet@capulet.lit/balcony' id='s2c1' type='get'>"
+ "<ping xmlns='urn:xmpp:ping'/>"
+ "</iq>";
// @formatter:on
DummyConnection con = new DummyConnection();
// Enable ping for this connection
PingManager.getInstanceFor(con);
IQ pingRequest = PacketParserUtils.parseIQ(TestUtils.getIQParser(control), con);
assertTrue(pingRequest instanceof Ping);
con.processPacket(pingRequest);
Packet pongPacket = con.getSentPacket();
assertTrue(pongPacket instanceof IQ);
IQ pong = (IQ) pongPacket;
assertEquals("juliet@capulet.lit/balcony", pong.getFrom());
assertEquals("capulet.lit", pong.getTo());
assertEquals("s2c1", pong.getPacketID());
assertEquals(IQ.Type.RESULT, pong.getType());
}
@Test
public void checkSendingPing() throws Exception {
dummyCon = new DummyConnection();
PingManager pinger = PingManager.getInstanceFor(dummyCon);
pinger.ping("test@myserver.com");
Packet sentPacket = dummyCon.getSentPacket();
assertTrue(sentPacket instanceof Ping);
}
@Test
public void checkSuccessfulPing() throws Exception {
threadedCon = new ThreadedDummyConnection();
PingManager pinger = PingManager.getInstanceFor(threadedCon);
boolean pingSuccess = pinger.ping("test@myserver.com");
assertTrue(pingSuccess);
}
/**
* DummyConnection will not reply so it will timeout.
* @throws Exception
*/
@Test
public void checkFailedPingOnTimeout() throws Exception {
dummyCon = new DummyConnection();
PingManager pinger = PingManager.getInstanceFor(dummyCon);
boolean pingSuccess = pinger.ping("test@myserver.com");
assertFalse(pingSuccess);
}
/**
* Server returns an exception for entity.
* @throws Exception
*/
@Test
public void checkFailedPingToEntityError() throws Exception {
threadedCon = new ThreadedDummyConnection();
//@formatter:off
String reply =
"<iq type='error' id='qrzSp-16' to='test@myserver.com'>" +
"<ping xmlns='urn:xmpp:ping'/>" +
"<error type='cancel'>" +
"<service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
"</error>" +
"</iq>";
//@formatter:on
IQ serviceUnavailable = PacketParserUtils.parseIQ(TestUtils.getIQParser(reply), threadedCon);
threadedCon.addIQReply(serviceUnavailable);
PingManager pinger = PingManager.getInstanceFor(threadedCon);
boolean pingSuccess = pinger.ping("test@myserver.com");
assertFalse(pingSuccess);
}
@Test
public void checkPingToServerSuccess() throws Exception {
ThreadedDummyConnection con = new ThreadedDummyConnection();
PingManager pinger = PingManager.getInstanceFor(con);
boolean pingSuccess = pinger.pingMyServer();
assertTrue(pingSuccess);
}
/**
* Server returns an exception.
* @throws Exception
*/
@Test
public void checkPingToServerError() throws Exception {
ThreadedDummyConnection con = new ThreadedDummyConnection();
//@formatter:off
String reply =
"<iq type='error' id='qrzSp-16' to='test@myserver.com' from='" + con.getServiceName() + "'>" +
"<ping xmlns='urn:xmpp:ping'/>" +
"<error type='cancel'>" +
"<service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
"</error>" +
"</iq>";
//@formatter:on
IQ serviceUnavailable = PacketParserUtils.parseIQ(TestUtils.getIQParser(reply), con);
con.addIQReply(serviceUnavailable);
PingManager pinger = PingManager.getInstanceFor(con);
boolean pingSuccess = pinger.pingMyServer();
assertTrue(pingSuccess);
}
@Test
public void checkPingToServerTimeout() throws Exception {
DummyConnection con = new DummyConnection();
PingManager pinger = PingManager.getInstanceFor(con);
boolean pingSuccess = pinger.pingMyServer();
assertFalse(pingSuccess);
}
@Test
public void checkSuccessfulDiscoRequest() throws Exception {
ThreadedDummyConnection con = new ThreadedDummyConnection();
DiscoverInfo info = new DiscoverInfo();
info.addFeature(Ping.NAMESPACE);
//@formatter:off
String reply =
"<iq type='result' id='qrzSp-16' to='test@myserver.com'>" +
"<query xmlns='http://jabber.org/protocol/disco#info'><identity category='client' type='pc' name='Pidgin'/>" +
"<feature var='urn:xmpp:ping'/>" +
"</query></iq>";
//@formatter:on
IQ discoReply = PacketParserUtils.parseIQ(TestUtils.getIQParser(reply), con);
con.addIQReply(discoReply);
PingManager pinger = PingManager.getInstanceFor(con);
boolean pingSupported = pinger.isPingSupported("test@myserver.com");
assertTrue(pingSupported);
}
@Test
public void checkUnuccessfulDiscoRequest() throws Exception {
ThreadedDummyConnection con = new ThreadedDummyConnection();
DiscoverInfo info = new DiscoverInfo();
info.addFeature(Ping.NAMESPACE);
//@formatter:off
String reply =
"<iq type='result' id='qrzSp-16' to='test@myserver.com'>" +
"<query xmlns='http://jabber.org/protocol/disco#info'><identity category='client' type='pc' name='Pidgin'/>" +
"<feature var='urn:xmpp:noping'/>" +
"</query></iq>";
//@formatter:on
IQ discoReply = PacketParserUtils.parseIQ(TestUtils.getIQParser(reply), con);
con.addIQReply(discoReply);
PingManager pinger = PingManager.getInstanceFor(con);
boolean pingSupported = pinger.isPingSupported("test@myserver.com");
assertFalse(pingSupported);
}
}

View file

@ -3,7 +3,7 @@
* $Revision$
* $Date$
*
* Copyright 2003-2007 Jive Software.
* Copyright 2011 Robin Collier
*
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -33,7 +33,12 @@ import org.jivesoftware.smackx.packet.DiscoverInfo.Identity;
import org.jivesoftware.smackx.pubsub.packet.PubSub;
import org.junit.Assert;
import org.junit.Test;
/**
*
* @author Robin Collier
*
*/
public class ConfigureFormTest
{
@Test
@ -83,7 +88,9 @@ public class ConfigureFormTest
Node node = mgr.getNode("princely_musings");
SmackConfiguration.setPacketReplyTimeout(100);
SmackConfiguration.setPacketReplyTimeout(100);
con.setTimeout();
node.getNodeConfiguration();
}
}

View file

@ -3,7 +3,7 @@
* $Revision$
* $Date$
*
* Copyright 2003-2007 Jive Software.
* Copyright 2011 Robin Collier
*
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -19,21 +19,31 @@
*/
package org.jivesoftware.smackx.pubsub;
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import java.io.Reader;
import java.io.StringReader;
import org.jivesoftware.smack.ThreadedDummyConnection;
import org.jivesoftware.smackx.pubsub.provider.ItemsProvider;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.xmlpull.mxp1.MXParser;
import org.xmlpull.v1.XmlPullParser;
import static org.custommonkey.xmlunit.XMLAssert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.Reader;
import java.io.StringReader;
import org.jivesoftware.smack.TestUtils;
import org.jivesoftware.smack.ThreadedDummyConnection;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
import org.jivesoftware.smackx.pubsub.provider.ItemsProvider;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.xmlpull.mxp1.MXParser;
import org.xmlpull.v1.XmlPullParser;
/**
*
* @author Robin Collier
*
*/
public class ItemValidationTest
{
private ThreadedDummyConnection connection;
@ -90,37 +100,146 @@ public class ItemValidationTest
assertXMLEqual(nodeIdCtrl, itemWithNodeId.toXML());
}
// @Test
// public void parseBasicItemWithoutNode() throws Exception
// {
// XmlPullParser parser = new MXParser();
// Reader reader = new StringReader(
// "<event xmlns='http://jabber.org/protocol/pubsub#event'>" +
// "<items node='testNode'>" +
// "<item id='testid1' />" +
// "</items></event>");
// parser.setInput(reader);
// ItemsProvider itemsProvider = new ItemsProvider();
// ItemsExtension ext = (ItemsExtension) itemsProvider.parseExtension(parser);
// Item basicItem = (Item) ext.getItems().get(0);
//
// assertEquals("testid1", basicItem.getId());
// assertNull(basicItem.getNode());
// }
// @Test
// public void parseBasicItemNode() throws Exception
// {
// BlockingQueue<Item> itemQ = new ArrayBlockingQueue<Item>(1);
//
// setupListener(itemQ);
// Message itemMsg = getMessage("<item id='testid1' node='testNode'>");
// connection.addMessage(itemMsg);
//
// Item basicItem = itemQ.poll(2, TimeUnit.SECONDS);
//
// assertNotNull(basicItem);
// assertEquals("testid1", basicItem.getId());
// assertEquals("testNode", basicItem.getNode());
// }
@Test
public void parseBasicItem() throws Exception
{
XmlPullParser parser = TestUtils.getMessageParser(
"<message from='pubsub.myserver.com' to='francisco@denmark.lit' id='foo'>" +
"<event xmlns='http://jabber.org/protocol/pubsub#event'>" +
"<items node='testNode'>" +
"<item id='testid1' />" +
"</items>" +
"</event>" +
"</message>");
Packet message = PacketParserUtils.parseMessage(parser);
PacketExtension eventExt = message.getExtension(PubSubNamespace.EVENT.getXmlns());
assertTrue(eventExt instanceof EventElement);
EventElement event = (EventElement) eventExt;
assertEquals(EventElementType.items, event.getEventType());
assertEquals(1, event.getExtensions().size());
assertTrue(event.getExtensions().get(0) instanceof ItemsExtension);
assertEquals(1, ((ItemsExtension)event.getExtensions().get(0)).items.size());
PacketExtension itemExt = ((ItemsExtension)event.getExtensions().get(0)).items.get(0);
assertTrue(itemExt instanceof Item);
assertEquals("testid1", ((Item)itemExt).getId());
}
@Test
public void parseSimplePayloadItem() throws Exception
{
String itemContent = "<foo xmlns='smack:test'>Some text</foo>";
XmlPullParser parser = TestUtils.getMessageParser(
"<message from='pubsub.myserver.com' to='francisco@denmark.lit' id='foo'>" +
"<event xmlns='http://jabber.org/protocol/pubsub#event'>" +
"<items node='testNode'>" +
"<item id='testid1' >" +
itemContent +
"</item>" +
"</items>" +
"</event>" +
"</message>");
Packet message = PacketParserUtils.parseMessage(parser);
PacketExtension eventExt = message.getExtension(PubSubNamespace.EVENT.getXmlns());
EventElement event = (EventElement) eventExt;
PacketExtension itemExt = ((ItemsExtension)event.getExtensions().get(0)).items.get(0);
assertTrue(itemExt instanceof PayloadItem<?>);
PayloadItem<?> item = (PayloadItem<?>)itemExt;
assertEquals("testid1", item.getId());
assertTrue(item.getPayload() instanceof SimplePayload);
SimplePayload payload = (SimplePayload) item.getPayload();
assertEquals("foo", payload.getElementName());
assertEquals("smack:test", payload.getNamespace());
assertXMLEqual(itemContent, payload.toXML());
}
@Test
public void parseComplexItem() throws Exception
{
String itemContent =
"<entry xmlns='http://www.w3.org/2005/Atom'>" +
"<title>Soliloquy</title>" +
"<summary>" +
"To be, or not to be: that is the question:" +
"Whether 'tis nobler in the mind to suffer" +
"The slings and arrows of outrageous fortune," +
"Or to take arms against a sea of troubles," +
"And by opposing end them?" +
"</summary>" +
"<link rel='alternate' type='text/html' href='http://denmark.lit/2003/12/13/atom03'/>" +
"<id>tag:denmark.lit,2003:entry-32397</id>" +
"<published>2003-12-13T18:30:02Z</published>" +
"<updated>2003-12-13T18:30:02Z</updated>" +
"</entry>";
XmlPullParser parser = TestUtils.getMessageParser(
"<message from='pubsub.myserver.com' to='francisco@denmark.lit' id='foo'>" +
"<event xmlns='http://jabber.org/protocol/pubsub#event'>" +
"<items node='testNode'>" +
"<item id='testid1' >" +
itemContent +
"</item>" +
"</items>" +
"</event>" +
"</message>");
Packet message = PacketParserUtils.parseMessage(parser);
PacketExtension eventExt = message.getExtension(PubSubNamespace.EVENT.getXmlns());
EventElement event = (EventElement) eventExt;
PacketExtension itemExt = ((ItemsExtension)event.getExtensions().get(0)).items.get(0);
assertTrue(itemExt instanceof PayloadItem<?>);
PayloadItem<?> item = (PayloadItem<?>)itemExt;
assertEquals("testid1", item.getId());
assertTrue(item.getPayload() instanceof SimplePayload);
SimplePayload payload = (SimplePayload) item.getPayload();
assertEquals("entry", payload.getElementName());
assertEquals("http://www.w3.org/2005/Atom", payload.getNamespace());
assertXMLEqual(itemContent, payload.toXML());
}
@Test
public void parseEmptyTag() throws Exception
{
String itemContent = "<foo xmlns='smack:test'><bar/></foo>";
XmlPullParser parser = TestUtils.getMessageParser(
"<message from='pubsub.myserver.com' to='francisco@denmark.lit' id='foo'>" +
"<event xmlns='http://jabber.org/protocol/pubsub#event'>" +
"<items node='testNode'>" +
"<item id='testid1' >" +
itemContent +
"</item>" +
"</items>" +
"</event>" +
"</message>");
Packet message = PacketParserUtils.parseMessage(parser);
PacketExtension eventExt = message.getExtension(PubSubNamespace.EVENT.getXmlns());
assertTrue(eventExt instanceof EventElement);
EventElement event = (EventElement) eventExt;
assertEquals(EventElementType.items, event.getEventType());
assertEquals(1, event.getExtensions().size());
assertTrue(event.getExtensions().get(0) instanceof ItemsExtension);
assertEquals(1, ((ItemsExtension)event.getExtensions().get(0)).items.size());
PacketExtension itemExt = ((ItemsExtension)event.getExtensions().get(0)).items.get(0);
assertTrue(itemExt instanceof PayloadItem<?>);
PayloadItem<?> item = (PayloadItem<?>)itemExt;
assertEquals("testid1", item.getId());
assertTrue(item.getPayload() instanceof SimplePayload);
assertXMLEqual(itemContent, ((SimplePayload)item.getPayload()).toXML());
}
}

View file

@ -13,16 +13,14 @@
*/
package org.jivesoftware.smackx.receipts;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.io.StringReader;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Properties;
import java.util.TimeZone;
import org.jivesoftware.smack.DummyConnection;
import org.jivesoftware.smack.packet.Message;
@ -76,7 +74,7 @@ public class DeliveryReceiptTest {
DeliveryReceiptManager drm = DeliveryReceiptManager.getInstanceFor(c);
TestReceiptReceivedListener rrl = new TestReceiptReceivedListener();
drm.registerReceiptReceivedListener(rrl);
drm.addReceiptReceivedListener(rrl);
Message m = new Message("romeo@montague.com", Message.Type.normal);
m.setFrom("julia@capulet.com");
@ -88,7 +86,7 @@ public class DeliveryReceiptTest {
assertEquals("original-test-id", rrl.receiptId);
}
private static class TestReceiptReceivedListener implements DeliveryReceiptManager.ReceiptReceivedListener {
private static class TestReceiptReceivedListener implements ReceiptReceivedListener {
public String receiptId = null;
@Override
public void onReceiptReceived(String fromJid, String toJid, String receiptId) {