Merged the 3.2 branch back into trunk.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@12588 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
rcollier 2011-09-09 01:26:22 +00:00
commit 3f89df061d
16 changed files with 383 additions and 240 deletions

View File

@ -26,9 +26,9 @@
<!-- Smack Version -->
<property name="version.major" value="3" />
<property name="version.minor" value="2" />
<property name="version.minor" value="3" />
<property name="version.revision" value="0" />
<property name="version.extra" value="" />
<property name="version.extra" value="SNAPSHOT" />
<if>
<equals arg1="${version.extra}" arg2=""/>

View File

@ -28,4 +28,7 @@
<!-- Port of the local Socks5 proxy -->
<localSocks5ProxyPort>7777</localSocks5ProxyPort>
<!-- Port of the local Socks5 proxy -->
<packetCollectorSize>10000</packetCollectorSize>
</smack>

View File

@ -141,6 +141,17 @@ hr {
<div id="pageBody">
<h2>3.2.1 -- <span style="font-weight: normal;">July 4, 2011</span></h2>
<h3>Bug</h3>
<ul>
<li>[<a href='http://issues.igniterealtime.org/browse/SMACK-129'>SMACK-129</a>] - MultiUserChat will Store Messages in its PacketCollector irregardless of whether or not they are being read</li>
<li>[<a href='http://issues.igniterealtime.org/browse/SMACK-230'>SMACK-230</a>] - Disconnect Can Cause Null Pointer Exception</li>
<li>[<a href='http://issues.igniterealtime.org/browse/SMACK-273'>SMACK-273</a>] - Bug in RoomListenerMultiplexor.java</li>
<li>[<a href='http://issues.igniterealtime.org/browse/SMACK-329'>SMACK-329</a>] - XHTMLText uses improper format for br tag</li>
<li>[<a href='http://issues.igniterealtime.org/browse/SMACK-338'>SMACK-338</a>] - IBB filetransfer doesn&#39;t work as expected</li>
<li>[<a href='http://issues.igniterealtime.org/browse/SMACK-324'>SMACK-324</a>] - Investigate SASL issue with jabberd2 servers</li>
</ul>
<h2>3.2.0 -- <span style="font-weight: normal;">May 3, 2011</span></h2>
<h3>New Feature</h3>
<ul>

View File

@ -32,8 +32,9 @@ import java.util.LinkedList;
* use than a {@link PacketListener} when you need to wait for a specific
* result.<p>
*
* Each packet collector will queue up to 2^16 packets for processing before
* older packets are automatically dropped.
* Each packet collector will queue up a configured number of packets for processing before
* older packets are automatically dropped. The default number is retrieved by
* {@link SmackConfiguration#getPacketCollectorSize()}.
*
* @see Connection#createPacketCollector(PacketFilter)
* @author Matt Tucker
@ -45,7 +46,7 @@ public class PacketCollector {
* reached, older packets will be automatically dropped from the queue as
* new packets are added.
*/
private static final int MAX_PACKETS = 65536;
private int maxPackets = SmackConfiguration.getPacketCollectorSize();
private PacketFilter packetFilter;
private LinkedList<Packet> resultQueue;
@ -65,6 +66,19 @@ public class PacketCollector {
this.resultQueue = new LinkedList<Packet>();
}
/**
* Creates a new packet collector. If the packet filter is <tt>null</tt>, then
* all packets will match this collector.
*
* @param conection the connection the collector is tied to.
* @param packetFilter determines which packets will be returned by this collector.
* @param maxSize the maximum number of packets that will be stored in the collector.
*/
protected PacketCollector(Connection conection, PacketFilter packetFilter, int maxSize) {
this(conection, packetFilter);
maxPackets = maxSize;
}
/**
* Explicitly cancels the packet collector so that no more results are
* queued up. Once a packet collector has been cancelled, it cannot be
@ -180,7 +194,7 @@ public class PacketCollector {
}
if (packetFilter == null || packetFilter.accept(packet)) {
// If the max number of packets has been reached, remove the oldest one.
if (resultQueue.size() == MAX_PACKETS) {
if (resultQueue.size() == maxPackets) {
resultQueue.removeLast();
}
// Add the new packet.

View File

@ -44,14 +44,15 @@ import java.util.*;
*/
public final class SmackConfiguration {
private static final String SMACK_VERSION = "3.2.0";
private static final String SMACK_VERSION = "3.2.1";
private static int packetReplyTimeout = 5000;
private static int keepAliveInterval = 30000;
private static Vector<String> defaultMechs = new Vector<String>();
private static boolean localSocks5ProxyEnabled = true;
private static int localSocks5ProxyPort = 7777;
private static int localSocks5ProxyPort = 7778;
private static int packetCollectorSize = 5000;
private SmackConfiguration() {
}
@ -85,20 +86,22 @@ public final class SmackConfiguration {
parseClassToLoad(parser);
}
else if (parser.getName().equals("packetReplyTimeout")) {
packetReplyTimeout =
parseIntProperty(parser, packetReplyTimeout);
packetReplyTimeout = parseIntProperty(parser, packetReplyTimeout);
}
else if (parser.getName().equals("keepAliveInterval")) {
keepAliveInterval = parseIntProperty(parser, keepAliveInterval);
}
else if (parser.getName().equals("mechName")) {
defaultMechs.add(parser.nextText());
} else if (parser.getName().equals("localSocks5ProxyEnabled")) {
localSocks5ProxyEnabled = Boolean.parseBoolean(parser
.nextText());
} else if (parser.getName().equals("localSocks5ProxyPort")) {
localSocks5ProxyPort = parseIntProperty(parser,
localSocks5ProxyPort);
}
else if (parser.getName().equals("localSocks5ProxyEnabled")) {
localSocks5ProxyEnabled = Boolean.parseBoolean(parser.nextText());
}
else if (parser.getName().equals("localSocks5ProxyPort")) {
localSocks5ProxyPort = parseIntProperty(parser, localSocks5ProxyPort);
}
else if (parser.getName().equals("packetCollectorSize")) {
packetCollectorSize = parseIntProperty(parser, packetCollectorSize);
}
}
eventType = parser.next();
@ -184,6 +187,26 @@ public final class SmackConfiguration {
keepAliveInterval = interval;
}
/**
* Gets the default max size of a packet collector before it will delete
* the older packets.
*
* @return The number of packets to queue before deleting older packets.
*/
public static int getPacketCollectorSize() {
return packetCollectorSize;
}
/**
* Sets the default max size of a packet collector before it will delete
* the older packets.
*
* @param The number of packets to queue before deleting older packets.
*/
public static void setPacketCollectorSize(int collectorSize) {
packetCollectorSize = collectorSize;
}
/**
* Add a SASL mechanism to the list to be used.
*

View File

@ -419,7 +419,7 @@ public class XMPPConnection extends Connection {
saslAuthentication.init();
}
public void disconnect(Presence unavailablePresence) {
public synchronized void disconnect(Presence unavailablePresence) {
// If not connected, ignore this request.
if (packetReader == null || packetWriter == null) {
return;

View File

@ -115,7 +115,7 @@ public class ServiceDiscoveryManager {
/**
* Returns the type of client that will be returned when asked for the client identity in a
* disco request. The valid types are defined by the category client. Follow this link to learn
* the possible types: <a href="http://www.jabber.org/registrar/disco-categories.html#client">Jabber::Registrar</a>.
* the possible types: <a href="http://xmpp.org/registrar/disco-categories.html#client">Jabber::Registrar</a>.
*
* @return the type of client that will be returned when asked for the client identity in a
* disco request.
@ -127,7 +127,7 @@ public class ServiceDiscoveryManager {
/**
* Sets the type of client that will be returned when asked for the client identity in a
* disco request. The valid types are defined by the category client. Follow this link to learn
* the possible types: <a href="http://www.jabber.org/registrar/disco-categories.html#client">Jabber::Registrar</a>.
* the possible types: <a href="http://xmpp.org/registrar/disco-categories.html#client">Jabber::Registrar</a>.
*
* @param type the type of client that will be returned when asked for the client identity in a
* disco request.

View File

@ -131,7 +131,7 @@ public class XHTMLText {
*
*/
public void appendBrTag() {
text.append("<br>");
text.append("<br/>");
}
/**

View File

@ -326,10 +326,7 @@ public class EnhancedDebugger implements SmackDebugger {
@Override
public void actionPerformed(ActionEvent e) {
for(int i=0; i< messagesTable.getRowCount();i++)
{
messagesTable.removeRow(i);
}
messagesTable.setRowCount(0);
}
});

View File

@ -324,7 +324,8 @@ public class FileTransferNegotiator {
throw new XMPPException(error.getMessage(), error);
}
if (isByteStream && isIBB && field.getType().equals(FormField.TYPE_LIST_MULTI)) {
//if (isByteStream && isIBB && field.getType().equals(FormField.TYPE_LIST_MULTI)) {
if (isByteStream && isIBB) {
return new FaultTolerantNegotiator(connection,
byteStreamTransferManager,
inbandTransferManager);

View File

@ -20,6 +20,7 @@
package org.jivesoftware.smackx.muc;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.packet.Packet;
import java.util.LinkedList;
@ -38,7 +39,7 @@ class ConnectionDetachedPacketCollector {
* reached, older packets will be automatically dropped from the queue as
* new packets are added.
*/
private static final int MAX_PACKETS = 65536;
private int maxPackets = SmackConfiguration.getPacketCollectorSize();
private LinkedList<Packet> resultQueue;
@ -50,6 +51,15 @@ class ConnectionDetachedPacketCollector {
this.resultQueue = new LinkedList<Packet>();
}
/**
* Creates a new packet collector. If the packet filter is <tt>null</tt>, then
* all packets will match this collector.
*/
public ConnectionDetachedPacketCollector(int maxSize) {
this.resultQueue = new LinkedList<Packet>();
maxPackets = maxSize;
}
/**
* Polls to see if a packet is currently available and returns it, or
* immediately returns <tt>null</tt> if no packets are currently in the
@ -124,7 +134,7 @@ class ConnectionDetachedPacketCollector {
return;
}
// If the max number of packets has been reached, remove the oldest one.
if (resultQueue.size() == MAX_PACKETS) {
if (resultQueue.size() == maxPackets) {
resultQueue.removeLast();
}
// Add the new packet.

View File

@ -60,7 +60,7 @@ class RoomListenerMultiplexor implements ConnectionListener {
*/
public static RoomListenerMultiplexor getRoomMultiplexor(Connection conn) {
synchronized (monitors) {
if (!monitors.containsKey(conn)) {
if (!monitors.containsKey(conn) || monitors.get(conn).get() == null) {
RoomListenerMultiplexor rm = new RoomListenerMultiplexor(conn, new RoomMultiplexFilter(),
new RoomMultiplexListener());

View File

@ -13,11 +13,10 @@
*/
package org.jivesoftware.smackx.pubsub;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smackx.pubsub.provider.ItemProvider;
import com.sun.corba.se.impl.protocol.giopmsgheaders.Message;
/**
* This class represents an item that has been, or will be published to a
* pubsub node. An <tt>Item</tt> has several properties that are dependent

View File

@ -40,252 +40,249 @@ import org.junit.Test;
* @see <a href="http://xmpp.org/rfcs/rfc3921.html#roster">Roster Management</a>
* @author Guenther Niess
*/
public class ChatConnectionTest
{
public class ChatConnectionTest {
private DummyConnection connection;
private DummyConnection connection;
@Before
public void setUp() throws Exception
{
// Uncomment this to enable debug output
// Connection.DEBUG_ENABLED = true;
@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");
}
connection = new DummyConnection();
connection.connect();
connection.login("me", "secret");
}
@After
public void tearDown() throws Exception
{
if (connection != null)
connection.disconnect();
}
@After
public void tearDown() throws Exception {
if (connection != null)
connection.disconnect();
}
/**
* Confirm that a new chat is created when a chat message is received but
* there is no thread id for a user with only a base jid.
*/
@Test
public void chatCreatedWithIncomingChatNoThreadBaseJid()
{
TestChatManagerListener listener = new TestChatManagerListener();
connection.getChatManager().addChatListener(listener);
/**
* Confirm that a new chat is created when a chat message is received but
* there is no thread id for a user with only a base jid.
*/
@Test
public void chatCreatedWithIncomingChatNoThreadBaseJid()
{
TestChatManagerListener listener = new TestChatManagerListener();
connection.getChatManager().addChatListener(listener);
Packet incomingChat = createChatPacket(null, false);
processServerMessage(incomingChat);
Packet incomingChat = createChatPacket(null, false);
processServerMessage(incomingChat);
Chat newChat = listener.getNewChat();
assertNotNull(newChat);
}
Chat newChat = listener.getNewChat();
assertNotNull(newChat);
}
/**
* Confirm that a new chat is created when a chat message is received but
* there is no thread id for a user with a full jid.
*/
@Test
public void chatCreatedWhenIncomingChatNoThreadFullJid()
{
TestChatManagerListener listener = new TestChatManagerListener();
connection.getChatManager().addChatListener(listener);
/**
* Confirm that a new chat is created when a chat message is received but
* there is no thread id for a user with a full jid.
*/
@Test
public void chatCreatedWhenIncomingChatNoThreadFullJid()
{
TestChatManagerListener listener = new TestChatManagerListener();
connection.getChatManager().addChatListener(listener);
Packet incomingChat = createChatPacket(null, true);
processServerMessage(incomingChat);
Packet incomingChat = createChatPacket(null, true);
processServerMessage(incomingChat);
Chat newChat = listener.getNewChat();
assertNotNull(newChat);
}
Chat newChat = listener.getNewChat();
assertNotNull(newChat);
}
/**
* Confirm that an existing chat created with a base jid is matched to an
* incoming chat message that has no thread id and the user is a full jid.
*/
@Test
public void chatFoundWhenNoThreadFullJid()
{
TestChatManagerListener listener = new TestChatManagerListener();
connection.getChatManager().addChatListener(listener);
Chat outgoing = connection.getChatManager().createChat("you@testserver", null);
/**
* Confirm that an existing chat created with a base jid is matched to an
* incoming chat message that has no thread id and the user is a full jid.
*/
@Test
public void chatFoundWhenNoThreadFullJid()
{
TestChatManagerListener listener = new TestChatManagerListener();
connection.getChatManager().addChatListener(listener);
Chat outgoing = connection.getChatManager().createChat("you@testserver", null);
Packet incomingChat = createChatPacket(null, true);
processServerMessage(incomingChat);
Packet incomingChat = createChatPacket(null, true);
processServerMessage(incomingChat);
Chat newChat = listener.getNewChat();
assertNotNull(newChat);
assertTrue(newChat == outgoing);
}
Chat newChat = listener.getNewChat();
assertNotNull(newChat);
assertTrue(newChat == outgoing);
}
/**
* Confirm that an existing chat created with a base jid is matched to an
* incoming chat message that has no thread id and the user is a base jid.
*/
@Test
public void chatFoundWhenNoThreadBaseJid()
{
TestChatManagerListener listener = new TestChatManagerListener();
connection.getChatManager().addChatListener(listener);
Chat outgoing = connection.getChatManager().createChat("you@testserver", null);
/**
* Confirm that an existing chat created with a base jid is matched to an
* incoming chat message that has no thread id and the user is a base jid.
*/
@Test
public void chatFoundWhenNoThreadBaseJid()
{
TestChatManagerListener listener = new TestChatManagerListener();
connection.getChatManager().addChatListener(listener);
Chat outgoing = connection.getChatManager().createChat("you@testserver", null);
Packet incomingChat = createChatPacket(null, false);
processServerMessage(incomingChat);
Packet incomingChat = createChatPacket(null, false);
processServerMessage(incomingChat);
Chat newChat = listener.getNewChat();
assertNotNull(newChat);
assertTrue(newChat == outgoing);
}
Chat newChat = listener.getNewChat();
assertNotNull(newChat);
assertTrue(newChat == outgoing);
}
/**
* Confirm that an existing chat created with a base jid is matched to an
* incoming chat message that has the same id and the user is a full jid.
*/
@Test
public void chatFoundWithSameThreadFullJid()
{
TestChatManagerListener listener = new TestChatManagerListener();
connection.getChatManager().addChatListener(listener);
Chat outgoing = connection.getChatManager().createChat("you@testserver", null);
/**
* Confirm that an existing chat created with a base jid is matched to an
* incoming chat message that has the same id and the user is a full jid.
*/
@Test
public void chatFoundWithSameThreadFullJid()
{
TestChatManagerListener listener = new TestChatManagerListener();
connection.getChatManager().addChatListener(listener);
Chat outgoing = connection.getChatManager().createChat("you@testserver", null);
Packet incomingChat = createChatPacket(outgoing.getThreadID(), true);
processServerMessage(incomingChat);
Packet incomingChat = createChatPacket(outgoing.getThreadID(), true);
processServerMessage(incomingChat);
Chat newChat = listener.getNewChat();
assertNotNull(newChat);
assertTrue(newChat == outgoing);
}
Chat newChat = listener.getNewChat();
assertNotNull(newChat);
assertTrue(newChat == outgoing);
}
/**
* Confirm that an existing chat created with a base jid is matched to an
* incoming chat message that has the same id and the user is a base jid.
*/
@Test
public void chatFoundWithSameThreadBaseJid()
{
TestChatManagerListener listener = new TestChatManagerListener();
connection.getChatManager().addChatListener(listener);
Chat outgoing = connection.getChatManager().createChat("you@testserver", null);
/**
* Confirm that an existing chat created with a base jid is matched to an
* incoming chat message that has the same id and the user is a base jid.
*/
@Test
public void chatFoundWithSameThreadBaseJid()
{
TestChatManagerListener listener = new TestChatManagerListener();
connection.getChatManager().addChatListener(listener);
Chat outgoing = connection.getChatManager().createChat("you@testserver", null);
Packet incomingChat = createChatPacket(outgoing.getThreadID(), false);
processServerMessage(incomingChat);
Packet incomingChat = createChatPacket(outgoing.getThreadID(), false);
processServerMessage(incomingChat);
Chat newChat = listener.getNewChat();
assertNotNull(newChat);
assertTrue(newChat == outgoing);
}
Chat newChat = listener.getNewChat();
assertNotNull(newChat);
assertTrue(newChat == outgoing);
}
/**
* Confirm that an existing chat created with a base jid is not matched to
* an incoming chat message that has a different id and the same user as a
* base jid.
*/
@Ignore
@Test
public void chatNotFoundWithDiffThreadBaseJid()
{
TestChatManagerListener listener = new TestChatManagerListener();
connection.getChatManager().addChatListener(listener);
Chat outgoing = connection.getChatManager().createChat("you@testserver", null);
/**
* Confirm that an existing chat created with a base jid is not matched to
* an incoming chat message that has a different id and the same user as a
* base jid.
*/
@Ignore
@Test
public void chatNotFoundWithDiffThreadBaseJid()
{
TestChatManagerListener listener = new TestChatManagerListener();
connection.getChatManager().addChatListener(listener);
Chat outgoing = connection.getChatManager().createChat("you@testserver", null);
Packet incomingChat = createChatPacket(outgoing.getThreadID() + "ff", false);
processServerMessage(incomingChat);
Packet incomingChat = createChatPacket(outgoing.getThreadID() + "ff", false);
processServerMessage(incomingChat);
Chat newChat = listener.getNewChat();
assertNotNull(newChat);
assertFalse(newChat == outgoing);
}
Chat newChat = listener.getNewChat();
assertNotNull(newChat);
assertFalse(newChat == outgoing);
}
/**
* Confirm that an existing chat created with a base jid is not matched to
* an incoming chat message that has a different id and the same base jid.
*/
@Ignore
@Test
public void chatNotFoundWithDiffThreadFullJid()
{
TestChatManagerListener listener = new TestChatManagerListener();
connection.getChatManager().addChatListener(listener);
Chat outgoing = connection.getChatManager().createChat("you@testserver", null);
/**
* Confirm that an existing chat created with a base jid is not matched to
* an incoming chat message that has a different id and the same base jid.
*/
@Ignore
@Test
public void chatNotFoundWithDiffThreadFullJid()
{
TestChatManagerListener listener = new TestChatManagerListener();
connection.getChatManager().addChatListener(listener);
Chat outgoing = connection.getChatManager().createChat("you@testserver", null);
Packet incomingChat = createChatPacket(outgoing.getThreadID() + "ff", true);
processServerMessage(incomingChat);
Packet incomingChat = createChatPacket(outgoing.getThreadID() + "ff", true);
processServerMessage(incomingChat);
Chat newChat = listener.getNewChat();
assertNotNull(newChat);
assertFalse(newChat == outgoing);
}
Chat newChat = listener.getNewChat();
assertNotNull(newChat);
assertFalse(newChat == outgoing);
}
private Packet createChatPacket(final String threadId, final boolean isFullJid)
{
Message chatMsg = new Message("me@testserver", Message.Type.chat);
chatMsg.setBody("the body message");
chatMsg.setFrom("you@testserver" + (isFullJid ? "/resource" : ""));
if (threadId != null)
chatMsg.addExtension(new PacketExtension()
{
@Override
public String toXML()
{
return "<thread>" + threadId + "</thread>";
}
@Override
public String getNamespace()
{
return null;
}
@Override
public String getElementName()
{
return "thread";
}
});
return chatMsg;
}
private void processServerMessage(Packet incomingChat)
{
TestChatServer chatServer = new TestChatServer(incomingChat);
chatServer.start();
try
{
chatServer.join();
} catch (InterruptedException e)
{
fail();
}
}
class TestChatManagerListener implements ChatManagerListener
{
private Chat newChat;
private Packet createChatPacket(final String threadId, final boolean isFullJid)
{
Message chatMsg = new Message("me@testserver", Message.Type.chat);
chatMsg.setBody("the body message");
chatMsg.setFrom("you@testserver" + (isFullJid ? "/resource" : ""));
if (threadId != null)
chatMsg.addExtension(new PacketExtension()
{
@Override
public void chatCreated(Chat chat, boolean createdLocally)
public String toXML()
{
newChat = chat;
}
public Chat getNewChat()
{
return newChat;
}
}
private class TestChatServer extends Thread
{
private Packet chatPacket;
TestChatServer(Packet chatMsg)
{
chatPacket = chatMsg;
return "<thread>" + threadId + "</thread>";
}
@Override
public void run()
public String getNamespace()
{
connection.processPacket(chatPacket);
return null;
}
@Override
public String getElementName()
{
return "thread";
}
});
return chatMsg;
}
private void processServerMessage(Packet incomingChat)
{
TestChatServer chatServer = new TestChatServer(incomingChat);
chatServer.start();
try
{
chatServer.join();
} catch (InterruptedException e)
{
fail();
}
}
class TestChatManagerListener implements ChatManagerListener
{
private Chat newChat;
@Override
public void chatCreated(Chat chat, boolean createdLocally)
{
newChat = chat;
}
public Chat getNewChat()
{
return newChat;
}
}
private class TestChatServer extends Thread
{
private Packet chatPacket;
TestChatServer(Packet chatMsg)
{
chatPacket = chatMsg;
}
@Override
public void run()
{
connection.processPacket(chatPacket);
}
}
}

View File

@ -0,0 +1,32 @@
package org.jivesoftware.smack;
import org.junit.Test;
import static org.junit.Assert.*;
public class SmackConfigTest
{
@Test
public void validatePacketCollectorSize()
{
assertEquals(10000, SmackConfiguration.getPacketCollectorSize());
}
@Test
public void validateKeepAliveInterval()
{
assertEquals(30000, SmackConfiguration.getKeepAliveInterval());
}
@Test
public void validateLocalSocks5ProxyPort()
{
assertEquals(7777, SmackConfiguration.getLocalSocks5ProxyPort());
}
@Test
public void validateIsLocalSocks5Proxy()
{
assertTrue(SmackConfiguration.isLocalSocks5ProxyEnabled());
}
}

View File

@ -2,6 +2,17 @@ package org.jivesoftware.smackx.pubsub;
import static org.junit.Assert.assertEquals;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.ThreadedDummyConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smack.packet.XMPPError.Condition;
import org.jivesoftware.smackx.packet.DiscoverInfo;
import org.jivesoftware.smackx.packet.DiscoverInfo.Identity;
import org.jivesoftware.smackx.pubsub.packet.PubSub;
import org.junit.Assert;
import org.junit.Test;
public class ConfigureFormTest
@ -13,4 +24,49 @@ public class ConfigureFormTest
form.setChildrenAssociationPolicy(ChildrenAssociationPolicy.owners);
assertEquals(ChildrenAssociationPolicy.owners, form.getChildrenAssociationPolicy());
}
@Test
public void getConfigFormWithInsufficientPriviliges() throws XMPPException
{
ThreadedDummyConnection con = new ThreadedDummyConnection();
PubSubManager mgr = new PubSubManager(con);
DiscoverInfo info = new DiscoverInfo();
Identity ident = new Identity("pubsub", null);
ident.setType("leaf");
info.addIdentity(ident);
con.addIQReply(info);
Node node = mgr.getNode("princely_musings");
PubSub errorIq = new PubSub();
XMPPError error = new XMPPError(Condition.forbidden);
errorIq.setError(error);
con.addIQReply(errorIq);
try
{
node.getNodeConfiguration();
}
catch (XMPPException e)
{
Assert.assertEquals(XMPPError.Type.AUTH, e.getXMPPError().getType());
}
}
@Test (expected=XMPPException.class)
public void getConfigFormWithTimeout() throws XMPPException
{
ThreadedDummyConnection con = new ThreadedDummyConnection();
PubSubManager mgr = new PubSubManager(con);
DiscoverInfo info = new DiscoverInfo();
Identity ident = new Identity("pubsub", null);
ident.setType("leaf");
info.addIdentity(ident);
con.addIQReply(info);
Node node = mgr.getNode("princely_musings");
SmackConfiguration.setPacketReplyTimeout(100);
node.getNodeConfiguration();
}
}