2424import org .buddycloud .channelserver .pubsub .model .NodeItem ;
2525import org .buddycloud .channelserver .pubsub .model .NodeSubscription ;
2626import org .buddycloud .channelserver .pubsub .model .impl .NodeAffiliationImpl ;
27+ import org .buddycloud .channelserver .pubsub .model .impl .NodeItemImpl ;
2728import org .buddycloud .channelserver .pubsub .model .impl .NodeSubscriptionImpl ;
2829import org .buddycloud .channelserver .pubsub .subscription .Subscriptions ;
2930import org .buddycloud .channelserver .utils .node .NodeAclRefuseReason ;
@@ -662,4 +663,70 @@ public void testPagingAfterItemWithInvalidNode() throws Exception {
662663
663664 assertEquals ("Error expected" , "error" , p .getElement ().attributeValue ("type" ));
664665 }
666+
667+ @ Test
668+ public void testGetItemNotFoundIfSingleItemNotFound () throws Exception {
669+ element .addAttribute ("node" , "/user/francisco@denmark.lit/posts" );
670+ element .addElement ("item" ).addAttribute ("id" , "12345" );
671+
672+ Mockito .when (channelManager .getNodeItem (eq (node ), Mockito .anyString ()))
673+ .thenReturn (null );
674+ Mockito .when (channelManager .getUserSubscription (node , jid )).thenReturn (
675+ new NodeSubscriptionImpl (node , jid , Subscriptions .subscribed ));
676+ Mockito .when (channelManager .getUserAffiliation (node , jid )).thenReturn (
677+ new NodeAffiliationImpl (node , jid , Affiliations .member , new Date ()));
678+
679+ itemsGet .process (element , jid , request , null );
680+
681+ Packet p = queue .poll ();
682+ assertEquals ("Error expected" , "error" , p .getElement ().attributeValue ("type" ));
683+ assertEquals (
684+ "Expected 'cancel'" ,
685+ "cancel" ,
686+ p .getElement ().element ("error" ).attributeValue ("type" )
687+ );
688+ assertNotNull (p .getElement ().element ("error" ).element ("item-not-found" ));
689+ }
690+
691+
692+ @ Test
693+ public void testCanRetrieveSingleItem () throws Exception {
694+
695+ String id = "12345" ;
696+ String payload = "<entry>entry text</entry>" ;
697+
698+ element .addAttribute ("node" , node );
699+ element .addElement ("item" ).addAttribute ("id" , id );
700+
701+ NodeItem nodeItem = new NodeItemImpl (node , id , new Date (), payload );
702+ Mockito .when (channelManager .getNodeItem (eq (node ), Mockito .anyString ()))
703+ .thenReturn (nodeItem );
704+ Mockito .when (channelManager .getUserSubscription (node , jid )).thenReturn (
705+ new NodeSubscriptionImpl (node , jid , Subscriptions .subscribed ));
706+ Mockito .when (channelManager .getUserAffiliation (node , jid )).thenReturn (
707+ new NodeAffiliationImpl (node , jid , Affiliations .member , new Date ()));
708+
709+ itemsGet .process (element , jid , request , null );
710+
711+ Packet p = queue .poll ();
712+ Packet response = queue .poll ();
713+ Element element = response .getElement ();
714+
715+ Assert .assertEquals (IQ .Type .result .toString (),
716+ element .attributeValue ("type" ));
717+ Assert .assertEquals (node , element .element ("pubsub" ).element ("items" )
718+ .attributeValue ("node" ));
719+
720+ Assert .assertEquals (1 , element .element ("pubsub" ).element ("items" )
721+ .nodeCount ());
722+ Assert .assertEquals (
723+ node ,
724+ element .element ("pubsub" ).element ("items" ).attributeValue ("node" )
725+ );
726+ Assert .assertEquals (id , element .element ("pubsub" ).element ("items" )
727+ .element ("item" ).attributeValue ("id" ));
728+ Assert .assertEquals ("entry text" ,
729+ element .element ("pubsub" ).element ("items" ).element ("item" )
730+ .elementText ("entry" ));
731+ }
665732}
0 commit comments