Author: berndf
Date: Fri Apr 24 09:40:40 2009
New Revision: 768239

URL: http://svn.apache.org/viewvc?rev=768239&view=rev
Log:
[vysper] fix unit tests by retrieving the message from direct queue now (adjust 
tests to earlier refactoring) (LABS-337, LABS 340)

Modified:
    
mina/sandbox/vysper/trunk/src/test/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceHandlerBaseTestCase.java
    
mina/sandbox/vysper/trunk/src/test/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceSubRequestOutHandlerTestCase.java
    
mina/sandbox/vysper/trunk/src/test/java/org/apache/vysper/xmpp/server/TestSessionContext.java

Modified: 
mina/sandbox/vysper/trunk/src/test/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceHandlerBaseTestCase.java
URL: 
http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/src/test/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceHandlerBaseTestCase.java?rev=768239&r1=768238&r2=768239&view=diff
==============================================================================
--- 
mina/sandbox/vysper/trunk/src/test/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceHandlerBaseTestCase.java
 (original)
+++ 
mina/sandbox/vysper/trunk/src/test/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceHandlerBaseTestCase.java
 Fri Apr 24 09:40:40 2009
@@ -123,6 +123,10 @@
         assertStanzasRelayed(expectedRelayedAndDelivered, 
expectedRelayedAndDelivered);
     }
 
+    protected void assertStanzasReceivedDirectly(int expectedReceivedDirectly) 
{
+        assertEquals(expectedReceivedDirectly, 
sessionContext.getRecordedResponsesTotal());
+    }
+
     protected void assertStanzasRelayed(int expectedRelayed, int 
expectedDelivered) {
         assertEquals(expectedRelayed, ((StanzaReceiverRelay) 
sessionContext.getServerRuntimeContext().getStanzaRelay()).getCountRelayed());
         assertEquals(expectedDelivered, ((StanzaReceiverRelay) 
sessionContext.getServerRuntimeContext().getStanzaRelay()).getCountDelivered());
@@ -151,8 +155,8 @@
         } catch (Exception e) {
             fail(e.toString());
         }
-        assertEquals(rosterPush.getTo(), entity);
-        assertEquals(contact, rosterItem.getJid());
+        assertEquals(rosterPush.getTo().getFullQualifiedName(), 
entity.getFullQualifiedName());
+        assertEquals(contact.getFullQualifiedName(), 
rosterItem.getJid().getFullQualifiedName());
         assertEquals(subscriptionType, rosterItem.getSubscriptionType());
         assertEquals(subscriptionType, rosterItem.getSubscriptionType());
         assertEquals(askSubscriptionType, rosterItem.getAskSubscriptionType());

Modified: 
mina/sandbox/vysper/trunk/src/test/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceSubRequestOutHandlerTestCase.java
URL: 
http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/src/test/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceSubRequestOutHandlerTestCase.java?rev=768239&r1=768238&r2=768239&view=diff
==============================================================================
--- 
mina/sandbox/vysper/trunk/src/test/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceSubRequestOutHandlerTestCase.java
 (original)
+++ 
mina/sandbox/vysper/trunk/src/test/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceSubRequestOutHandlerTestCase.java
 Fri Apr 24 09:40:40 2009
@@ -44,10 +44,13 @@
         XMPPCoreStanza requestApproval = 
XMPPCoreStanza.getWrapper(StanzaBuilder.createPresenceStanza(unrelatedUser.getEntityFQ(),
 initiatingUser.getEntity(), null, PresenceStanzaType.SUBSCRIBED, null, 
null).getFinalStanza());
         handler.executeCore(requestApproval, 
sessionContext.getServerRuntimeContext(), false, sessionContext);
 
-        // subscribed stanza not delivered to client
+        // 3 roster pushes but...
+        for (int i = 1; i <= 3; i++) {
+            Stanza stanza = sessionContext.getNextRecordedResponse();
+            assertEquals("iq", stanza.getName());
+        }
+        // ... BUT no subscription approval (presence) or anything additional 
to the roster pushes
         assertNull(sessionContext.getNextRecordedResponse());
-        // 3 roster pushes
-        assertStanzasDeliveredAndRelayed(3);
 
         resetRecordedStanzas();
     }
@@ -55,31 +58,34 @@
     private void requestSubscribeToUnrelated_Outbound() {
         setResourceState(initiatingUser.getBoundResourceId(), 
ResourceState.AVAILABLE_INTERESTED);
 
+        // SUBSCRIBE FROM
         XMPPCoreStanza initialPresence = 
XMPPCoreStanza.getWrapper(StanzaBuilder.createPresenceStanza(initiatingUser.getEntityFQ(),
 unrelatedUser.getEntity(), null, PresenceStanzaType.SUBSCRIBE, null, 
null).getFinalStanza());
 
         handler.executeCore(initialPresence, 
sessionContext.getServerRuntimeContext(), true, sessionContext);
         assertEquals(ResourceState.AVAILABLE_INTERESTED, getResourceState());
 
         // 1 to TO + 3 roster pushes
-        assertStanzasDeliveredAndRelayed(1+3);
+        assertStanzasDeliveredAndRelayed(1);
+        assertStanzasReceivedDirectly(3);
 
-        // roster push for interested initiator
-        Stanza initiatorNotification = initiatingUser.getNextStanza();
+        // roster push for 1 interested initiator of _same_ session
+        Stanza initiatorNotification = 
sessionContext.getNextRecordedResponseForResource(initiatingUser.getBoundResourceId());
         assertTrue(checkRosterPush(initiatorNotification, 
initiatingUser.getEntityFQ(), unrelatedUser.getEntity(), NONE, ASK_SUBSCRIBE));
-        assertNull(initiatingUser.getNextStanza()); // no more stanzas
 
         // no stanzas for not interested
-        assertNull(anotherAvailableUser.getNextStanza());
+        
assertNull(sessionContext.getNextRecordedResponseForResource(anotherAvailableUser.getBoundResourceId()));
 
+        // roster 2 interested resources of _same_ session...
+        
         // roster push for interested
-        Stanza interestedResourceNotification = 
anotherInterestedUser.getNextStanza();
+        Stanza interestedResourceNotification = 
sessionContext.getNextRecordedResponseForResource(anotherInterestedUser.getBoundResourceId());
         assertTrue(checkRosterPush(interestedResourceNotification, new 
EntityImpl(initiatingUser.getEntity(), 
anotherInterestedUser.getBoundResourceId()), unrelatedUser.getEntity(), NONE, 
ASK_SUBSCRIBE));
-        assertNull(anotherInterestedUser.getNextStanza()); // no more stanzas
+        
assertNull(sessionContext.getNextRecordedResponseForResource(anotherInterestedUser.getBoundResourceId()));
 // no more stanzas
 
-        // roster push for interested
-        Stanza interestedNotYetAvailResourceNotification = 
anotherInterestedNotAvailUser.getNextStanza();
+        // roster push for interested but not avail
+        Stanza interestedNotYetAvailResourceNotification = 
sessionContext.getNextRecordedResponseForResource(anotherInterestedNotAvailUser.getBoundResourceId());
         assertTrue(checkRosterPush(interestedNotYetAvailResourceNotification, 
new EntityImpl(initiatingUser.getEntity(), 
anotherInterestedNotAvailUser.getBoundResourceId()), unrelatedUser.getEntity(), 
NONE, ASK_SUBSCRIBE));
-        assertNull(anotherInterestedNotAvailUser.getNextStanza()); // no more 
stanzas
+        
assertNull(sessionContext.getNextRecordedResponseForResource(anotherInterestedNotAvailUser.getBoundResourceId()));
 // no more stanzas;
 
         // sub request sent to contact
         assertTrue(checkPresence(unrelatedUser.getNextStanza(), 
PresenceStanzaType.SUBSCRIBE, initiatingUser.getEntity(), null));
@@ -94,18 +100,27 @@
 
         setResourceState(initiatingUser.getBoundResourceId(), 
ResourceState.AVAILABLE_INTERESTED);
 
+        // SUBSCRIBE FROM
         XMPPCoreStanza initialPresence = 
XMPPCoreStanza.getWrapper(StanzaBuilder.createPresenceStanza(initiatingUser.getEntityFQ(),
 subscribed_FROM.getEntity(), null, PresenceStanzaType.SUBSCRIBE, null, 
null).getFinalStanza());
 
         handler.executeCore(initialPresence, 
sessionContext.getServerRuntimeContext(), true, sessionContext);
         assertEquals(ResourceState.AVAILABLE_INTERESTED, getResourceState());
 
         // 1 to TO + 3 roster pushes
-        assertStanzasDeliveredAndRelayed(1+3);
+        assertStanzasDeliveredAndRelayed(1);
+        assertStanzasReceivedDirectly(3);
 
-        // roster push for interested initiator
-        Stanza initiatorNotification = initiatingUser.getNextStanza();
+        // roster push for 1 interested initiator...
+        Stanza initiatorNotification = 
sessionContext.getNextRecordedResponseForResource(initiatingUser.getBoundResourceId());
         assertTrue(checkRosterPush(initiatorNotification, 
initiatingUser.getEntityFQ(), subscribed_FROM.getEntity(), FROM, 
ASK_SUBSCRIBE));
-        assertNull(initiatingUser.getNextStanza()); // no more stanzas
+
+        // .. and 2 interested resources of _same_ session
+        Stanza anotherInterestedUserNotification = 
sessionContext.getNextRecordedResponseForResource(anotherInterestedUser.getBoundResourceId());
+        assertTrue(checkRosterPush(anotherInterestedUserNotification, 
anotherInterestedUser.getEntityFQ(), subscribed_FROM.getEntity(), FROM, 
ASK_SUBSCRIBE));
+        Stanza anotherInterestedNotAvailUserNotification = 
sessionContext.getNextRecordedResponseForResource(anotherInterestedNotAvailUser.getBoundResourceId());
+        assertTrue(checkRosterPush(anotherInterestedNotAvailUserNotification, 
anotherInterestedNotAvailUser.getEntityFQ(), subscribed_FROM.getEntity(), FROM, 
ASK_SUBSCRIBE));
+
+        assertNull(sessionContext.getNextRecordedResponse()); // no more 
stanzas
 
         // sub request sent to contact
         assertTrue(checkPresence(subscribed_FROM.getNextStanza(), 
PresenceStanzaType.SUBSCRIBE, initiatingUser.getEntity(), null)); 

Modified: 
mina/sandbox/vysper/trunk/src/test/java/org/apache/vysper/xmpp/server/TestSessionContext.java
URL: 
http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/src/test/java/org/apache/vysper/xmpp/server/TestSessionContext.java?rev=768239&r1=768238&r2=768239&view=diff
==============================================================================
--- 
mina/sandbox/vysper/trunk/src/test/java/org/apache/vysper/xmpp/server/TestSessionContext.java
 (original)
+++ 
mina/sandbox/vysper/trunk/src/test/java/org/apache/vysper/xmpp/server/TestSessionContext.java
 Fri Apr 24 09:40:40 2009
@@ -28,6 +28,7 @@
 
 import java.util.LinkedList;
 import java.util.Queue;
+import java.util.Iterator;
 
 /**
  * makes response available for testing
@@ -38,6 +39,7 @@
     private boolean closed = false;
     private boolean switchToTLSCalled;
     private boolean isReopeningXMLStream;
+    private int recordedResponsesTotal = 0;
 
     public static TestSessionContext createSessionContext(Entity entity) {
         SessionStateHolder sessionStateHolder = new SessionStateHolder();
@@ -73,6 +75,19 @@
         return recordedResponses.poll();
     }
 
+    public Stanza getNextRecordedResponseForResource(String resource) {
+        for (Iterator<Stanza> it = recordedResponses.iterator(); 
it.hasNext();) {
+            Stanza recordedResponse = it.next();
+            if (recordedResponse.getTo() != null && 
recordedResponse.getTo().isResourceSet()) {
+                if (recordedResponse.getTo().getResource().equals(resource)) {
+                    it.remove();
+                    return recordedResponse;
+                }
+            }
+        }
+        return null;
+    }
+
     public void close() {
         closed = true;
     }
@@ -86,8 +101,14 @@
      * @throws IllegalStateException if NOT NULL, and there is already a 
stanza recorded
      */
     public void write(Stanza stanza) {
-        if (recordedResponses.size() > 0 && stanza != null) throw new 
IllegalStateException("stanza already recorded");
-        recordedResponses.add(stanza);
+        if (stanza == null) {
+            recordedResponses.clear();
+            recordedResponsesTotal = 0;
+            return;
+        } else {
+            recordedResponses.add(stanza);
+            recordedResponsesTotal++;
+        }
     }
 
     public void setSessionState(SessionState sessionState) {
@@ -119,4 +140,8 @@
         ((StanzaReceiverRelay) 
getServerRuntimeContext().getStanzaRelay()).add(entity, relay);
         return relay;
     }
+
+    public int getRecordedResponsesTotal() {
+        return recordedResponsesTotal;
+    }
 }


Reply via email to