You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by ng...@apache.org on 2011/02/27 23:57:36 UTC

svn commit: r1075174 [1/2] - in /mina/vysper/trunk/server/core/src: main/java/org/apache/vysper/xmpp/cryptography/ main/java/org/apache/vysper/xmpp/modules/core/base/handler/ main/java/org/apache/vysper/xmpp/modules/core/bind/handler/ main/java/org/apa...

Author: ngn
Date: Sun Feb 27 22:57:35 2011
New Revision: 1075174

URL: http://svn.apache.org/viewvc?rev=1075174&view=rev
Log:
Adding additional unit tests for core module

Added:
    mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/StanzaAssert.java
    mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/cryptography/
    mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/cryptography/FileBasedTLSContextFactoryTestCase.java
    mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/cryptography/InputStreamBasedTLSContextFactoryTestCase.java
    mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/cryptography/TLSContextFactoryTestTemplate.java
    mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/core/bind/
    mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/core/bind/handler/
    mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/core/bind/handler/BindIQHandlerTestCase.java
    mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/core/compatibility/
    mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/core/compatibility/jabber_iq_auth/
    mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/core/compatibility/jabber_iq_auth/handler/
    mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/core/compatibility/jabber_iq_auth/handler/AuthCompatibilityIQHandlerTestCase.java
    mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0092_software_version/
    mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0092_software_version/SoftwareVersionIQHandlerTestCase.java
    mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0092_software_version/SoftwareVersionModuleTestCase.java
    mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0202_entity_time/
    mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0202_entity_time/EntityTimeIQHandlerTestCase.java
    mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0202_entity_time/EntityTimeModuleTestCase.java
    mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0202_entity_time/EntityTimeXEP0090IQHandlerTestCase.java
    mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/server/components/
    mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/server/components/ComponentStanzaProcessorTestCase.java
    mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/server/s2s/DefaultXMPPServerConnectorRegistryTestCase.java
    mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/server/s2s/FeaturesHandlerTestCase.java
    mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/server/s2s/TlsProceedHandlerTestCase.java
Removed:
    mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/parser/io/
Modified:
    mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/cryptography/AbstractTLSContextFactory.java
    mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/DefaultIQHandler.java
    mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/XMPPCoreStanzaHandler.java
    mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/bind/handler/BindIQHandler.java
    mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/compatibility/jabber_iq_auth/handler/AuthCompatibilityIQHandler.java
    mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0092_software_version/SoftwareVersionIQHandler.java
    mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0202_entity_time/EntityTimeIQHandler.java
    mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0202_entity_time/EntityTimeXEP0090IQHandler.java
    mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0220_server_dailback/DialbackIdGenerator.java
    mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/protocol/AbstractStanzaHandlerLookup.java
    mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/server/components/ComponentStanzaProcessor.java
    mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/server/s2s/DefaultXMPPServerConnectorRegistry.java
    mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/server/s2s/FeaturesHandler.java
    mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/server/s2s/TlsProceedHandler.java
    mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/server/s2s/XMPPServerConnector.java
    mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/protocol/StanzaHandlerLookupTestCase.java

Modified: mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/cryptography/AbstractTLSContextFactory.java
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/cryptography/AbstractTLSContextFactory.java?rev=1075174&r1=1075173&r2=1075174&view=diff
==============================================================================
--- mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/cryptography/AbstractTLSContextFactory.java (original)
+++ mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/cryptography/AbstractTLSContextFactory.java Sun Feb 27 22:57:35 2011
@@ -38,12 +38,14 @@ public abstract class AbstractTLSContext
 
     private static final String PROTOCOL = "TLS";
 
+    private static final String DEFAULT_ALGORITHM = "SunX509";
+
     private static final String KEY_MANAGER_FACTORY_ALGORITHM;
 
     static {
         String algorithm = Security.getProperty("ssl.KeyManagerFactory.algorithm");
-        if (algorithm == null)
-            algorithm = "SunX509";
+        if (algorithm == null) algorithm = DEFAULT_ALGORITHM;
+        
         KEY_MANAGER_FACTORY_ALGORITHM = algorithm;
     }
 
@@ -51,7 +53,7 @@ public abstract class AbstractTLSContext
 
     protected String password = null;
 
-    protected TrustManagerFactory trustManagerFactory = null;
+    protected TrustManagerFactory trustManagerFactory = new BogusTrustManagerFactory();
 
     // NOTE: The keystore was generated using keytool:
     //   keytool -genkey -alias bogus -keysize 512 -validity 3650

Modified: mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/DefaultIQHandler.java
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/DefaultIQHandler.java?rev=1075174&r1=1075173&r2=1075174&view=diff
==============================================================================
--- mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/DefaultIQHandler.java (original)
+++ mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/DefaultIQHandler.java Sun Feb 27 22:57:35 2011
@@ -55,9 +55,6 @@ public abstract class DefaultIQHandler e
     }
 
     @Override
-    protected abstract boolean verifyNamespace(Stanza stanza);
-
-    @Override
     protected Stanza executeIQLogic(IQStanza stanza, ServerRuntimeContext serverRuntimeContext, boolean outboundStanza,
             SessionContext sessionContext) {
 

Modified: mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/XMPPCoreStanzaHandler.java
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/XMPPCoreStanzaHandler.java?rev=1075174&r1=1075173&r2=1075174&view=diff
==============================================================================
--- mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/XMPPCoreStanzaHandler.java (original)
+++ mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/XMPPCoreStanzaHandler.java Sun Feb 27 22:57:35 2011
@@ -22,6 +22,7 @@ package org.apache.vysper.xmpp.modules.c
 import org.apache.vysper.xml.fragment.Attribute;
 import org.apache.vysper.xmpp.addressing.Entity;
 import org.apache.vysper.xmpp.addressing.EntityImpl;
+import org.apache.vysper.xmpp.protocol.NamespaceURIs;
 import org.apache.vysper.xmpp.protocol.ResponseStanzaContainer;
 import org.apache.vysper.xmpp.protocol.ResponseStanzaContainerImpl;
 import org.apache.vysper.xmpp.protocol.SessionStateHolder;
@@ -46,6 +47,8 @@ public abstract class XMPPCoreStanzaHand
     final static Logger logger = LoggerFactory.getLogger(XMPPCoreStanzaHandler.class);
 
     public boolean verify(Stanza stanza) {
+        if(stanza == null) return false;
+        
         boolean typeVerified = verifyType(stanza);
         boolean namespaceVerified = verifyNamespace(stanza);
         return typeVerified && namespaceVerified;
@@ -58,7 +61,7 @@ public abstract class XMPPCoreStanzaHand
     protected abstract boolean verifyType(Stanza stanza);
 
     protected boolean verifyNamespace(Stanza stanza) {
-        return true;
+        return NamespaceURIs.JABBER_CLIENT.equals(stanza.getNamespaceURI());
     }
 
     public ResponseStanzaContainer execute(Stanza anyStanza, ServerRuntimeContext serverRuntimeContext,

Modified: mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/bind/handler/BindIQHandler.java
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/bind/handler/BindIQHandler.java?rev=1075174&r1=1075173&r2=1075174&view=diff
==============================================================================
--- mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/bind/handler/BindIQHandler.java (original)
+++ mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/bind/handler/BindIQHandler.java Sun Feb 27 22:57:35 2011
@@ -39,13 +39,9 @@ import org.apache.vysper.xmpp.state.reso
 public class BindIQHandler extends DefaultIQHandler {
 
     @Override
-    protected boolean verifyNamespace(Stanza stanza) {
-        return verifyInnerNamespace(stanza, NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_BIND);
-    }
-
-    @Override
     protected boolean verifyInnerElement(Stanza stanza) {
-        return verifyInnerElementWorker(stanza, "bind");
+        return verifyInnerNamespace(stanza, NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_BIND) && 
+            verifyInnerElementWorker(stanza, "bind");
     }
 
     @Override
@@ -85,4 +81,5 @@ public class BindIQHandler extends Defau
 
         return stanzaBuilder.build();
     }
+
 }

Modified: mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/compatibility/jabber_iq_auth/handler/AuthCompatibilityIQHandler.java
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/compatibility/jabber_iq_auth/handler/AuthCompatibilityIQHandler.java?rev=1075174&r1=1075173&r2=1075174&view=diff
==============================================================================
--- mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/compatibility/jabber_iq_auth/handler/AuthCompatibilityIQHandler.java (original)
+++ mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/compatibility/jabber_iq_auth/handler/AuthCompatibilityIQHandler.java Sun Feb 27 22:57:35 2011
@@ -39,8 +39,8 @@ import org.apache.vysper.xmpp.stanza.Sta
 public class AuthCompatibilityIQHandler extends IQHandler {
 
     @Override
-    protected boolean verifyNamespace(Stanza stanza) {
-        return verifyInnerNamespace(stanza, NamespaceURIs.JABBER_IQ_AUTH_COMPATIBILITY);
+    public boolean verify(Stanza stanza) {
+        return super.verify(stanza) && verifyInnerNamespace(stanza, NamespaceURIs.JABBER_IQ_AUTH_COMPATIBILITY);
     }
 
     @Override
@@ -60,10 +60,9 @@ public class AuthCompatibilityIQHandler 
             return ServerErrorResponses.getStanzaError(StanzaErrorCondition.SERVICE_UNAVAILABLE, stanza,
                     StanzaErrorType.CANCEL, "jabber:iq:auth not supported", "en", null);
 
+        case RESULT:
         case ERROR:
             break; // ignore errors in compatibility only namespace
-        default:
-            throw new RuntimeException("iq stanza type not supported: " + stanza.getIQType());
         }
 
         return null;

Modified: mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0092_software_version/SoftwareVersionIQHandler.java
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0092_software_version/SoftwareVersionIQHandler.java?rev=1075174&r1=1075173&r2=1075174&view=diff
==============================================================================
--- mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0092_software_version/SoftwareVersionIQHandler.java (original)
+++ mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0092_software_version/SoftwareVersionIQHandler.java Sun Feb 27 22:57:35 2011
@@ -43,13 +43,8 @@ public class SoftwareVersionIQHandler ex
             + System.getProperty("os.arch", "") + " " + System.getProperty("os.version", "");
 
     @Override
-    protected boolean verifyNamespace(Stanza stanza) {
-        return verifyInnerNamespace(stanza, NamespaceURIs.JABBER_IQ_VERSION);
-    }
-
-    @Override
     protected boolean verifyInnerElement(Stanza stanza) {
-        return verifyInnerElementWorker(stanza, "query");
+        return verifyInnerElementWorker(stanza, "query") && verifyInnerNamespace(stanza, NamespaceURIs.JABBER_IQ_VERSION);
     }
 
     @Override

Modified: mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0202_entity_time/EntityTimeIQHandler.java
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0202_entity_time/EntityTimeIQHandler.java?rev=1075174&r1=1075173&r2=1075174&view=diff
==============================================================================
--- mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0202_entity_time/EntityTimeIQHandler.java (original)
+++ mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0202_entity_time/EntityTimeIQHandler.java Sun Feb 27 22:57:35 2011
@@ -44,13 +44,8 @@ public class EntityTimeIQHandler extends
     }
 
     @Override
-    protected boolean verifyNamespace(Stanza stanza) {
-        return verifyInnerNamespace(stanza, NamespaceURIs.URN_XMPP_TIME);
-    }
-
-    @Override
     protected boolean verifyInnerElement(Stanza stanza) {
-        return verifyInnerElementWorker(stanza, "time");
+        return verifyInnerElementWorker(stanza, "time") && verifyInnerNamespace(stanza, NamespaceURIs.URN_XMPP_TIME);
     }
 
     @Override

Modified: mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0202_entity_time/EntityTimeXEP0090IQHandler.java
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0202_entity_time/EntityTimeXEP0090IQHandler.java?rev=1075174&r1=1075173&r2=1075174&view=diff
==============================================================================
--- mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0202_entity_time/EntityTimeXEP0090IQHandler.java (original)
+++ mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0202_entity_time/EntityTimeXEP0090IQHandler.java Sun Feb 27 22:57:35 2011
@@ -56,13 +56,8 @@ public class EntityTimeXEP0090IQHandler 
     }
 
     @Override
-    protected boolean verifyNamespace(Stanza stanza) {
-        return verifyInnerNamespace(stanza, NamespaceURIs.JABBER_IQ_TIME);
-    }
-
-    @Override
     protected boolean verifyInnerElement(Stanza stanza) {
-        return verifyInnerElementWorker(stanza, "query");
+        return verifyInnerElementWorker(stanza, "query") && verifyInnerNamespace(stanza, NamespaceURIs.JABBER_IQ_TIME);
     }
 
     @Override

Modified: mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0220_server_dailback/DialbackIdGenerator.java
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0220_server_dailback/DialbackIdGenerator.java?rev=1075174&r1=1075173&r2=1075174&view=diff
==============================================================================
--- mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0220_server_dailback/DialbackIdGenerator.java (original)
+++ mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0220_server_dailback/DialbackIdGenerator.java Sun Feb 27 22:57:35 2011
@@ -28,6 +28,7 @@ import javax.crypto.spec.SecretKeySpec;
 
 import org.apache.commons.codec.binary.Hex;
 import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.lang.Validate;
 import org.apache.vysper.xmpp.addressing.Entity;
 
 
@@ -50,6 +51,10 @@ public class DialbackIdGenerator {
     }
     
     public String generate(Entity receiving, Entity originating, String streamId) {
+        Validate.notNull(receiving, "receiving can not be null");
+        Validate.notNull(originating, "originating can not be null");
+        Validate.notNull(streamId, "streamId can not be null");
+        
         try {
             mac.update(receiving.getDomain().getBytes("UTF-16"));
             mac.update(" ".getBytes("UTF-16"));

Modified: mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/protocol/AbstractStanzaHandlerLookup.java
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/protocol/AbstractStanzaHandlerLookup.java?rev=1075174&r1=1075173&r2=1075174&view=diff
==============================================================================
--- mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/protocol/AbstractStanzaHandlerLookup.java (original)
+++ mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/protocol/AbstractStanzaHandlerLookup.java Sun Feb 27 22:57:35 2011
@@ -20,7 +20,6 @@
 package org.apache.vysper.xmpp.protocol;
 
 import java.util.ArrayList;
-import java.util.LinkedHashMap;
 import java.util.List;
 
 import org.apache.vysper.xml.fragment.XMLElement;

Modified: mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/server/components/ComponentStanzaProcessor.java
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/server/components/ComponentStanzaProcessor.java?rev=1075174&r1=1075173&r2=1075174&view=diff
==============================================================================
--- mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/server/components/ComponentStanzaProcessor.java (original)
+++ mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/server/components/ComponentStanzaProcessor.java Sun Feb 27 22:57:35 2011
@@ -64,8 +64,7 @@ public class ComponentStanzaProcessor im
         StanzaHandler stanzaHandler = componentStanzaHandlerLookup.getHandler(xmppStanza);
 
         if (stanzaHandler == null) {
-            unhandledStanza(stanza);
-            return;
+            throw new RuntimeException("no handler for stanza");
         }
 
         ResponseStanzaContainer responseStanzaContainer = null;
@@ -73,13 +72,14 @@ public class ComponentStanzaProcessor im
             responseStanzaContainer = stanzaHandler.execute(stanza, serverRuntimeContext, false, sessionContext,
                     sessionStateHolder);
         } catch (ProtocolException e) {
-            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+            // TODO handle 
+            e.printStackTrace();
         }
 
         if (responseStanzaContainer != null && responseStanzaContainer.getResponseStanza() != null) {
             Stanza responseStanza = responseStanzaContainer.getResponseStanza();
             try {
-                IgnoreFailureStrategy failureStrategy = new IgnoreFailureStrategy(); // TODO call back module
+                IgnoreFailureStrategy failureStrategy = IgnoreFailureStrategy.IGNORE_FAILURE_STRATEGY; // TODO call back module
                 serverRuntimeContext.getStanzaRelay().relay(responseStanza.getTo(), responseStanza, failureStrategy);
             } catch (DeliveryException e) {
                 throw new RuntimeException(e);
@@ -88,10 +88,6 @@ public class ComponentStanzaProcessor im
 
     }
 
-    private void unhandledStanza(Stanza stanza) {
-        throw new RuntimeException("no handler for stanza");
-    }
-
     public void processTLSEstablished(SessionContext sessionContext, SessionStateHolder sessionStateHolder) {
         throw new RuntimeException("should not be called for components, which only acts as an established session");
     }

Modified: mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/server/s2s/DefaultXMPPServerConnectorRegistry.java
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/server/s2s/DefaultXMPPServerConnectorRegistry.java?rev=1075174&r1=1075173&r2=1075174&view=diff
==============================================================================
--- mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/server/s2s/DefaultXMPPServerConnectorRegistry.java (original)
+++ mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/server/s2s/DefaultXMPPServerConnectorRegistry.java Sun Feb 27 22:57:35 2011
@@ -37,7 +37,7 @@ import org.apache.vysper.xmpp.server.Ses
 public class DefaultXMPPServerConnectorRegistry implements XMPPServerConnectorRegistry {
 
     private ServerRuntimeContext serverRuntimeContext;
-    private Map<Entity, DefaultXMPPServerConnector> connectors = new ConcurrentHashMap<Entity, DefaultXMPPServerConnector>();
+    private Map<Entity, XMPPServerConnector> connectors = new ConcurrentHashMap<Entity, XMPPServerConnector>();
     
     public DefaultXMPPServerConnectorRegistry(ServerRuntimeContext serverRuntimeContext) {
         this.serverRuntimeContext = serverRuntimeContext;
@@ -48,7 +48,7 @@ public class DefaultXMPPServerConnectorR
      */
     @SpecCompliant(spec = "draft-ietf-xmpp-3920bis-22", section = "10.4", status = SpecCompliant.ComplianceStatus.FINISHED, coverage = SpecCompliant.ComplianceCoverage.COMPLETE)
     public synchronized XMPPServerConnector connect(Entity server) throws RemoteServerNotFoundException, RemoteServerTimeoutException {
-        DefaultXMPPServerConnector connector = connectors.get(server);
+        XMPPServerConnector connector = connectors.get(server);
 
         if(connector != null && connector.isClosed()) {
             connectors.remove(server);
@@ -56,7 +56,7 @@ public class DefaultXMPPServerConnectorR
         } 
         
         if(connector == null) {
-            connector = new DefaultXMPPServerConnector(server, serverRuntimeContext, null, null);
+            connector = createConnector(server, serverRuntimeContext, null, null);
             connector.start();
 
             connectors.put(server, connector);
@@ -67,16 +67,20 @@ public class DefaultXMPPServerConnectorR
     
     @SpecCompliant(spec = "draft-ietf-xmpp-3920bis-22", section = "10.4", status = SpecCompliant.ComplianceStatus.FINISHED, coverage = SpecCompliant.ComplianceCoverage.COMPLETE)
     public synchronized XMPPServerConnector connectForDialback(Entity server, SessionContext orginalSessionContext, SessionStateHolder originalSessionStateHolder) throws RemoteServerNotFoundException, RemoteServerTimeoutException {
-        DefaultXMPPServerConnector connector = new DefaultXMPPServerConnector(server, serverRuntimeContext, orginalSessionContext, originalSessionStateHolder);
+        XMPPServerConnector connector = createConnector(server, serverRuntimeContext, orginalSessionContext, originalSessionStateHolder);
         connector.start();
         return connector;
     }
     
+    protected XMPPServerConnector createConnector(Entity otherServer, ServerRuntimeContext serverRuntimeContext, SessionContext dialbackSessionContext, SessionStateHolder dialbackSessionStateHolder) {
+        return new DefaultXMPPServerConnector(otherServer, serverRuntimeContext, dialbackSessionContext, dialbackSessionStateHolder);
+    }
+    
     /* (non-Javadoc)
      * @see org.apache.vysper.xmpp.server.s2s.XMPPServerConnectorRegistry#close()
      */
     public void close() {
-        for(DefaultXMPPServerConnector connector : connectors.values()) {
+        for(XMPPServerConnector connector : connectors.values()) {
             connector.close();
         }
     }

Modified: mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/server/s2s/FeaturesHandler.java
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/server/s2s/FeaturesHandler.java?rev=1075174&r1=1075173&r2=1075174&view=diff
==============================================================================
--- mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/server/s2s/FeaturesHandler.java (original)
+++ mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/server/s2s/FeaturesHandler.java Sun Feb 27 22:57:35 2011
@@ -51,7 +51,6 @@ public class FeaturesHandler implements 
         if (stanza == null) return false;
         if (!getName().equals(stanza.getName())) return false;
         String namespaceURI = stanza.getNamespaceURI();
-        if (namespaceURI == null) return false;
         return namespaceURI.equals(NamespaceURIs.HTTP_ETHERX_JABBER_ORG_STREAMS);
     }
 

Modified: mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/server/s2s/TlsProceedHandler.java
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/server/s2s/TlsProceedHandler.java?rev=1075174&r1=1075173&r2=1075174&view=diff
==============================================================================
--- mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/server/s2s/TlsProceedHandler.java (original)
+++ mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/server/s2s/TlsProceedHandler.java Sun Feb 27 22:57:35 2011
@@ -47,7 +47,6 @@ public class TlsProceedHandler implement
         if (stanza == null) return false;
         if (!getName().equals(stanza.getName())) return false;
         String namespaceURI = stanza.getNamespaceURI();
-        if (namespaceURI == null) return false;
         return namespaceURI.equals(NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_TLS);
     }
 

Modified: mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/server/s2s/XMPPServerConnector.java
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/server/s2s/XMPPServerConnector.java?rev=1075174&r1=1075173&r2=1075174&view=diff
==============================================================================
--- mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/server/s2s/XMPPServerConnector.java (original)
+++ mina/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/server/s2s/XMPPServerConnector.java Sun Feb 27 22:57:35 2011
@@ -19,6 +19,8 @@
  */
 package org.apache.vysper.xmpp.server.s2s;
 
+import org.apache.vysper.xmpp.delivery.failure.RemoteServerNotFoundException;
+import org.apache.vysper.xmpp.delivery.failure.RemoteServerTimeoutException;
 import org.apache.vysper.xmpp.stanza.Stanza;
 import org.apache.vysper.xmpp.writer.StanzaWriter;
 
@@ -30,6 +32,18 @@ import org.apache.vysper.xmpp.writer.Sta
 public interface XMPPServerConnector extends StanzaWriter {
 
     /**
+     * Connect and authenticate the XMPP server connector
+     */
+    void start() throws RemoteServerNotFoundException, RemoteServerTimeoutException;
+    
+    /**
+     * Is this XMPP server connector closed?
+     * @return true if the connector is closed
+     */
+    boolean isClosed();
+
+    
+    /**
      * Write a {@link Stanza} to another XMPP server
      * @param stanza The {@link Stanza} to write
      */

Added: mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/StanzaAssert.java
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/StanzaAssert.java?rev=1075174&view=auto
==============================================================================
--- mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/StanzaAssert.java (added)
+++ mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/StanzaAssert.java Sun Feb 27 22:57:35 2011
@@ -0,0 +1,37 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+
+package org.apache.vysper;
+
+import org.apache.vysper.xml.fragment.Renderer;
+import org.apache.vysper.xmpp.stanza.Stanza;
+import org.junit.Assert;
+
+public class StanzaAssert {
+
+    public static void assertEquals(Stanza expected, Stanza actual) {
+        try {
+            Assert.assertEquals(expected, actual);
+        } catch(Throwable e) {
+            // print something useful
+            Assert.assertEquals(new Renderer(expected).getComplete(), new Renderer(actual).getComplete());
+        }
+    }
+}

Added: mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/cryptography/FileBasedTLSContextFactoryTestCase.java
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/cryptography/FileBasedTLSContextFactoryTestCase.java?rev=1075174&view=auto
==============================================================================
--- mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/cryptography/FileBasedTLSContextFactoryTestCase.java (added)
+++ mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/cryptography/FileBasedTLSContextFactoryTestCase.java Sun Feb 27 22:57:35 2011
@@ -0,0 +1,51 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.vysper.xmpp.cryptography;
+
+import java.io.File;
+import java.io.IOException;
+import java.security.GeneralSecurityException;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+
+/**
+ */
+public class FileBasedTLSContextFactoryTestCase extends TLSContextFactoryTestTemplate {
+
+    protected AbstractTLSContextFactory createTLSContextFactory() {
+        return createTLSContextFactory("src/main/config/bogus_mina_tls.cert");
+    }
+    
+    protected AbstractTLSContextFactory createTLSContextFactory(String path) {
+        File keystore = new File(path);
+        return new FileBasedTLSContextFactory(keystore);
+    }
+    
+    @Test(expected=IOException.class)
+    public void nonExistingKeystoreFile() throws GeneralSecurityException, IOException {
+        AbstractTLSContextFactory contextFactory = createTLSContextFactory("dummy");
+        
+        contextFactory.setPassword("boguspw");
+        
+        Assert.assertNotNull(contextFactory.getSSLContext());
+    }
+}

Added: mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/cryptography/InputStreamBasedTLSContextFactoryTestCase.java
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/cryptography/InputStreamBasedTLSContextFactoryTestCase.java?rev=1075174&view=auto
==============================================================================
--- mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/cryptography/InputStreamBasedTLSContextFactoryTestCase.java (added)
+++ mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/cryptography/InputStreamBasedTLSContextFactoryTestCase.java Sun Feb 27 22:57:35 2011
@@ -0,0 +1,33 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.vysper.xmpp.cryptography;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+
+/**
+ */
+public class InputStreamBasedTLSContextFactoryTestCase extends TLSContextFactoryTestTemplate {
+
+    protected AbstractTLSContextFactory createTLSContextFactory() throws FileNotFoundException {
+        FileInputStream in = new FileInputStream("src/main/config/bogus_mina_tls.cert");
+        return new InputStreamBasedTLSContextFactory(in);
+    }
+}

Added: mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/cryptography/TLSContextFactoryTestTemplate.java
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/cryptography/TLSContextFactoryTestTemplate.java?rev=1075174&view=auto
==============================================================================
--- mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/cryptography/TLSContextFactoryTestTemplate.java (added)
+++ mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/cryptography/TLSContextFactoryTestTemplate.java Sun Feb 27 22:57:35 2011
@@ -0,0 +1,52 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.vysper.xmpp.cryptography;
+
+import java.io.IOException;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+
+/**
+ */
+public abstract class TLSContextFactoryTestTemplate {
+
+    protected abstract AbstractTLSContextFactory createTLSContextFactory() throws Exception;
+    
+    @Test
+    public void test() throws Exception {
+        AbstractTLSContextFactory contextFactory = createTLSContextFactory();
+        
+        contextFactory.setPassword("boguspw");
+        
+        Assert.assertNotNull(contextFactory.getSSLContext());
+    }
+
+    @Test(expected=IOException.class)
+    public void invalidPassphrase() throws Exception {
+        AbstractTLSContextFactory contextFactory = createTLSContextFactory();
+        
+        contextFactory.setPassword("dummy");
+        
+        Assert.assertNotNull(contextFactory.getSSLContext());
+    }
+
+}

Added: mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/core/bind/handler/BindIQHandlerTestCase.java
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/core/bind/handler/BindIQHandlerTestCase.java?rev=1075174&view=auto
==============================================================================
--- mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/core/bind/handler/BindIQHandlerTestCase.java (added)
+++ mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/core/bind/handler/BindIQHandlerTestCase.java Sun Feb 27 22:57:35 2011
@@ -0,0 +1,165 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.vysper.xmpp.modules.core.bind.handler;
+
+import junit.framework.Assert;
+
+import org.apache.vysper.StanzaAssert;
+import org.apache.vysper.xmpp.addressing.Entity;
+import org.apache.vysper.xmpp.addressing.EntityImpl;
+import org.apache.vysper.xmpp.delivery.StanzaRelay;
+import org.apache.vysper.xmpp.delivery.failure.DeliveryException;
+import org.apache.vysper.xmpp.delivery.failure.IgnoreFailureStrategy;
+import org.apache.vysper.xmpp.protocol.NamespaceURIs;
+import org.apache.vysper.xmpp.protocol.ProtocolException;
+import org.apache.vysper.xmpp.protocol.ResponseStanzaContainer;
+import org.apache.vysper.xmpp.protocol.ResponseStanzaContainerImpl;
+import org.apache.vysper.xmpp.protocol.SessionStateHolder;
+import org.apache.vysper.xmpp.protocol.StanzaHandler;
+import org.apache.vysper.xmpp.server.ServerRuntimeContext;
+import org.apache.vysper.xmpp.server.SessionContext;
+import org.apache.vysper.xmpp.stanza.IQStanza;
+import org.apache.vysper.xmpp.stanza.IQStanzaType;
+import org.apache.vysper.xmpp.stanza.Stanza;
+import org.apache.vysper.xmpp.stanza.StanzaBuilder;
+import org.apache.vysper.xmpp.state.resourcebinding.BindException;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+/**
+ */
+public class BindIQHandlerTestCase {
+
+    private static final Entity FROM = EntityImpl.parseUnchecked("other.org");
+    
+    private ServerRuntimeContext serverRuntimeContext = Mockito.mock(ServerRuntimeContext.class);
+    private SessionContext sessionContext = Mockito.mock(SessionContext.class);
+    private IQStanza stanza = (IQStanza) IQStanza.getWrapper(buildStanza());
+    
+    private BindIQHandler handler = new BindIQHandler();
+    
+    @Before
+    public void before() throws BindException {
+        Mockito.when(sessionContext.getInitiatingEntity()).thenReturn(FROM);
+    }
+    
+    private Stanza buildStanza() {
+        return buildStanza("iq", NamespaceURIs.JABBER_CLIENT, "bind", NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_BIND);
+    }
+
+    private Stanza buildStanza(String name, String namespaceUri) {
+        return buildStanza(name, namespaceUri, "bind", NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_BIND);
+    }
+    
+    private Stanza buildStanza(String name, String namespaceUri, String innerName, String innerNamespaceUri) {
+        return new StanzaBuilder(name, namespaceUri)
+            .addAttribute("id", "1")
+            .startInnerElement(innerName, innerNamespaceUri)
+            .build();
+    }
+    
+    @Test
+    public void nameMustBeIq() {
+        Assert.assertEquals("iq", handler.getName());
+    }
+
+    @Test
+    public void verifyNullStanza() {
+        Assert.assertFalse(handler.verify(null));
+    }
+
+    @Test
+    public void verifyInvalidName() {
+        Assert.assertFalse(handler.verify(buildStanza("dummy", NamespaceURIs.JABBER_CLIENT)));
+    }
+
+    @Test
+    public void verifyInvalidNamespace() {
+        Assert.assertFalse(handler.verify(buildStanza("iq", "dummy")));
+    }
+
+    @Test
+    public void verifyNullNamespace() {
+        Assert.assertFalse(handler.verify(buildStanza("iq", null)));
+    }
+
+    @Test
+    public void verifyNullInnerNamespace() {
+        Assert.assertFalse(handler.verify(buildStanza("iq", NamespaceURIs.JABBER_CLIENT, "bind", null)));
+    }
+
+    @Test
+    public void verifyInvalidInnerNamespace() {
+        Assert.assertFalse(handler.verify(buildStanza("iq", NamespaceURIs.JABBER_CLIENT, "bind", "dummy")));
+    }
+    
+    @Test
+    public void verifyInvalidInnerName() {
+        Assert.assertFalse(handler.verify(buildStanza("iq", NamespaceURIs.JABBER_CLIENT, "dummy", NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_BIND)));
+    }
+
+    @Test
+    public void verifyMissingInnerElement() {
+        Stanza stanza = new StanzaBuilder("iq", NamespaceURIs.JABBER_CLIENT).build();
+        Assert.assertFalse(handler.verify(stanza));
+    }
+    
+    @Test
+    public void verifyValidStanza() {
+        Assert.assertTrue(handler.verify(stanza));
+    }
+
+    @Test
+    public void sessionIsRequired() {
+        Assert.assertTrue(handler.isSessionRequired());
+    }
+
+    @Test
+    public void handleSet() throws BindException {
+        Mockito.when(sessionContext.bindResource()).thenReturn("res");
+        
+        Stanza response = handler.handleSet(stanza, serverRuntimeContext, sessionContext);
+        
+        Stanza expectedResponse = StanzaBuilder.createIQStanza(null, null, IQStanzaType.RESULT, stanza.getID())
+            .startInnerElement("bind", NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_BIND)
+            .startInnerElement("jid",  NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_BIND)
+            .addText(new EntityImpl(FROM, "res").getFullQualifiedName())
+            .build();
+        
+        StanzaAssert.assertEquals(expectedResponse, response);
+    }
+
+    @Test
+    public void handleSetWithBindException() throws BindException {
+        Mockito.when(sessionContext.bindResource()).thenThrow(new BindException());
+        
+        Stanza response = handler.handleSet(stanza, serverRuntimeContext, sessionContext);
+        
+        Stanza expectedResponse = StanzaBuilder.createIQStanza(null, null, IQStanzaType.ERROR, stanza.getID())
+            .startInnerElement("error", NamespaceURIs.JABBER_CLIENT)
+            .addAttribute("type", "cancel")
+            .startInnerElement("not-allowed", NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_STANZAS)
+            .build();
+        
+        StanzaAssert.assertEquals(expectedResponse, response);
+    }
+
+}

Added: mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/core/compatibility/jabber_iq_auth/handler/AuthCompatibilityIQHandlerTestCase.java
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/core/compatibility/jabber_iq_auth/handler/AuthCompatibilityIQHandlerTestCase.java?rev=1075174&view=auto
==============================================================================
--- mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/core/compatibility/jabber_iq_auth/handler/AuthCompatibilityIQHandlerTestCase.java (added)
+++ mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/core/compatibility/jabber_iq_auth/handler/AuthCompatibilityIQHandlerTestCase.java Sun Feb 27 22:57:35 2011
@@ -0,0 +1,157 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.vysper.xmpp.modules.core.compatibility.jabber_iq_auth.handler;
+
+import junit.framework.Assert;
+
+import org.apache.vysper.StanzaAssert;
+import org.apache.vysper.xmpp.protocol.NamespaceURIs;
+import org.apache.vysper.xmpp.protocol.ResponseStanzaContainer;
+import org.apache.vysper.xmpp.protocol.SessionStateHolder;
+import org.apache.vysper.xmpp.server.ServerRuntimeContext;
+import org.apache.vysper.xmpp.server.SessionContext;
+import org.apache.vysper.xmpp.stanza.IQStanza;
+import org.apache.vysper.xmpp.stanza.IQStanzaType;
+import org.apache.vysper.xmpp.stanza.Stanza;
+import org.apache.vysper.xmpp.stanza.StanzaBuilder;
+import org.apache.vysper.xmpp.state.resourcebinding.BindException;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+/**
+ */
+public class AuthCompatibilityIQHandlerTestCase {
+
+    private ServerRuntimeContext serverRuntimeContext = Mockito.mock(ServerRuntimeContext.class);
+    private SessionContext sessionContext = Mockito.mock(SessionContext.class);
+    private IQStanza stanzaWithSet = (IQStanza) IQStanza.getWrapper(buildStanza("set"));
+    private IQStanza stanzaWithGet = (IQStanza) IQStanza.getWrapper(buildStanza("get"));
+    private IQStanza stanzaWithResult = (IQStanza) IQStanza.getWrapper(buildStanza("result"));
+    private IQStanza stanzaWithError = (IQStanza) IQStanza.getWrapper(buildStanza("error"));
+    private SessionStateHolder sessionStateHolder = new SessionStateHolder();
+    
+    private AuthCompatibilityIQHandler handler = new AuthCompatibilityIQHandler();
+    
+    private Stanza buildStanza(String type) {
+        return buildStanza("iq", NamespaceURIs.JABBER_CLIENT, "query", NamespaceURIs.JABBER_IQ_AUTH_COMPATIBILITY, type);
+    }
+
+    private Stanza buildStanza(String name, String namespaceUri, String type) {
+        return buildStanza(name, namespaceUri, "query", NamespaceURIs.JABBER_IQ_AUTH_COMPATIBILITY, type);
+    }
+    
+    private Stanza buildStanza(String name, String namespaceUri, String innerName, String innerNamespaceUri, String type) {
+        return new StanzaBuilder(name, namespaceUri)
+            .addAttribute("type", type)
+            .addAttribute("id", "1")
+            .startInnerElement(innerName, innerNamespaceUri)
+            .build();
+    }
+    
+    @Test
+    public void nameMustBeIq() {
+        Assert.assertEquals("iq", handler.getName());
+    }
+
+    @Test
+    public void verifyNullStanza() {
+        Assert.assertFalse(handler.verify(null));
+    }
+
+    @Test
+    public void verifyInvalidName() {
+        Assert.assertFalse(handler.verify(buildStanza("dummy", NamespaceURIs.JABBER_CLIENT, "set")));
+    }
+
+    @Test
+    public void verifyInvalidNamespace() {
+        Assert.assertFalse(handler.verify(buildStanza("iq", "dummy", "set")));
+    }
+
+    @Test
+    public void verifyNullNamespace() {
+        Assert.assertFalse(handler.verify(buildStanza("iq", null, "set")));
+    }
+
+    @Test
+    public void verifyNullInnerNamespace() {
+        Assert.assertFalse(handler.verify(buildStanza("iq", NamespaceURIs.JABBER_CLIENT, "query", null, "set")));
+    }
+
+    @Test
+    public void verifyInvalidInnerNamespace() {
+        Assert.assertFalse(handler.verify(buildStanza("iq", NamespaceURIs.JABBER_CLIENT, "query", "dummy", "set")));
+    }
+    
+    @Test
+    public void verifyMissingInnerElement() {
+        Stanza stanza = new StanzaBuilder("iq", NamespaceURIs.JABBER_CLIENT).build();
+        Assert.assertFalse(handler.verify(stanza));
+    }
+    
+    @Test
+    public void verifyValidStanza() {
+        Assert.assertTrue(handler.verify(stanzaWithSet));
+    }
+
+    @Test
+    public void sessionIsRequired() {
+        Assert.assertTrue(handler.isSessionRequired());
+    }
+
+    @Test
+    public void handleSet() throws BindException {
+        assertResponse(stanzaWithSet);
+    }
+
+    @Test
+    public void handleGet() throws BindException {
+        assertResponse(stanzaWithGet);
+    }
+    
+    @Test
+    public void handleResult() throws BindException {
+        Assert.assertNull(handler.execute(stanzaWithResult, serverRuntimeContext, false, sessionContext, sessionStateHolder));
+    }
+    
+    @Test
+    public void handleError() throws BindException {
+        Assert.assertNull(handler.execute(stanzaWithError, serverRuntimeContext, false, sessionContext, sessionStateHolder));
+    }
+    
+    
+    
+    private void assertResponse(Stanza stanza) {
+        ResponseStanzaContainer response = handler.execute(stanza, serverRuntimeContext, false, sessionContext, sessionStateHolder);
+
+        Stanza expectedResponse = StanzaBuilder.createIQStanza(null, null, IQStanzaType.ERROR, "1")
+            .startInnerElement("query", NamespaceURIs.JABBER_IQ_AUTH_COMPATIBILITY).endInnerElement()
+            .startInnerElement("error",  NamespaceURIs.JABBER_CLIENT)
+            .addAttribute("type", "cancel")
+            .startInnerElement("service-unavailable", NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_STANZAS).endInnerElement()
+            .startInnerElement("text", NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_STANZAS)
+            .addAttribute(NamespaceURIs.XML, "lang", "en")
+            .addText("jabber:iq:auth not supported")
+            .build();
+        
+        StanzaAssert.assertEquals(expectedResponse, response.getResponseStanza());
+    }
+
+}

Added: mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0092_software_version/SoftwareVersionIQHandlerTestCase.java
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0092_software_version/SoftwareVersionIQHandlerTestCase.java?rev=1075174&view=auto
==============================================================================
--- mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0092_software_version/SoftwareVersionIQHandlerTestCase.java (added)
+++ mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0092_software_version/SoftwareVersionIQHandlerTestCase.java Sun Feb 27 22:57:35 2011
@@ -0,0 +1,165 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.vysper.xmpp.modules.extension.xep0092_software_version;
+
+import junit.framework.Assert;
+
+import org.apache.vysper.StanzaAssert;
+import org.apache.vysper.xml.fragment.XMLElement;
+import org.apache.vysper.xml.fragment.XMLSemanticError;
+import org.apache.vysper.xmpp.addressing.Entity;
+import org.apache.vysper.xmpp.addressing.EntityImpl;
+import org.apache.vysper.xmpp.delivery.StanzaRelay;
+import org.apache.vysper.xmpp.delivery.failure.DeliveryException;
+import org.apache.vysper.xmpp.delivery.failure.IgnoreFailureStrategy;
+import org.apache.vysper.xmpp.protocol.NamespaceURIs;
+import org.apache.vysper.xmpp.protocol.ProtocolException;
+import org.apache.vysper.xmpp.protocol.ResponseStanzaContainer;
+import org.apache.vysper.xmpp.protocol.ResponseStanzaContainerImpl;
+import org.apache.vysper.xmpp.protocol.SessionStateHolder;
+import org.apache.vysper.xmpp.protocol.StanzaHandler;
+import org.apache.vysper.xmpp.server.ServerRuntimeContext;
+import org.apache.vysper.xmpp.server.SessionContext;
+import org.apache.vysper.xmpp.stanza.IQStanza;
+import org.apache.vysper.xmpp.stanza.IQStanzaType;
+import org.apache.vysper.xmpp.stanza.Stanza;
+import org.apache.vysper.xmpp.stanza.StanzaBuilder;
+import org.apache.vysper.xmpp.state.resourcebinding.BindException;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+/**
+ */
+public class SoftwareVersionIQHandlerTestCase {
+
+    private static final Entity FROM = EntityImpl.parseUnchecked("other.org");
+    
+    private ServerRuntimeContext serverRuntimeContext = Mockito.mock(ServerRuntimeContext.class);
+    private SessionContext sessionContext = Mockito.mock(SessionContext.class);
+    private IQStanza stanza = (IQStanza) IQStanza.getWrapper(buildStanza());
+    
+    private SoftwareVersionIQHandler handler = new SoftwareVersionIQHandler();
+    
+    @Before
+    public void before() throws BindException {
+        Mockito.when(sessionContext.getInitiatingEntity()).thenReturn(FROM);
+    }
+    
+    private Stanza buildStanza() {
+        return buildStanza("iq", NamespaceURIs.JABBER_CLIENT, "query", NamespaceURIs.JABBER_IQ_VERSION);
+    }
+
+    private Stanza buildStanza(String name, String namespaceUri) {
+        return buildStanza(name, namespaceUri, "query", NamespaceURIs.JABBER_IQ_VERSION);
+    }
+    
+    private Stanza buildStanza(String name, String namespaceUri, String innerName, String innerNamespaceUri) {
+        return new StanzaBuilder(name, namespaceUri)
+            .addAttribute("type", "get")
+            .addAttribute("id", "1")
+            .startInnerElement(innerName, innerNamespaceUri)
+            .build();
+    }
+    
+    @Test
+    public void nameMustBeIq() {
+        Assert.assertEquals("iq", handler.getName());
+    }
+
+    @Test
+    public void verifyNullStanza() {
+        Assert.assertFalse(handler.verify(null));
+    }
+
+    @Test
+    public void verifyInvalidName() {
+        Assert.assertFalse(handler.verify(buildStanza("dummy", NamespaceURIs.JABBER_CLIENT)));
+    }
+
+    @Test
+    public void verifyInvalidNamespace() {
+        Assert.assertFalse(handler.verify(buildStanza("iq", "dummy")));
+    }
+
+    @Test
+    public void verifyNullNamespace() {
+        Assert.assertFalse(handler.verify(buildStanza("iq", null)));
+    }
+
+    @Test
+    public void verifyNullInnerNamespace() {
+        Assert.assertFalse(handler.verify(buildStanza("iq", NamespaceURIs.JABBER_CLIENT, "query", null)));
+    }
+
+    @Test
+    public void verifyInvalidInnerNamespace() {
+        Assert.assertFalse(handler.verify(buildStanza("iq", NamespaceURIs.JABBER_CLIENT, "query", "dummy")));
+    }
+    
+    @Test
+    public void verifyInvalidInnerName() {
+        Assert.assertFalse(handler.verify(buildStanza("iq", NamespaceURIs.JABBER_CLIENT, "dummy", NamespaceURIs.JABBER_IQ_VERSION)));
+    }
+
+    @Test
+    public void verifyMissingInnerElement() {
+        Stanza stanza = new StanzaBuilder("iq", NamespaceURIs.JABBER_CLIENT).build();
+        Assert.assertFalse(handler.verify(stanza));
+    }
+    
+    @Test
+    public void verifyValidStanza() {
+        Assert.assertTrue(handler.verify(stanza));
+    }
+
+    @Test
+    public void sessionIsRequired() {
+        Assert.assertTrue(handler.isSessionRequired());
+    }
+
+    @Test
+    public void handleGet() throws BindException, XMLSemanticError {
+        Stanza response = handler.handleGet(stanza, serverRuntimeContext, sessionContext);
+        
+        // <iq xmlns="jabber:client" type="result" id="1">
+        // <query xmlns="jabber:iq:version"><name>Apache Vysper XMPP Server</name>
+        // <version>Unknown</version><os>Mac OS X x86_64 10.6.6</os></query></iq>
+
+        Assert.assertNotNull(response);
+        Assert.assertEquals("iq", response.getName());
+        Assert.assertEquals(NamespaceURIs.JABBER_CLIENT, response.getNamespaceURI());
+        Assert.assertEquals("result", response.getAttributeValue("type"));
+        Assert.assertEquals("1", response.getAttributeValue("id"));
+        
+        XMLElement query = response.getSingleInnerElementsNamed("query", NamespaceURIs.JABBER_IQ_VERSION);
+        Assert.assertEquals(3, query.getInnerElements().size());
+        
+        XMLElement name = query.getSingleInnerElementsNamed("name", NamespaceURIs.JABBER_IQ_VERSION);
+        Assert.assertEquals("Apache Vysper XMPP Server", name.getInnerText().getText());
+        
+        XMLElement version = query.getSingleInnerElementsNamed("version", NamespaceURIs.JABBER_IQ_VERSION);
+        Assert.assertNotNull(version.getInnerText().getText());
+        
+        XMLElement os = query.getSingleInnerElementsNamed("os", NamespaceURIs.JABBER_IQ_VERSION);
+        Assert.assertNotNull(os.getInnerText().getText());
+        
+    }
+}

Added: mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0092_software_version/SoftwareVersionModuleTestCase.java
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0092_software_version/SoftwareVersionModuleTestCase.java?rev=1075174&view=auto
==============================================================================
--- mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0092_software_version/SoftwareVersionModuleTestCase.java (added)
+++ mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0092_software_version/SoftwareVersionModuleTestCase.java Sun Feb 27 22:57:35 2011
@@ -0,0 +1,89 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.vysper.xmpp.modules.extension.xep0092_software_version;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.apache.vysper.xmpp.modules.servicediscovery.management.Feature;
+import org.apache.vysper.xmpp.modules.servicediscovery.management.InfoElement;
+import org.apache.vysper.xmpp.modules.servicediscovery.management.InfoRequest;
+import org.apache.vysper.xmpp.modules.servicediscovery.management.ServerInfoRequestListener;
+import org.apache.vysper.xmpp.modules.servicediscovery.management.ServiceDiscoveryRequestException;
+import org.apache.vysper.xmpp.protocol.HandlerDictionary;
+import org.apache.vysper.xmpp.protocol.NamespaceHandlerDictionary;
+import org.apache.vysper.xmpp.protocol.NamespaceURIs;
+import org.junit.Test;
+
+/**
+ */
+public class SoftwareVersionModuleTestCase {
+
+    private SoftwareVersionModule module = new SoftwareVersionModule();
+    
+    @Test
+    public void nameMustBeProvided() {
+        Assert.assertNotNull(module.getName());
+    }
+
+    @Test
+    public void versionMustBeProvided() {
+        Assert.assertNotNull(module.getVersion());
+    }
+    
+    @Test
+    public void getServerInfosFor() throws ServiceDiscoveryRequestException {
+        List<ServerInfoRequestListener> serverInfoRequestListeners = new ArrayList<ServerInfoRequestListener>();
+        
+        module.addServerInfoRequestListeners(serverInfoRequestListeners);
+        
+        Assert.assertEquals(1, serverInfoRequestListeners.size());
+        
+        List<InfoElement> infoElements = serverInfoRequestListeners.get(0).getServerInfosFor(new InfoRequest(null, null, null, null));
+        
+        Assert.assertEquals(1, infoElements.size());
+        Assert.assertTrue(infoElements.get(0) instanceof Feature);
+        Assert.assertEquals(NamespaceURIs.JABBER_IQ_VERSION, ((Feature)infoElements.get(0)).getVar());
+    }
+
+    @Test
+    public void getServerInfosForWithNode() throws ServiceDiscoveryRequestException {
+        List<ServerInfoRequestListener> serverInfoRequestListeners = new ArrayList<ServerInfoRequestListener>();
+        module.addServerInfoRequestListeners(serverInfoRequestListeners);
+        Assert.assertEquals(1, serverInfoRequestListeners.size());
+        
+        Assert.assertNull(serverInfoRequestListeners.get(0).getServerInfosFor(new InfoRequest(null, null, "node", null)));
+    }
+    
+    @Test
+    public void addHandlerDictionaries() {
+        List<HandlerDictionary> dictionaries = new ArrayList<HandlerDictionary>();
+        
+        module.addHandlerDictionaries(dictionaries);
+        
+        Assert.assertEquals(1, dictionaries.size());
+        Assert.assertTrue(dictionaries.get(0) instanceof NamespaceHandlerDictionary);
+        NamespaceHandlerDictionary namespaceHandlerDictionary = (NamespaceHandlerDictionary) dictionaries.get(0);
+        
+        Assert.assertEquals(NamespaceURIs.JABBER_IQ_VERSION, namespaceHandlerDictionary.getNamespaceURI());
+    }
+}

Added: mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0202_entity_time/EntityTimeIQHandlerTestCase.java
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0202_entity_time/EntityTimeIQHandlerTestCase.java?rev=1075174&view=auto
==============================================================================
--- mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0202_entity_time/EntityTimeIQHandlerTestCase.java (added)
+++ mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0202_entity_time/EntityTimeIQHandlerTestCase.java Sun Feb 27 22:57:35 2011
@@ -0,0 +1,142 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.vysper.xmpp.modules.extension.xep0202_entity_time;
+
+import java.util.regex.Pattern;
+
+import junit.framework.Assert;
+
+import org.apache.vysper.xml.fragment.XMLElement;
+import org.apache.vysper.xml.fragment.XMLSemanticError;
+import org.apache.vysper.xmpp.protocol.NamespaceURIs;
+import org.apache.vysper.xmpp.server.ServerRuntimeContext;
+import org.apache.vysper.xmpp.server.SessionContext;
+import org.apache.vysper.xmpp.stanza.IQStanza;
+import org.apache.vysper.xmpp.stanza.Stanza;
+import org.apache.vysper.xmpp.stanza.StanzaBuilder;
+import org.apache.vysper.xmpp.state.resourcebinding.BindException;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+/**
+ */
+public class EntityTimeIQHandlerTestCase {
+
+    private ServerRuntimeContext serverRuntimeContext = Mockito.mock(ServerRuntimeContext.class);
+    private SessionContext sessionContext = Mockito.mock(SessionContext.class);
+    private IQStanza stanza = (IQStanza) IQStanza.getWrapper(buildStanza());
+    
+    private EntityTimeIQHandler handler = new EntityTimeIQHandler();
+    
+    private Stanza buildStanza() {
+        return buildStanza("iq", NamespaceURIs.JABBER_CLIENT, "time", NamespaceURIs.URN_XMPP_TIME);
+    }
+
+    private Stanza buildStanza(String name, String namespaceUri) {
+        return buildStanza(name, namespaceUri, "time", NamespaceURIs.URN_XMPP_TIME);
+    }
+    
+    private Stanza buildStanza(String name, String namespaceUri, String innerName, String innerNamespaceUri) {
+        return new StanzaBuilder(name, namespaceUri)
+            .addAttribute("type", "get")
+            .addAttribute("id", "1")
+            .startInnerElement(innerName, innerNamespaceUri)
+            .build();
+    }
+    
+    @Test
+    public void nameMustBeIq() {
+        Assert.assertEquals("iq", handler.getName());
+    }
+
+    @Test
+    public void verifyNullStanza() {
+        Assert.assertFalse(handler.verify(null));
+    }
+
+    @Test
+    public void verifyInvalidName() {
+        Assert.assertFalse(handler.verify(buildStanza("dummy", NamespaceURIs.JABBER_CLIENT)));
+    }
+
+    @Test
+    public void verifyInvalidNamespace() {
+        Assert.assertFalse(handler.verify(buildStanza("iq", "dummy")));
+    }
+
+    @Test
+    public void verifyNullNamespace() {
+        Assert.assertFalse(handler.verify(buildStanza("iq", null)));
+    }
+
+    @Test
+    public void verifyNullInnerNamespace() {
+        Assert.assertFalse(handler.verify(buildStanza("iq", NamespaceURIs.JABBER_CLIENT, "time", null)));
+    }
+
+    @Test
+    public void verifyInvalidInnerNamespace() {
+        Assert.assertFalse(handler.verify(buildStanza("iq", NamespaceURIs.JABBER_CLIENT, "time", "dummy")));
+    }
+    
+    @Test
+    public void verifyInvalidInnerName() {
+        Assert.assertFalse(handler.verify(buildStanza("iq", NamespaceURIs.JABBER_CLIENT, "dummy", NamespaceURIs.URN_XMPP_TIME)));
+    }
+
+    @Test
+    public void verifyMissingInnerElement() {
+        Stanza stanza = new StanzaBuilder("iq", NamespaceURIs.JABBER_CLIENT).build();
+        Assert.assertFalse(handler.verify(stanza));
+    }
+    
+    @Test
+    public void verifyValidStanza() {
+        Assert.assertTrue(handler.verify(stanza));
+    }
+
+    @Test
+    public void sessionIsRequired() {
+        Assert.assertTrue(handler.isSessionRequired());
+    }
+
+    @Test
+    public void handleGet() throws BindException, XMLSemanticError {
+        Stanza response = handler.handleGet(stanza, serverRuntimeContext, sessionContext);
+        
+        Assert.assertNotNull(response);
+        Assert.assertEquals("iq", response.getName());
+        Assert.assertEquals(NamespaceURIs.JABBER_CLIENT, response.getNamespaceURI());
+        Assert.assertEquals("result", response.getAttributeValue("type"));
+        Assert.assertEquals("1", response.getAttributeValue("id"));
+        
+        XMLElement time = response.getSingleInnerElementsNamed("time", NamespaceURIs.URN_XMPP_TIME);
+        Assert.assertEquals(2, time.getInnerElements().size());
+        
+        XMLElement tzo = time.getSingleInnerElementsNamed("tzo", NamespaceURIs.URN_XMPP_TIME);
+        
+        Pattern tzPattern = Pattern.compile("[+-]\\d\\d:\\d\\d");
+        Assert.assertTrue(tzPattern.matcher(tzo.getInnerText().getText()).matches());
+        
+        Pattern utcPattern = Pattern.compile("\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z");
+        XMLElement utc = time.getSingleInnerElementsNamed("utc", NamespaceURIs.URN_XMPP_TIME);
+        Assert.assertTrue(utcPattern.matcher(utc.getInnerText().getText()).matches());
+    }
+}

Added: mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0202_entity_time/EntityTimeModuleTestCase.java
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0202_entity_time/EntityTimeModuleTestCase.java?rev=1075174&view=auto
==============================================================================
--- mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0202_entity_time/EntityTimeModuleTestCase.java (added)
+++ mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0202_entity_time/EntityTimeModuleTestCase.java Sun Feb 27 22:57:35 2011
@@ -0,0 +1,99 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.vysper.xmpp.modules.extension.xep0202_entity_time;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.apache.vysper.xmpp.modules.servicediscovery.management.Feature;
+import org.apache.vysper.xmpp.modules.servicediscovery.management.InfoElement;
+import org.apache.vysper.xmpp.modules.servicediscovery.management.InfoRequest;
+import org.apache.vysper.xmpp.modules.servicediscovery.management.ServerInfoRequestListener;
+import org.apache.vysper.xmpp.modules.servicediscovery.management.ServiceDiscoveryRequestException;
+import org.apache.vysper.xmpp.protocol.HandlerDictionary;
+import org.apache.vysper.xmpp.protocol.NamespaceHandlerDictionary;
+import org.apache.vysper.xmpp.protocol.NamespaceURIs;
+import org.junit.Test;
+
+/**
+ */
+public class EntityTimeModuleTestCase {
+
+    private EntityTimeModule module = new EntityTimeModule();
+    
+    @Test
+    public void nameMustBeProvided() {
+        Assert.assertNotNull(module.getName());
+    }
+
+    @Test
+    public void versionMustBeProvided() {
+        Assert.assertNotNull(module.getVersion());
+    }
+    
+    @Test
+    public void getServerInfosFor() throws ServiceDiscoveryRequestException {
+        List<ServerInfoRequestListener> serverInfoRequestListeners = new ArrayList<ServerInfoRequestListener>();
+        
+        module.addServerInfoRequestListeners(serverInfoRequestListeners);
+        
+        Assert.assertEquals(1, serverInfoRequestListeners.size());
+        
+        List<InfoElement> infoElements = serverInfoRequestListeners.get(0).getServerInfosFor(new InfoRequest(null, null, null, null));
+        
+        Assert.assertEquals(2, infoElements.size());
+        assertFeature(infoElements, 0, NamespaceURIs.URN_XMPP_TIME);
+        assertFeature(infoElements, 1, NamespaceURIs.JABBER_IQ_TIME);
+    }
+
+    private void assertFeature(List<InfoElement> infoElements, int index, String feature) {
+        Assert.assertTrue(infoElements.get(index) instanceof Feature);
+        Assert.assertEquals(feature, ((Feature)infoElements.get(index)).getVar());
+    }
+
+    @Test
+    public void getServerInfosForWithNode() throws ServiceDiscoveryRequestException {
+        List<ServerInfoRequestListener> serverInfoRequestListeners = new ArrayList<ServerInfoRequestListener>();
+        module.addServerInfoRequestListeners(serverInfoRequestListeners);
+        Assert.assertEquals(1, serverInfoRequestListeners.size());
+        
+        Assert.assertNull(serverInfoRequestListeners.get(0).getServerInfosFor(new InfoRequest(null, null, "node", null)));
+    }
+    
+    @Test
+    public void addHandlerDictionaries() {
+        List<HandlerDictionary> dictionaries = new ArrayList<HandlerDictionary>();
+        
+        module.addHandlerDictionaries(dictionaries);
+        
+        Assert.assertEquals(2, dictionaries.size());
+
+        assertHandlerNamespace(dictionaries, 0, NamespaceURIs.URN_XMPP_TIME);
+        assertHandlerNamespace(dictionaries, 1, NamespaceURIs.JABBER_IQ_TIME);
+    }
+
+    private void assertHandlerNamespace(List<HandlerDictionary> dictionaries, int index, String feature) {
+        Assert.assertTrue(dictionaries.get(index) instanceof NamespaceHandlerDictionary);
+        NamespaceHandlerDictionary namespaceHandlerDictionary1 = (NamespaceHandlerDictionary) dictionaries.get(index);
+        Assert.assertEquals(feature, namespaceHandlerDictionary1.getNamespaceURI());
+    }
+}

Added: mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0202_entity_time/EntityTimeXEP0090IQHandlerTestCase.java
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0202_entity_time/EntityTimeXEP0090IQHandlerTestCase.java?rev=1075174&view=auto
==============================================================================
--- mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0202_entity_time/EntityTimeXEP0090IQHandlerTestCase.java (added)
+++ mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0202_entity_time/EntityTimeXEP0090IQHandlerTestCase.java Sun Feb 27 22:57:35 2011
@@ -0,0 +1,145 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.vysper.xmpp.modules.extension.xep0202_entity_time;
+
+import java.util.regex.Pattern;
+
+import junit.framework.Assert;
+
+import org.apache.vysper.xml.fragment.XMLElement;
+import org.apache.vysper.xml.fragment.XMLSemanticError;
+import org.apache.vysper.xmpp.protocol.NamespaceURIs;
+import org.apache.vysper.xmpp.server.ServerRuntimeContext;
+import org.apache.vysper.xmpp.server.SessionContext;
+import org.apache.vysper.xmpp.stanza.IQStanza;
+import org.apache.vysper.xmpp.stanza.Stanza;
+import org.apache.vysper.xmpp.stanza.StanzaBuilder;
+import org.apache.vysper.xmpp.state.resourcebinding.BindException;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+/**
+ */
+public class EntityTimeXEP0090IQHandlerTestCase {
+
+    private ServerRuntimeContext serverRuntimeContext = Mockito.mock(ServerRuntimeContext.class);
+    private SessionContext sessionContext = Mockito.mock(SessionContext.class);
+    private IQStanza stanza = (IQStanza) IQStanza.getWrapper(buildStanza());
+    
+    private EntityTimeXEP0090IQHandler handler = new EntityTimeXEP0090IQHandler();
+    
+    private Stanza buildStanza() {
+        return buildStanza("iq", NamespaceURIs.JABBER_CLIENT, "query", NamespaceURIs.JABBER_IQ_TIME);
+    }
+
+    private Stanza buildStanza(String name, String namespaceUri) {
+        return buildStanza(name, namespaceUri, "query", NamespaceURIs.JABBER_IQ_TIME);
+    }
+    
+    private Stanza buildStanza(String name, String namespaceUri, String innerName, String innerNamespaceUri) {
+        return new StanzaBuilder(name, namespaceUri)
+            .addAttribute("type", "get")
+            .addAttribute("id", "1")
+            .startInnerElement(innerName, innerNamespaceUri)
+            .build();
+    }
+    
+    @Test
+    public void nameMustBeIq() {
+        Assert.assertEquals("iq", handler.getName());
+    }
+
+    @Test
+    public void verifyNullStanza() {
+        Assert.assertFalse(handler.verify(null));
+    }
+
+    @Test
+    public void verifyInvalidName() {
+        Assert.assertFalse(handler.verify(buildStanza("dummy", NamespaceURIs.JABBER_CLIENT)));
+    }
+
+    @Test
+    public void verifyInvalidNamespace() {
+        Assert.assertFalse(handler.verify(buildStanza("iq", "dummy")));
+    }
+
+    @Test
+    public void verifyNullNamespace() {
+        Assert.assertFalse(handler.verify(buildStanza("iq", null)));
+    }
+
+    @Test
+    public void verifyNullInnerNamespace() {
+        Assert.assertFalse(handler.verify(buildStanza("iq", NamespaceURIs.JABBER_CLIENT, "query", null)));
+    }
+
+    @Test
+    public void verifyInvalidInnerNamespace() {
+        Assert.assertFalse(handler.verify(buildStanza("iq", NamespaceURIs.JABBER_CLIENT, "query", "dummy")));
+    }
+    
+    @Test
+    public void verifyInvalidInnerName() {
+        Assert.assertFalse(handler.verify(buildStanza("iq", NamespaceURIs.JABBER_CLIENT, "dummy", NamespaceURIs.JABBER_IQ_TIME)));
+    }
+
+    @Test
+    public void verifyMissingInnerElement() {
+        Stanza stanza = new StanzaBuilder("iq", NamespaceURIs.JABBER_CLIENT).build();
+        Assert.assertFalse(handler.verify(stanza));
+    }
+    
+    @Test
+    public void verifyValidStanza() {
+        Assert.assertTrue(handler.verify(stanza));
+    }
+
+    @Test
+    public void sessionIsRequired() {
+        Assert.assertTrue(handler.isSessionRequired());
+    }
+
+    @Test
+    public void handleGet() throws BindException, XMLSemanticError {
+        Stanza response = handler.handleGet(stanza, serverRuntimeContext, sessionContext);
+        
+        Assert.assertNotNull(response);
+        Assert.assertEquals("iq", response.getName());
+        Assert.assertEquals(NamespaceURIs.JABBER_CLIENT, response.getNamespaceURI());
+        Assert.assertEquals("result", response.getAttributeValue("type"));
+        Assert.assertEquals("1", response.getAttributeValue("id"));
+        
+        XMLElement query = response.getSingleInnerElementsNamed("query", NamespaceURIs.JABBER_IQ_TIME);
+        Assert.assertEquals(3, query.getInnerElements().size());
+
+        // 20020910T17:58:35
+        Pattern utcPattern = Pattern.compile("\\d{8}T\\d{2}:\\d{2}:\\d{2}");
+        XMLElement utc = query.getSingleInnerElementsNamed("utc", NamespaceURIs.JABBER_IQ_TIME);
+        Assert.assertTrue(utcPattern.matcher(utc.getInnerText().getText()).matches());
+
+        XMLElement tz = query.getSingleInnerElementsNamed("tz", NamespaceURIs.JABBER_IQ_TIME);
+        Assert.assertNotNull(tz.getInnerText().getText());
+
+        XMLElement display = query.getSingleInnerElementsNamed("display", NamespaceURIs.JABBER_IQ_TIME);
+        Assert.assertNotNull(display.getInnerText().getText());
+
+    }
+}

Modified: mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/protocol/StanzaHandlerLookupTestCase.java
URL: http://svn.apache.org/viewvc/mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/protocol/StanzaHandlerLookupTestCase.java?rev=1075174&r1=1075173&r2=1075174&view=diff
==============================================================================
--- mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/protocol/StanzaHandlerLookupTestCase.java (original)
+++ mina/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/protocol/StanzaHandlerLookupTestCase.java Sun Feb 27 22:57:35 2011
@@ -93,18 +93,6 @@ public class StanzaHandlerLookupTestCase
         return new StanzaHandlerLookup(null);
     }
 
-    public void testLookupCoreHandlerServerNS() {
-        StanzaHandlerLookup stanzaHandlerLookup = initStanzaHandlerLookup();
-        stanzaHandlerLookup.addDictionary(new BaseStreamStanzaDictionary());
-
-        Stanza stanza = new StanzaBuilder("iq", NamespaceURIs.JABBER_SERVER).build();
-        StanzaHandler handler = stanzaHandlerLookup.getHandler(stanza);
-
-        assertNotNull("handler found", handler);
-        assertTrue("iq handler found", handler instanceof IQHandler);
-
-    }
-
     public void testLookupCoreHandlerWrongNamespace() {
         StanzaHandlerLookup stanzaHandlerLookup = initStanzaHandlerLookup();
         stanzaHandlerLookup.addDictionary(new BaseStreamStanzaDictionary());
@@ -112,7 +100,7 @@ public class StanzaHandlerLookupTestCase
         Stanza stanza = new StanzaBuilder("iq", "arbitraryNamespace").build();
         StanzaHandler handler = stanzaHandlerLookup.getHandler(stanza);
 
-        assertTrue("iq handler with arbitrary namespace not found", handler instanceof IQHandler);
+        assertTrue("iq handler with arbitrary namespace not found", handler instanceof ServiceUnavailableStanzaErrorHandler);
     }
 
     public void testLookupPresenceHandler() {