summaryrefslogtreecommitdiffstats
path: root/server/tests/src/com/vaadin
diff options
context:
space:
mode:
authorJonatan Kronqvist <jonatan@vaadin.com>2014-04-14 11:53:11 +0300
committerJonatan Kronqvist <jonatan@vaadin.com>2014-04-14 12:06:05 +0300
commit416e2f97bcaf93e4d2a782149a963fca95b8400e (patch)
treeeac6d22107b7c2d7bf6371e5278078f02bb860e9 /server/tests/src/com/vaadin
parentd2e24feb09ccba7f3a2f253687488774af2bc340 (diff)
parenteda9edcbde781d29ff5939defb61ba5fb159e206 (diff)
downloadvaadin-framework-416e2f97bcaf93e4d2a782149a963fca95b8400e.tar.gz
vaadin-framework-416e2f97bcaf93e4d2a782149a963fca95b8400e.zip
Merge branch 'master' into 7.2
72d0aa0 Update Window Javadoc based on 7.2 API review changes ee203f5 Apply abstract ordered layout settings for replaced component (#13568) 02998d8 Updated Window API based on 7.2 API review cd94b21 Discourage use of setNeedsLayout while a layout is running (#13542) f374bc7 Make ComboBox always immediate (#4054) aec102a Update 3rd party license information (#13449) 013d32d Remove old widget from tab content on replace (#12931). 3d0ff32 Prevent duplicate detach() calls with push (#13261) a452bad Refactor VaadinPortletRequest extending. (#13551) 55dfd29 Prevent duplicate session destroy events (#12612) 2067d4e Don't allocate unnecessary memory for empty array of Objects in MethodProperty (#10446). 00a9af5 Refactor PushConfigurationTest. Merge: no Change-Id: I6563769a77f91a68cfeadcb3306dd71fe431863c
Diffstat (limited to 'server/tests/src/com/vaadin')
-rw-r--r--server/tests/src/com/vaadin/data/util/MethodPropertyMemoryConsumption.java145
-rw-r--r--server/tests/src/com/vaadin/server/VaadinGateInRequestTests.java39
-rw-r--r--server/tests/src/com/vaadin/server/VaadinHttpAndPortletRequestTests.java140
-rw-r--r--server/tests/src/com/vaadin/server/VaadinLiferayRequestTests.java39
-rw-r--r--server/tests/src/com/vaadin/server/VaadinPortletTests.java94
-rw-r--r--server/tests/src/com/vaadin/server/VaadinServiceTest.java22
-rw-r--r--server/tests/src/com/vaadin/server/VaadinWebSpherePortalRequestTests.java39
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/LayoutSettingsOnReplace.java85
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/window/WindowTest.java53
9 files changed, 653 insertions, 3 deletions
diff --git a/server/tests/src/com/vaadin/data/util/MethodPropertyMemoryConsumption.java b/server/tests/src/com/vaadin/data/util/MethodPropertyMemoryConsumption.java
new file mode 100644
index 0000000000..caff33cf50
--- /dev/null
+++ b/server/tests/src/com/vaadin/data/util/MethodPropertyMemoryConsumption.java
@@ -0,0 +1,145 @@
+/*
+ * 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.data.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.lang.reflect.Field;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Test for MethodProperty: don't allocate unnecessary Object arrays.
+ *
+ * @since 7.2
+ * @author Vaadin Ltd
+ */
+public class MethodPropertyMemoryConsumption {
+
+ @Test
+ public void testSetArguments() throws NoSuchFieldException,
+ SecurityException, IllegalArgumentException, IllegalAccessException {
+ TestBean bean = new TestBean();
+ TestMethodProperty<String> property = new TestMethodProperty<String>(
+ bean, "name");
+ Object[] getArgs = property.getGetArgs();
+ Object[] setArgs = property.getSetArgs();
+
+ Field getArgsField = TestMethodProperty.class
+ .getDeclaredField("getArgs");
+ getArgsField.setAccessible(true);
+
+ Field setArgsField = TestMethodProperty.class
+ .getDeclaredField("setArgs");
+ setArgsField.setAccessible(true);
+
+ Assert.assertSame("setArguments method sets non-default instance"
+ + " of empty Object array for getArgs",
+ getArgsField.get(property), getArgs);
+
+ Assert.assertSame("setArguments method sets non-default instance"
+ + " of empty Object array for setArgs",
+ setArgsField.get(property), setArgs);
+ }
+
+ @Test
+ public void testDefaultCtor() {
+ TestBean bean = new TestBean();
+ TestMethodProperty<String> property = new TestMethodProperty<String>(
+ bean, "name");
+
+ Object[] getArgs = property.getGetArgs();
+ Object[] setArgs = property.getSetArgs();
+
+ TestBean otherBean = new TestBean();
+ TestMethodProperty<String> otherProperty = new TestMethodProperty<String>(
+ otherBean, "name");
+ Assert.assertSame("setArguments method uses different instance"
+ + " of empty Object array for getArgs", getArgs,
+ otherProperty.getGetArgs());
+ Assert.assertSame("setArguments method uses different instance"
+ + " of empty Object array for setArgs", setArgs,
+ otherProperty.getSetArgs());
+ }
+
+ @Test
+ public void testDefaultArgsSerialization() throws IOException,
+ ClassNotFoundException {
+ TestBean bean = new TestBean();
+ TestMethodProperty<String> property = new TestMethodProperty<String>(
+ bean, "name");
+
+ ByteArrayOutputStream sourceOutStream = new ByteArrayOutputStream();
+ ObjectOutputStream outStream = new ObjectOutputStream(sourceOutStream);
+ outStream.writeObject(property);
+
+ ObjectInputStream inputStream = new ObjectInputStream(
+ new ByteArrayInputStream(sourceOutStream.toByteArray()));
+ Object red = inputStream.readObject();
+ TestMethodProperty<?> deserialized = (TestMethodProperty<?>) red;
+
+ Assert.assertNotNull("Deseriliation doesn't call setArguments method",
+ deserialized.getGetArgs());
+ Assert.assertNotNull("Deseriliation doesn't call setArguments method",
+ deserialized.getSetArgs());
+
+ }
+
+ public static class TestMethodProperty<T> extends MethodProperty<T> {
+
+ public TestMethodProperty(Object instance, String beanPropertyName) {
+ super(instance, beanPropertyName);
+ }
+
+ @Override
+ public void setArguments(Object[] getArgs, Object[] setArgs,
+ int setArgumentIndex) {
+ super.setArguments(getArgs, setArgs, setArgumentIndex);
+ this.getArgs = getArgs;
+ this.setArgs = setArgs;
+ }
+
+ Object[] getGetArgs() {
+ return getArgs;
+ }
+
+ Object[] getSetArgs() {
+ return setArgs;
+ }
+
+ private transient Object[] getArgs;
+ private transient Object[] setArgs;
+ }
+
+ public static class TestBean implements Serializable {
+
+ private String name;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ }
+}
diff --git a/server/tests/src/com/vaadin/server/VaadinGateInRequestTests.java b/server/tests/src/com/vaadin/server/VaadinGateInRequestTests.java
new file mode 100644
index 0000000000..017613661e
--- /dev/null
+++ b/server/tests/src/com/vaadin/server/VaadinGateInRequestTests.java
@@ -0,0 +1,39 @@
+/*
+ * 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 static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+
+import com.vaadin.server.VaadinPortlet.VaadinGateInRequest;
+
+public class VaadinGateInRequestTests extends
+ VaadinHttpAndPortletRequestTests<VaadinGateInRequest> {
+
+ @Override
+ protected VaadinGateInRequest createSut() {
+
+ VaadinGateInRequest request = new VaadinGateInRequest(portletRequest,
+ vaadinPortletService);
+
+ // Although partial mocking can be considered a code smell,
+ // here it's actually quite useful to mock reflection calls.
+ VaadinGateInRequest spy = spy(request);
+ doReturn(servletRequest).when(spy).getServletRequest(portletRequest);
+
+ return spy;
+ }
+}
diff --git a/server/tests/src/com/vaadin/server/VaadinHttpAndPortletRequestTests.java b/server/tests/src/com/vaadin/server/VaadinHttpAndPortletRequestTests.java
new file mode 100644
index 0000000000..01d501c4fb
--- /dev/null
+++ b/server/tests/src/com/vaadin/server/VaadinHttpAndPortletRequestTests.java
@@ -0,0 +1,140 @@
+/*
+ * 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 static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Enumeration;
+import java.util.Map;
+
+import javax.portlet.PortletRequest;
+import javax.servlet.http.HttpServletRequest;
+
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import com.vaadin.server.VaadinPortlet.VaadinHttpAndPortletRequest;
+import com.vaadin.server.VaadinPortletService;
+
+//Have to ignore this class - otherwise JUnit tries to instantiate it...
+@Ignore
+public abstract class VaadinHttpAndPortletRequestTests<T extends VaadinHttpAndPortletRequest> {
+
+ protected VaadinHttpAndPortletRequest sut;
+ protected HttpServletRequest servletRequest;
+ protected PortletRequest portletRequest;
+ protected VaadinPortletService vaadinPortletService;
+
+ protected abstract T createSut();
+
+ @Before
+ public void setup() {
+ portletRequest = mock(PortletRequest.class);
+ vaadinPortletService = mock(VaadinPortletService.class);
+ servletRequest = mock(HttpServletRequest.class);
+
+ sut = createSut();
+ }
+
+ @Test
+ public void parameterIsFetchedFromServletRequest() {
+ when(servletRequest.getParameter("foo")).thenReturn("bar");
+
+ String parameter = sut.getParameter("foo");
+
+ assertThat(parameter, is("bar"));
+ }
+
+ @Test
+ public void originalParameterIsOverridden() {
+ when(servletRequest.getParameter("foo")).thenReturn("braa");
+ when(portletRequest.getParameter("foo")).thenReturn("bar");
+
+ String parameter = sut.getParameter("foo");
+
+ assertThat(parameter, is("bar"));
+ }
+
+ @Test
+ public void remoteAddressIsFetchedFromServletRequest() {
+ when(servletRequest.getRemoteAddr()).thenReturn("foo");
+
+ String remoteAddr = sut.getRemoteAddr();
+
+ assertThat(remoteAddr, is("foo"));
+ }
+
+ @Test
+ public void remoteHostIsFetchedFromServletRequest() {
+ when(servletRequest.getRemoteHost()).thenReturn("foo");
+
+ String remoteHost = sut.getRemoteHost();
+
+ assertThat(remoteHost, is("foo"));
+ }
+
+ @Test
+ public void remotePortIsFetchedFromServletRequest() {
+ when(servletRequest.getRemotePort()).thenReturn(12345);
+
+ int remotePort = sut.getRemotePort();
+
+ assertThat(remotePort, is(12345));
+ }
+
+ @Test
+ public void headerIsFetchedFromServletRequest() {
+ when(servletRequest.getHeader("foo")).thenReturn("bar");
+
+ String header = sut.getHeader("foo");
+
+ assertThat(header, is("bar"));
+ }
+
+ @Test
+ public void headerNamesAreFetchedFromServletRequest() {
+ Enumeration expectedHeaderNames = mock(Enumeration.class);
+ when(servletRequest.getHeaderNames()).thenReturn(expectedHeaderNames);
+
+ Enumeration<String> actualHeaderNames = sut.getHeaderNames();
+
+ assertThat(actualHeaderNames, is(expectedHeaderNames));
+ }
+
+ @Test
+ public void headersAreFetchedFromServletRequest() {
+ Enumeration expectedHeaders = mock(Enumeration.class);
+ when(servletRequest.getHeaders("foo")).thenReturn(expectedHeaders);
+
+ Enumeration<String> actualHeaders = sut.getHeaders("foo");
+
+ assertThat(actualHeaders, is(expectedHeaders));
+ }
+
+ @Test
+ public void parameterMapIsFetchedFromServletRequest() {
+ Map expectedParameterMap = mock(Map.class);
+ when(servletRequest.getParameterMap()).thenReturn(expectedParameterMap);
+
+ Map<String, String[]> actualParameterMap = sut.getParameterMap();
+
+ assertThat(actualParameterMap, is(expectedParameterMap));
+ }
+}
diff --git a/server/tests/src/com/vaadin/server/VaadinLiferayRequestTests.java b/server/tests/src/com/vaadin/server/VaadinLiferayRequestTests.java
new file mode 100644
index 0000000000..074941a556
--- /dev/null
+++ b/server/tests/src/com/vaadin/server/VaadinLiferayRequestTests.java
@@ -0,0 +1,39 @@
+/*
+ * 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 static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+
+import com.vaadin.server.VaadinPortlet.VaadinLiferayRequest;
+
+public class VaadinLiferayRequestTests extends
+ VaadinHttpAndPortletRequestTests<VaadinLiferayRequest> {
+
+ @Override
+ protected VaadinLiferayRequest createSut() {
+
+ VaadinLiferayRequest request = new VaadinLiferayRequest(portletRequest,
+ vaadinPortletService);
+
+ // Although partial mocking can be considered a code smell,
+ // here it's actually quite useful to mock reflection calls.
+ VaadinLiferayRequest spy = spy(request);
+ doReturn(servletRequest).when(spy).getServletRequest(portletRequest);
+
+ return spy;
+ }
+} \ No newline at end of file
diff --git a/server/tests/src/com/vaadin/server/VaadinPortletTests.java b/server/tests/src/com/vaadin/server/VaadinPortletTests.java
new file mode 100644
index 0000000000..93f8fd0778
--- /dev/null
+++ b/server/tests/src/com/vaadin/server/VaadinPortletTests.java
@@ -0,0 +1,94 @@
+/*
+ * 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 static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.IsInstanceOf.instanceOf;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import javax.portlet.PortalContext;
+import javax.portlet.PortletRequest;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.vaadin.server.VaadinPortlet.VaadinGateInRequest;
+import com.vaadin.server.VaadinPortlet.VaadinLiferayRequest;
+import com.vaadin.server.VaadinPortlet.VaadinWebSpherePortalRequest;
+
+public class VaadinPortletTests {
+
+ private VaadinPortlet sut;
+ private PortletRequest portletRequest;
+ private PortalContext portalContext;
+
+ @Before
+ public void setup() {
+ sut = new VaadinPortlet();
+
+ portletRequest = mock(PortletRequest.class);
+ portalContext = mock(PortalContext.class);
+
+ when(portletRequest.getPortalContext()).thenReturn(portalContext);
+ }
+
+ private void mockPortalInfo(String name) {
+ when(portalContext.getPortalInfo()).thenReturn(name);
+ }
+
+ private VaadinPortletRequest createRequest() {
+ VaadinPortletRequest request = sut.createVaadinRequest(portletRequest);
+ return request;
+ }
+
+ @Test
+ public void gateInRequestIsCreated() {
+ mockPortalInfo("gatein");
+
+ VaadinPortletRequest request = createRequest();
+
+ assertThat(request, instanceOf(VaadinGateInRequest.class));
+ }
+
+ @Test
+ public void liferayRequestIsCreated() {
+ mockPortalInfo("liferay");
+
+ VaadinPortletRequest request = createRequest();
+
+ assertThat(request, instanceOf(VaadinLiferayRequest.class));
+ }
+
+ @Test
+ public void webspherePortalRequestIsCreated() {
+ mockPortalInfo("websphere portal");
+
+ VaadinPortletRequest request = createRequest();
+
+ assertThat(request, instanceOf(VaadinWebSpherePortalRequest.class));
+ }
+
+ @Test
+ public void defaultPortletRequestIsCreated() {
+ mockPortalInfo("foobar");
+
+ VaadinPortletRequest request = createRequest();
+
+ assertThat(request, instanceOf(VaadinPortletRequest.class));
+ }
+
+}
diff --git a/server/tests/src/com/vaadin/server/VaadinServiceTest.java b/server/tests/src/com/vaadin/server/VaadinServiceTest.java
index cead5df79c..77eb155378 100644
--- a/server/tests/src/com/vaadin/server/VaadinServiceTest.java
+++ b/server/tests/src/com/vaadin/server/VaadinServiceTest.java
@@ -29,6 +29,16 @@ import org.junit.Test;
*/
public class VaadinServiceTest {
+ private class TestSessionDestroyListener implements SessionDestroyListener {
+
+ int callCount = 0;
+
+ @Override
+ public void sessionDestroy(SessionDestroyEvent event) {
+ callCount++;
+ }
+ }
+
@Test
public void testFireSessionDestroy() throws ServletException {
ServletConfig servletConfig = new MockServletConfig();
@@ -36,6 +46,10 @@ public class VaadinServiceTest {
servlet.init(servletConfig);
VaadinService service = servlet.getService();
+ TestSessionDestroyListener listener = new TestSessionDestroyListener();
+
+ service.addSessionDestroyListener(listener);
+
MockVaadinSession vaadinSession = new MockVaadinSession(service);
service.fireSessionDestroy(vaadinSession);
Assert.assertEquals(
@@ -45,9 +59,11 @@ public class VaadinServiceTest {
vaadinSession.valueUnbound(EasyMock
.createMock(HttpSessionBindingEvent.class));
- org.junit.Assert.assertEquals(
- "'fireSessionDestroy' method may not call 'close' "
- + "method for closing session", 1,
+ Assert.assertEquals("'fireSessionDestroy' method may not call 'close' "
+ + "method for closing session", 1,
vaadinSession.getCloseCount());
+
+ Assert.assertEquals("SessionDestroyListeners not called exactly once",
+ 1, listener.callCount);
}
}
diff --git a/server/tests/src/com/vaadin/server/VaadinWebSpherePortalRequestTests.java b/server/tests/src/com/vaadin/server/VaadinWebSpherePortalRequestTests.java
new file mode 100644
index 0000000000..0da85c7111
--- /dev/null
+++ b/server/tests/src/com/vaadin/server/VaadinWebSpherePortalRequestTests.java
@@ -0,0 +1,39 @@
+/*
+ * 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 static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+
+import com.vaadin.server.VaadinPortlet.VaadinWebSpherePortalRequest;
+
+public class VaadinWebSpherePortalRequestTests extends
+ VaadinHttpAndPortletRequestTests<VaadinWebSpherePortalRequest> {
+
+ @Override
+ protected VaadinWebSpherePortalRequest createSut() {
+
+ VaadinWebSpherePortalRequest request = new VaadinWebSpherePortalRequest(
+ portletRequest, vaadinPortletService);
+
+ // Although partial mocking can be considered a code smell,
+ // here it's actually quite useful to mock reflection calls.
+ VaadinWebSpherePortalRequest spy = spy(request);
+ doReturn(servletRequest).when(spy).getServletRequest(portletRequest);
+
+ return spy;
+ }
+} \ No newline at end of file
diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/LayoutSettingsOnReplace.java b/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/LayoutSettingsOnReplace.java
new file mode 100644
index 0000000000..0af21d8cb8
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/LayoutSettingsOnReplace.java
@@ -0,0 +1,85 @@
+/*
+ * 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.tests.server.component.abstractorderedlayout;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.ui.AbstractComponent;
+import com.vaadin.ui.AbstractOrderedLayout;
+import com.vaadin.ui.Alignment;
+
+/**
+ * Tests for abstract layout settings which should be preserved on replace
+ * component
+ *
+ * @since 7.2
+ * @author Vaadin Ltd
+ */
+public class LayoutSettingsOnReplace {
+
+ @Test
+ public void testExpandRatio() {
+ AbstractOrderedLayout layout = new AbstractOrderedLayout() {
+ };
+
+ AbstractComponent first = new AbstractComponent() {
+ };
+ AbstractComponent second = new AbstractComponent() {
+ };
+
+ layout.addComponent(first);
+ layout.addComponent(second);
+
+ int ratio = 2;
+ layout.setExpandRatio(first, ratio);
+ layout.setExpandRatio(second, 1);
+
+ AbstractComponent replace = new AbstractComponent() {
+ };
+ layout.replaceComponent(first, replace);
+
+ Assert.assertEquals("Expand ratio for replaced component is not "
+ + "the same as for previous one", ratio,
+ layout.getExpandRatio(replace), 0.0001);
+ }
+
+ @Test
+ public void testAlignment() {
+ AbstractOrderedLayout layout = new AbstractOrderedLayout() {
+ };
+
+ AbstractComponent first = new AbstractComponent() {
+ };
+ AbstractComponent second = new AbstractComponent() {
+ };
+
+ layout.addComponent(first);
+ layout.addComponent(second);
+
+ Alignment alignment = Alignment.BOTTOM_RIGHT;
+ layout.setComponentAlignment(first, alignment);
+ layout.setComponentAlignment(second, Alignment.MIDDLE_CENTER);
+
+ AbstractComponent replace = new AbstractComponent() {
+ };
+ layout.replaceComponent(first, replace);
+
+ Assert.assertEquals("Alignment for replaced component is not "
+ + "the same as for previous one", alignment,
+ layout.getComponentAlignment(replace));
+ }
+}
diff --git a/server/tests/src/com/vaadin/tests/server/component/window/WindowTest.java b/server/tests/src/com/vaadin/tests/server/component/window/WindowTest.java
new file mode 100644
index 0000000000..2cd19ee153
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/server/component/window/WindowTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.tests.server.component.window;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Window;
+
+public class WindowTest {
+
+ public Window window;
+
+ @Before
+ public void setup() {
+ window = new Window();
+ }
+
+ @Test
+ public void testAssistiveDescription() {
+ Label l1 = new Label("label 1");
+ Button b2 = new Button("button 2");
+ window.setAssistiveDescription(l1, b2);
+
+ Assert.assertEquals(2, window.getAssistiveDescription().length);
+ Assert.assertEquals(l1, window.getAssistiveDescription()[0]);
+ Assert.assertEquals(b2, window.getAssistiveDescription()[1]);
+
+ // Modifying return value must not change actual value
+ window.getAssistiveDescription()[0] = null;
+
+ Assert.assertEquals(2, window.getAssistiveDescription().length);
+ Assert.assertEquals(l1, window.getAssistiveDescription()[0]);
+ Assert.assertEquals(b2, window.getAssistiveDescription()[1]);
+
+ }
+}