]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fixed test which had never passed
authorArtur Signell <artur@vaadin.com>
Wed, 22 May 2013 08:19:22 +0000 (11:19 +0300)
committerVaadin Code Review <review@vaadin.com>
Wed, 22 May 2013 15:12:56 +0000 (15:12 +0000)
Change-Id: Ice20a168dd8c0dc14f8e4600f24e2b788cb38bc4

server/tests/src/com/vaadin/server/MockServletConfig.java [new file with mode: 0644]
server/tests/src/com/vaadin/server/MockServletContext.java [new file with mode: 0644]
server/tests/src/com/vaadin/server/VaadinSessionTest.java

diff --git a/server/tests/src/com/vaadin/server/MockServletConfig.java b/server/tests/src/com/vaadin/server/MockServletConfig.java
new file mode 100644 (file)
index 0000000..b1e046c
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2000-2013 Vaadin Ltd.
+ * 
+ * Licensed 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 com.vaadin.server;
+
+import java.util.Collections;
+import java.util.Enumeration;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+
+/**
+ * 
+ * @since
+ * @author Vaadin Ltd
+ */
+public class MockServletConfig implements ServletConfig {
+
+    private ServletContext context = new MockServletContext();
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletConfig#getServletName()
+     */
+    @Override
+    public String getServletName() {
+        return "Mock Servlet";
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletConfig#getServletContext()
+     */
+    @Override
+    public ServletContext getServletContext() {
+        return context;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletConfig#getInitParameter(java.lang.String)
+     */
+    @Override
+    public String getInitParameter(String name) {
+        return null;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletConfig#getInitParameterNames()
+     */
+    @Override
+    public Enumeration getInitParameterNames() {
+        return Collections.enumeration(Collections.EMPTY_LIST);
+    }
+
+}
diff --git a/server/tests/src/com/vaadin/server/MockServletContext.java b/server/tests/src/com/vaadin/server/MockServletContext.java
new file mode 100644 (file)
index 0000000..40d7919
--- /dev/null
@@ -0,0 +1,304 @@
+/*
+ * Copyright 2000-2013 Vaadin Ltd.
+ * 
+ * Licensed 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 com.vaadin.server;
+
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.Set;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.Servlet;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+
+/**
+ * 
+ * @since
+ * @author Vaadin Ltd
+ */
+public class MockServletContext implements ServletContext {
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletContext#getContext(java.lang.String)
+     */
+    @Override
+    public ServletContext getContext(String uripath) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletContext#getMajorVersion()
+     */
+    @Override
+    public int getMajorVersion() {
+        return 2;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletContext#getMinorVersion()
+     */
+    @Override
+    public int getMinorVersion() {
+        return 4;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletContext#getMimeType(java.lang.String)
+     */
+    @Override
+    public String getMimeType(String file) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletContext#getResourcePaths(java.lang.String)
+     */
+    @Override
+    public Set getResourcePaths(String path) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletContext#getResource(java.lang.String)
+     */
+    @Override
+    public URL getResource(String path) throws MalformedURLException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletContext#getResourceAsStream(java.lang.String)
+     */
+    @Override
+    public InputStream getResourceAsStream(String path) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletContext#getRequestDispatcher(java.lang.String)
+     */
+    @Override
+    public RequestDispatcher getRequestDispatcher(String path) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletContext#getNamedDispatcher(java.lang.String)
+     */
+    @Override
+    public RequestDispatcher getNamedDispatcher(String name) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletContext#getServlet(java.lang.String)
+     */
+    @Override
+    public Servlet getServlet(String name) throws ServletException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletContext#getServlets()
+     */
+    @Override
+    public Enumeration getServlets() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletContext#getServletNames()
+     */
+    @Override
+    public Enumeration getServletNames() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletContext#log(java.lang.String)
+     */
+    @Override
+    public void log(String msg) {
+        // TODO Auto-generated method stub
+
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletContext#log(java.lang.Exception,
+     * java.lang.String)
+     */
+    @Override
+    public void log(Exception exception, String msg) {
+        // TODO Auto-generated method stub
+
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletContext#log(java.lang.String,
+     * java.lang.Throwable)
+     */
+    @Override
+    public void log(String message, Throwable throwable) {
+        // TODO Auto-generated method stub
+
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletContext#getRealPath(java.lang.String)
+     */
+    @Override
+    public String getRealPath(String path) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletContext#getServerInfo()
+     */
+    @Override
+    public String getServerInfo() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletContext#getInitParameter(java.lang.String)
+     */
+    @Override
+    public String getInitParameter(String name) {
+        return null;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletContext#getInitParameterNames()
+     */
+    @Override
+    public Enumeration getInitParameterNames() {
+        return Collections.enumeration(Collections.EMPTY_LIST);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletContext#getAttribute(java.lang.String)
+     */
+    @Override
+    public Object getAttribute(String name) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletContext#getAttributeNames()
+     */
+    @Override
+    public Enumeration getAttributeNames() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletContext#setAttribute(java.lang.String,
+     * java.lang.Object)
+     */
+    @Override
+    public void setAttribute(String name, Object object) {
+        // TODO Auto-generated method stub
+
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletContext#removeAttribute(java.lang.String)
+     */
+    @Override
+    public void removeAttribute(String name) {
+        // TODO Auto-generated method stub
+
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletContext#getServletContextName()
+     */
+    @Override
+    public String getServletContextName() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+}
index 61a1581a6fbf7195ff5038ec2b1fcd565bd39613..68f198410cac97c739177c1747720905f33360ef 100644 (file)
@@ -18,6 +18,7 @@ package com.vaadin.server;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.locks.ReentrantLock;
 
+import javax.servlet.ServletConfig;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
 import javax.servlet.http.HttpSessionBindingEvent;
@@ -30,7 +31,6 @@ import org.junit.Test;
 
 import com.vaadin.server.ClientConnector.DetachEvent;
 import com.vaadin.server.ClientConnector.DetachListener;
-import com.vaadin.tests.util.MockDeploymentConfiguration;
 import com.vaadin.ui.UI;
 import com.vaadin.util.CurrentInstance;
 
@@ -39,6 +39,7 @@ public class VaadinSessionTest {
     private VaadinSession session;
     private VaadinServlet mockServlet;
     private VaadinServletService mockService;
+    private ServletConfig mockServletConfig;
     private HttpSession mockHttpSession;
     private WrappedSession mockWrappedSession;
     private VaadinServletRequest vaadinRequest;
@@ -46,24 +47,22 @@ public class VaadinSessionTest {
 
     @Before
     public void setup() throws Exception {
-        mockServlet = new VaadinServlet() {
-            @Override
-            public String getServletName() {
-                return "mockServlet";
-            };
-        };
-
-        mockService = new VaadinServletService(mockServlet,
-                new MockDeploymentConfiguration());
-        mockService.init();
+        mockServletConfig = new MockServletConfig();
+        mockServlet = new VaadinServlet();
+        mockServlet.init(mockServletConfig);
+        mockService = mockServlet.getService();
 
         mockHttpSession = EasyMock.createMock(HttpSession.class);
         mockWrappedSession = new WrappedHttpSession(mockHttpSession) {
             final ReentrantLock lock = new ReentrantLock();
+            {
+                lock.lock();
+            }
 
             @Override
             public Object getAttribute(String name) {
-                if ("mockServlet.lock".equals(name)) {
+                String lockAttribute = mockService.getServiceName() + ".lock";
+                if (lockAttribute.equals(name)) {
                     return lock;
                 }
                 return super.getAttribute(name);