mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-10 17:49:38 +02:00
Merge trunk (3.2 release) up to the 3.2 branch for development on 3.2.x releases.
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/branches/smack_3_2_0@12370 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
commit
22d04c26e3
27 changed files with 689 additions and 235 deletions
|
@ -0,0 +1,77 @@
|
|||
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();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
package org.jivesoftware.smack.filters;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
import org.jivesoftware.smack.filter.FromMatchesFilter;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
import org.junit.Test;
|
||||
|
||||
public class FromMatchesFilterTest {
|
||||
private static final String BASE_JID1 = "ss@muc.myserver.com";
|
||||
private static final String FULL_JID1_R1 = BASE_JID1 + "/resource";
|
||||
private static final String FULL_JID1_R2 = BASE_JID1 + "/resource2";
|
||||
private static final String BASE_JID2 = "sss@muc.myserver.com";
|
||||
private static final String FULL_JID2 = BASE_JID2 + "/resource";
|
||||
|
||||
private static final String SERVICE_JID1 = "muc.myserver.com";
|
||||
private static final String SERVICE_JID2 = "pubsub.myserver.com";
|
||||
|
||||
@Test
|
||||
public void compareMatchingFullJid()
|
||||
{
|
||||
FromMatchesFilter filter = new FromMatchesFilter(FULL_JID1_R1);
|
||||
Packet packet = new Packet() {
|
||||
@Override
|
||||
public String toXML() { return null; }
|
||||
};
|
||||
|
||||
packet.setFrom(FULL_JID1_R1);
|
||||
assertTrue(filter.accept(packet));
|
||||
|
||||
packet.setFrom(BASE_JID1);
|
||||
assertFalse(filter.accept(packet));
|
||||
|
||||
packet.setFrom(FULL_JID1_R2);
|
||||
assertFalse(filter.accept(packet));
|
||||
|
||||
packet.setFrom(BASE_JID2);
|
||||
assertFalse(filter.accept(packet));
|
||||
|
||||
packet.setFrom(FULL_JID2);
|
||||
assertFalse(filter.accept(packet));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareMatchingBaseJid()
|
||||
{
|
||||
FromMatchesFilter filter = new FromMatchesFilter(BASE_JID1);
|
||||
Packet packet = new Packet() {
|
||||
@Override
|
||||
public String toXML() { return null; }
|
||||
};
|
||||
|
||||
packet.setFrom(BASE_JID1);
|
||||
assertTrue(filter.accept(packet));
|
||||
|
||||
packet.setFrom(FULL_JID1_R1);
|
||||
assertTrue(filter.accept(packet));
|
||||
|
||||
packet.setFrom(FULL_JID1_R2);
|
||||
assertTrue(filter.accept(packet));
|
||||
|
||||
packet.setFrom(BASE_JID2);
|
||||
assertFalse(filter.accept(packet));
|
||||
|
||||
packet.setFrom(FULL_JID2);
|
||||
assertFalse(filter.accept(packet));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareMatchingServiceJid()
|
||||
{
|
||||
FromMatchesFilter filter = new FromMatchesFilter(SERVICE_JID1);
|
||||
Packet packet = new Packet() {
|
||||
@Override
|
||||
public String toXML() { return null; }
|
||||
};
|
||||
|
||||
packet.setFrom(SERVICE_JID1);
|
||||
assertTrue(filter.accept(packet));
|
||||
|
||||
packet.setFrom(SERVICE_JID2);
|
||||
assertFalse(filter.accept(packet));
|
||||
|
||||
packet.setFrom(BASE_JID1);
|
||||
assertFalse(filter.accept(packet));
|
||||
|
||||
packet.setFrom(FULL_JID1_R1);
|
||||
assertFalse(filter.accept(packet));
|
||||
|
||||
}
|
||||
}
|
|
@ -8,6 +8,8 @@
|
|||
package org.jivesoftware.smack.packet;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
|
@ -105,6 +107,7 @@ public class MessageTest {
|
|||
assertXMLEqual(control, message.toXML());
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void multipleMessageBodiesTest() throws IOException, SAXException, ParserConfigurationException {
|
||||
final String messageBody1 = "This is a test of the emergency broadcast system, 1.";
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.custommonkey.xmlunit.DetailedDiff;
|
|||
import org.custommonkey.xmlunit.Diff;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.xmlpull.mxp1.MXParser;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
@ -714,6 +715,7 @@ public class PacketParserUtilsTest {
|
|||
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void multipleMessageBodiesParsingTest() throws Exception {
|
||||
String control = XMLBuilder.create("message")
|
||||
|
@ -733,7 +735,6 @@ public class PacketParserUtilsTest {
|
|||
.a("xml:lang", "sp")
|
||||
.t("This is a test of the emergency broadcast system, 3.")
|
||||
.asString(outputProperties);
|
||||
|
||||
|
||||
Packet message = PacketParserUtils.parseMessage(getParser(control));
|
||||
assertXMLEqual(control, message.toXML());
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
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);
|
||||
}
|
||||
}
|
50
test-unit/org/jivesoftware/smackx/muc/RoomInfoTest.java
Normal file
50
test-unit/org/jivesoftware/smackx/muc/RoomInfoTest.java
Normal file
|
@ -0,0 +1,50 @@
|
|||
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());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ConfigureFormTest
|
||||
{
|
||||
@Test
|
||||
public void checkChildrenAssocPolicy()
|
||||
{
|
||||
ConfigureForm form = new ConfigureForm(FormType.submit);
|
||||
form.setChildrenAssociationPolicy(ChildrenAssociationPolicy.owners);
|
||||
assertEquals(ChildrenAssociationPolicy.owners, form.getChildrenAssociationPolicy());
|
||||
}
|
||||
}
|
107
test-unit/org/jivesoftware/smackx/pubsub/ItemValidationTest.java
Normal file
107
test-unit/org/jivesoftware/smackx/pubsub/ItemValidationTest.java
Normal file
|
@ -0,0 +1,107 @@
|
|||
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;
|
||||
|
||||
public class ItemValidationTest
|
||||
{
|
||||
private ThreadedDummyConnection connection;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
// Uncomment this to enable debug output
|
||||
// Connection.DEBUG_ENABLED = true;
|
||||
|
||||
connection = new ThreadedDummyConnection();
|
||||
connection.connect();
|
||||
connection.login("me", "secret");
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception
|
||||
{
|
||||
if (connection != null)
|
||||
connection.disconnect();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyBasicItem() throws Exception
|
||||
{
|
||||
Item simpleItem = new Item();
|
||||
String simpleCtrl = "<item />";
|
||||
assertXMLEqual(simpleCtrl, simpleItem.toXML());
|
||||
|
||||
Item idItem = new Item("uniqueid");
|
||||
String idCtrl = "<item id='uniqueid'/>";
|
||||
assertXMLEqual(idCtrl, idItem.toXML());
|
||||
|
||||
Item itemWithNodeId = new Item("testId", "testNode");
|
||||
String nodeIdCtrl = "<item id='testId' node='testNode' />";
|
||||
assertXMLEqual(nodeIdCtrl, itemWithNodeId.toXML());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyPayloadItem() throws Exception
|
||||
{
|
||||
SimplePayload payload = new SimplePayload(null, null, "<data>This is the payload</data>");
|
||||
|
||||
PayloadItem<SimplePayload> simpleItem = new PayloadItem<SimplePayload>(payload);
|
||||
String simpleCtrl = "<item>" + payload.toXML() + "</item>";
|
||||
assertXMLEqual(simpleCtrl, simpleItem.toXML());
|
||||
|
||||
PayloadItem<SimplePayload> idItem = new PayloadItem<SimplePayload>("uniqueid", payload);
|
||||
String idCtrl = "<item id='uniqueid'>" + payload.toXML() + "</item>";
|
||||
assertXMLEqual(idCtrl, idItem.toXML());
|
||||
|
||||
PayloadItem<SimplePayload> itemWithNodeId = new PayloadItem<SimplePayload>("testId", "testNode", payload);
|
||||
String nodeIdCtrl = "<item id='testId' node='testNode'>" + payload.toXML() + "</item>";
|
||||
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());
|
||||
// }
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue