Author: ngn
Date: Wed Jul 28 17:05:57 2010
New Revision: 980126

URL: http://svn.apache.org/viewvc?rev=980126&view=rev
Log:
First stab at integration tests. Merge of VYSPER-221 (by Bogdan Pistol) and my 
code.

Added:
    
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/java/org/apache/vysper/xmpp/extension/xep0124/inttests/
    
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/java/org/apache/vysper/xmpp/extension/xep0124/inttests/BoshIntegrationTest.java
    
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/java/org/apache/vysper/xmpp/extension/xep0124/inttests/IntegrationTestTemplate.java
    
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/java/org/apache/vysper/xmpp/extension/xep0124/inttests/MethodsNotAllowedIntegrationTest.java
    
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/resources/log4j.properties
Modified:
    mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/pom.xml
    
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshHandler.java
    
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshServlet.java
    
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/java/org/apache/vysper/xmpp/extension/xep0124/XMLUtil.java

Modified: mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/pom.xml
URL: 
http://svn.apache.org/viewvc/mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/pom.xml?rev=980126&r1=980125&r2=980126&view=diff
==============================================================================
--- mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/pom.xml (original)
+++ mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/pom.xml Wed Jul 28 
17:05:57 2010
@@ -74,5 +74,20 @@
       <version>3.0</version>
       <scope>test</scope>
     </dependency>
+    
+    <dependency>
+      <groupId>org.apache.httpcomponents</groupId>
+      <artifactId>httpclient</artifactId>
+      <version>4.0.1</version>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>commons-codec</groupId>
+      <artifactId>commons-codec</artifactId>
+      <version>1.3</version>
+      <scope>test</scope>
+    </dependency>
+
   </dependencies>
 </project>

Modified: 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshHandler.java
URL: 
http://svn.apache.org/viewvc/mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshHandler.java?rev=980126&r1=980125&r2=980126&view=diff
==============================================================================
--- 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshHandler.java
 (original)
+++ 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshHandler.java
 Wed Jul 28 17:05:57 2010
@@ -57,6 +57,15 @@ public class BoshHandler {
         sessions = new ConcurrentHashMap<String, BoshBackedSessionContext>();
     }
 
+    
+    /**
+     * Getting for the {...@link ServerRuntimeContext}
+     * @return The current {...@link ServerRuntimeContext}
+     */
+    public ServerRuntimeContext getServerRuntimeContext() {
+        return serverRuntimeContext;
+    }
+
     /**
      * Setter for the {...@link ServerRuntimeContext}
      * @param serverRuntimeContext

Modified: 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshServlet.java
URL: 
http://svn.apache.org/viewvc/mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshServlet.java?rev=980126&r1=980125&r2=980126&view=diff
==============================================================================
--- 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshServlet.java
 (original)
+++ 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/main/java/org/apache/vysper/xmpp/extension/xep0124/BoshServlet.java
 Wed Jul 28 17:05:57 2010
@@ -23,6 +23,7 @@ import java.io.BufferedInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
@@ -61,6 +62,7 @@ public class BoshServlet extends HttpSer
 
     private byte[] flashCrossDomainPolicy;
 
+    // TODO we should be secure by default, allowing all domains by default is 
probably not the best thing
     private String accessControlAllowOrigin = "*";
 
     private String accessControlMaxAge = "86400"; // one day in seconds
@@ -94,15 +96,34 @@ public class BoshServlet extends HttpSer
         bis.close();
         flashCrossDomainPolicy = baos.toByteArray();
     }
+    
+    private byte[] createDefaultFlashCrossDomainPolicy() {
+        String crossDomain = "<?xml version='1.0'?>" 
+            + "<!DOCTYPE cross-domain-policy SYSTEM 
'http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd'>"
+            + "<cross-domain-policy>"
+            + "<allow-access-from domain='" + 
boshHandler.getServerRuntimeContext().getServerEnitity().getDomain() + "' />"
+            + "</cross-domain-policy>"; 
+        try {
+            return crossDomain.getBytes("UTF-8");
+        } catch (UnsupportedEncodingException shouldNotHappen) {
+            throw new RuntimeException(shouldNotHappen);
+        }
+    }
 
     @Override
     protected void doGet(HttpServletRequest req, HttpServletResponse resp) 
throws ServletException, IOException {
         resp.addDateHeader("Date", System.currentTimeMillis());
         resp.addHeader("Server", SERVER_IDENTIFICATION);
-        if (FLASH_CROSS_DOMAIN_POLICY_URI.equals(req.getRequestURI()) && 
flashCrossDomainPolicy != null) {
+        if (FLASH_CROSS_DOMAIN_POLICY_URI.equals(req.getRequestURI())){
             resp.setContentType(XML_CONTENT_TYPE);
-            resp.setContentLength(flashCrossDomainPolicy.length);
-            resp.getOutputStream().write(flashCrossDomainPolicy);
+            if(flashCrossDomainPolicy != null) {
+                resp.setContentLength(flashCrossDomainPolicy.length);
+                resp.getOutputStream().write(flashCrossDomainPolicy);
+            } else {
+                byte[] tempFlashCrossDomainPolicy = 
createDefaultFlashCrossDomainPolicy();
+                resp.setContentLength(tempFlashCrossDomainPolicy.length);
+                resp.getOutputStream().write(tempFlashCrossDomainPolicy);
+            }
         } else {
             resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, 
INFO_GET);
         }

Modified: 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/java/org/apache/vysper/xmpp/extension/xep0124/XMLUtil.java
URL: 
http://svn.apache.org/viewvc/mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/java/org/apache/vysper/xmpp/extension/xep0124/XMLUtil.java?rev=980126&r1=980125&r2=980126&view=diff
==============================================================================
--- 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/java/org/apache/vysper/xmpp/extension/xep0124/XMLUtil.java
 (original)
+++ 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/java/org/apache/vysper/xmpp/extension/xep0124/XMLUtil.java
 Wed Jul 28 17:05:57 2010
@@ -20,6 +20,7 @@
 package org.apache.vysper.xmpp.extension.xep0124;
 
 import java.io.IOException;
+import java.io.InputStream;
 
 import org.apache.mina.core.buffer.IoBuffer;
 import org.apache.vysper.charset.CharsetUtil;
@@ -61,6 +62,23 @@ public class XMLUtil implements ContentH
         reader = new DefaultNonBlockingXMLReader();
         reader.setContentHandler(this);
     }
+    
+    public XMLUtil(InputStream xml) throws IOException {
+        input = IoBuffer.allocate(1024);
+        input.setAutoExpand(true);
+        byte[] buf = new byte[1024];
+        for (;;) {
+            int n = xml.read(buf);
+            if (n == -1) {
+                break;
+            }
+            input.put(buf, 0, n);
+        }
+        input.flip();
+        builderFactory = new StanzaBuilderFactory();
+        reader = new DefaultNonBlockingXMLReader();
+        reader.setContentHandler(this);
+    }
 
     public Stanza parse() throws IOException, SAXException {
         reader.parse(input, CharsetUtil.UTF8_DECODER);

Added: 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/java/org/apache/vysper/xmpp/extension/xep0124/inttests/BoshIntegrationTest.java
URL: 
http://svn.apache.org/viewvc/mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/java/org/apache/vysper/xmpp/extension/xep0124/inttests/BoshIntegrationTest.java?rev=980126&view=auto
==============================================================================
--- 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/java/org/apache/vysper/xmpp/extension/xep0124/inttests/BoshIntegrationTest.java
 (added)
+++ 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/java/org/apache/vysper/xmpp/extension/xep0124/inttests/BoshIntegrationTest.java
 Wed Jul 28 17:05:57 2010
@@ -0,0 +1,154 @@
+/*
+ *  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.extension.xep0124.inttests;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.vysper.xml.fragment.XMLElement;
+import org.apache.vysper.xmpp.protocol.NamespaceURIs;
+import org.apache.vysper.xmpp.stanza.Stanza;
+import org.junit.Test;
+import org.xml.sax.SAXException;
+
+/**
+ * Integration tests with Apache HttpComponents Client
+ * 
+ * @author The Apache MINA Project ([email protected])
+ */
+public class BoshIntegrationTest extends IntegrationTestTemplate {
+
+    @Test
+    public void test() throws ClientProtocolException, IOException, 
IllegalStateException, SAXException {
+        // initial request
+        Stanza boshResponse = sendRequest("<body rid='100' 
xmlns='http://jabber.org/protocol/httpbind' to='vysper.org' xml:lang='en' 
wait='60' hold='1' ver='1.9' xmpp:version='1.0' xmlns:xmpp='urn:xmpp:xbosh'/>");
+        String sid = boshResponse.getAttributeValue("sid");
+        assertNotNull(sid);
+        assertNotNull(boshResponse.getAttributeValue("requests"));
+        assertNotNull(boshResponse.getAttributeValue("inactivity"));
+        assertNotNull(boshResponse.getAttributeValue("hold"));
+        assertNotNull(boshResponse.getAttributeValue("wait"));
+        assertNotNull(boshResponse.getAttributeValue("polling"));
+        assertEquals("vysper.org", boshResponse.getAttributeValue("from"));
+        assertEquals("1.9", boshResponse.getAttributeValue("ver"));
+        assertEquals(1, boshResponse.getInnerElements().size());
+        assertEquals("features", 
boshResponse.getInnerElements().get(0).getName());
+        assertEquals(NamespaceURIs.HTTP_ETHERX_JABBER_ORG_STREAMS, 
boshResponse.getInnerElements().get(0)
+                .getNamespaceURI());
+        
assertFalse(boshResponse.getInnerElements().get(0).getInnerElements().isEmpty());
+        XMLElement mechanisms = null;
+        for (XMLElement element : 
boshResponse.getInnerElements().get(0).getInnerElements()) {
+            if (element.getName().equals("mechanisms")
+                    && 
element.getNamespaceURI().equals(NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_SASL))
 {
+                mechanisms = element;
+                break;
+            }
+        }
+        assertNotNull(mechanisms);
+        boolean isPlain = false;
+        for (XMLElement element : mechanisms.getInnerElements()) {
+            assertEquals("mechanism", element.getName());
+            if (element.getInnerText().getText().equals("PLAIN")) {
+                isPlain = true;
+            }
+        }
+        assertTrue("Only plain auth supported by test", isPlain);
+
+        // SASL request
+        String auth = getPlainAuth("user1", "password1");
+        boshResponse = sendRequest("<body rid='101' 
xmlns='http://jabber.org/protocol/httpbind' sid='" + sid
+                + "'><auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' 
mechanism='PLAIN'>" + auth + "</auth></body>");
+        assertEquals(1, boshResponse.getInnerElements().size());
+        assertEquals("success", 
boshResponse.getInnerElements().get(0).getName());
+        assertEquals(NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_SASL, 
boshResponse.getInnerElements().get(0)
+                .getNamespaceURI());
+
+        // connection restart
+        boshResponse = sendRequest("<body rid='102' 
xmlns='http://jabber.org/protocol/httpbind' sid='" + sid
+                + "' to='vysper.org' xml:lang='en' xmpp:restart='true' 
xmlns:xmpp='urn:xmpp:xbosh'/>");
+        assertEquals(1, boshResponse.getInnerElements().size());
+        assertEquals("features", 
boshResponse.getInnerElements().get(0).getName());
+        assertEquals(NamespaceURIs.HTTP_ETHERX_JABBER_ORG_STREAMS, 
boshResponse.getInnerElements().get(0)
+                .getNamespaceURI());
+        
assertFalse(boshResponse.getInnerElements().get(0).getInnerElements().isEmpty());
+        boolean isBind = false;
+        for (XMLElement element : 
boshResponse.getInnerElements().get(0).getInnerElements()) {
+            if (element.getName().equals("bind")
+                    && 
element.getNamespaceURI().equals(NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_BIND))
 {
+                isBind = true;
+                break;
+            }
+        }
+
+        assertTrue("Cannot test further because the 'bind' feature is not 
present after connection restart.", isBind);
+
+        // resource binding
+        // note that Vysper will ignore the resource from the client and will 
generate its own resource (this is allowed by the XMPP specification)
+        boshResponse = sendRequest("<body rid='103' 
xmlns='http://jabber.org/protocol/httpbind' sid='"
+                + sid
+                + "'><iq type='set' id='200' xmlns='jabber:client'><bind 
xmlns='urn:ietf:params:xml:ns:xmpp-bind'><resource>"
+                + "HttpClient</resource></bind></iq></body>");
+        assertEquals(1, boshResponse.getInnerElements().size());
+        XMLElement iq = boshResponse.getInnerElements().get(0);
+        assertEquals("iq", iq.getName());
+        assertEquals(NamespaceURIs.JABBER_CLIENT, iq.getNamespaceURI());
+        assertEquals("result", iq.getAttributeValue("type"));
+        assertEquals("200", iq.getAttributeValue("id"));
+        assertEquals(1, iq.getInnerElements().size());
+        XMLElement bind = iq.getInnerElements().get(0);
+        assertEquals("bind", bind.getName());
+        assertEquals(NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_BIND, 
bind.getNamespaceURI());
+        assertEquals(1, bind.getInnerElements().size());
+        assertEquals("jid", bind.getInnerElements().get(0).getName());
+        String jid = bind.getInnerElements().get(0).getInnerText().getText();
+        assertNotNull(jid);
+        assertTrue(jid.matches("[email protected]/.+"));
+        
+        System.out.println("JID " + jid + " is connected to the Vysper 
server");
+    }
+
+    private String getPlainAuth(String user, String pass) {
+        List<Byte> list = new ArrayList<Byte>();
+        list.add((byte) 0);
+        addAll(list, user);
+        list.add((byte) 0);
+        addAll(list, pass);
+        byte[] array = new byte[list.size()];
+        for (int i = 0; i < list.size(); i++) {
+            array[i] = list.get(i);
+        }
+        return new String(Base64.encodeBase64(array));
+    }
+
+    private void addAll(List<Byte> list, String s) {
+        for (byte b : s.getBytes()) {
+            list.add(b);
+        }
+    }
+
+}

Added: 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/java/org/apache/vysper/xmpp/extension/xep0124/inttests/IntegrationTestTemplate.java
URL: 
http://svn.apache.org/viewvc/mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/java/org/apache/vysper/xmpp/extension/xep0124/inttests/IntegrationTestTemplate.java?rev=980126&view=auto
==============================================================================
--- 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/java/org/apache/vysper/xmpp/extension/xep0124/inttests/IntegrationTestTemplate.java
 (added)
+++ 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/java/org/apache/vysper/xmpp/extension/xep0124/inttests/IntegrationTestTemplate.java
 Wed Jul 28 17:05:57 2010
@@ -0,0 +1,123 @@
+/*
+ *  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.extension.xep0124.inttests;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNotNull;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.ServerSocket;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.vysper.storage.StorageProviderRegistry;
+import org.apache.vysper.storage.inmemory.MemoryStorageProviderRegistry;
+import org.apache.vysper.xmpp.addressing.EntityImpl;
+import org.apache.vysper.xmpp.authorization.AccountManagement;
+import org.apache.vysper.xmpp.extension.xep0124.BoshEndpoint;
+import org.apache.vysper.xmpp.extension.xep0124.XMLUtil;
+import org.apache.vysper.xmpp.protocol.NamespaceURIs;
+import org.apache.vysper.xmpp.server.XMPPServer;
+import org.apache.vysper.xmpp.stanza.Stanza;
+import org.junit.After;
+import org.junit.Before;
+import org.xml.sax.SAXException;
+
+
+public class IntegrationTestTemplate {
+
+    protected HttpClient httpclient = new DefaultHttpClient();
+    protected XMPPServer server;
+    
+    protected int serverPort;
+    
+    private int findFreePort() throws IOException {
+        ServerSocket ss = null;
+        try {
+            ss = new ServerSocket(0);
+            ss.setReuseAddress(true);
+            return ss.getLocalPort();
+        } finally {
+            if(ss != null) {
+                ss.close();
+            }
+        }
+    }
+    
+    protected String getServerUrl() {
+        return "http://localhost:"; + serverPort + "/";
+    }
+    
+    protected Stanza sendRequest(String request) throws 
ClientProtocolException, IOException, IllegalStateException, SAXException {
+        HttpPost post = new HttpPost(getServerUrl());
+        HttpEntity entity = new StringEntity(request);
+        post.setEntity(entity);
+        HttpResponse response = httpclient.execute(post);
+        
+        assertNotNull(response.getEntity());
+        Stanza boshResponse = new 
XMLUtil(response.getEntity().getContent()).parse();
+
+        assertEquals("body", boshResponse.getName());
+        assertEquals(NamespaceURIs.XEP0124_BOSH, 
boshResponse.getNamespaceURI());
+        return boshResponse;
+    }
+
+    
+    @Before
+    public void startServer() throws Exception {
+        StorageProviderRegistry providerRegistry = new 
MemoryStorageProviderRegistry();
+
+        final AccountManagement accountManagement = (AccountManagement) 
providerRegistry
+                .retrieve(AccountManagement.class);
+
+        if 
(!accountManagement.verifyAccountExists(EntityImpl.parse("[email protected]"))) {
+            accountManagement.addUser("[email protected]", "password1");
+        }
+        
+        server = new XMPPServer("vysper.org");
+        server.setStorageProviderRegistry(providerRegistry);
+
+        server.setTLSCertificateInfo(new 
File("src/test/resources/bogus_mina_tls.cert"), "boguspw");
+        
+        BoshEndpoint boshEndpoint = new BoshEndpoint();
+        int port = findFreePort();
+        
+        boshEndpoint.setPort(port);
+        server.addEndpoint(boshEndpoint);
+        
+        server.start();
+        System.out.println("Vysper BOSH server running on port " + port);
+
+        serverPort = port;
+    }
+    
+    @After
+    public void tearDown() throws Exception {
+        httpclient.getConnectionManager().shutdown();
+        server.stop();
+    }
+
+}

Added: 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/java/org/apache/vysper/xmpp/extension/xep0124/inttests/MethodsNotAllowedIntegrationTest.java
URL: 
http://svn.apache.org/viewvc/mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/java/org/apache/vysper/xmpp/extension/xep0124/inttests/MethodsNotAllowedIntegrationTest.java?rev=980126&view=auto
==============================================================================
--- 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/java/org/apache/vysper/xmpp/extension/xep0124/inttests/MethodsNotAllowedIntegrationTest.java
 (added)
+++ 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/java/org/apache/vysper/xmpp/extension/xep0124/inttests/MethodsNotAllowedIntegrationTest.java
 Wed Jul 28 17:05:57 2010
@@ -0,0 +1,64 @@
+/*
+ *  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.extension.xep0124.inttests;
+
+import junit.framework.Assert;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPut;
+import org.junit.Test;
+
+
+
+public class MethodsNotAllowedIntegrationTest extends IntegrationTestTemplate {
+
+    
+    
+    @Test
+    public void doNotAllowGet() throws Exception {
+        HttpResponse response = httpclient.execute(new 
HttpGet(getServerUrl()));
+
+        Assert.assertEquals(405, response.getStatusLine().getStatusCode());
+    }
+
+    @Test
+    public void allowGettingCrossdomain() throws Exception {
+        HttpResponse response = httpclient.execute(new HttpGet(getServerUrl() 
+ "crossdomain.xml"));
+
+        Assert.assertEquals(200, response.getStatusLine().getStatusCode());
+    }
+
+    
+    @Test
+    public void doNotAllowPut() throws Exception {
+        HttpResponse response = httpclient.execute(new 
HttpPut(getServerUrl()));
+
+        Assert.assertEquals(405, response.getStatusLine().getStatusCode());
+    }
+
+    @Test
+    public void doNotAllowDelete() throws Exception {
+        HttpResponse response = httpclient.execute(new 
HttpDelete(getServerUrl()));
+
+        Assert.assertEquals(405, response.getStatusLine().getStatusCode());
+    }
+}

Added: 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/resources/log4j.properties
URL: 
http://svn.apache.org/viewvc/mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/resources/log4j.properties?rev=980126&view=auto
==============================================================================
--- 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/resources/log4j.properties
 (added)
+++ 
mina/vysper/trunk/server/extensions/xep0124-xep0206-bosh/src/test/resources/log4j.properties
 Wed Jul 28 17:05:57 2010
@@ -0,0 +1,28 @@
+# 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.
+
+log4j.rootLogger=INFO, C
+
+log4j.logger.org.apache.vysper.mina.XmppIoHandlerAdapter=WARN,C
+log4j.logger.org.apache.mina.filter.executor.ExecutorFilter=WARN,C
+log4j.logger.org.apache.http=DEBUG
+
+
+log4j.appender.C=org.apache.log4j.ConsoleAppender 
+log4j.appender.C.layout=org.apache.log4j.PatternLayout 
+log4j.appender.C.layout.ConversionPattern=%m%n
+


Reply via email to