Author: markt
Date: Fri Mar 15 20:41:58 2013
New Revision: 1457105

URL: http://svn.apache.org/r1457105
Log:
Add a test that confirms BZ 54631 is not an issue.
An added bonus was that this test found the close process was not correct. That 
has now been fixed.

Added:
    
tomcat/trunk/test/org/apache/tomcat/websocket/pojo/TestPojoMethodMapping.java   
(with props)

Added: 
tomcat/trunk/test/org/apache/tomcat/websocket/pojo/TestPojoMethodMapping.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/websocket/pojo/TestPojoMethodMapping.java?rev=1457105&view=auto
==============================================================================
--- 
tomcat/trunk/test/org/apache/tomcat/websocket/pojo/TestPojoMethodMapping.java 
(added)
+++ 
tomcat/trunk/test/org/apache/tomcat/websocket/pojo/TestPojoMethodMapping.java 
Fri Mar 15 20:41:58 2013
@@ -0,0 +1,152 @@
+/*
+ *  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.tomcat.websocket.pojo;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.websocket.ClientEndpoint;
+import javax.websocket.ContainerProvider;
+import javax.websocket.OnClose;
+import javax.websocket.OnMessage;
+import javax.websocket.OnOpen;
+import javax.websocket.Session;
+import javax.websocket.WebSocketContainer;
+import javax.websocket.server.PathParam;
+import javax.websocket.server.ServerEndpoint;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.catalina.Context;
+import org.apache.catalina.startup.Tomcat;
+import org.apache.catalina.startup.TomcatBaseTest;
+import org.apache.tomcat.websocket.pojo.Util.ServerConfigListener;
+import org.apache.tomcat.websocket.pojo.Util.SingletonConfigurator;
+
+public class TestPojoMethodMapping extends TomcatBaseTest {
+
+    private static final String PARAM_ONE = "abcde";
+    private static final String PARAM_TWO = "12345";
+    private static final String PARAM_THREE = "true";
+
+    @Test
+    public void test() throws Exception {
+
+        // Set up utility classes
+        Server server = new Server();
+        SingletonConfigurator.setInstance(server);
+        ServerConfigListener.setPojoClazz(Server.class);
+
+        Tomcat tomcat = getTomcatInstance();
+        // Must have a real docBase - just use temp
+        Context ctx =
+            tomcat.addContext("", System.getProperty("java.io.tmpdir"));
+        ctx.addApplicationListener(ServerConfigListener.class.getName());
+
+        WebSocketContainer wsContainer =
+                ContainerProvider.getWebSocketContainer();
+
+
+        tomcat.start();
+
+        Client client = new Client();
+        URI uri = new URI("http://localhost:"; + getPort() + "/" + PARAM_ONE +
+                "/" + PARAM_TWO + "/" + PARAM_THREE);
+
+        Session session = wsContainer.connectToServer(client, uri);
+        session.getBasicRemote().sendText("NO-OP");
+        session.close();
+
+        // Give server 5s to close
+        int count = 0;
+        while (count < 50) {
+            if (server.isClosed()) {
+                break;
+            }
+            count++;
+            Thread.sleep(100);
+        }
+        if (count == 50) {
+            Assert.fail("Server did not process an onClose event within 5 " +
+                    "seconds of the client sending a close message");
+        }
+
+        // Check no errors
+        List<String> errors = server.getErrors();
+        for (String error : errors) {
+            System.err.println(error);
+        }
+        Assert.assertEquals("Found errors", 0, errors.size());
+    }
+
+
+    @ClientEndpoint
+    public static final class Client {
+    }
+
+
+    @ServerEndpoint(value="/{one}/{two}/{three}",
+            configurator=SingletonConfigurator.class)
+    public static final class Server {
+
+        private final List<String> errors = new ArrayList<>();
+        private volatile boolean closed;
+
+        @OnOpen
+        public void onOpen(@PathParam("one") String p1, @PathParam("two")int 
p2,
+                @PathParam("three")boolean p3) {
+            checkParams("onOpen", p1, p2, p3);
+        }
+
+        @OnMessage
+        public void onMessage(@SuppressWarnings("unused") String msg,
+                @PathParam("one") String p1, @PathParam("two")int p2,
+                @PathParam("three")boolean p3) {
+            checkParams("onMessage", p1, p2, p3);
+        }
+
+        @OnClose
+        public void onClose(@PathParam("one") String p1,
+                @PathParam("two")int p2, @PathParam("three")boolean p3) {
+            checkParams("onClose", p1, p2, p3);
+            closed = true;
+        }
+
+        public List<String> getErrors() {
+            return errors;
+        }
+
+        public boolean isClosed() {
+            return closed;
+        }
+
+        private void checkParams(String method, String p1, int p2, boolean p3) 
{
+            checkParam(method, PARAM_ONE, p1);
+            checkParam(method, PARAM_TWO, Integer.toString(p2));
+            checkParam(method, PARAM_THREE, Boolean.toString(p3));
+        }
+
+        private void checkParam(String method, String expected, String actual) 
{
+            if (!expected.equals(actual)) {
+                errors.add("Method [" + method + "]. Expected [" + expected +
+                        "] was + [" + actual + "]");
+            }
+        }
+    }
+}

Propchange: 
tomcat/trunk/test/org/apache/tomcat/websocket/pojo/TestPojoMethodMapping.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to