mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-12-06 13:11:08 +01:00
Normalize newlines to '\n'
Change all \r\n into unix style newlines. Add missing newlines at the end of a file and activate the newline checkstyle module, that enforces '\n' as newline and a newline at the end of every file.
This commit is contained in:
parent
1e57f1c659
commit
d069e1be64
364 changed files with 50349 additions and 50346 deletions
|
|
@ -14,50 +14,50 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Robin Collier
|
||||
*
|
||||
*/
|
||||
class CarExtension implements PacketExtension
|
||||
{
|
||||
private String color;
|
||||
private int numTires;
|
||||
|
||||
public CarExtension(String col, int num)
|
||||
{
|
||||
color = col;
|
||||
numTires = num;
|
||||
}
|
||||
|
||||
public String getColor()
|
||||
{
|
||||
return color;
|
||||
}
|
||||
|
||||
public int getNumTires()
|
||||
{
|
||||
return numTires;
|
||||
}
|
||||
|
||||
public String getElementName()
|
||||
{
|
||||
return "car";
|
||||
}
|
||||
|
||||
public String getNamespace()
|
||||
{
|
||||
return "pubsub:test:vehicle";
|
||||
}
|
||||
|
||||
public String toXML()
|
||||
{
|
||||
return "<" + getElementName() + " xmlns='" + getNamespace() + "'><paint color='" +
|
||||
getColor() + "'/><tires num='" + getNumTires() + "'/></" + getElementName() + ">";
|
||||
}
|
||||
|
||||
}
|
||||
class CarExtension implements PacketExtension
|
||||
{
|
||||
private String color;
|
||||
private int numTires;
|
||||
|
||||
public CarExtension(String col, int num)
|
||||
{
|
||||
color = col;
|
||||
numTires = num;
|
||||
}
|
||||
|
||||
public String getColor()
|
||||
{
|
||||
return color;
|
||||
}
|
||||
|
||||
public int getNumTires()
|
||||
{
|
||||
return numTires;
|
||||
}
|
||||
|
||||
public String getElementName()
|
||||
{
|
||||
return "car";
|
||||
}
|
||||
|
||||
public String getNamespace()
|
||||
{
|
||||
return "pubsub:test:vehicle";
|
||||
}
|
||||
|
||||
public String toXML()
|
||||
{
|
||||
return "<" + getElementName() + " xmlns='" + getNamespace() + "'><paint color='" +
|
||||
getColor() + "'/><tires num='" + getNumTires() + "'/></" + getElementName() + ">";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,40 +14,40 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
import org.jivesoftware.smack.provider.PacketExtensionProvider;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
import org.jivesoftware.smack.provider.PacketExtensionProvider;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Robin Collier
|
||||
*
|
||||
*/
|
||||
public class CarExtensionProvider implements PacketExtensionProvider
|
||||
{
|
||||
|
||||
public PacketExtension parseExtension(XmlPullParser parser) throws Exception
|
||||
{
|
||||
String color = null;
|
||||
int numTires = 0;
|
||||
|
||||
for (int i=0; i<2; i++)
|
||||
{
|
||||
while (parser.next() != XmlPullParser.START_TAG);
|
||||
|
||||
if (parser.getName().equals("paint"))
|
||||
{
|
||||
color = parser.getAttributeValue(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
numTires = Integer.parseInt(parser.getAttributeValue(0));
|
||||
}
|
||||
}
|
||||
while (parser.next() != XmlPullParser.END_TAG);
|
||||
return new CarExtension(color, numTires);
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
public class CarExtensionProvider implements PacketExtensionProvider
|
||||
{
|
||||
|
||||
public PacketExtension parseExtension(XmlPullParser parser) throws Exception
|
||||
{
|
||||
String color = null;
|
||||
int numTires = 0;
|
||||
|
||||
for (int i=0; i<2; i++)
|
||||
{
|
||||
while (parser.next() != XmlPullParser.START_TAG);
|
||||
|
||||
if (parser.getName().equals("paint"))
|
||||
{
|
||||
color = parser.getAttributeValue(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
numTires = Integer.parseInt(parser.getAttributeValue(0));
|
||||
}
|
||||
}
|
||||
while (parser.next() != XmlPullParser.END_TAG);
|
||||
return new CarExtension(color, numTires);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,76 +14,76 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smackx.packet.DiscoverInfo;
|
||||
import org.jivesoftware.smackx.packet.DiscoverItems;
|
||||
import org.jivesoftware.smackx.packet.DiscoverInfo.Identity;
|
||||
import org.jivesoftware.smackx.pubsub.test.SingleUserTestCase;
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smackx.packet.DiscoverInfo;
|
||||
import org.jivesoftware.smackx.packet.DiscoverItems;
|
||||
import org.jivesoftware.smackx.packet.DiscoverInfo.Identity;
|
||||
import org.jivesoftware.smackx.pubsub.test.SingleUserTestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Robin Collier
|
||||
*
|
||||
*/
|
||||
public class EntityUseCases extends SingleUserTestCase
|
||||
{
|
||||
public void testDiscoverPubsubInfo() throws Exception
|
||||
{
|
||||
DiscoverInfo supportedFeatures = getManager().getSupportedFeatures();
|
||||
assertNotNull(supportedFeatures);
|
||||
}
|
||||
|
||||
public void testDiscoverNodeInfo() throws Exception
|
||||
{
|
||||
LeafNode myNode = getManager().createNode("DiscoNode" + System.currentTimeMillis());
|
||||
DiscoverInfo info = myNode.discoverInfo();
|
||||
assertTrue(info.getIdentities().hasNext());
|
||||
Identity ident = info.getIdentities().next();
|
||||
|
||||
assertEquals("leaf", ident.getType());
|
||||
}
|
||||
|
||||
public void testDiscoverNodeItems() throws Exception
|
||||
{
|
||||
LeafNode myNode = getRandomPubnode(getManager(), true, false);
|
||||
myNode.send(new Item());
|
||||
myNode.send(new Item());
|
||||
myNode.send(new Item());
|
||||
myNode.send(new Item());
|
||||
DiscoverItems items = myNode.discoverItems();
|
||||
|
||||
int count = 0;
|
||||
|
||||
for(Iterator<DiscoverItems.Item> it = items.getItems(); it.hasNext(); it.next(),count++);
|
||||
|
||||
assertEquals(4, count);
|
||||
}
|
||||
|
||||
public void testDiscoverSubscriptions() throws Exception
|
||||
{
|
||||
getManager().getSubscriptions();
|
||||
}
|
||||
|
||||
public void testDiscoverNodeSubscriptions() throws Exception
|
||||
{
|
||||
LeafNode myNode = getRandomPubnode(getManager(), true, true);
|
||||
myNode.subscribe(getConnection(0).getUser());
|
||||
List<Subscription> subscriptions = myNode.getSubscriptions();
|
||||
|
||||
assertTrue(subscriptions.size() < 3);
|
||||
|
||||
for (Subscription subscription : subscriptions)
|
||||
{
|
||||
assertNull(subscription.getNode());
|
||||
}
|
||||
}
|
||||
|
||||
public void testRetrieveAffiliation() throws Exception
|
||||
{
|
||||
getManager().getAffiliations();
|
||||
}
|
||||
}
|
||||
*/
|
||||
public class EntityUseCases extends SingleUserTestCase
|
||||
{
|
||||
public void testDiscoverPubsubInfo() throws Exception
|
||||
{
|
||||
DiscoverInfo supportedFeatures = getManager().getSupportedFeatures();
|
||||
assertNotNull(supportedFeatures);
|
||||
}
|
||||
|
||||
public void testDiscoverNodeInfo() throws Exception
|
||||
{
|
||||
LeafNode myNode = getManager().createNode("DiscoNode" + System.currentTimeMillis());
|
||||
DiscoverInfo info = myNode.discoverInfo();
|
||||
assertTrue(info.getIdentities().hasNext());
|
||||
Identity ident = info.getIdentities().next();
|
||||
|
||||
assertEquals("leaf", ident.getType());
|
||||
}
|
||||
|
||||
public void testDiscoverNodeItems() throws Exception
|
||||
{
|
||||
LeafNode myNode = getRandomPubnode(getManager(), true, false);
|
||||
myNode.send(new Item());
|
||||
myNode.send(new Item());
|
||||
myNode.send(new Item());
|
||||
myNode.send(new Item());
|
||||
DiscoverItems items = myNode.discoverItems();
|
||||
|
||||
int count = 0;
|
||||
|
||||
for(Iterator<DiscoverItems.Item> it = items.getItems(); it.hasNext(); it.next(),count++);
|
||||
|
||||
assertEquals(4, count);
|
||||
}
|
||||
|
||||
public void testDiscoverSubscriptions() throws Exception
|
||||
{
|
||||
getManager().getSubscriptions();
|
||||
}
|
||||
|
||||
public void testDiscoverNodeSubscriptions() throws Exception
|
||||
{
|
||||
LeafNode myNode = getRandomPubnode(getManager(), true, true);
|
||||
myNode.subscribe(getConnection(0).getUser());
|
||||
List<Subscription> subscriptions = myNode.getSubscriptions();
|
||||
|
||||
assertTrue(subscriptions.size() < 3);
|
||||
|
||||
for (Subscription subscription : subscriptions)
|
||||
{
|
||||
assertNull(subscription.getNode());
|
||||
}
|
||||
}
|
||||
|
||||
public void testRetrieveAffiliation() throws Exception
|
||||
{
|
||||
getManager().getAffiliations();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,69 +14,69 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.packet.XMPPError;
|
||||
import org.jivesoftware.smackx.pubsub.test.PubSubTestCase;
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.packet.XMPPError;
|
||||
import org.jivesoftware.smackx.pubsub.test.PubSubTestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Robin Collier
|
||||
*
|
||||
*/
|
||||
public class MultiUserSubscriptionUseCases extends PubSubTestCase
|
||||
{
|
||||
|
||||
@Override
|
||||
protected int getMaxConnections()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public void testGetItemsWithSingleSubscription() throws XMPPException
|
||||
{
|
||||
LeafNode node = getRandomPubnode(getManager(0), true, false);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
|
||||
LeafNode user2Node = (LeafNode) getManager(1).getNode(node.getId());
|
||||
user2Node.subscribe(getBareJID(1));
|
||||
|
||||
Collection<? extends Item> items = user2Node.getItems();
|
||||
assertTrue(items.size() == 5);
|
||||
}
|
||||
|
||||
public void testGetItemsWithMultiSubscription() throws XMPPException
|
||||
{
|
||||
LeafNode node = getRandomPubnode(getManager(0), true, false);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
|
||||
LeafNode user2Node = (LeafNode) getManager(1).getNode(node.getId());
|
||||
Subscription sub1 = user2Node.subscribe(getBareJID(1));
|
||||
|
||||
Subscription sub2 = user2Node.subscribe(getBareJID(1));
|
||||
|
||||
try
|
||||
{
|
||||
user2Node.getItems();
|
||||
}
|
||||
catch (XMPPException exc)
|
||||
{
|
||||
assertEquals("bad-request", exc.getXMPPError().getCondition());
|
||||
assertEquals(XMPPError.Type.MODIFY, exc.getXMPPError().getType());
|
||||
}
|
||||
List<Item> items = user2Node.getItems(sub1.getId());
|
||||
assertTrue(items.size() == 5);
|
||||
}
|
||||
}
|
||||
*/
|
||||
public class MultiUserSubscriptionUseCases extends PubSubTestCase
|
||||
{
|
||||
|
||||
@Override
|
||||
protected int getMaxConnections()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public void testGetItemsWithSingleSubscription() throws XMPPException
|
||||
{
|
||||
LeafNode node = getRandomPubnode(getManager(0), true, false);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
|
||||
LeafNode user2Node = (LeafNode) getManager(1).getNode(node.getId());
|
||||
user2Node.subscribe(getBareJID(1));
|
||||
|
||||
Collection<? extends Item> items = user2Node.getItems();
|
||||
assertTrue(items.size() == 5);
|
||||
}
|
||||
|
||||
public void testGetItemsWithMultiSubscription() throws XMPPException
|
||||
{
|
||||
LeafNode node = getRandomPubnode(getManager(0), true, false);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
|
||||
LeafNode user2Node = (LeafNode) getManager(1).getNode(node.getId());
|
||||
Subscription sub1 = user2Node.subscribe(getBareJID(1));
|
||||
|
||||
Subscription sub2 = user2Node.subscribe(getBareJID(1));
|
||||
|
||||
try
|
||||
{
|
||||
user2Node.getItems();
|
||||
}
|
||||
catch (XMPPException exc)
|
||||
{
|
||||
assertEquals("bad-request", exc.getXMPPError().getCondition());
|
||||
assertEquals(XMPPError.Type.MODIFY, exc.getXMPPError().getType());
|
||||
}
|
||||
List<Item> items = user2Node.getItems(sub1.getId());
|
||||
assertTrue(items.size() == 5);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,135 +14,135 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smackx.pubsub.test.SingleUserTestCase;
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smackx.pubsub.test.SingleUserTestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Robin Collier
|
||||
*
|
||||
*/
|
||||
public class OwnerUseCases extends SingleUserTestCase
|
||||
{
|
||||
public void testCreateInstantNode() throws Exception
|
||||
{
|
||||
LeafNode node = getManager().createNode();
|
||||
assertNotNull(node);
|
||||
assertNotNull(node.getId());
|
||||
}
|
||||
|
||||
public void testCreateNamedNode() throws Exception
|
||||
{
|
||||
String id = "TestNamedNode" + System.currentTimeMillis();
|
||||
LeafNode node = getManager().createNode(id);
|
||||
assertEquals(id, node.getId());
|
||||
}
|
||||
|
||||
public void testCreateConfiguredNode() throws Exception
|
||||
{
|
||||
// Generate reasonably unique for multiple tests
|
||||
String id = "TestConfigNode" + System.currentTimeMillis();
|
||||
|
||||
// Create and configure a node
|
||||
ConfigureForm form = new ConfigureForm(FormType.submit);
|
||||
form.setAccessModel(AccessModel.open);
|
||||
form.setDeliverPayloads(false);
|
||||
form.setNotifyRetract(true);
|
||||
form.setPersistentItems(true);
|
||||
form.setPublishModel(PublishModel.open);
|
||||
|
||||
LeafNode node = (LeafNode)getManager().createNode(id, form);
|
||||
|
||||
ConfigureForm currentForm = node.getNodeConfiguration();
|
||||
assertEquals(AccessModel.open, currentForm.getAccessModel());
|
||||
assertFalse(currentForm.isDeliverPayloads());
|
||||
assertTrue(currentForm.isNotifyRetract());
|
||||
assertTrue(currentForm.isPersistItems());
|
||||
assertEquals(PublishModel.open, currentForm.getPublishModel());
|
||||
}
|
||||
|
||||
public void testCreateAndUpdateConfiguredNode() throws Exception
|
||||
{
|
||||
// Generate reasonably unique for multiple tests
|
||||
String id = "TestConfigNode2" + System.currentTimeMillis();
|
||||
|
||||
// Create and configure a node
|
||||
ConfigureForm form = new ConfigureForm(FormType.submit);
|
||||
form.setAccessModel(AccessModel.open);
|
||||
form.setDeliverPayloads(false);
|
||||
form.setNotifyRetract(true);
|
||||
form.setPersistentItems(true);
|
||||
form.setPublishModel(PublishModel.open);
|
||||
|
||||
LeafNode myNode = (LeafNode)getManager().createNode(id, form);
|
||||
ConfigureForm config = myNode.getNodeConfiguration();
|
||||
|
||||
assertEquals(AccessModel.open, config.getAccessModel());
|
||||
assertFalse(config.isDeliverPayloads());
|
||||
assertTrue(config.isNotifyRetract());
|
||||
assertTrue(config.isPersistItems());
|
||||
assertEquals(PublishModel.open, config.getPublishModel());
|
||||
|
||||
ConfigureForm submitForm = new ConfigureForm(config.createAnswerForm());
|
||||
submitForm.setAccessModel(AccessModel.whitelist);
|
||||
submitForm.setDeliverPayloads(true);
|
||||
submitForm.setNotifyRetract(false);
|
||||
submitForm.setPersistentItems(false);
|
||||
submitForm.setPublishModel(PublishModel.publishers);
|
||||
myNode.sendConfigurationForm(submitForm);
|
||||
|
||||
ConfigureForm newConfig = myNode.getNodeConfiguration();
|
||||
assertEquals(AccessModel.whitelist, newConfig.getAccessModel());
|
||||
assertTrue(newConfig.isDeliverPayloads());
|
||||
assertFalse(newConfig.isNotifyRetract());
|
||||
assertFalse(newConfig.isPersistItems());
|
||||
assertEquals(PublishModel.publishers, newConfig.getPublishModel());
|
||||
}
|
||||
|
||||
public void testGetDefaultConfig() throws Exception
|
||||
{
|
||||
ConfigureForm form = getManager().getDefaultConfiguration();
|
||||
assertNotNull(form);
|
||||
}
|
||||
|
||||
public void testDeleteNode() throws Exception
|
||||
{
|
||||
LeafNode myNode = getManager().createNode();
|
||||
assertNotNull(getManager().getNode(myNode.getId()));
|
||||
|
||||
getManager(0).deleteNode(myNode.getId());
|
||||
|
||||
try
|
||||
{
|
||||
assertNull(getManager().getNode(myNode.getId()));
|
||||
fail("Node should not exist");
|
||||
}
|
||||
catch (XMPPException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void testPurgeItems() throws XMPPException
|
||||
{
|
||||
LeafNode node = getRandomPubnode(getManager(), true, false);
|
||||
|
||||
node.send(new Item());
|
||||
node.send(new Item());
|
||||
node.send(new Item());
|
||||
node.send(new Item());
|
||||
node.send(new Item());
|
||||
|
||||
Collection<? extends Item> items = node.getItems();
|
||||
assertTrue(items.size() == 5);
|
||||
|
||||
node.deleteAllItems();
|
||||
items = node.getItems();
|
||||
|
||||
// Pubsub service may keep the last notification (in spec), so 0 or 1 may be returned on get items.
|
||||
assertTrue(items.size() < 2);
|
||||
}
|
||||
}
|
||||
*/
|
||||
public class OwnerUseCases extends SingleUserTestCase
|
||||
{
|
||||
public void testCreateInstantNode() throws Exception
|
||||
{
|
||||
LeafNode node = getManager().createNode();
|
||||
assertNotNull(node);
|
||||
assertNotNull(node.getId());
|
||||
}
|
||||
|
||||
public void testCreateNamedNode() throws Exception
|
||||
{
|
||||
String id = "TestNamedNode" + System.currentTimeMillis();
|
||||
LeafNode node = getManager().createNode(id);
|
||||
assertEquals(id, node.getId());
|
||||
}
|
||||
|
||||
public void testCreateConfiguredNode() throws Exception
|
||||
{
|
||||
// Generate reasonably unique for multiple tests
|
||||
String id = "TestConfigNode" + System.currentTimeMillis();
|
||||
|
||||
// Create and configure a node
|
||||
ConfigureForm form = new ConfigureForm(FormType.submit);
|
||||
form.setAccessModel(AccessModel.open);
|
||||
form.setDeliverPayloads(false);
|
||||
form.setNotifyRetract(true);
|
||||
form.setPersistentItems(true);
|
||||
form.setPublishModel(PublishModel.open);
|
||||
|
||||
LeafNode node = (LeafNode)getManager().createNode(id, form);
|
||||
|
||||
ConfigureForm currentForm = node.getNodeConfiguration();
|
||||
assertEquals(AccessModel.open, currentForm.getAccessModel());
|
||||
assertFalse(currentForm.isDeliverPayloads());
|
||||
assertTrue(currentForm.isNotifyRetract());
|
||||
assertTrue(currentForm.isPersistItems());
|
||||
assertEquals(PublishModel.open, currentForm.getPublishModel());
|
||||
}
|
||||
|
||||
public void testCreateAndUpdateConfiguredNode() throws Exception
|
||||
{
|
||||
// Generate reasonably unique for multiple tests
|
||||
String id = "TestConfigNode2" + System.currentTimeMillis();
|
||||
|
||||
// Create and configure a node
|
||||
ConfigureForm form = new ConfigureForm(FormType.submit);
|
||||
form.setAccessModel(AccessModel.open);
|
||||
form.setDeliverPayloads(false);
|
||||
form.setNotifyRetract(true);
|
||||
form.setPersistentItems(true);
|
||||
form.setPublishModel(PublishModel.open);
|
||||
|
||||
LeafNode myNode = (LeafNode)getManager().createNode(id, form);
|
||||
ConfigureForm config = myNode.getNodeConfiguration();
|
||||
|
||||
assertEquals(AccessModel.open, config.getAccessModel());
|
||||
assertFalse(config.isDeliverPayloads());
|
||||
assertTrue(config.isNotifyRetract());
|
||||
assertTrue(config.isPersistItems());
|
||||
assertEquals(PublishModel.open, config.getPublishModel());
|
||||
|
||||
ConfigureForm submitForm = new ConfigureForm(config.createAnswerForm());
|
||||
submitForm.setAccessModel(AccessModel.whitelist);
|
||||
submitForm.setDeliverPayloads(true);
|
||||
submitForm.setNotifyRetract(false);
|
||||
submitForm.setPersistentItems(false);
|
||||
submitForm.setPublishModel(PublishModel.publishers);
|
||||
myNode.sendConfigurationForm(submitForm);
|
||||
|
||||
ConfigureForm newConfig = myNode.getNodeConfiguration();
|
||||
assertEquals(AccessModel.whitelist, newConfig.getAccessModel());
|
||||
assertTrue(newConfig.isDeliverPayloads());
|
||||
assertFalse(newConfig.isNotifyRetract());
|
||||
assertFalse(newConfig.isPersistItems());
|
||||
assertEquals(PublishModel.publishers, newConfig.getPublishModel());
|
||||
}
|
||||
|
||||
public void testGetDefaultConfig() throws Exception
|
||||
{
|
||||
ConfigureForm form = getManager().getDefaultConfiguration();
|
||||
assertNotNull(form);
|
||||
}
|
||||
|
||||
public void testDeleteNode() throws Exception
|
||||
{
|
||||
LeafNode myNode = getManager().createNode();
|
||||
assertNotNull(getManager().getNode(myNode.getId()));
|
||||
|
||||
getManager(0).deleteNode(myNode.getId());
|
||||
|
||||
try
|
||||
{
|
||||
assertNull(getManager().getNode(myNode.getId()));
|
||||
fail("Node should not exist");
|
||||
}
|
||||
catch (XMPPException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void testPurgeItems() throws XMPPException
|
||||
{
|
||||
LeafNode node = getRandomPubnode(getManager(), true, false);
|
||||
|
||||
node.send(new Item());
|
||||
node.send(new Item());
|
||||
node.send(new Item());
|
||||
node.send(new Item());
|
||||
node.send(new Item());
|
||||
|
||||
Collection<? extends Item> items = node.getItems();
|
||||
assertTrue(items.size() == 5);
|
||||
|
||||
node.deleteAllItems();
|
||||
items = node.getItems();
|
||||
|
||||
// Pubsub service may keep the last notification (in spec), so 0 or 1 may be returned on get items.
|
||||
assertTrue(items.size() < 2);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,153 +14,153 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.packet.XMPPError;
|
||||
import org.jivesoftware.smack.packet.XMPPError.Condition;
|
||||
import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
|
||||
import org.jivesoftware.smackx.pubsub.test.SingleUserTestCase;
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.packet.XMPPError;
|
||||
import org.jivesoftware.smack.packet.XMPPError.Condition;
|
||||
import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
|
||||
import org.jivesoftware.smackx.pubsub.test.SingleUserTestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Robin Collier
|
||||
*
|
||||
*/
|
||||
public class PublisherUseCases extends SingleUserTestCase
|
||||
{
|
||||
public void testSendNodeTrNot() throws Exception
|
||||
{
|
||||
getPubnode(false, false).send();
|
||||
}
|
||||
|
||||
public void testSendNodeTrPay_WithOutPayload() throws XMPPException
|
||||
{
|
||||
LeafNode node = getPubnode(false, true);
|
||||
|
||||
try
|
||||
{
|
||||
node.send(new Item());
|
||||
fail("Exception should be thrown when there is no payload");
|
||||
}
|
||||
catch (XMPPException e) {
|
||||
XMPPError err = e.getXMPPError();
|
||||
assertTrue(err.getType().equals(XMPPError.Type.MODIFY));
|
||||
assertTrue(err.getCondition().equals(Condition.bad_request.toString()));
|
||||
assertNotNull(err.getExtension("payload-required", PubSubNamespace.ERROR.getXmlns()));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
node.send(new Item("test" + System.currentTimeMillis()));
|
||||
fail("Exception should be thrown when there is no payload");
|
||||
}
|
||||
catch (XMPPException e) {
|
||||
XMPPError err = e.getXMPPError();
|
||||
assertTrue(err.getType().equals(XMPPError.Type.MODIFY));
|
||||
assertTrue(err.getCondition().equals(Condition.bad_request.toString()));
|
||||
assertNotNull(err.getExtension("payload-required", PubSubNamespace.ERROR.getXmlns()));
|
||||
}
|
||||
}
|
||||
|
||||
public void testSendNodeTrPay_WithPayload() throws XMPPException
|
||||
{
|
||||
LeafNode node = getPubnode(false, true);
|
||||
node.send(new PayloadItem<SimplePayload>(null,
|
||||
new SimplePayload("book", "pubsub:test:book", "<book xmlns='pubsub:test:book'><title>Lord of the Rings</title></book>")));
|
||||
node.send(new PayloadItem<SimplePayload>("test" + System.currentTimeMillis(),
|
||||
new SimplePayload("book", "pubsub:test:book", "<book xmlns='pubsub:test:book'><title>Two Towers</title></book>")));
|
||||
}
|
||||
|
||||
public void testSendNodePerNot() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(true, false);
|
||||
node.send(new Item());
|
||||
node.send(new Item("test" + System.currentTimeMillis()));
|
||||
node.send(new PayloadItem<SimplePayload>(null,
|
||||
new SimplePayload("book", "pubsub:test:book", "<book xmlns='pubsub:test:book'><title>Lord of the Rings</title></book>")));
|
||||
node.send(new PayloadItem<SimplePayload>("test" + System.currentTimeMillis(),
|
||||
new SimplePayload("book", "pubsub:test:book", "<book xmlns='pubsub:test:book'><title>Two Towers</title></book>")));
|
||||
}
|
||||
|
||||
public void testSendPerPay_WithPayload() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(true, true);
|
||||
node.send(new PayloadItem<SimplePayload>(null,
|
||||
new SimplePayload("book", "pubsub:test:book", "<book xmlns='pubsub:test:book'><title>Lord of the Rings</title></book>")));
|
||||
node.send(new PayloadItem<SimplePayload>("test" + System.currentTimeMillis(),
|
||||
new SimplePayload("book", "pubsub:test:book", "<book xmlns='pubsub:test:book'><title>Two Towers</title></book>")));
|
||||
}
|
||||
|
||||
public void testSendPerPay_NoPayload() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(true, true);
|
||||
try
|
||||
{
|
||||
node.send(new Item());
|
||||
fail("Exception should be thrown when there is no payload");
|
||||
}
|
||||
catch (XMPPException e) {
|
||||
XMPPError err = e.getXMPPError();
|
||||
assertTrue(err.getType().equals(XMPPError.Type.MODIFY));
|
||||
assertTrue(err.getCondition().equals(Condition.bad_request.toString()));
|
||||
assertNotNull(err.getExtension("payload-required", PubSubNamespace.ERROR.getXmlns()));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
node.send(new Item("test" + System.currentTimeMillis()));
|
||||
fail("Exception should be thrown when there is no payload");
|
||||
}
|
||||
catch (XMPPException e) {
|
||||
XMPPError err = e.getXMPPError();
|
||||
assertTrue(err.getType().equals(XMPPError.Type.MODIFY));
|
||||
assertTrue(err.getCondition().equals(Condition.bad_request.toString()));
|
||||
assertNotNull(err.getExtension("payload-required", PubSubNamespace.ERROR.getXmlns()));
|
||||
}
|
||||
}
|
||||
|
||||
public void testDeleteItems() throws XMPPException
|
||||
{
|
||||
LeafNode node = getPubnode(true, false);
|
||||
|
||||
node.send(new Item("1"));
|
||||
node.send(new Item("2"));
|
||||
node.send(new Item("3"));
|
||||
node.send(new Item("4"));
|
||||
|
||||
node.deleteItem("1");
|
||||
Collection<? extends Item> items = node.getItems();
|
||||
|
||||
assertEquals(3, items.size());
|
||||
}
|
||||
|
||||
public void testPersistItems() throws XMPPException
|
||||
{
|
||||
LeafNode node = getPubnode(true, false);
|
||||
|
||||
node.send(new Item("1"));
|
||||
node.send(new Item("2"));
|
||||
node.send(new Item("3"));
|
||||
node.send(new Item("4"));
|
||||
|
||||
Collection<? extends Item> items = node.getItems();
|
||||
|
||||
assertTrue(items.size() == 4);
|
||||
}
|
||||
|
||||
public void testItemOverwritten() throws XMPPException
|
||||
{
|
||||
LeafNode node = getPubnode(true, false);
|
||||
|
||||
node.send(new PayloadItem<SimplePayload>("1", new SimplePayload("test", null, "<test/>")));
|
||||
node.send(new PayloadItem<SimplePayload>("1", new SimplePayload("test2", null, "<test2/>")));
|
||||
|
||||
List<? extends Item> items = node.getItems();
|
||||
assertEquals(1, items.size());
|
||||
assertEquals("1", items.get(0).getId());
|
||||
}
|
||||
}
|
||||
*/
|
||||
public class PublisherUseCases extends SingleUserTestCase
|
||||
{
|
||||
public void testSendNodeTrNot() throws Exception
|
||||
{
|
||||
getPubnode(false, false).send();
|
||||
}
|
||||
|
||||
public void testSendNodeTrPay_WithOutPayload() throws XMPPException
|
||||
{
|
||||
LeafNode node = getPubnode(false, true);
|
||||
|
||||
try
|
||||
{
|
||||
node.send(new Item());
|
||||
fail("Exception should be thrown when there is no payload");
|
||||
}
|
||||
catch (XMPPException e) {
|
||||
XMPPError err = e.getXMPPError();
|
||||
assertTrue(err.getType().equals(XMPPError.Type.MODIFY));
|
||||
assertTrue(err.getCondition().equals(Condition.bad_request.toString()));
|
||||
assertNotNull(err.getExtension("payload-required", PubSubNamespace.ERROR.getXmlns()));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
node.send(new Item("test" + System.currentTimeMillis()));
|
||||
fail("Exception should be thrown when there is no payload");
|
||||
}
|
||||
catch (XMPPException e) {
|
||||
XMPPError err = e.getXMPPError();
|
||||
assertTrue(err.getType().equals(XMPPError.Type.MODIFY));
|
||||
assertTrue(err.getCondition().equals(Condition.bad_request.toString()));
|
||||
assertNotNull(err.getExtension("payload-required", PubSubNamespace.ERROR.getXmlns()));
|
||||
}
|
||||
}
|
||||
|
||||
public void testSendNodeTrPay_WithPayload() throws XMPPException
|
||||
{
|
||||
LeafNode node = getPubnode(false, true);
|
||||
node.send(new PayloadItem<SimplePayload>(null,
|
||||
new SimplePayload("book", "pubsub:test:book", "<book xmlns='pubsub:test:book'><title>Lord of the Rings</title></book>")));
|
||||
node.send(new PayloadItem<SimplePayload>("test" + System.currentTimeMillis(),
|
||||
new SimplePayload("book", "pubsub:test:book", "<book xmlns='pubsub:test:book'><title>Two Towers</title></book>")));
|
||||
}
|
||||
|
||||
public void testSendNodePerNot() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(true, false);
|
||||
node.send(new Item());
|
||||
node.send(new Item("test" + System.currentTimeMillis()));
|
||||
node.send(new PayloadItem<SimplePayload>(null,
|
||||
new SimplePayload("book", "pubsub:test:book", "<book xmlns='pubsub:test:book'><title>Lord of the Rings</title></book>")));
|
||||
node.send(new PayloadItem<SimplePayload>("test" + System.currentTimeMillis(),
|
||||
new SimplePayload("book", "pubsub:test:book", "<book xmlns='pubsub:test:book'><title>Two Towers</title></book>")));
|
||||
}
|
||||
|
||||
public void testSendPerPay_WithPayload() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(true, true);
|
||||
node.send(new PayloadItem<SimplePayload>(null,
|
||||
new SimplePayload("book", "pubsub:test:book", "<book xmlns='pubsub:test:book'><title>Lord of the Rings</title></book>")));
|
||||
node.send(new PayloadItem<SimplePayload>("test" + System.currentTimeMillis(),
|
||||
new SimplePayload("book", "pubsub:test:book", "<book xmlns='pubsub:test:book'><title>Two Towers</title></book>")));
|
||||
}
|
||||
|
||||
public void testSendPerPay_NoPayload() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(true, true);
|
||||
try
|
||||
{
|
||||
node.send(new Item());
|
||||
fail("Exception should be thrown when there is no payload");
|
||||
}
|
||||
catch (XMPPException e) {
|
||||
XMPPError err = e.getXMPPError();
|
||||
assertTrue(err.getType().equals(XMPPError.Type.MODIFY));
|
||||
assertTrue(err.getCondition().equals(Condition.bad_request.toString()));
|
||||
assertNotNull(err.getExtension("payload-required", PubSubNamespace.ERROR.getXmlns()));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
node.send(new Item("test" + System.currentTimeMillis()));
|
||||
fail("Exception should be thrown when there is no payload");
|
||||
}
|
||||
catch (XMPPException e) {
|
||||
XMPPError err = e.getXMPPError();
|
||||
assertTrue(err.getType().equals(XMPPError.Type.MODIFY));
|
||||
assertTrue(err.getCondition().equals(Condition.bad_request.toString()));
|
||||
assertNotNull(err.getExtension("payload-required", PubSubNamespace.ERROR.getXmlns()));
|
||||
}
|
||||
}
|
||||
|
||||
public void testDeleteItems() throws XMPPException
|
||||
{
|
||||
LeafNode node = getPubnode(true, false);
|
||||
|
||||
node.send(new Item("1"));
|
||||
node.send(new Item("2"));
|
||||
node.send(new Item("3"));
|
||||
node.send(new Item("4"));
|
||||
|
||||
node.deleteItem("1");
|
||||
Collection<? extends Item> items = node.getItems();
|
||||
|
||||
assertEquals(3, items.size());
|
||||
}
|
||||
|
||||
public void testPersistItems() throws XMPPException
|
||||
{
|
||||
LeafNode node = getPubnode(true, false);
|
||||
|
||||
node.send(new Item("1"));
|
||||
node.send(new Item("2"));
|
||||
node.send(new Item("3"));
|
||||
node.send(new Item("4"));
|
||||
|
||||
Collection<? extends Item> items = node.getItems();
|
||||
|
||||
assertTrue(items.size() == 4);
|
||||
}
|
||||
|
||||
public void testItemOverwritten() throws XMPPException
|
||||
{
|
||||
LeafNode node = getPubnode(true, false);
|
||||
|
||||
node.send(new PayloadItem<SimplePayload>("1", new SimplePayload("test", null, "<test/>")));
|
||||
node.send(new PayloadItem<SimplePayload>("1", new SimplePayload("test2", null, "<test2/>")));
|
||||
|
||||
List<? extends Item> items = node.getItems();
|
||||
assertEquals(1, items.size());
|
||||
assertEquals("1", items.get(0).getId());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,267 +14,267 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smackx.FormField;
|
||||
import org.jivesoftware.smackx.pubsub.test.SingleUserTestCase;
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smackx.FormField;
|
||||
import org.jivesoftware.smackx.pubsub.test.SingleUserTestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Robin Collier
|
||||
*
|
||||
*/
|
||||
public class SubscriberUseCases extends SingleUserTestCase
|
||||
{
|
||||
public void testSubscribe() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(false, false);
|
||||
Subscription sub = node.subscribe(getJid());
|
||||
|
||||
assertEquals(getJid(), sub.getJid());
|
||||
assertNotNull(sub.getId());
|
||||
assertEquals(node.getId(), sub.getNode());
|
||||
assertEquals(Subscription.State.subscribed, sub.getState());
|
||||
}
|
||||
|
||||
public void testSubscribeBadJid() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(false, false);
|
||||
|
||||
try
|
||||
{
|
||||
node.subscribe("this@over.here");
|
||||
fail();
|
||||
}
|
||||
catch (XMPPException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void testSubscribeWithOptions() throws Exception
|
||||
{
|
||||
SubscribeForm form = new SubscribeForm(FormType.submit);
|
||||
form.setDeliverOn(true);
|
||||
Calendar expire = Calendar.getInstance();
|
||||
expire.set(2020, 1, 1);
|
||||
form.setExpiry(expire.getTime());
|
||||
LeafNode node = getPubnode(false, false);
|
||||
node.subscribe(getJid(), form);
|
||||
}
|
||||
|
||||
public void testSubscribeConfigRequired() throws Exception
|
||||
{
|
||||
ConfigureForm form = new ConfigureForm(FormType.submit);
|
||||
form.setAccessModel(AccessModel.open);
|
||||
|
||||
// Openfire specific field - nothing in the spec yet
|
||||
FormField required = new FormField("pubsub#subscription_required");
|
||||
required.setType(FormField.TYPE_BOOLEAN);
|
||||
form.addField(required);
|
||||
form.setAnswer("pubsub#subscription_required", true);
|
||||
LeafNode node = (LeafNode)getManager().createNode("Pubnode" + System.currentTimeMillis(), form);
|
||||
|
||||
Subscription sub = node.subscribe(getJid());
|
||||
|
||||
assertEquals(getJid(), sub.getJid());
|
||||
assertNotNull(sub.getId());
|
||||
assertEquals(node.getId(), sub.getNode());
|
||||
assertEquals(true, sub.isConfigRequired());
|
||||
}
|
||||
|
||||
public void testUnsubscribe() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(false, false);
|
||||
node.subscribe(getJid());
|
||||
Collection<Subscription> subs = node.getSubscriptions();
|
||||
|
||||
node.unsubscribe(getJid());
|
||||
Collection<Subscription> afterSubs = node.getSubscriptions();
|
||||
assertEquals(subs.size()-1, afterSubs.size());
|
||||
}
|
||||
|
||||
public void testUnsubscribeWithMultipleNoSubId() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(false, false);
|
||||
node.subscribe(getBareJID(0));
|
||||
node.subscribe(getBareJID(0));
|
||||
node.subscribe(getBareJID(0));
|
||||
|
||||
try
|
||||
{
|
||||
node.unsubscribe(getBareJID(0));
|
||||
fail("Unsubscribe with no subid should fail");
|
||||
}
|
||||
catch (XMPPException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void testUnsubscribeWithMultipleWithSubId() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(false, false);
|
||||
node.subscribe(getJid());
|
||||
Subscription sub = node.subscribe(getJid());
|
||||
node.subscribe(getJid());
|
||||
node.unsubscribe(getJid(), sub.getId());
|
||||
}
|
||||
|
||||
public void testGetOptions() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(false, false);
|
||||
Subscription sub = node.subscribe(getJid());
|
||||
SubscribeForm form = node.getSubscriptionOptions(getJid(), sub.getId());
|
||||
assertNotNull(form);
|
||||
}
|
||||
|
||||
// public void testSubscribeWithConfig() throws Exception
|
||||
// {
|
||||
// LeafNode node = getPubnode(false, false);
|
||||
//
|
||||
// Subscription sub = node.subscribe(getBareJID(0));
|
||||
//
|
||||
// assertEquals(getBareJID(0), sub.getJid());
|
||||
// assertNotNull(sub.getId());
|
||||
// assertEquals(node.getId(), sub.getNode());
|
||||
// assertEquals(true, sub.isConfigRequired());
|
||||
// }
|
||||
//
|
||||
public void testGetItems() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(true, false);
|
||||
runNodeTests(node);
|
||||
}
|
||||
|
||||
private void runNodeTests(LeafNode node) throws Exception
|
||||
{
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
|
||||
Collection<? extends Item> items = node.getItems();
|
||||
assertTrue(items.size() == 5);
|
||||
|
||||
long curTime = System.currentTimeMillis();
|
||||
node.send(new Item("1-" + curTime));
|
||||
node.send(new Item("2-" + curTime));
|
||||
node.send(new Item("3-" + curTime));
|
||||
node.send(new Item("4-" + curTime));
|
||||
node.send(new Item("5-" + curTime));
|
||||
|
||||
items = node.getItems();
|
||||
assertTrue(items.size() == 10);
|
||||
|
||||
LeafNode payloadNode = getPubnode(true, true);
|
||||
|
||||
Map<String , String> idPayload = new HashMap<String, String>();
|
||||
idPayload.put("6-" + curTime, "<a/>");
|
||||
idPayload.put("7-" + curTime, "<a href=\"/up/here\"/>");
|
||||
idPayload.put("8-" + curTime, "<entity>text<inner></inner></entity>");
|
||||
idPayload.put("9-" + curTime, "<entity><inner><text></text></inner></entity>");
|
||||
|
||||
for (Map.Entry<String, String> payload : idPayload.entrySet())
|
||||
{
|
||||
payloadNode.send(new PayloadItem<SimplePayload>(payload.getKey(), new SimplePayload("a", "pubsub:test", payload.getValue())));
|
||||
}
|
||||
|
||||
payloadNode.send(new PayloadItem<SimplePayload>("6-" + curTime, new SimplePayload("a", "pubsub:test", "<a xmlns='pubsub:test'/>")));
|
||||
payloadNode.send(new PayloadItem<SimplePayload>("7-" + curTime, new SimplePayload("a", "pubsub:test", "<a xmlns='pubsub:test' href=\'/up/here\'/>")));
|
||||
payloadNode.send(new PayloadItem<SimplePayload>("8-" + curTime, new SimplePayload("entity", "pubsub:test", "<entity xmlns='pubsub:test'>text<inner>a</inner></entity>")));
|
||||
payloadNode.send(new PayloadItem<SimplePayload>("9-" + curTime, new SimplePayload("entity", "pubsub:test", "<entity xmlns='pubsub:test'><inner><text>b</text></inner></entity>")));
|
||||
|
||||
List<PayloadItem<SimplePayload>> payloadItems = payloadNode.getItems();
|
||||
Map<String, PayloadItem<SimplePayload>> idMap = new HashMap<String, PayloadItem<SimplePayload>>();
|
||||
|
||||
for (PayloadItem<SimplePayload> payloadItem : payloadItems)
|
||||
{
|
||||
idMap.put(payloadItem.getId(), payloadItem);
|
||||
}
|
||||
|
||||
assertEquals(4, payloadItems.size());
|
||||
|
||||
PayloadItem<SimplePayload> testItem = idMap.get("6-" + curTime);
|
||||
assertNotNull(testItem);
|
||||
assertXMLEqual("<a xmlns='pubsub:test'/>", testItem.getPayload().toXML());
|
||||
|
||||
testItem = idMap.get("7-" + curTime);
|
||||
assertNotNull(testItem);
|
||||
assertXMLEqual("<a xmlns='pubsub:test' href=\'/up/here\'/>", testItem.getPayload().toXML());
|
||||
|
||||
testItem = idMap.get("8-" + curTime);
|
||||
assertNotNull(testItem);
|
||||
assertXMLEqual("<entity xmlns='pubsub:test'>text<inner>a</inner></entity>", testItem.getPayload().toXML());
|
||||
|
||||
testItem = idMap.get("9-" + curTime);
|
||||
assertNotNull(testItem);
|
||||
assertXMLEqual("<entity xmlns='pubsub:test'><inner><text>b</text></inner></entity>", testItem.getPayload().toXML());
|
||||
}
|
||||
|
||||
public void testGetSpecifiedItems() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(true, true);
|
||||
|
||||
node.send(new PayloadItem<SimplePayload>("1", new SimplePayload("a", "pubsub:test", "<a xmlns='pubsub:test' href='1'/>")));
|
||||
node.send(new PayloadItem<SimplePayload>("2", new SimplePayload("a", "pubsub:test", "<a xmlns='pubsub:test' href='2'/>")));
|
||||
node.send(new PayloadItem<SimplePayload>("3", new SimplePayload("a", "pubsub:test", "<a xmlns='pubsub:test' href='3'/>")));
|
||||
node.send(new PayloadItem<SimplePayload>("4", new SimplePayload("a", "pubsub:test", "<a xmlns='pubsub:test' href='4'/>")));
|
||||
node.send(new PayloadItem<SimplePayload>("5", new SimplePayload("a", "pubsub:test", "<a xmlns='pubsub:test' href='5'/>")));
|
||||
|
||||
Collection<String> ids = new ArrayList<String>(3);
|
||||
ids.add("1");
|
||||
ids.add("3");
|
||||
ids.add("4");
|
||||
|
||||
List<PayloadItem<SimplePayload>> items = node.getItems(ids);
|
||||
assertEquals(3, items.size());
|
||||
assertEquals("1", items.get(0).getId());
|
||||
assertXMLEqual("<a xmlns='pubsub:test' href='1'/>", items.get(0).getPayload().toXML());
|
||||
assertEquals( "3", items.get(1).getId());
|
||||
assertXMLEqual("<a xmlns='pubsub:test' href='3'/>", items.get(1).getPayload().toXML());
|
||||
assertEquals("4", items.get(2).getId());
|
||||
assertXMLEqual("<a xmlns='pubsub:test' href='4'/>", items.get(2).getPayload().toXML());
|
||||
}
|
||||
|
||||
public void testGetLastNItems() throws XMPPException
|
||||
{
|
||||
LeafNode node = getPubnode(true, false);
|
||||
|
||||
node.send(new Item("1"));
|
||||
node.send(new Item("2"));
|
||||
node.send(new Item("3"));
|
||||
node.send(new Item("4"));
|
||||
node.send(new Item("5"));
|
||||
|
||||
List<Item> items = node.getItems(2);
|
||||
assertEquals(2, items.size());
|
||||
assertTrue(listContainsId("4", items));
|
||||
assertTrue(listContainsId("5", items));
|
||||
}
|
||||
|
||||
private static boolean listContainsId(String id, List<Item> items)
|
||||
{
|
||||
for (Item item : items)
|
||||
{
|
||||
if (item.getId().equals(id))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private String getJid()
|
||||
{
|
||||
return getConnection(0).getUser();
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
public class SubscriberUseCases extends SingleUserTestCase
|
||||
{
|
||||
public void testSubscribe() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(false, false);
|
||||
Subscription sub = node.subscribe(getJid());
|
||||
|
||||
assertEquals(getJid(), sub.getJid());
|
||||
assertNotNull(sub.getId());
|
||||
assertEquals(node.getId(), sub.getNode());
|
||||
assertEquals(Subscription.State.subscribed, sub.getState());
|
||||
}
|
||||
|
||||
public void testSubscribeBadJid() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(false, false);
|
||||
|
||||
try
|
||||
{
|
||||
node.subscribe("this@over.here");
|
||||
fail();
|
||||
}
|
||||
catch (XMPPException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void testSubscribeWithOptions() throws Exception
|
||||
{
|
||||
SubscribeForm form = new SubscribeForm(FormType.submit);
|
||||
form.setDeliverOn(true);
|
||||
Calendar expire = Calendar.getInstance();
|
||||
expire.set(2020, 1, 1);
|
||||
form.setExpiry(expire.getTime());
|
||||
LeafNode node = getPubnode(false, false);
|
||||
node.subscribe(getJid(), form);
|
||||
}
|
||||
|
||||
public void testSubscribeConfigRequired() throws Exception
|
||||
{
|
||||
ConfigureForm form = new ConfigureForm(FormType.submit);
|
||||
form.setAccessModel(AccessModel.open);
|
||||
|
||||
// Openfire specific field - nothing in the spec yet
|
||||
FormField required = new FormField("pubsub#subscription_required");
|
||||
required.setType(FormField.TYPE_BOOLEAN);
|
||||
form.addField(required);
|
||||
form.setAnswer("pubsub#subscription_required", true);
|
||||
LeafNode node = (LeafNode)getManager().createNode("Pubnode" + System.currentTimeMillis(), form);
|
||||
|
||||
Subscription sub = node.subscribe(getJid());
|
||||
|
||||
assertEquals(getJid(), sub.getJid());
|
||||
assertNotNull(sub.getId());
|
||||
assertEquals(node.getId(), sub.getNode());
|
||||
assertEquals(true, sub.isConfigRequired());
|
||||
}
|
||||
|
||||
public void testUnsubscribe() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(false, false);
|
||||
node.subscribe(getJid());
|
||||
Collection<Subscription> subs = node.getSubscriptions();
|
||||
|
||||
node.unsubscribe(getJid());
|
||||
Collection<Subscription> afterSubs = node.getSubscriptions();
|
||||
assertEquals(subs.size()-1, afterSubs.size());
|
||||
}
|
||||
|
||||
public void testUnsubscribeWithMultipleNoSubId() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(false, false);
|
||||
node.subscribe(getBareJID(0));
|
||||
node.subscribe(getBareJID(0));
|
||||
node.subscribe(getBareJID(0));
|
||||
|
||||
try
|
||||
{
|
||||
node.unsubscribe(getBareJID(0));
|
||||
fail("Unsubscribe with no subid should fail");
|
||||
}
|
||||
catch (XMPPException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void testUnsubscribeWithMultipleWithSubId() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(false, false);
|
||||
node.subscribe(getJid());
|
||||
Subscription sub = node.subscribe(getJid());
|
||||
node.subscribe(getJid());
|
||||
node.unsubscribe(getJid(), sub.getId());
|
||||
}
|
||||
|
||||
public void testGetOptions() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(false, false);
|
||||
Subscription sub = node.subscribe(getJid());
|
||||
SubscribeForm form = node.getSubscriptionOptions(getJid(), sub.getId());
|
||||
assertNotNull(form);
|
||||
}
|
||||
|
||||
// public void testSubscribeWithConfig() throws Exception
|
||||
// {
|
||||
// LeafNode node = getPubnode(false, false);
|
||||
//
|
||||
// Subscription sub = node.subscribe(getBareJID(0));
|
||||
//
|
||||
// assertEquals(getBareJID(0), sub.getJid());
|
||||
// assertNotNull(sub.getId());
|
||||
// assertEquals(node.getId(), sub.getNode());
|
||||
// assertEquals(true, sub.isConfigRequired());
|
||||
// }
|
||||
//
|
||||
public void testGetItems() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(true, false);
|
||||
runNodeTests(node);
|
||||
}
|
||||
|
||||
private void runNodeTests(LeafNode node) throws Exception
|
||||
{
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
|
||||
Collection<? extends Item> items = node.getItems();
|
||||
assertTrue(items.size() == 5);
|
||||
|
||||
long curTime = System.currentTimeMillis();
|
||||
node.send(new Item("1-" + curTime));
|
||||
node.send(new Item("2-" + curTime));
|
||||
node.send(new Item("3-" + curTime));
|
||||
node.send(new Item("4-" + curTime));
|
||||
node.send(new Item("5-" + curTime));
|
||||
|
||||
items = node.getItems();
|
||||
assertTrue(items.size() == 10);
|
||||
|
||||
LeafNode payloadNode = getPubnode(true, true);
|
||||
|
||||
Map<String , String> idPayload = new HashMap<String, String>();
|
||||
idPayload.put("6-" + curTime, "<a/>");
|
||||
idPayload.put("7-" + curTime, "<a href=\"/up/here\"/>");
|
||||
idPayload.put("8-" + curTime, "<entity>text<inner></inner></entity>");
|
||||
idPayload.put("9-" + curTime, "<entity><inner><text></text></inner></entity>");
|
||||
|
||||
for (Map.Entry<String, String> payload : idPayload.entrySet())
|
||||
{
|
||||
payloadNode.send(new PayloadItem<SimplePayload>(payload.getKey(), new SimplePayload("a", "pubsub:test", payload.getValue())));
|
||||
}
|
||||
|
||||
payloadNode.send(new PayloadItem<SimplePayload>("6-" + curTime, new SimplePayload("a", "pubsub:test", "<a xmlns='pubsub:test'/>")));
|
||||
payloadNode.send(new PayloadItem<SimplePayload>("7-" + curTime, new SimplePayload("a", "pubsub:test", "<a xmlns='pubsub:test' href=\'/up/here\'/>")));
|
||||
payloadNode.send(new PayloadItem<SimplePayload>("8-" + curTime, new SimplePayload("entity", "pubsub:test", "<entity xmlns='pubsub:test'>text<inner>a</inner></entity>")));
|
||||
payloadNode.send(new PayloadItem<SimplePayload>("9-" + curTime, new SimplePayload("entity", "pubsub:test", "<entity xmlns='pubsub:test'><inner><text>b</text></inner></entity>")));
|
||||
|
||||
List<PayloadItem<SimplePayload>> payloadItems = payloadNode.getItems();
|
||||
Map<String, PayloadItem<SimplePayload>> idMap = new HashMap<String, PayloadItem<SimplePayload>>();
|
||||
|
||||
for (PayloadItem<SimplePayload> payloadItem : payloadItems)
|
||||
{
|
||||
idMap.put(payloadItem.getId(), payloadItem);
|
||||
}
|
||||
|
||||
assertEquals(4, payloadItems.size());
|
||||
|
||||
PayloadItem<SimplePayload> testItem = idMap.get("6-" + curTime);
|
||||
assertNotNull(testItem);
|
||||
assertXMLEqual("<a xmlns='pubsub:test'/>", testItem.getPayload().toXML());
|
||||
|
||||
testItem = idMap.get("7-" + curTime);
|
||||
assertNotNull(testItem);
|
||||
assertXMLEqual("<a xmlns='pubsub:test' href=\'/up/here\'/>", testItem.getPayload().toXML());
|
||||
|
||||
testItem = idMap.get("8-" + curTime);
|
||||
assertNotNull(testItem);
|
||||
assertXMLEqual("<entity xmlns='pubsub:test'>text<inner>a</inner></entity>", testItem.getPayload().toXML());
|
||||
|
||||
testItem = idMap.get("9-" + curTime);
|
||||
assertNotNull(testItem);
|
||||
assertXMLEqual("<entity xmlns='pubsub:test'><inner><text>b</text></inner></entity>", testItem.getPayload().toXML());
|
||||
}
|
||||
|
||||
public void testGetSpecifiedItems() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(true, true);
|
||||
|
||||
node.send(new PayloadItem<SimplePayload>("1", new SimplePayload("a", "pubsub:test", "<a xmlns='pubsub:test' href='1'/>")));
|
||||
node.send(new PayloadItem<SimplePayload>("2", new SimplePayload("a", "pubsub:test", "<a xmlns='pubsub:test' href='2'/>")));
|
||||
node.send(new PayloadItem<SimplePayload>("3", new SimplePayload("a", "pubsub:test", "<a xmlns='pubsub:test' href='3'/>")));
|
||||
node.send(new PayloadItem<SimplePayload>("4", new SimplePayload("a", "pubsub:test", "<a xmlns='pubsub:test' href='4'/>")));
|
||||
node.send(new PayloadItem<SimplePayload>("5", new SimplePayload("a", "pubsub:test", "<a xmlns='pubsub:test' href='5'/>")));
|
||||
|
||||
Collection<String> ids = new ArrayList<String>(3);
|
||||
ids.add("1");
|
||||
ids.add("3");
|
||||
ids.add("4");
|
||||
|
||||
List<PayloadItem<SimplePayload>> items = node.getItems(ids);
|
||||
assertEquals(3, items.size());
|
||||
assertEquals("1", items.get(0).getId());
|
||||
assertXMLEqual("<a xmlns='pubsub:test' href='1'/>", items.get(0).getPayload().toXML());
|
||||
assertEquals( "3", items.get(1).getId());
|
||||
assertXMLEqual("<a xmlns='pubsub:test' href='3'/>", items.get(1).getPayload().toXML());
|
||||
assertEquals("4", items.get(2).getId());
|
||||
assertXMLEqual("<a xmlns='pubsub:test' href='4'/>", items.get(2).getPayload().toXML());
|
||||
}
|
||||
|
||||
public void testGetLastNItems() throws XMPPException
|
||||
{
|
||||
LeafNode node = getPubnode(true, false);
|
||||
|
||||
node.send(new Item("1"));
|
||||
node.send(new Item("2"));
|
||||
node.send(new Item("3"));
|
||||
node.send(new Item("4"));
|
||||
node.send(new Item("5"));
|
||||
|
||||
List<Item> items = node.getItems(2);
|
||||
assertEquals(2, items.size());
|
||||
assertTrue(listContainsId("4", items));
|
||||
assertTrue(listContainsId("5", items));
|
||||
}
|
||||
|
||||
private static boolean listContainsId(String id, List<Item> items)
|
||||
{
|
||||
for (Item item : items)
|
||||
{
|
||||
if (item.getId().equals(id))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private String getJid()
|
||||
{
|
||||
return getConnection(0).getUser();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,27 +14,27 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smackx.pubsub.test.SingleUserTestCase;
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smackx.pubsub.test.SingleUserTestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Robin Collier
|
||||
*
|
||||
*/
|
||||
public class TestAPI extends SingleUserTestCase
|
||||
{
|
||||
public void testGetNonexistentNode()
|
||||
{
|
||||
try
|
||||
{
|
||||
getManager().getNode("" + System.currentTimeMillis());
|
||||
assertTrue(false);
|
||||
}
|
||||
catch (XMPPException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
public class TestAPI extends SingleUserTestCase
|
||||
{
|
||||
public void testGetNonexistentNode()
|
||||
{
|
||||
try
|
||||
{
|
||||
getManager().getNode("" + System.currentTimeMillis());
|
||||
assertTrue(false);
|
||||
}
|
||||
catch (XMPPException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -14,121 +14,121 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Robin Collier
|
||||
*
|
||||
*/
|
||||
public class TestMessageContent extends TestCase
|
||||
{
|
||||
String payloadXmlWithNS = "<book xmlns='pubsub:test:book'><author name='Stephen King'/></book>";
|
||||
|
||||
public void testItemWithId()
|
||||
{
|
||||
Item item = new Item("123");
|
||||
assertEquals("<item id='123'/>", item.toXML());
|
||||
assertEquals("item", item.getElementName());
|
||||
assertNull(item.getNamespace());
|
||||
}
|
||||
|
||||
public void testItemWithNoId()
|
||||
{
|
||||
Item item = new Item();
|
||||
assertEquals("<item/>", item.toXML());
|
||||
|
||||
Item itemNull = new Item(null);
|
||||
assertEquals("<item/>", itemNull.toXML());
|
||||
}
|
||||
|
||||
public void testSimplePayload()
|
||||
{
|
||||
SimplePayload payloadNS = new SimplePayload("book", "pubsub:test:book", payloadXmlWithNS);
|
||||
|
||||
assertEquals(payloadXmlWithNS, payloadNS.toXML());
|
||||
|
||||
String payloadXmlWithNoNS = "<book><author name='Stephen King'/></book>";
|
||||
SimplePayload payloadNoNS = new SimplePayload("book", null, "<book><author name='Stephen King'/></book>");
|
||||
|
||||
assertEquals(payloadXmlWithNoNS, payloadNoNS.toXML());
|
||||
|
||||
}
|
||||
|
||||
public void testPayloadItemWithId()
|
||||
{
|
||||
SimplePayload payload = new SimplePayload("book", "pubsub:test:book", payloadXmlWithNS);
|
||||
PayloadItem<SimplePayload> item = new PayloadItem<SimplePayload>("123", payload);
|
||||
|
||||
String xml = "<item id='123'>" + payloadXmlWithNS + "</item>";
|
||||
assertEquals(xml, item.toXML());
|
||||
assertEquals("item", item.getElementName());
|
||||
}
|
||||
|
||||
public void testPayloadItemWithNoId()
|
||||
{
|
||||
SimplePayload payload = new SimplePayload("book", "pubsub:test:book", payloadXmlWithNS);
|
||||
PayloadItem<SimplePayload> item = new PayloadItem<SimplePayload>(null, payload);
|
||||
|
||||
String xml = "<item>" + payloadXmlWithNS + "</item>";
|
||||
assertEquals(xml, item.toXML());
|
||||
}
|
||||
|
||||
public void testPayloadItemWithIdNoPayload()
|
||||
{
|
||||
try
|
||||
{
|
||||
PayloadItem<SimplePayload> item = new PayloadItem<SimplePayload>("123", null);
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void testPayloadItemWithNoIdNoPayload()
|
||||
{
|
||||
try
|
||||
{
|
||||
PayloadItem<SimplePayload> item = new PayloadItem<SimplePayload>(null, null);
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void testRetractItem()
|
||||
{
|
||||
RetractItem item = new RetractItem("1234");
|
||||
|
||||
assertEquals("<retract id='1234'/>", item.toXML());
|
||||
assertEquals("retract", item.getElementName());
|
||||
|
||||
try
|
||||
{
|
||||
new RetractItem(null);
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetItemsRequest()
|
||||
{
|
||||
GetItemsRequest request = new GetItemsRequest("testId");
|
||||
assertEquals("<items node='testId'/>", request.toXML());
|
||||
|
||||
request = new GetItemsRequest("testId", 5);
|
||||
assertEquals("<items node='testId' max_items='5'/>", request.toXML());
|
||||
|
||||
request = new GetItemsRequest("testId", "qwerty");
|
||||
assertEquals("<items node='testId' subid='qwerty'/>", request.toXML());
|
||||
|
||||
request = new GetItemsRequest("testId", "qwerty", 5);
|
||||
assertEquals("<items node='testId' subid='qwerty' max_items='5'/>", request.toXML());
|
||||
}
|
||||
}
|
||||
*/
|
||||
public class TestMessageContent extends TestCase
|
||||
{
|
||||
String payloadXmlWithNS = "<book xmlns='pubsub:test:book'><author name='Stephen King'/></book>";
|
||||
|
||||
public void testItemWithId()
|
||||
{
|
||||
Item item = new Item("123");
|
||||
assertEquals("<item id='123'/>", item.toXML());
|
||||
assertEquals("item", item.getElementName());
|
||||
assertNull(item.getNamespace());
|
||||
}
|
||||
|
||||
public void testItemWithNoId()
|
||||
{
|
||||
Item item = new Item();
|
||||
assertEquals("<item/>", item.toXML());
|
||||
|
||||
Item itemNull = new Item(null);
|
||||
assertEquals("<item/>", itemNull.toXML());
|
||||
}
|
||||
|
||||
public void testSimplePayload()
|
||||
{
|
||||
SimplePayload payloadNS = new SimplePayload("book", "pubsub:test:book", payloadXmlWithNS);
|
||||
|
||||
assertEquals(payloadXmlWithNS, payloadNS.toXML());
|
||||
|
||||
String payloadXmlWithNoNS = "<book><author name='Stephen King'/></book>";
|
||||
SimplePayload payloadNoNS = new SimplePayload("book", null, "<book><author name='Stephen King'/></book>");
|
||||
|
||||
assertEquals(payloadXmlWithNoNS, payloadNoNS.toXML());
|
||||
|
||||
}
|
||||
|
||||
public void testPayloadItemWithId()
|
||||
{
|
||||
SimplePayload payload = new SimplePayload("book", "pubsub:test:book", payloadXmlWithNS);
|
||||
PayloadItem<SimplePayload> item = new PayloadItem<SimplePayload>("123", payload);
|
||||
|
||||
String xml = "<item id='123'>" + payloadXmlWithNS + "</item>";
|
||||
assertEquals(xml, item.toXML());
|
||||
assertEquals("item", item.getElementName());
|
||||
}
|
||||
|
||||
public void testPayloadItemWithNoId()
|
||||
{
|
||||
SimplePayload payload = new SimplePayload("book", "pubsub:test:book", payloadXmlWithNS);
|
||||
PayloadItem<SimplePayload> item = new PayloadItem<SimplePayload>(null, payload);
|
||||
|
||||
String xml = "<item>" + payloadXmlWithNS + "</item>";
|
||||
assertEquals(xml, item.toXML());
|
||||
}
|
||||
|
||||
public void testPayloadItemWithIdNoPayload()
|
||||
{
|
||||
try
|
||||
{
|
||||
PayloadItem<SimplePayload> item = new PayloadItem<SimplePayload>("123", null);
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void testPayloadItemWithNoIdNoPayload()
|
||||
{
|
||||
try
|
||||
{
|
||||
PayloadItem<SimplePayload> item = new PayloadItem<SimplePayload>(null, null);
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void testRetractItem()
|
||||
{
|
||||
RetractItem item = new RetractItem("1234");
|
||||
|
||||
assertEquals("<retract id='1234'/>", item.toXML());
|
||||
assertEquals("retract", item.getElementName());
|
||||
|
||||
try
|
||||
{
|
||||
new RetractItem(null);
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetItemsRequest()
|
||||
{
|
||||
GetItemsRequest request = new GetItemsRequest("testId");
|
||||
assertEquals("<items node='testId'/>", request.toXML());
|
||||
|
||||
request = new GetItemsRequest("testId", 5);
|
||||
assertEquals("<items node='testId' max_items='5'/>", request.toXML());
|
||||
|
||||
request = new GetItemsRequest("testId", "qwerty");
|
||||
assertEquals("<items node='testId' subid='qwerty'/>", request.toXML());
|
||||
|
||||
request = new GetItemsRequest("testId", "qwerty", 5);
|
||||
assertEquals("<items node='testId' subid='qwerty' max_items='5'/>", request.toXML());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,79 +14,79 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.pubsub.test;
|
||||
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.jivesoftware.smackx.pubsub.AccessModel;
|
||||
import org.jivesoftware.smackx.pubsub.ConfigureForm;
|
||||
import org.jivesoftware.smackx.pubsub.FormType;
|
||||
import org.jivesoftware.smackx.pubsub.LeafNode;
|
||||
import org.jivesoftware.smackx.pubsub.PubSubManager;
|
||||
package org.jivesoftware.smackx.pubsub.test;
|
||||
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.jivesoftware.smackx.pubsub.AccessModel;
|
||||
import org.jivesoftware.smackx.pubsub.ConfigureForm;
|
||||
import org.jivesoftware.smackx.pubsub.FormType;
|
||||
import org.jivesoftware.smackx.pubsub.LeafNode;
|
||||
import org.jivesoftware.smackx.pubsub.PubSubManager;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Robin Collier
|
||||
*
|
||||
*/
|
||||
abstract public class PubSubTestCase extends SmackTestCase
|
||||
{
|
||||
private PubSubManager[] manager;
|
||||
|
||||
public PubSubTestCase(String arg0)
|
||||
{
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
public PubSubTestCase()
|
||||
{
|
||||
super("PubSub Test Case");
|
||||
}
|
||||
|
||||
protected LeafNode getRandomPubnode(PubSubManager pubMgr, boolean persistItems, boolean deliverPayload) throws XMPPException
|
||||
{
|
||||
ConfigureForm form = new ConfigureForm(FormType.submit);
|
||||
form.setPersistentItems(persistItems);
|
||||
form.setDeliverPayloads(deliverPayload);
|
||||
form.setAccessModel(AccessModel.open);
|
||||
return (LeafNode)pubMgr.createNode("/test/Pubnode" + System.currentTimeMillis(), form);
|
||||
}
|
||||
|
||||
protected LeafNode getPubnode(PubSubManager pubMgr, boolean persistItems, boolean deliverPayload, String nodeId) throws XMPPException
|
||||
{
|
||||
LeafNode node = null;
|
||||
|
||||
try
|
||||
{
|
||||
node = (LeafNode)pubMgr.getNode(nodeId);
|
||||
}
|
||||
catch (XMPPException e)
|
||||
{
|
||||
ConfigureForm form = new ConfigureForm(FormType.submit);
|
||||
form.setPersistentItems(persistItems);
|
||||
form.setDeliverPayloads(deliverPayload);
|
||||
form.setAccessModel(AccessModel.open);
|
||||
node = (LeafNode)pubMgr.createNode(nodeId, form);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
protected PubSubManager getManager(int idx)
|
||||
{
|
||||
if (manager == null)
|
||||
{
|
||||
manager = new PubSubManager[getMaxConnections()];
|
||||
|
||||
for(int i=0; i<manager.length; i++)
|
||||
{
|
||||
manager[i] = new PubSubManager(getConnection(i), getService());
|
||||
}
|
||||
}
|
||||
return manager[idx];
|
||||
}
|
||||
|
||||
protected String getService()
|
||||
{
|
||||
return "pubsub." + getServiceName();
|
||||
}
|
||||
}
|
||||
*/
|
||||
abstract public class PubSubTestCase extends SmackTestCase
|
||||
{
|
||||
private PubSubManager[] manager;
|
||||
|
||||
public PubSubTestCase(String arg0)
|
||||
{
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
public PubSubTestCase()
|
||||
{
|
||||
super("PubSub Test Case");
|
||||
}
|
||||
|
||||
protected LeafNode getRandomPubnode(PubSubManager pubMgr, boolean persistItems, boolean deliverPayload) throws XMPPException
|
||||
{
|
||||
ConfigureForm form = new ConfigureForm(FormType.submit);
|
||||
form.setPersistentItems(persistItems);
|
||||
form.setDeliverPayloads(deliverPayload);
|
||||
form.setAccessModel(AccessModel.open);
|
||||
return (LeafNode)pubMgr.createNode("/test/Pubnode" + System.currentTimeMillis(), form);
|
||||
}
|
||||
|
||||
protected LeafNode getPubnode(PubSubManager pubMgr, boolean persistItems, boolean deliverPayload, String nodeId) throws XMPPException
|
||||
{
|
||||
LeafNode node = null;
|
||||
|
||||
try
|
||||
{
|
||||
node = (LeafNode)pubMgr.getNode(nodeId);
|
||||
}
|
||||
catch (XMPPException e)
|
||||
{
|
||||
ConfigureForm form = new ConfigureForm(FormType.submit);
|
||||
form.setPersistentItems(persistItems);
|
||||
form.setDeliverPayloads(deliverPayload);
|
||||
form.setAccessModel(AccessModel.open);
|
||||
node = (LeafNode)pubMgr.createNode(nodeId, form);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
protected PubSubManager getManager(int idx)
|
||||
{
|
||||
if (manager == null)
|
||||
{
|
||||
manager = new PubSubManager[getMaxConnections()];
|
||||
|
||||
for(int i=0; i<manager.length; i++)
|
||||
{
|
||||
manager[i] = new PubSubManager(getConnection(i), getService());
|
||||
}
|
||||
}
|
||||
return manager[idx];
|
||||
}
|
||||
|
||||
protected String getService()
|
||||
{
|
||||
return "pubsub." + getServiceName();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,33 +14,33 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.pubsub.test;
|
||||
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smackx.pubsub.LeafNode;
|
||||
import org.jivesoftware.smackx.pubsub.PubSubManager;
|
||||
package org.jivesoftware.smackx.pubsub.test;
|
||||
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smackx.pubsub.LeafNode;
|
||||
import org.jivesoftware.smackx.pubsub.PubSubManager;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Robin Collier
|
||||
*
|
||||
*/
|
||||
public class SingleUserTestCase extends PubSubTestCase
|
||||
{
|
||||
protected PubSubManager getManager()
|
||||
{
|
||||
return getManager(0);
|
||||
}
|
||||
|
||||
protected LeafNode getPubnode(boolean persistItems, boolean deliverPayload) throws XMPPException
|
||||
{
|
||||
return getRandomPubnode(getManager(), persistItems, deliverPayload);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getMaxConnections()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
public class SingleUserTestCase extends PubSubTestCase
|
||||
{
|
||||
protected PubSubManager getManager()
|
||||
{
|
||||
return getManager(0);
|
||||
}
|
||||
|
||||
protected LeafNode getPubnode(boolean persistItems, boolean deliverPayload) throws XMPPException
|
||||
{
|
||||
return getRandomPubnode(getManager(), persistItems, deliverPayload);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getMaxConnections()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue