/*
* Created on 2009-08-05
*/
package org.jivesoftware.smackx.pubsub;
import junit.framework.TestCase;
public class TestMessageContent extends TestCase
{
String payloadXmlWithNS = "";
public void testItemWithId()
{
Item item = new Item("123");
assertEquals(" ", item.toXML());
assertEquals("item", item.getElementName());
assertNull(item.getNamespace());
}
public void testItemWithNoId()
{
Item item = new Item();
assertEquals(" ", item.toXML());
Item itemNull = new Item(null);
assertEquals(" ", itemNull.toXML());
}
public void testSimplePayload()
{
SimplePayload payloadNS = new SimplePayload("book", "pubsub:test:book", payloadXmlWithNS);
assertEquals(payloadXmlWithNS, payloadNS.toXML());
String payloadXmlWithNoNS = "";
SimplePayload payloadNoNS = new SimplePayload("book", null, "");
assertEquals(payloadXmlWithNoNS, payloadNoNS.toXML());
}
public void testPayloadItemWithId()
{
SimplePayload payload = new SimplePayload("book", "pubsub:test:book", payloadXmlWithNS);
PayloadItem item = new PayloadItem("123", payload);
String xml = "- " + payloadXmlWithNS + "
";
assertEquals(xml, item.toXML());
assertEquals("item", item.getElementName());
}
public void testPayloadItemWithNoId()
{
SimplePayload payload = new SimplePayload("book", "pubsub:test:book", payloadXmlWithNS);
PayloadItem item = new PayloadItem(null, payload);
String xml = "- " + payloadXmlWithNS + "
";
assertEquals(xml, item.toXML());
}
public void testPayloadItemWithIdNoPayload()
{
try
{
PayloadItem item = new PayloadItem("123", null);
fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException e)
{
}
}
public void testPayloadItemWithNoIdNoPayload()
{
try
{
PayloadItem item = new PayloadItem(null, null);
fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException e)
{
}
}
public void testRetractItem()
{
RetractItem item = new RetractItem("1234");
assertEquals("", 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("", request.toXML());
request = new GetItemsRequest("testId", 5);
assertEquals("", request.toXML());
request = new GetItemsRequest("testId", "qwerty");
assertEquals("", request.toXML());
request = new GetItemsRequest("testId", "qwerty", 5);
assertEquals("", request.toXML());
}
}