summaryrefslogtreecommitdiffstats
path: root/tests/server-side/com/vaadin/server
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2012-08-30 15:27:50 +0300
committerArtur Signell <artur@vaadin.com>2012-08-30 16:08:05 +0300
commit876182aaa34682503338a4dcdd119b3ebc256f97 (patch)
tree8e54b81cfcbecb5c54b725ca3a612b6e18e228cd /tests/server-side/com/vaadin/server
parent691220a5b24370d56f7c15d5a05c57a6c76dcb83 (diff)
downloadvaadin-framework-876182aaa34682503338a4dcdd119b3ebc256f97.tar.gz
vaadin-framework-876182aaa34682503338a4dcdd119b3ebc256f97.zip
Moved server tests from tests/server-side to server/tests/src (#9299)
Diffstat (limited to 'tests/server-side/com/vaadin/server')
-rw-r--r--tests/server-side/com/vaadin/server/JSONSerializerTest.java140
-rw-r--r--tests/server-side/com/vaadin/server/TestAbstractApplicationServletStaticFilesLocation.java205
2 files changed, 0 insertions, 345 deletions
diff --git a/tests/server-side/com/vaadin/server/JSONSerializerTest.java b/tests/server-side/com/vaadin/server/JSONSerializerTest.java
deleted file mode 100644
index 05139e6f1a..0000000000
--- a/tests/server-side/com/vaadin/server/JSONSerializerTest.java
+++ /dev/null
@@ -1,140 +0,0 @@
-package com.vaadin.server;
-
-/*
- * Copyright 2011 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.
- */
-import java.lang.reflect.Type;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-import com.vaadin.server.JsonCodec.BeanProperty;
-import com.vaadin.shared.ui.splitpanel.AbstractSplitPanelState;
-
-/**
- * Tests for {@link JsonCodec}
- *
- * @author Vaadin Ltd
- * @since 7.0
- *
- */
-public class JSONSerializerTest extends TestCase {
- HashMap<String, AbstractSplitPanelState> stringToStateMap;
- HashMap<AbstractSplitPanelState, String> stateToStringMap;
-
- public void testStringToBeanMapSerialization() throws Exception {
- Type mapType = getClass().getDeclaredField("stringToStateMap")
- .getGenericType();
- stringToStateMap = new HashMap<String, AbstractSplitPanelState>();
- AbstractSplitPanelState s = new AbstractSplitPanelState();
- AbstractSplitPanelState s2 = new AbstractSplitPanelState();
- s.setCaption("State 1");
- s.setId("foo");
- s2.setCaption("State 2");
- s2.setId("bar");
- stringToStateMap.put("string - state 1", s);
- stringToStateMap.put("String - state 2", s2);
-
- Object encodedMap = JsonCodec.encode(stringToStateMap, null, mapType,
- null).getEncodedValue();
-
- ensureDecodedCorrectly(stringToStateMap, encodedMap, mapType);
- }
-
- public void testBeanToStringMapSerialization() throws Exception {
- Type mapType = getClass().getDeclaredField("stateToStringMap")
- .getGenericType();
- stateToStringMap = new HashMap<AbstractSplitPanelState, String>();
- AbstractSplitPanelState s = new AbstractSplitPanelState();
- AbstractSplitPanelState s2 = new AbstractSplitPanelState();
- s.setCaption("State 1");
- s2.setCaption("State 2");
- stateToStringMap.put(s, "string - state 1");
- stateToStringMap.put(s2, "String - state 2");
-
- Object encodedMap = JsonCodec.encode(stateToStringMap, null, mapType,
- null).getEncodedValue();
-
- ensureDecodedCorrectly(stateToStringMap, encodedMap, mapType);
- }
-
- private void ensureDecodedCorrectly(Object original, Object encoded,
- Type type) throws Exception {
- Object serverSideDecoded = JsonCodec.decodeInternalOrCustomType(type,
- encoded, null);
- assertTrue("Server decoded", equals(original, serverSideDecoded));
-
- }
-
- private boolean equals(Object o1, Object o2) throws Exception {
- if (o1 == null) {
- return (o2 == null);
- }
- if (o2 == null) {
- return false;
- }
-
- if (o1 instanceof Map) {
- if (!(o2 instanceof Map)) {
- return false;
- }
- return equalsMap((Map) o1, (Map) o2);
- }
-
- if (o1.getClass() != o2.getClass()) {
- return false;
- }
-
- if (o1 instanceof Collection || o1 instanceof Number
- || o1 instanceof String) {
- return o1.equals(o2);
- }
-
- return equalsBean(o1, o2);
- }
-
- private boolean equalsBean(Object o1, Object o2) throws Exception {
- for (BeanProperty property : JsonCodec.getProperties(o1.getClass())) {
- Object c1 = property.getValue(o1);
- Object c2 = property.getValue(o2);
- if (!equals(c1, c2)) {
- return false;
- }
- }
- return true;
- }
-
- private boolean equalsMap(Map o1, Map o2) throws Exception {
- for (Object key1 : o1.keySet()) {
- Object key2 = key1;
- if (!(o2.containsKey(key2))) {
- // Try to fins a key that is equal
- for (Object k2 : o2.keySet()) {
- if (equals(key1, k2)) {
- key2 = k2;
- break;
- }
- }
- }
- if (!equals(o1.get(key1), o2.get(key2))) {
- return false;
- }
-
- }
- return true;
- }
-}
diff --git a/tests/server-side/com/vaadin/server/TestAbstractApplicationServletStaticFilesLocation.java b/tests/server-side/com/vaadin/server/TestAbstractApplicationServletStaticFilesLocation.java
deleted file mode 100644
index df16e98bba..0000000000
--- a/tests/server-side/com/vaadin/server/TestAbstractApplicationServletStaticFilesLocation.java
+++ /dev/null
@@ -1,205 +0,0 @@
-package com.vaadin.server;
-
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Enumeration;
-import java.util.Properties;
-
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-
-import com.vaadin.server.AbstractApplicationServlet;
-import com.vaadin.server.ApplicationServlet;
-
-import junit.framework.TestCase;
-
-public class TestAbstractApplicationServletStaticFilesLocation extends TestCase {
-
- ApplicationServlet servlet;
-
- private Method getStaticFilesLocationMethod;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
-
- servlet = new ApplicationServlet();
-
- // Workaround to avoid calling init and creating servlet config
- Field f = AbstractApplicationServlet.class
- .getDeclaredField("applicationProperties");
- f.setAccessible(true);
- f.set(servlet, new Properties());
-
- getStaticFilesLocationMethod = AbstractApplicationServlet.class
- .getDeclaredMethod(
- "getStaticFilesLocation",
- new Class[] { javax.servlet.http.HttpServletRequest.class });
- getStaticFilesLocationMethod.setAccessible(true);
-
- }
-
- public class DummyServletConfig implements ServletConfig {
-
- // public DummyServletConfig(Map<String,String> initParameters, )
- @Override
- public String getInitParameter(String name) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public Enumeration<Object> getInitParameterNames() {
- return new Enumeration<Object>() {
-
- @Override
- public boolean hasMoreElements() {
- return false;
- }
-
- @Override
- public Object nextElement() {
- return null;
- }
- };
- }
-
- @Override
- public ServletContext getServletContext() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public String getServletName() {
- // TODO Auto-generated method stub
- return null;
- }
-
- }
-
- public void testWidgetSetLocation() throws Exception {
- String location;
-
- /* SERVLETS */
- // http://dummy.host:8080/contextpath/servlet
- // should return /contextpath
- location = testLocation("http://dummy.host:8080", "/contextpath",
- "/servlet", "");
- assertEquals("/contextpath", location);
-
- // http://dummy.host:8080/servlet
- // should return ""
- location = testLocation("http://dummy.host:8080", "", "/servlet", "");
- assertEquals("", location);
-
- // http://dummy.host/contextpath/servlet/extra/stuff
- // should return /contextpath
- location = testLocation("http://dummy.host", "/contextpath",
- "/servlet", "/extra/stuff");
- assertEquals("/contextpath", location);
-
- // http://dummy.host/context/path/servlet/extra/stuff
- // should return /context/path
- location = testLocation("http://dummy.host", "/context/path",
- "/servlet", "/extra/stuff");
- assertEquals("/context/path", location);
-
- /* Include requests */
- location = testIncludedLocation("http://my.portlet.server", "/user",
- "/tmpservletlocation1", "");
- assertEquals("Wrong widgetset location", "/user", location);
-
- }
-
- private String testLocation(String base, String contextPath,
- String servletPath, String pathInfo) throws Exception {
-
- HttpServletRequest request = createNonIncludeRequest(base, contextPath,
- servletPath, pathInfo);
- // Set request into replay mode
- replay(request);
-
- String location = (String) getStaticFilesLocationMethod.invoke(servlet,
- request);
- return location;
- }
-
- private String testIncludedLocation(String base, String portletContextPath,
- String servletPath, String pathInfo) throws Exception {
-
- HttpServletRequest request = createIncludeRequest(base,
- portletContextPath, servletPath, pathInfo);
- // Set request into replay mode
- replay(request);
-
- String location = (String) getStaticFilesLocationMethod.invoke(servlet,
- request);
- return location;
- }
-
- private HttpServletRequest createIncludeRequest(String base,
- String realContextPath, String realServletPath, String pathInfo)
- throws Exception {
- HttpServletRequest request = createRequest(base, "", "", pathInfo);
- expect(request.getAttribute("javax.servlet.include.context_path"))
- .andReturn(realContextPath).anyTimes();
- expect(request.getAttribute("javax.servlet.include.servlet_path"))
- .andReturn(realServletPath).anyTimes();
-
- return request;
- }
-
- private HttpServletRequest createNonIncludeRequest(String base,
- String realContextPath, String realServletPath, String pathInfo)
- throws Exception {
- HttpServletRequest request = createRequest(base, realContextPath,
- realServletPath, pathInfo);
- expect(request.getAttribute("javax.servlet.include.context_path"))
- .andReturn(null).anyTimes();
- expect(request.getAttribute("javax.servlet.include.servlet_path"))
- .andReturn(null).anyTimes();
-
- return request;
- }
-
- /**
- * Creates a HttpServletRequest mock using the supplied parameters.
- *
- * @param base
- * The base url, e.g. http://localhost:8080
- * @param contextPath
- * The context path where the application is deployed, e.g.
- * /mycontext
- * @param servletPath
- * The servlet path to the servlet we are testing, e.g. /myapp
- * @param pathInfo
- * Any text following the servlet path in the request, not
- * including query parameters, e.g. /UIDL/
- * @return A mock HttpServletRequest object useful for testing
- * @throws MalformedURLException
- */
- private HttpServletRequest createRequest(String base, String contextPath,
- String servletPath, String pathInfo) throws MalformedURLException {
- URL url = new URL(base + contextPath + pathInfo);
- HttpServletRequest request = createMock(HttpServletRequest.class);
- expect(request.isSecure()).andReturn(
- url.getProtocol().equalsIgnoreCase("https")).anyTimes();
- expect(request.getServerName()).andReturn(url.getHost()).anyTimes();
- expect(request.getServerPort()).andReturn(url.getPort()).anyTimes();
- expect(request.getRequestURI()).andReturn(url.getPath()).anyTimes();
- expect(request.getContextPath()).andReturn(contextPath).anyTimes();
- expect(request.getPathInfo()).andReturn(pathInfo).anyTimes();
- expect(request.getServletPath()).andReturn(servletPath).anyTimes();
-
- return request;
- }
-
-}