package org.buddycloud.channelserver.packetprocessor.iq.namespace.pubsub.result;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

import junit.framework.Assert;

import org.buddycloud.channelserver.channel.ChannelManager;
import org.buddycloud.channelserver.db.ClosableIteratorImpl;
import org.buddycloud.channelserver.db.CloseableIterator;
import org.buddycloud.channelserver.db.exception.NodeStoreException;
import org.buddycloud.channelserver.db.mock.Mock;
import org.buddycloud.channelserver.packetHandler.iq.IQTestHandler;
import org.buddycloud.channelserver.packetprocessor.iq.namespace.pubsub.JabberPubsub;
import org.buddycloud.channelserver.pubsub.accessmodel.AccessModels;
import org.buddycloud.channelserver.pubsub.affiliation.Affiliations;
import org.buddycloud.channelserver.pubsub.model.NodeItem;
import org.buddycloud.channelserver.pubsub.model.NodeSubscription;
import org.buddycloud.channelserver.pubsub.model.impl.NodeAffiliationImpl;
import org.buddycloud.channelserver.pubsub.model.impl.NodeSubscriptionImpl;
import org.buddycloud.channelserver.pubsub.subscription.Subscriptions;
import org.buddycloud.channelserver.utils.node.NodeAclRefuseReason;
import org.buddycloud.channelserver.utils.node.NodeViewAcl;
import org.dom4j.Element;
import org.dom4j.Namespace;
import org.dom4j.QName;
import org.dom4j.tree.BaseElement;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.xmpp.packet.IQ;
import org.xmpp.packet.JID;
import org.xmpp.packet.Packet;
import org.xmpp.packet.PacketError;
import org.xmpp.resultsetmanagement.ResultSetImpl;

public class ItemsResultTest extends IQTestHandler {

	private IQ request;
	private ItemsResult itemsResult;
	private Element element;
	private BlockingQueue<Packet> queue = new LinkedBlockingQueue<Packet>();

	private String node = "/user/pamela@denmark.lit/posts";
	private JID jid = new JID("juliet@shakespeare.lit");
	private ChannelManager channelManager;

	@Before
	public void setUp() throws Exception {

		queue = new LinkedBlockingQueue<Packet>();
		itemsResult = new ItemsResult(channelManager);
		request = readStanzaAsIq("/iq/pubsub/items/reply.stanza");
		element = new BaseElement("items");

		channelManager = Mockito.mock(Mock.class);
		itemsResult.setChannelManager(channelManager);
	}

	@Test
	public void testPassingItemsAsElementNameReturnsTrue() {
		Assert.assertTrue(itemsResult.accept(element));
	}

	@Test
	public void testPassingNotItemsAsElementNameReturnsFalse() {
		Element element = new BaseElement("not-items");
		Assert.assertFalse(itemsResult.accept(element));
	}

	@Test(expected=NullPointerException.class)
	public void testMissingNodeAttributeThrowsException() throws Exception {
		itemsResult.process(element, jid, request, null);
	}
	
	@Test(expected=NullPointerException.class)
	public void testMissingItemsElementThrowsException() {
		itemsResult.process(element, jid, request, null);
	}
}
@@ -71,24 +71,52 @@
 ub.result;%0A%0A
+import java.io.IOException;%0A
 import java.
@@ -1385,16 +1385,52 @@
 iewAcl;%0A
+import org.dom4j.DocumentException;%0A
 import o
@@ -3054,17 +3054,185 @@
 ption() 
-%7B
+throws Exception %7B%0A%09%09%0A%09%09request = toIq(readStanzaAsString(%0A%09%09%09%09%22/iq/pubsub/item/delete/request.stanza%22).replaceFirst(%0A%09%09%09%09%22%3Citem id='item-id' notify='true' /%3E%22, %22%22));%0A%09%09
 %0A%09%09items

Declare thrown exception