labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ber...@apache.org
Subject svn commit: r740831 - in /labs/vysper/src: main/java/org/apache/vysper/xmpp/delivery/ main/java/org/apache/vysper/xmpp/modules/core/im/handler/ main/java/org/apache/vysper/xmpp/protocol/ main/java/org/apache/vysper/xmpp/server/ main/java/org/apache/vys...
Date Wed, 04 Feb 2009 19:13:25 GMT
Author: berndf
Date: Wed Feb  4 19:13:24 2009
New Revision: 740831

URL: http://svn.apache.org/viewvc?rev=740831&view=rev
Log:
[vysper] fix how roster pushes get sent; plus more docs and cleanups

Modified:
    labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/DeliveringInboundStanzaRelay.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceAvailabilityHandler.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceSubscriptionHandler.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/ProtocolWorker.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/server/AbstractSessionContext.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/state/resourcebinding/ResourceRegistry.java
    labs/vysper/src/test/java/org/apache/vysper/xmpp/delivery/DeliveringStanzaRelayTestCase.java
    labs/vysper/src/test/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceAvailInitialOutHandlerTestCase.java
    labs/vysper/src/test/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceSubRequestOutHandlerTestCase.java
    labs/vysper/src/test/java/org/apache/vysper/xmpp/protocol/ProtocolWorkerProcessTestCase.java
    labs/vysper/src/test/java/org/apache/vysper/xmpp/server/TestSessionContext.java
    labs/vysper/src/test/java/org/apache/vysper/xmpp/state/resourcebinding/ResourceRegistryTestCase.java

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/DeliveringInboundStanzaRelay.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/DeliveringInboundStanzaRelay.java?rev=740831&r1=740830&r2=740831&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/DeliveringInboundStanzaRelay.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/DeliveringInboundStanzaRelay.java
Wed Feb  4 19:13:24 2009
@@ -61,10 +61,6 @@
         Future<RelayResult> resultFuture = executor.submit(new Relay(receiver, stanza,
deliveryFailureStrategy));
     }
 
-    public boolean receiverIsOnline(Entity receiver) {
-        return !resourceRegistry.getSessions(receiver).isEmpty();
-    }
-       
     private class Relay implements Callable<RelayResult> {
         private Entity receiver;
         private Stanza stanza;

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceAvailabilityHandler.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceAvailabilityHandler.java?rev=740831&r1=740830&r2=740831&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceAvailabilityHandler.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceAvailabilityHandler.java
Wed Feb  4 19:13:24 2009
@@ -20,21 +20,27 @@
 import org.apache.vysper.compliance.SpecCompliant;
 import org.apache.vysper.xmpp.addressing.Entity;
 import org.apache.vysper.xmpp.addressing.EntityImpl;
+import org.apache.vysper.xmpp.modules.core.base.handler.XMPPCoreStanzaHandler;
 import org.apache.vysper.xmpp.modules.roster.RosterException;
 import org.apache.vysper.xmpp.modules.roster.RosterItem;
 import org.apache.vysper.xmpp.modules.roster.RosterUtils;
 import org.apache.vysper.xmpp.modules.roster.SubscriptionType;
 import org.apache.vysper.xmpp.modules.roster.persistence.RosterManager;
-import org.apache.vysper.xmpp.modules.core.base.handler.XMPPCoreStanzaHandler;
 import org.apache.vysper.xmpp.server.ServerRuntimeContext;
 import org.apache.vysper.xmpp.server.SessionContext;
 import org.apache.vysper.xmpp.server.response.ServerErrorResponses;
+import org.apache.vysper.xmpp.stanza.PresenceStanza;
+import org.apache.vysper.xmpp.stanza.PresenceStanzaType;
 import static org.apache.vysper.xmpp.stanza.PresenceStanzaType.*;
-import org.apache.vysper.xmpp.stanza.*;
+import org.apache.vysper.xmpp.stanza.Stanza;
+import org.apache.vysper.xmpp.stanza.StanzaBuilder;
+import org.apache.vysper.xmpp.stanza.StanzaErrorCondition;
+import org.apache.vysper.xmpp.stanza.StanzaErrorType;
+import org.apache.vysper.xmpp.stanza.XMPPCoreStanza;
+import org.apache.vysper.xmpp.stanza.XMPPCoreStanzaVerifier;
 import org.apache.vysper.xmpp.state.resourcebinding.ResourceRegistry;
 import org.apache.vysper.xmpp.state.resourcebinding.ResourceState;
 import org.apache.vysper.xmpp.xmlfragment.Attribute;
-import org.apache.vysper.xmpp.writer.DenseStanzaLogRenderer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -63,13 +69,6 @@
         XMPPCoreStanzaVerifier verifier = presenceStanza.getCoreVerifier();
         ResourceRegistry registry = serverRuntimeContext.getResourceRegistry();
 
-        boolean hasFrom = verifier.attributePresent("from");
-        boolean hasTo = verifier.attributePresent("to");
-        boolean isOutboundStanzaDerived = !hasFrom && hasTo && (sessionContext
!= null && !sessionContext.isServerToServer());
-        if (isOutboundStanza != isOutboundStanzaDerived) {
-            logger.warn("mismatch between isOutboundStanza ({}) and isOutboundStanzaDerived
({}) in stanza {}", new Object[] {isOutboundStanza, isOutboundStanzaDerived, DenseStanzaLogRenderer.render(presenceStanza)});
-        }
-
         // check if presence reception is turned of either globally or locally
         if (!serverRuntimeContext.getServerFeatures().isRelayingPresence() ||
             (sessionContext != null && sessionContext.getAttribute(SessionContext.SESSION_ATTRIBUTE_PRESENCE_STANZA_NO_RECEIVE)
!= null)) {

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceSubscriptionHandler.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceSubscriptionHandler.java?rev=740831&r1=740830&r2=740831&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceSubscriptionHandler.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceSubscriptionHandler.java
Wed Feb  4 19:13:24 2009
@@ -42,7 +42,6 @@
 import org.apache.vysper.xmpp.stanza.Stanza;
 import org.apache.vysper.xmpp.stanza.XMPPCoreStanzaVerifier;
 import org.apache.vysper.xmpp.state.resourcebinding.ResourceRegistry;
-import org.apache.vysper.xmpp.writer.DenseStanzaLogRenderer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -69,16 +68,8 @@
         XMPPCoreStanzaVerifier verifier = presenceStanza.getCoreVerifier();
         ResourceRegistry registry = serverRuntimeContext.getResourceRegistry();
 
-        boolean hasFrom = verifier.attributePresent("from");
-        boolean hasTo = verifier.attributePresent("to");
-        boolean isOutboundStanzaDerived = !hasFrom && hasTo && (sessionContext
!= null && !sessionContext.isServerToServer());
-        if (isOutboundStanza != isOutboundStanzaDerived) {
-            logger.warn("mismatch between isOutboundStanza ({}) and isOutboundStanzaDerived
({}) in stanza {}", new Object[] {isOutboundStanza, isOutboundStanzaDerived, DenseStanzaLogRenderer.render(presenceStanza)});
-        }
-
         PresenceStanzaType type = presenceStanza.getPresenceType();
 
-
         if (isOutboundStanza) {
 			// this is an outbound subscription
 			// request/approval/cancellation/unsubscription
@@ -204,16 +195,13 @@
             return;
         }
 
-        // write inbound stanza to the user
-        sessionContext.getResponseWriter().write(stanza);
-
         // send roster push to all interested resources
         // TODO do this only once, since inbound is multiplexed on DeliveringInboundStanzaRelay
level already
         List<String> resources = registry.getInterestedResources(user);
         for (String resource : resources) {
             Entity userResource = new EntityImpl(user, resource);
             Stanza push = RosterStanzaUtils.createRosterItemPushIQ(userResource, sessionContext.nextSequenceValue(),
rosterItem);
-            sessionContext.getResponseWriter().write(push);
+            relayToResourceDirectly(registry, resource, push);
         }
 
 	}
@@ -304,7 +292,7 @@
         for (String resource : resources) {
             Entity userResource = new EntityImpl(user, resource);
             Stanza push = RosterStanzaUtils.createRosterItemPushIQ(userResource, sessionContext.nextSequenceValue(),
rosterItem);
-            relayStanza(userResource, push, sessionContext);
+            relayToResourceDirectly(registry, resource, push);
         }
     }
 
@@ -366,16 +354,13 @@
             return;
         }
 
-        // write inbound stanza to the user
-        sessionContext.getResponseWriter().write(stanza);
-
         // send roster push to all interested resources
         // TODO do this only once, since inbound is multiplexed on DeliveringInboundStanzaRelay
level already
         List<String> resources = registry.getInterestedResources(user);
         for (String resource : resources) {
             Entity userResource = new EntityImpl(user, resource);
             Stanza push = RosterStanzaUtils.createRosterItemPushIQ(userResource, sessionContext.nextSequenceValue(),
rosterItem);
-            sessionContext.getResponseWriter().write(push);
+            relayToResourceDirectly(registry, resource, push);
         }
 	}
 
@@ -653,16 +638,13 @@
 
 		if (result == OK || result == ALREADY_SET) {
 
-            // write inbound stanza to the user 
-            sessionContext.getResponseWriter().write(stanza);
-
             // send roster push to all interested resources
             // TODO do this only once, since inbound is multiplexed on DeliveringInboundStanzaRelay
level already 
 			List<String> resources = registry.getInterestedResources(user);
 			for (String resource : resources) {
 				Entity userResource = new EntityImpl(user, resource);
 				Stanza push = RosterStanzaUtils.createRosterItemPushIQ(userResource, sessionContext.nextSequenceValue(),
rosterItem);
-                relayStanza(userResource, push, sessionContext);
+                relayToResourceDirectly(registry, resource, push);
 			}
 		} else {
 			// silently drop the stanza
@@ -769,7 +751,7 @@
 
         // TODO check if user has blocked contact
     
-        // write inbound stanza to the user 
+        // write inbound subscription request to the user 
         sessionContext.getResponseWriter().write(stanza);
 
 		return null;
@@ -876,12 +858,18 @@
 		for (String resource : resources) {
 			Entity userResource = new EntityImpl(user, resource);
 			Stanza push = RosterStanzaUtils.createRosterItemPushIQ(userResource, sessionContext.nextSequenceValue(),
rosterItem);
-            try {
-                stanzaRelay.relay(userResource, push, new IgnoreFailureStrategy());
-			} catch (DeliveryException e) {
-				e.printStackTrace();
-			}
-		}
+            relayToResourceDirectly(registry, resource, push);
+        }
 	}
 
+    private void relayToResourceDirectly(ResourceRegistry registry, String resource, Stanza
push) {
+        try {
+            SessionContext targetContext = registry.getSessionContext(resource);
+            if (targetContext == null) return;
+            targetContext.getResponseWriter().write(push);
+        } catch (RuntimeException e) {
+            e.printStackTrace();
+        }
+    }
+
 }

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/ProtocolWorker.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/ProtocolWorker.java?rev=740831&r1=740830&r2=740831&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/ProtocolWorker.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/ProtocolWorker.java Wed Feb
 4 19:13:24 2009
@@ -160,8 +160,7 @@
 
         try {
             stateAwareProtocolWorker.processStanza(sessionContext, sessionStateHolder,
-                                                   stanza, stanzaHandler
-            );
+                                                   stanza, stanzaHandler);
         } catch (Exception e) {
             logger.error("error executing handler {} with stanza {}", stanzaHandler.getClass().getName(),
DenseStanzaLogRenderer.render(stanza));
             e.printStackTrace();
@@ -180,6 +179,4 @@
         sessionStateHolder.setState(SessionState.ENCRYPTED);
         sessionContext.setIsReopeningXMLStream();
     }
-
-
 }

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/server/AbstractSessionContext.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/server/AbstractSessionContext.java?rev=740831&r1=740830&r2=740831&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/server/AbstractSessionContext.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/server/AbstractSessionContext.java Wed
Feb  4 19:13:24 2009
@@ -68,6 +68,8 @@
     }
 
     public void setInitiatingEntity(Entity entity) {
+        if (entity == null) throw new IllegalArgumentException("initiating entity must not
be set to NULL");
+        if (entity.isResourceSet()) throw new IllegalArgumentException("initiating entity
must be bare JID");
         this.initiatingEntity = entity;
     }
 

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/state/resourcebinding/ResourceRegistry.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/state/resourcebinding/ResourceRegistry.java?rev=740831&r1=740830&r2=740831&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/state/resourcebinding/ResourceRegistry.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/state/resourcebinding/ResourceRegistry.java
Wed Feb  4 19:13:24 2009
@@ -58,13 +58,15 @@
     protected final Map<String, SessionData> boundResources = new HashMap<String,
SessionData>();
 
     /**
+     * an entity's list of resources
      * maps bare JID to all its bound resources. the list of resource ids might not be emtpy,
and if there
      * is more than one id, the list usually spans more than 1 session 
      */
     protected final Map<Entity, List<String>> entityResources = new HashMap<Entity,
List<String>>();
 
     /**
-     * maps a session to all the resource ids bound to it. this is a subset of
+     * a session's list of resources
+     * maps a session to all the resource ids bound to it.
      */
     protected final Map<SessionContext, List<String>> sessionResources = new
HashMap<SessionContext, List<String>>();
 
@@ -120,19 +122,30 @@
      * </unbind></iq>
      * @param resourceId
      */
-    public void unbindResource(String resourceId) {
+    public boolean unbindResource(String resourceId) {
+        boolean noResourceRemainsForSession = false;
 		synchronized (boundResources) {
 			synchronized (entityResources) {
     			synchronized (sessionResources) {
                     SessionContext sessionContext = getSessionContext(resourceId);
-                    List<String> resourceListForSession = getResourceList(sessionContext.getInitiatingEntity());
+
+                    // remove from entity's list of resources
+                    List<String> resourceListForEntity = getResourceList(sessionContext.getInitiatingEntity());
+                    resourceListForEntity.remove(resourceId);
+                    if (resourceListForEntity.isEmpty()) entityResources.remove(sessionContext.getInitiatingEntity());

+
+                    // remove from session's list of resources
+                    List<String> resourceListForSession = sessionResources.get(sessionContext);
                     resourceListForSession.remove(resourceId);
-                    sessionResources.get(sessionContext).remove(resourceId);
-                    // TODO end session if last resource got unbound
+                    noResourceRemainsForSession = resourceListForSession.isEmpty();
+                    if (noResourceRemainsForSession) sessionResources.remove(sessionContext);
+
+                    // remove from overall list of bound resource
                     boundResources.remove(resourceId);
     			}
 			}
 		}
+        return noResourceRemainsForSession;
 	}
 
     /**
@@ -191,7 +204,7 @@
         return resourceList;
     }
 
-    protected SessionContext getSessionContext(String resourceId) {
+    public SessionContext getSessionContext(String resourceId) {
 		SessionData data = boundResources.get(resourceId);
 		if (data == null) return null;
 		return data.context;
@@ -236,6 +249,12 @@
 		return Collections.singletonList(entity.getResource());
 	}
 
+    /**
+     * retrieves all sessions handling this entity. note: if given entity is not a bare JID,
it will return only the
+     * session for the JID's resource part. if it's a bare JID, it will return all session
for the JID. 
+     * @param entity
+     * @return
+     */
     public List<SessionContext> getSessions(Entity entity) {
 		List<SessionContext> sessionContexts = new ArrayList<SessionContext>();
 
@@ -257,10 +276,10 @@
 	 */
 	public void setResourceState(String resourceId, ResourceState state) {
 		SessionData data = boundResources.get(resourceId);
-		if (data == null)
-			throw new IllegalArgumentException("resource not registered: "
-					+ resourceId);
-		data.state = state;
+		if (data == null) {
+            throw new IllegalArgumentException("resource not registered: " + resourceId);
+        }
+        data.state = state;
 	}
 
     /**
@@ -277,46 +296,13 @@
 		return data.state;
 	}
 
-    public void setResourcePriority(String resource, int priority) {
-        if (resource == null) return;
-        SessionData data = boundResources.get(resource);
+    public void setResourcePriority(String resourceId, int priority) {
+        if (resourceId == null) return;
+        SessionData data = boundResources.get(resourceId);
 		if (data == null) return;
 		data.priority = priority;
     }
 
-    /**
-	 * Checks whether the given resource is connected.
-	 * 
-	 * @param resourceId
-	 *            the resource identifier
-	 * @return true if the resource is connected, false otherwise
-	 */
-	public boolean isResourceConnected(String resourceId) {
-		return CONNECTED.equals(getResourceState(resourceId));
-	}
-
-    /**
-	 * Checks whether the given resource is available.
-	 * 
-	 * @param resourceId
-	 *            the resource identifier
-	 * @return true if the resource is available, false otherwise.
-	 */
-	public boolean isResourceAvailable(String resourceId) {
-        return isAvailable(getResourceState(resourceId));
-	}
-
-	/**
-	 * Checks whether the given resource is interested.
-	 * 
-	 * @param resourceId
-	 *            the resource identifier
-	 * @return true if the resource is interested, false otherwise
-	 */
-	public boolean isResourceInterested(String resourceId) {
-		return isInterested(getResourceState(resourceId));
-	}
-
 	public List<String> getInterestedResources(Entity entity) {
         List<String> resources = getResourceList(entity);
         List<String> result = new ArrayList<String>();

Modified: labs/vysper/src/test/java/org/apache/vysper/xmpp/delivery/DeliveringStanzaRelayTestCase.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/test/java/org/apache/vysper/xmpp/delivery/DeliveringStanzaRelayTestCase.java?rev=740831&r1=740830&r2=740831&view=diff
==============================================================================
--- labs/vysper/src/test/java/org/apache/vysper/xmpp/delivery/DeliveringStanzaRelayTestCase.java
(original)
+++ labs/vysper/src/test/java/org/apache/vysper/xmpp/delivery/DeliveringStanzaRelayTestCase.java
Wed Feb  4 19:13:24 2009
@@ -59,7 +59,8 @@
         EntityImpl toEntity = EntityImpl.parse("userTo@vysper.org");
         TestSessionContext sessionContext = TestSessionContext.createSessionContext(toEntity);
         String resource = resourceRegistry.bindSession(sessionContext);
-        resourceRegistry.unbindResource(resource);
+        boolean noResourceRemains = resourceRegistry.unbindResource(resource);
+        assertTrue(noResourceRemains);
 
         Stanza stanza = StanzaBuilder.createMessageStanza(fromEntity, toEntity, "en", "Hello").getFinalStanza();
 

Modified: labs/vysper/src/test/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceAvailInitialOutHandlerTestCase.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/test/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceAvailInitialOutHandlerTestCase.java?rev=740831&r1=740830&r2=740831&view=diff
==============================================================================
--- labs/vysper/src/test/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceAvailInitialOutHandlerTestCase.java
(original)
+++ labs/vysper/src/test/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceAvailInitialOutHandlerTestCase.java
Wed Feb  4 19:13:24 2009
@@ -18,14 +18,15 @@
 package org.apache.vysper.xmpp.modules.core.im.handler;
 
 import org.apache.vysper.xmpp.addressing.EntityFormatException;
-import org.apache.vysper.xmpp.addressing.EntityImpl;
 import org.apache.vysper.xmpp.delivery.StanzaReceiverRelay;
 import static org.apache.vysper.xmpp.stanza.PresenceStanzaType.PROBE;
 import org.apache.vysper.xmpp.stanza.Stanza;
 import org.apache.vysper.xmpp.stanza.StanzaBuilder;
 import org.apache.vysper.xmpp.stanza.XMPPCoreStanza;
+import org.apache.vysper.xmpp.stanza.StanzaErrorCondition;
 import org.apache.vysper.xmpp.state.resourcebinding.BindException;
 import org.apache.vysper.xmpp.state.resourcebinding.ResourceState;
+import org.apache.vysper.xmpp.xmlfragment.XMLSemanticError;
 
 /**
  */
@@ -84,5 +85,34 @@
         assertNull(subscribed_TO.getNextStanza()); // pres NOT sent to TO contacts
     }
 
+    public void testInitialPresenceWithoutFrom() throws BindException, EntityFormatException,
XMLSemanticError {
+        // after setUp(), there is more than one bound resource
+        // so, if leaving from == null, the handler will not know from which resource the
presence really comes...
+        XMPPCoreStanza initialPresence = XMPPCoreStanza.getWrapper(StanzaBuilder.createPresenceStanza(null,
null, null, null, null, null).getFinalStanza());
+
+        Stanza stanza = handler.executeCore(initialPresence, sessionContext.getServerRuntimeContext(),
true, sessionContext);
+        // ... and will give an error:
+        assertEquals("error", stanza.getAttribute("type").getValue());
+        assertEquals(StanzaErrorCondition.UNKNOWN_SENDER.value(), stanza.getSingleInnerElementsNamed("error").getFirstInnerElement().getName());
+
+        sessionContext.getServerRuntimeContext().getResourceRegistry().unbindResource(anotherInterestedNotAvailUser.getBoundResourceId());
+        sessionContext.getServerRuntimeContext().getResourceRegistry().unbindResource(anotherInterestedUser.getBoundResourceId());
+        sessionContext.getServerRuntimeContext().getResourceRegistry().unbindResource(anotherAvailableUser.getBoundResourceId());
+        // 3 other resources got unbound, remaining one should now be unique
+        stanza = handler.executeCore(initialPresence, sessionContext.getServerRuntimeContext(),
true, sessionContext);
+        assertNull(stanza); // no return, esp no error stanza - all the handling is done
through relays
+        stanza = initiatingUser.getNextStanza();
+        assertNull(stanza.getAttribute("type"));
+        assertNull(stanza.getInnerElements());
+        assertNull(initiatingUser.getNextStanza()); // no second stanza
+
+        // now we run berserk :-) - when there is no resource remaining, from-resolution
fails again, and we get the same error again 
+        boolean noRemainingBinds = sessionContext.getServerRuntimeContext().getResourceRegistry().unbindResource(initiatingUser.getBoundResourceId());
+        assertTrue(noRemainingBinds);
+        stanza = handler.executeCore(initialPresence, sessionContext.getServerRuntimeContext(),
true, sessionContext);
+        assertEquals("error", stanza.getAttribute("type").getValue());
+        assertEquals(StanzaErrorCondition.UNKNOWN_SENDER.value(), stanza.getSingleInnerElementsNamed("error").getFirstInnerElement().getName());
+    }
+
 
 }

Modified: labs/vysper/src/test/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceSubRequestOutHandlerTestCase.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/test/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceSubRequestOutHandlerTestCase.java?rev=740831&r1=740830&r2=740831&view=diff
==============================================================================
--- labs/vysper/src/test/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceSubRequestOutHandlerTestCase.java
(original)
+++ labs/vysper/src/test/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceSubRequestOutHandlerTestCase.java
Wed Feb  4 19:13:24 2009
@@ -44,8 +44,8 @@
         XMPPCoreStanza requestApproval = XMPPCoreStanza.getWrapper(StanzaBuilder.createPresenceStanza(unrelatedUser.getEntityFQ(),
initiatingUser.getEntity(), null, PresenceStanzaType.SUBSCRIBED, null, null).getFinalStanza());
         handler.executeCore(requestApproval, sessionContext.getServerRuntimeContext(), false,
sessionContext);
 
-        // 1 subscribed
-        assertTrue(checkPresence(sessionContext.getRecordedResponse(), PresenceStanzaType.SUBSCRIBED,
unrelatedUser.getEntity(), null));
+        // subscribed stanza not delivered to client
+        assertNull(sessionContext.getRecordedResponse());
         // 3 roster pushes
         assertStanzasDeliveredAndRelayed(3);
 
@@ -138,4 +138,4 @@
         assertStanzasDeliveredAndRelayed(0); // TO subscription already exists with subscribed_BOTH
     }
 
-}
\ No newline at end of file
+}

Modified: labs/vysper/src/test/java/org/apache/vysper/xmpp/protocol/ProtocolWorkerProcessTestCase.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/test/java/org/apache/vysper/xmpp/protocol/ProtocolWorkerProcessTestCase.java?rev=740831&r1=740830&r2=740831&view=diff
==============================================================================
--- labs/vysper/src/test/java/org/apache/vysper/xmpp/protocol/ProtocolWorkerProcessTestCase.java
(original)
+++ labs/vysper/src/test/java/org/apache/vysper/xmpp/protocol/ProtocolWorkerProcessTestCase.java
Wed Feb  4 19:13:24 2009
@@ -260,8 +260,9 @@
         sessionContext.write(null); // reset
         
         // unbind second resource, leaving only one
-        sessionContext.getServerRuntimeContext().getResourceRegistry().unbindResource(secondBoundResource);
-        
+        boolean noResourceRemains = sessionContext.getServerRuntimeContext().getResourceRegistry().unbindResource(secondBoundResource);
+        assertFalse(noResourceRemains);
+
         // bare id allowed, only one resource is bound
         stanzaBuilder = StanzaBuilder.createIQStanza(null, null, IQStanzaType.GET, "test");
         stanzaBuilder.addAttribute("from", new EntityImpl("lea", server.getDomain(), null).getFullQualifiedName());

Modified: labs/vysper/src/test/java/org/apache/vysper/xmpp/server/TestSessionContext.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/test/java/org/apache/vysper/xmpp/server/TestSessionContext.java?rev=740831&r1=740830&r2=740831&view=diff
==============================================================================
--- labs/vysper/src/test/java/org/apache/vysper/xmpp/server/TestSessionContext.java (original)
+++ labs/vysper/src/test/java/org/apache/vysper/xmpp/server/TestSessionContext.java Wed Feb
 4 19:13:24 2009
@@ -39,7 +39,7 @@
     public static TestSessionContext createSessionContext(Entity entity) {
         SessionStateHolder sessionStateHolder = new SessionStateHolder();
         TestSessionContext sessionContext = new TestSessionContext(sessionStateHolder);
-        sessionContext.setInitiatingEntity(entity);
+        if (entity != null) sessionContext.setInitiatingEntity(entity.getBareJID());
         return sessionContext;
     }
 

Modified: labs/vysper/src/test/java/org/apache/vysper/xmpp/state/resourcebinding/ResourceRegistryTestCase.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/test/java/org/apache/vysper/xmpp/state/resourcebinding/ResourceRegistryTestCase.java?rev=740831&r1=740830&r2=740831&view=diff
==============================================================================
--- labs/vysper/src/test/java/org/apache/vysper/xmpp/state/resourcebinding/ResourceRegistryTestCase.java
(original)
+++ labs/vysper/src/test/java/org/apache/vysper/xmpp/state/resourcebinding/ResourceRegistryTestCase.java
Wed Feb  4 19:13:24 2009
@@ -133,8 +133,9 @@
         String resourceId1 = resourceRegistry.bindSession(sessionContext1);
         assertEquals(sessionContext1, resourceRegistry.getSessionContext(resourceId1));
         
-        resourceRegistry.unbindResource(resourceId1);
-        
+        boolean noResourceRemains = resourceRegistry.unbindResource(resourceId1);
+
+        assertTrue(noResourceRemains);
         assertNull(resourceRegistry.getSessionContext(resourceId1));
         assertEquals(0, resourceRegistry.getBoundResources(entity).size());
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org


Mime
View raw message