From 6c3d35cfb8985eaac86f30316333a84f6096b76b Mon Sep 17 00:00:00 2001 From: Sauli Tähkäpää Date: Fri, 2 Jan 2015 13:56:15 +0200 Subject: Refactor server unit tests. - Renamed tests to *Test and *TestBase. - Removed obsolete @Ignore annotations. - Split some design tests into smaller ones. Change-Id: I8e2a7d73ef620e584777c1e8e701917c0f69f876 --- server/ivy.xml | 2 + .../com/vaadin/server/VaadinGateInRequestTest.java | 39 ++++ .../vaadin/server/VaadinGateInRequestTests.java | 39 ---- .../VaadinHttpAndPortletRequestTestBase.java | 138 +++++++++++++ .../server/VaadinHttpAndPortletRequestTests.java | 140 ------------- .../vaadin/server/VaadinLiferayRequestTest.java | 39 ++++ .../vaadin/server/VaadinLiferayRequestTests.java | 39 ---- .../server/VaadinWebSpherePortalRequestTest.java | 39 ++++ .../server/VaadinWebSpherePortalRequestTests.java | 39 ---- .../tests/design/DesignReadInConstructor.java | 3 - .../vaadin/tests/design/InvalidLayoutTemplate.java | 3 - .../com/vaadin/tests/design/LayoutTemplate.java | 3 - .../src/com/vaadin/tests/design/LocaleTest.java | 183 ++++++++++++++++ .../design/ParseAllSupportedComponentsTest.java | 30 +-- .../com/vaadin/tests/design/ParseLayoutTest.java | 229 ++++++++++----------- .../src/com/vaadin/tests/design/TestLocale.java | 176 ---------------- .../design/designroot/DesignWithAnnotation.java | 3 - .../designroot/DesignWithEmptyAnnotation.java | 3 - .../designroot/ExtendedDesignWithAnnotation.java | 3 - .../ExtendedDesignWithEmptyAnnotation.java | 3 - .../ExtendedDesignWithEmptyAnnotationUI.java | 3 - .../vaadin/tests/design/nested/MyChildDesign.java | 3 - .../nested/MyChildDesignCustomComponent.java | 3 - .../vaadin/tests/design/nested/MyDesignRoot.java | 3 - .../tests/design/nested/MyExtendedChildDesign.java | 3 - .../design/nested/NestedCustomLayoutsTest.java | 82 ++++++++ .../design/nested/ReadNestedTemplatesTest.java | 71 +++++++ .../design/nested/TestNestedCustomLayouts.java | 80 ------- .../design/nested/TestReadNestedTemplates.java | 62 ------ .../design/nested/TestWriteNestedTemplates.java | 89 -------- .../design/nested/WriteNestedTemplatesTest.java | 89 ++++++++ .../nested/customlayouts/CustomAbsoluteLayout.java | 3 - .../nested/customlayouts/CustomAccordion.java | 3 - .../nested/customlayouts/CustomCssLayout.java | 3 - .../nested/customlayouts/CustomFormLayout.java | 3 - .../nested/customlayouts/CustomGridLayout.java | 3 - .../customlayouts/CustomHorizontalLayout.java | 3 - .../customlayouts/CustomHorizontalSplitPanel.java | 3 - .../design/nested/customlayouts/CustomPanel.java | 3 - .../nested/customlayouts/CustomTabSheet.java | 3 - .../nested/customlayouts/CustomVerticalLayout.java | 3 - .../customlayouts/CustomVerticalSplitPanel.java | 3 - 42 files changed, 812 insertions(+), 862 deletions(-) create mode 100644 server/tests/src/com/vaadin/server/VaadinGateInRequestTest.java delete mode 100644 server/tests/src/com/vaadin/server/VaadinGateInRequestTests.java create mode 100644 server/tests/src/com/vaadin/server/VaadinHttpAndPortletRequestTestBase.java delete mode 100644 server/tests/src/com/vaadin/server/VaadinHttpAndPortletRequestTests.java create mode 100644 server/tests/src/com/vaadin/server/VaadinLiferayRequestTest.java delete mode 100644 server/tests/src/com/vaadin/server/VaadinLiferayRequestTests.java create mode 100644 server/tests/src/com/vaadin/server/VaadinWebSpherePortalRequestTest.java delete mode 100644 server/tests/src/com/vaadin/server/VaadinWebSpherePortalRequestTests.java create mode 100644 server/tests/src/com/vaadin/tests/design/LocaleTest.java delete mode 100644 server/tests/src/com/vaadin/tests/design/TestLocale.java create mode 100644 server/tests/src/com/vaadin/tests/design/nested/NestedCustomLayoutsTest.java create mode 100644 server/tests/src/com/vaadin/tests/design/nested/ReadNestedTemplatesTest.java delete mode 100644 server/tests/src/com/vaadin/tests/design/nested/TestNestedCustomLayouts.java delete mode 100644 server/tests/src/com/vaadin/tests/design/nested/TestReadNestedTemplates.java delete mode 100644 server/tests/src/com/vaadin/tests/design/nested/TestWriteNestedTemplates.java create mode 100644 server/tests/src/com/vaadin/tests/design/nested/WriteNestedTemplatesTest.java (limited to 'server') diff --git a/server/ivy.xml b/server/ivy.xml index 2901be8090..b30e6a72ef 100644 --- a/server/ivy.xml +++ b/server/ivy.xml @@ -70,6 +70,8 @@ conf="test,ide -> default" /> + { + + @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/VaadinGateInRequestTests.java b/server/tests/src/com/vaadin/server/VaadinGateInRequestTests.java deleted file mode 100644 index 4478b4cf39..0000000000 --- a/server/tests/src/com/vaadin/server/VaadinGateInRequestTests.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2000-2014 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 { - - @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/VaadinHttpAndPortletRequestTestBase.java b/server/tests/src/com/vaadin/server/VaadinHttpAndPortletRequestTestBase.java new file mode 100644 index 0000000000..0f7cce5f75 --- /dev/null +++ b/server/tests/src/com/vaadin/server/VaadinHttpAndPortletRequestTestBase.java @@ -0,0 +1,138 @@ +/* + * Copyright 2000-2014 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; + +public abstract class VaadinHttpAndPortletRequestTestBase { + + 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 actualHeaderNames = sut.getHeaderNames(); + + assertThat(actualHeaderNames, is(expectedHeaderNames)); + } + + @Test + public void headersAreFetchedFromServletRequest() { + Enumeration expectedHeaders = mock(Enumeration.class); + when(servletRequest.getHeaders("foo")).thenReturn(expectedHeaders); + + Enumeration actualHeaders = sut.getHeaders("foo"); + + assertThat(actualHeaders, is(expectedHeaders)); + } + + @Test + public void parameterMapIsFetchedFromServletRequest() { + Map expectedParameterMap = mock(Map.class); + when(servletRequest.getParameterMap()).thenReturn(expectedParameterMap); + + Map actualParameterMap = sut.getParameterMap(); + + assertThat(actualParameterMap, is(expectedParameterMap)); + } +} diff --git a/server/tests/src/com/vaadin/server/VaadinHttpAndPortletRequestTests.java b/server/tests/src/com/vaadin/server/VaadinHttpAndPortletRequestTests.java deleted file mode 100644 index a87eb1870e..0000000000 --- a/server/tests/src/com/vaadin/server/VaadinHttpAndPortletRequestTests.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright 2000-2014 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 { - - 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 actualHeaderNames = sut.getHeaderNames(); - - assertThat(actualHeaderNames, is(expectedHeaderNames)); - } - - @Test - public void headersAreFetchedFromServletRequest() { - Enumeration expectedHeaders = mock(Enumeration.class); - when(servletRequest.getHeaders("foo")).thenReturn(expectedHeaders); - - Enumeration actualHeaders = sut.getHeaders("foo"); - - assertThat(actualHeaders, is(expectedHeaders)); - } - - @Test - public void parameterMapIsFetchedFromServletRequest() { - Map expectedParameterMap = mock(Map.class); - when(servletRequest.getParameterMap()).thenReturn(expectedParameterMap); - - Map actualParameterMap = sut.getParameterMap(); - - assertThat(actualParameterMap, is(expectedParameterMap)); - } -} diff --git a/server/tests/src/com/vaadin/server/VaadinLiferayRequestTest.java b/server/tests/src/com/vaadin/server/VaadinLiferayRequestTest.java new file mode 100644 index 0000000000..3024cd652f --- /dev/null +++ b/server/tests/src/com/vaadin/server/VaadinLiferayRequestTest.java @@ -0,0 +1,39 @@ +/* + * Copyright 2000-2014 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 VaadinLiferayRequestTest extends + VaadinHttpAndPortletRequestTestBase { + + @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; + } +} diff --git a/server/tests/src/com/vaadin/server/VaadinLiferayRequestTests.java b/server/tests/src/com/vaadin/server/VaadinLiferayRequestTests.java deleted file mode 100644 index 8ccd649ea4..0000000000 --- a/server/tests/src/com/vaadin/server/VaadinLiferayRequestTests.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2000-2014 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 { - - @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; - } -} diff --git a/server/tests/src/com/vaadin/server/VaadinWebSpherePortalRequestTest.java b/server/tests/src/com/vaadin/server/VaadinWebSpherePortalRequestTest.java new file mode 100644 index 0000000000..3a4c5c69be --- /dev/null +++ b/server/tests/src/com/vaadin/server/VaadinWebSpherePortalRequestTest.java @@ -0,0 +1,39 @@ +/* + * Copyright 2000-2014 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 VaadinWebSpherePortalRequestTest extends + VaadinHttpAndPortletRequestTestBase { + + @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; + } +} diff --git a/server/tests/src/com/vaadin/server/VaadinWebSpherePortalRequestTests.java b/server/tests/src/com/vaadin/server/VaadinWebSpherePortalRequestTests.java deleted file mode 100644 index a1abfbd280..0000000000 --- a/server/tests/src/com/vaadin/server/VaadinWebSpherePortalRequestTests.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2000-2014 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 { - - @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; - } -} diff --git a/server/tests/src/com/vaadin/tests/design/DesignReadInConstructor.java b/server/tests/src/com/vaadin/tests/design/DesignReadInConstructor.java index ce80d98324..6eccaf6a2c 100644 --- a/server/tests/src/com/vaadin/tests/design/DesignReadInConstructor.java +++ b/server/tests/src/com/vaadin/tests/design/DesignReadInConstructor.java @@ -15,12 +15,9 @@ */ package com.vaadin.tests.design; -import org.junit.Ignore; - import com.vaadin.ui.CssLayout; import com.vaadin.ui.declarative.Design; -@Ignore public class DesignReadInConstructor extends CssLayout { public DesignReadInConstructor() { diff --git a/server/tests/src/com/vaadin/tests/design/InvalidLayoutTemplate.java b/server/tests/src/com/vaadin/tests/design/InvalidLayoutTemplate.java index bdfa4b47cc..8a2dec5a35 100644 --- a/server/tests/src/com/vaadin/tests/design/InvalidLayoutTemplate.java +++ b/server/tests/src/com/vaadin/tests/design/InvalidLayoutTemplate.java @@ -15,8 +15,6 @@ */ package com.vaadin.tests.design; -import org.junit.Ignore; - import com.vaadin.ui.Button; import com.vaadin.ui.NativeButton; import com.vaadin.ui.TextField; @@ -27,7 +25,6 @@ import com.vaadin.ui.VerticalLayout; * @since * @author Vaadin Ltd */ -@Ignore public class InvalidLayoutTemplate extends VerticalLayout { private NativeButton firstButton; private NativeButton secondButton; diff --git a/server/tests/src/com/vaadin/tests/design/LayoutTemplate.java b/server/tests/src/com/vaadin/tests/design/LayoutTemplate.java index 95f30fb728..fdfddf5c08 100644 --- a/server/tests/src/com/vaadin/tests/design/LayoutTemplate.java +++ b/server/tests/src/com/vaadin/tests/design/LayoutTemplate.java @@ -15,8 +15,6 @@ */ package com.vaadin.tests.design; -import org.junit.Ignore; - import com.vaadin.ui.Button; import com.vaadin.ui.NativeButton; import com.vaadin.ui.VerticalLayout; @@ -27,7 +25,6 @@ import com.vaadin.ui.VerticalLayout; * @since * @author Vaadin Ltd */ -@Ignore public class LayoutTemplate extends VerticalLayout { private NativeButton firstButton; // assigned based on local id private NativeButton secondButton; // assigned based on id diff --git a/server/tests/src/com/vaadin/tests/design/LocaleTest.java b/server/tests/src/com/vaadin/tests/design/LocaleTest.java new file mode 100644 index 0000000000..939080fbbc --- /dev/null +++ b/server/tests/src/com/vaadin/tests/design/LocaleTest.java @@ -0,0 +1,183 @@ +/* + * Copyright 2000-2014 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.design; + +import java.io.ByteArrayInputStream; +import java.util.Locale; + +import junit.framework.TestCase; + +import org.jsoup.nodes.Document; +import org.jsoup.nodes.DocumentType; +import org.jsoup.nodes.Element; +import org.jsoup.nodes.Node; + +import com.vaadin.ui.Button; +import com.vaadin.ui.Component; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Label; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.declarative.Design; +import com.vaadin.ui.declarative.DesignContext; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * Tests the handling of the locale property in parsing and html generation. + * + * @since + * @author Vaadin Ltd + */ +public class LocaleTest { + DesignContext ctx; + + @Before + public void setUp() { + ctx = new DesignContext(); + } + + /* + * Checks that when the html corresponding to a component hierarchy is + * constructed, the result only contains locale attributes for a component + * if its locale differs from that of its parent. + */ + @Test + public void testHtmlGeneration() { + // create a component hierarchy + VerticalLayout vLayout = new VerticalLayout(); + vLayout.setLocale(Locale.US); + HorizontalLayout hLayout = new HorizontalLayout(); + hLayout.setLocale(Locale.ITALY); + vLayout.addComponent(hLayout); + Button b1 = new Button(); + b1.setLocale(Locale.ITALY); + Button b2 = new Button(); + b2.setLocale(Locale.US); + hLayout.addComponent(b1); + hLayout.addComponent(b2); + HorizontalLayout hlayout2 = new HorizontalLayout(); + hlayout2.setLocale(Locale.US); + vLayout.addComponent(hlayout2); + Label l = new Label(); + l.setLocale(Locale.US); + hlayout2.addComponent(l); + Label l2 = new Label(); + l2.setLocale(Locale.CANADA); + hlayout2.addComponent(l2); + ctx.setRootComponent(vLayout); + // create the html tree corresponding to the component hierarchy + Document doc = componentToDoc(ctx); + // check the created html + Element body = doc.body(); + Element evLayout = body.child(0); + assertEquals("Wrong locale information.", "en_US", + evLayout.attr("locale")); + Element ehLayout = evLayout.child(0); + assertEquals("Wrong locale information.", "it_IT", + ehLayout.attr("locale")); + Element eb1 = ehLayout.child(0); + assertTrue( + "The element should not have a locale specification, found locale " + + eb1.attr("locale"), "".equals(eb1.attr("locale"))); + Element eb2 = ehLayout.child(1); + assertEquals("Wrong locale information.", "en_US", eb2.attr("locale")); + Element ehLayout2 = evLayout.child(1); + assertTrue( + "The element should not have a locale specification, found locale " + + ehLayout2.attr("locale"), + "".equals(ehLayout2.attr("locale"))); + Element el1 = ehLayout2.child(0); + assertTrue( + "The element should not have a locale specification, found locale " + + el1.attr("locale"), "".equals(el1.attr("locale"))); + Element el2 = ehLayout2.child(1); + assertEquals("Wrong locale information.", "en_CA", el2.attr("locale")); + } + + private Document componentToDoc(DesignContext dc) { + // Create the html tree skeleton. + Document doc = new Document(""); + DocumentType docType = new DocumentType("html", "", "", ""); + doc.appendChild(docType); + Element html = doc.createElement("html"); + doc.appendChild(html); + html.appendChild(doc.createElement("head")); + Element body = doc.createElement("body"); + html.appendChild(body); + dc.writePackageMappings(doc); + + // Append the design under in the html tree. createNode + // creates the entire component hierarchy rooted at the + // given root node. + Component root = dc.getRootComponent(); + Node rootNode = dc.createElement(root); + body.appendChild(rootNode); + return doc; + + } + + /* + * Checks that the locale of a component is set when the html element + * corresponding to the component specifies a locale. + */ + @Test + public void testParsing() { + // create an html document + Document doc = new Document(""); + DocumentType docType = new DocumentType("html", "", "", ""); + doc.appendChild(docType); + Element html = doc.createElement("html"); + doc.appendChild(html); + html.appendChild(doc.createElement("head")); + Element body = doc.createElement("body"); + html.appendChild(body); + Element evLayout = doc.createElement("v-vertical-layout"); + evLayout.attr("locale", "en_US"); + body.appendChild(evLayout); + Element ehLayout = doc.createElement("v-horizontal-layout"); + evLayout.appendChild(ehLayout); + Element eb1 = doc.createElement("v-button"); + eb1.attr("locale", "en_US"); + ehLayout.appendChild(eb1); + Element eb2 = doc.createElement("v-button"); + eb2.attr("locale", "en_GB"); + ehLayout.appendChild(eb2); + Element eb3 = doc.createElement("v-button"); + ehLayout.appendChild(eb3); + + // parse the created document and check the constructed component + // hierarchy + String string = doc.html(); + VerticalLayout vLayout = (VerticalLayout) Design + .read(new ByteArrayInputStream(string.getBytes())); + assertEquals("Wrong locale.", new Locale("en", "US"), + vLayout.getLocale()); + HorizontalLayout hLayout = (HorizontalLayout) vLayout.getComponent(0); + assertEquals("The element should have the same locale as its parent.", + vLayout.getLocale(), hLayout.getLocale()); + Button b1 = (Button) hLayout.getComponent(0); + assertEquals("Wrong locale.", new Locale("en", "US"), b1.getLocale()); + Button b2 = (Button) hLayout.getComponent(1); + assertEquals("Wrong locale.", new Locale("en", "GB"), b2.getLocale()); + Button b3 = (Button) hLayout.getComponent(2); + assertEquals( + "The component should have the same locale as its parent.", + hLayout.getLocale(), b3.getLocale()); + } +} \ No newline at end of file diff --git a/server/tests/src/com/vaadin/tests/design/ParseAllSupportedComponentsTest.java b/server/tests/src/com/vaadin/tests/design/ParseAllSupportedComponentsTest.java index 4f3f205631..5f901cd746 100644 --- a/server/tests/src/com/vaadin/tests/design/ParseAllSupportedComponentsTest.java +++ b/server/tests/src/com/vaadin/tests/design/ParseAllSupportedComponentsTest.java @@ -22,26 +22,28 @@ import junit.framework.TestCase; import com.vaadin.ui.declarative.Design; import com.vaadin.ui.declarative.DesignContext; +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; /** * Just top level test case that contains all synchronizable components * * @author Vaadin Ltd */ -public class ParseAllSupportedComponentsTest extends TestCase { +public class ParseAllSupportedComponentsTest { + + @Test + public void allComponentsAreParsed() throws FileNotFoundException { + DesignContext ctx = Design + .read(new FileInputStream( + "server/tests/src/com/vaadin/tests/design/all-components.html"), + null); - public void testParsing() { - try { - DesignContext ctx = Design - .read(new FileInputStream( - "server/tests/src/com/vaadin/tests/design/all-components.html"), - null); - assertNotNull("The returned design context can not be null", ctx); - assertNotNull("the component root can not be null", - ctx.getRootComponent()); - } catch (FileNotFoundException e) { - e.printStackTrace(); - fail("Template parsing threw exception"); - } + assertThat(ctx, is(not(nullValue()))); + assertThat(ctx.getRootComponent(), is(not(nullValue()))); } } diff --git a/server/tests/src/com/vaadin/tests/design/ParseLayoutTest.java b/server/tests/src/com/vaadin/tests/design/ParseLayoutTest.java index c517b0e5e2..70376c79f8 100644 --- a/server/tests/src/com/vaadin/tests/design/ParseLayoutTest.java +++ b/server/tests/src/com/vaadin/tests/design/ParseLayoutTest.java @@ -22,25 +22,27 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; -import junit.framework.TestCase; - import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.nodes.Node; +import org.junit.Before; import org.junit.Test; -import com.vaadin.ui.Button; import com.vaadin.ui.Component; import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.Label; -import com.vaadin.ui.NativeButton; import com.vaadin.ui.TextArea; import com.vaadin.ui.TextField; import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.declarative.Design; import com.vaadin.ui.declarative.DesignContext; import com.vaadin.ui.declarative.DesignException; +import org.junit.rules.ExpectedException; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.junit.Assert.*; /** * A test for checking that parsing a layout preserves the IDs and the mapping @@ -50,45 +52,62 @@ import com.vaadin.ui.declarative.DesignException; * @since * @author Vaadin Ltd */ -public class ParseLayoutTest extends TestCase { +public class ParseLayoutTest { // The context is used for accessing the created component hierarchy. private DesignContext ctx; - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { ctx = Design .read(new FileInputStream( "server/tests/src/com/vaadin/tests/design/testFile.html"), null); } - /* - * Checks the component hierarchy created by parsing a design. Also checks - * that components can be found by id and caption. - */ @Test - public void testGettingByIDAndCaption() throws FileNotFoundException { - findElements(ctx); - checkHierarchy(ctx); - } - - /* - * Check that captions, ids and package mappings are preserved when an html - * tree is generated from a DesignContext containing the component root of - * the component hierarchy. Done by writing the design to a string and then - * reading it back, not using the original context information after reading - * the written design. The mapping from prefixes to package names is checked - * directly from the html tree. - */ + public void buttonWithIdIsParsed() { + Component button = ctx.getComponentByLocalId("firstButton"); + + assertThat(ctx.getComponentByCaption("Native click me"), is(button)); + assertThat(button.getCaption(), is("Native click me")); + } + @Test - public void testThatSerializationPreservesProperties() throws IOException { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - Design.write(ctx, out); - ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); - DesignContext newContext = Design.read(in, null); - findElements(newContext); - checkHierarchy(newContext); + public void buttonWithIdAndLocalIdIsParsed() { + Component button = ctx.getComponentById("secondButton"); + + assertThat(ctx.getComponentByCaption("Another button"), is(button)); + assertThat(ctx.getComponentByLocalId("localID"), is(button)); + assertThat(button.getCaption(), is("Another button")); + } + + @Test + public void buttonWithoutIdsIsParsed() { + assertThat(ctx.getComponentByCaption("Yet another button"), + is(not(nullValue()))); + } + + @Test + public void serializationPreservesProperties() throws IOException { + ByteArrayOutputStream out = serializeDesign(ctx); + ctx = deSerializeDesign(out); + + assertButtonProperties(); + } + + @Test + public void serializationPreservesHierarchy() throws IOException { + ByteArrayOutputStream out = serializeDesign(ctx); + ctx = deSerializeDesign(out); + + assertComponentHierarchy(); + } + + @Test + public void designIsSerializedWithCorrectPrefixesAndPackageNames() + throws IOException { + ByteArrayOutputStream out = serializeDesign(ctx); + // Check the mapping from prefixes to package names using the html tree String[] expectedPrefixes = { "my" }; String[] expectedPackageNames = { "com.addon.mypackage" }; @@ -114,13 +133,26 @@ public class ParseLayoutTest extends TestCase { index); } - /* - * Check that the field binding works if root instance with member fields is - * passed to the LayoutHandler - * - * @throws IOException - */ - public void testFieldBinding() throws IOException { + private DesignContext deSerializeDesign(ByteArrayOutputStream out) { + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + return Design.read(in, null); + } + + private ByteArrayOutputStream serializeDesign(DesignContext context) throws IOException { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Design.write(context, out); + + return out; + } + + private void assertButtonProperties() { + buttonWithIdAndLocalIdIsParsed(); + buttonWithIdIsParsed(); + buttonWithoutIdsIsParsed(); + } + + @Test + public void fieldsAreBoundToATemplate() throws IOException { LayoutTemplate template = new LayoutTemplate(); InputStream htmlFile = new FileInputStream( "server/tests/src/com/vaadin/tests/design/testFile.html"); @@ -132,92 +164,59 @@ public class ParseLayoutTest extends TestCase { assertEquals("Native click me", template.getFirstButton().getCaption()); } - /* - * Check that the field binding fails if some of the fields in the root - * instance were not bound - * - * @throws IOException - */ - public void testUnboundFields() throws IOException { + @Test(expected = DesignException.class) + public void fieldsCannotBeBoundToAnInvalidTemplate() throws IOException { InvalidLayoutTemplate template = new InvalidLayoutTemplate(); InputStream htmlFile = new FileInputStream( "server/tests/src/com/vaadin/tests/design/testFile.html"); - try { - Design.read(htmlFile, template); - // we are expecting an exception - fail(); - } catch (DesignException e) { - // expected - } + + Design.read(htmlFile, template); } - /* - * Checks that the correct components occur in the correct order in the - * component hierarchy rooted at context.getComponentRoot(). - */ - private void checkHierarchy(DesignContext context) { - Component root = context.getRootComponent(); + @Test + public void rootHasCorrectComponents() { + Component root = ctx.getRootComponent(); + VerticalLayout vlayout = (VerticalLayout) root; - int numComponents = vlayout.getComponentCount(); - assertEquals("Wrong number of child components", 3, numComponents); - // Check the contents of the horizontal layout + assertThat(vlayout.getComponentCount(), is(3)); + } + + @Test + public void rootChildHasCorrectComponents() { + Component root = ctx.getRootComponent(); + VerticalLayout vlayout = (VerticalLayout) root; HorizontalLayout hlayout = (HorizontalLayout) vlayout.getComponent(0); - int numHLComponents = hlayout.getComponentCount(); - assertEquals(5, numHLComponents); - Label label = (Label) hlayout.getComponent(0); - assertEquals("Wrong caption.", "FooBar", label.getCaption()); - NativeButton nb = (NativeButton) hlayout.getComponent(1); - assertEquals("Wrong caption.", "Native click me", nb.getCaption()); - nb = (NativeButton) hlayout.getComponent(2); - assertEquals("Wrong caption.", "Another button", nb.getCaption()); - nb = (NativeButton) hlayout.getComponent(3); - assertEquals("Wrong caption.", "Yet another button", nb.getCaption()); - Button b = (Button) hlayout.getComponent(4); - assertEquals("Wrong caption.", "Click me", b.getCaption()); - assertEquals("Wrong width.", 150f, b.getWidth()); + + assertThat(hlayout.getComponentCount(), is(5)); + assertThat(hlayout.getComponent(0).getCaption(), is("FooBar")); + assertThat(hlayout.getComponent(1).getCaption(), is("Native click me")); + assertThat(hlayout.getComponent(2).getCaption(), is("Another button")); + assertThat(hlayout.getComponent(3).getCaption(), is("Yet another button")); + assertThat(hlayout.getComponent(4).getCaption(), is("Click me")); + assertThat(hlayout.getComponent(4).getWidth(), is(150f)); // Check the remaining two components of the vertical layout + assertTextField(vlayout); + assertTextArea(vlayout); + } + + private void assertComponentHierarchy() { + rootHasCorrectComponents(); + rootChildHasCorrectComponents(); + } + + private void assertTextField(VerticalLayout vlayout) { TextField tf = (TextField) vlayout.getComponent(1); - assertEquals("Wrong caption.", "Text input", tf.getCaption()); - TextArea ta = (TextArea) vlayout.getComponent(2); - assertEquals("Wrong caption.", "Text area", ta.getCaption()); - assertEquals("Wrong width.", 300f, ta.getWidth()); - assertEquals("Wrong height.", 200f, ta.getHeight()); - } - - /* - * Checks that the correct elements are found using a local id, a global id - * or a caption. - */ - private void findElements(DesignContext designContext) { - NativeButton firstButton = (NativeButton) designContext - .getComponentByLocalId("firstButton"); - NativeButton firstButton_2 = (NativeButton) designContext - .getComponentByCaption("Native click me"); - NativeButton secondButton = (NativeButton) designContext - .getComponentById("secondButton"); - NativeButton secondButton_2 = (NativeButton) designContext - .getComponentByLocalId("localID"); - NativeButton secondButton_3 = (NativeButton) designContext - .getComponentByCaption("Another button"); - NativeButton thirdButton = (NativeButton) designContext - .getComponentByCaption("Yet another button"); - // Check that the first button was found using both identifiers. - assertEquals("The found buttons should be identical but they are not.", - firstButton, firstButton_2); - assertTrue("The found button element is incorrect.", firstButton - .getCaption().equals("Native click me")); - // Check that the second button was found using all three identifiers. - assertEquals("The found buttons should be identical but they are not.", - secondButton, secondButton_2); - assertEquals("The found buttons should be identical but they are not.", - secondButton_2, secondButton_3); - assertTrue("The found button is incorrect.", secondButton.getCaption() - .equals("Another button")); - // Check that the third button was found by caption. - assertTrue("The found button is incorrect.", thirdButton.getCaption() - .equals("Yet another button")); + + assertThat(tf.getCaption(), is("Text input")); } + private void assertTextArea(VerticalLayout layout) { + TextArea ta = (TextArea) layout.getComponent(2); + + assertThat(ta.getCaption(), is("Text area")); + assertThat(ta.getWidth(), is(300f)); + assertThat(ta.getHeight(), is(200f)); + } } diff --git a/server/tests/src/com/vaadin/tests/design/TestLocale.java b/server/tests/src/com/vaadin/tests/design/TestLocale.java deleted file mode 100644 index a4100f7d71..0000000000 --- a/server/tests/src/com/vaadin/tests/design/TestLocale.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright 2000-2014 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.design; - -import java.io.ByteArrayInputStream; -import java.util.Locale; - -import junit.framework.TestCase; - -import org.jsoup.nodes.Document; -import org.jsoup.nodes.DocumentType; -import org.jsoup.nodes.Element; -import org.jsoup.nodes.Node; - -import com.vaadin.ui.Button; -import com.vaadin.ui.Component; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.Label; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.ui.declarative.Design; -import com.vaadin.ui.declarative.DesignContext; - -/** - * Tests the handling of the locale property in parsing and html generation. - * - * @since - * @author Vaadin Ltd - */ -public class TestLocale extends TestCase { - DesignContext ctx; - - @Override - public void setUp() { - ctx = new DesignContext(); - } - - /* - * Checks that when the html corresponding to a component hierarchy is - * constructed, the result only contains locale attributes for a component - * if its locale differs from that of its parent. - */ - public void testHtmlGeneration() { - // create a component hierarchy - VerticalLayout vLayout = new VerticalLayout(); - vLayout.setLocale(Locale.US); - HorizontalLayout hLayout = new HorizontalLayout(); - hLayout.setLocale(Locale.ITALY); - vLayout.addComponent(hLayout); - Button b1 = new Button(); - b1.setLocale(Locale.ITALY); - Button b2 = new Button(); - b2.setLocale(Locale.US); - hLayout.addComponent(b1); - hLayout.addComponent(b2); - HorizontalLayout hlayout2 = new HorizontalLayout(); - hlayout2.setLocale(Locale.US); - vLayout.addComponent(hlayout2); - Label l = new Label(); - l.setLocale(Locale.US); - hlayout2.addComponent(l); - Label l2 = new Label(); - l2.setLocale(Locale.CANADA); - hlayout2.addComponent(l2); - ctx.setRootComponent(vLayout); - // create the html tree corresponding to the component hierarchy - Document doc = componentToDoc(ctx); - // check the created html - Element body = doc.body(); - Element evLayout = body.child(0); - assertEquals("Wrong locale information.", "en_US", - evLayout.attr("locale")); - Element ehLayout = evLayout.child(0); - assertEquals("Wrong locale information.", "it_IT", - ehLayout.attr("locale")); - Element eb1 = ehLayout.child(0); - assertTrue( - "The element should not have a locale specification, found locale " - + eb1.attr("locale"), "".equals(eb1.attr("locale"))); - Element eb2 = ehLayout.child(1); - assertEquals("Wrong locale information.", "en_US", eb2.attr("locale")); - Element ehLayout2 = evLayout.child(1); - assertTrue( - "The element should not have a locale specification, found locale " - + ehLayout2.attr("locale"), - "".equals(ehLayout2.attr("locale"))); - Element el1 = ehLayout2.child(0); - assertTrue( - "The element should not have a locale specification, found locale " - + el1.attr("locale"), "".equals(el1.attr("locale"))); - Element el2 = ehLayout2.child(1); - assertEquals("Wrong locale information.", "en_CA", el2.attr("locale")); - } - - private Document componentToDoc(DesignContext dc) { - // Create the html tree skeleton. - Document doc = new Document(""); - DocumentType docType = new DocumentType("html", "", "", ""); - doc.appendChild(docType); - Element html = doc.createElement("html"); - doc.appendChild(html); - html.appendChild(doc.createElement("head")); - Element body = doc.createElement("body"); - html.appendChild(body); - dc.writePackageMappings(doc); - - // Append the design under in the html tree. createNode - // creates the entire component hierarchy rooted at the - // given root node. - Component root = dc.getRootComponent(); - Node rootNode = dc.createElement(root); - body.appendChild(rootNode); - return doc; - - } - - /* - * Checks that the locale of a component is set when the html element - * corresponding to the component specifies a locale. - */ - public void testParsing() { - // create an html document - Document doc = new Document(""); - DocumentType docType = new DocumentType("html", "", "", ""); - doc.appendChild(docType); - Element html = doc.createElement("html"); - doc.appendChild(html); - html.appendChild(doc.createElement("head")); - Element body = doc.createElement("body"); - html.appendChild(body); - Element evLayout = doc.createElement("v-vertical-layout"); - evLayout.attr("locale", "en_US"); - body.appendChild(evLayout); - Element ehLayout = doc.createElement("v-horizontal-layout"); - evLayout.appendChild(ehLayout); - Element eb1 = doc.createElement("v-button"); - eb1.attr("locale", "en_US"); - ehLayout.appendChild(eb1); - Element eb2 = doc.createElement("v-button"); - eb2.attr("locale", "en_GB"); - ehLayout.appendChild(eb2); - Element eb3 = doc.createElement("v-button"); - ehLayout.appendChild(eb3); - - // parse the created document and check the constructed component - // hierarchy - String string = doc.html(); - VerticalLayout vLayout = (VerticalLayout) Design - .read(new ByteArrayInputStream(string.getBytes())); - assertEquals("Wrong locale.", new Locale("en", "US"), - vLayout.getLocale()); - HorizontalLayout hLayout = (HorizontalLayout) vLayout.getComponent(0); - assertEquals("The element should have the same locale as its parent.", - vLayout.getLocale(), hLayout.getLocale()); - Button b1 = (Button) hLayout.getComponent(0); - assertEquals("Wrong locale.", new Locale("en", "US"), b1.getLocale()); - Button b2 = (Button) hLayout.getComponent(1); - assertEquals("Wrong locale.", new Locale("en", "GB"), b2.getLocale()); - Button b3 = (Button) hLayout.getComponent(2); - assertEquals( - "The component should have the same locale as its parent.", - hLayout.getLocale(), b3.getLocale()); - } -} \ No newline at end of file diff --git a/server/tests/src/com/vaadin/tests/design/designroot/DesignWithAnnotation.java b/server/tests/src/com/vaadin/tests/design/designroot/DesignWithAnnotation.java index 70809cb694..ef9de9dcb0 100644 --- a/server/tests/src/com/vaadin/tests/design/designroot/DesignWithAnnotation.java +++ b/server/tests/src/com/vaadin/tests/design/designroot/DesignWithAnnotation.java @@ -15,8 +15,6 @@ */ package com.vaadin.tests.design.designroot; -import org.junit.Ignore; - import com.vaadin.annotations.DesignRoot; import com.vaadin.ui.Button; import com.vaadin.ui.Label; @@ -24,7 +22,6 @@ import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.declarative.Design; @DesignRoot("DesignWithEmptyAnnotation.html") -@Ignore public class DesignWithAnnotation extends VerticalLayout { public Button ok; diff --git a/server/tests/src/com/vaadin/tests/design/designroot/DesignWithEmptyAnnotation.java b/server/tests/src/com/vaadin/tests/design/designroot/DesignWithEmptyAnnotation.java index f6fb928e75..55fd571ee2 100644 --- a/server/tests/src/com/vaadin/tests/design/designroot/DesignWithEmptyAnnotation.java +++ b/server/tests/src/com/vaadin/tests/design/designroot/DesignWithEmptyAnnotation.java @@ -15,8 +15,6 @@ */ package com.vaadin.tests.design.designroot; -import org.junit.Ignore; - import com.vaadin.annotations.DesignRoot; import com.vaadin.ui.Button; import com.vaadin.ui.Label; @@ -24,7 +22,6 @@ import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.declarative.Design; @DesignRoot -@Ignore public class DesignWithEmptyAnnotation extends VerticalLayout { protected Button ok; diff --git a/server/tests/src/com/vaadin/tests/design/designroot/ExtendedDesignWithAnnotation.java b/server/tests/src/com/vaadin/tests/design/designroot/ExtendedDesignWithAnnotation.java index 14e4269e80..d47b4540df 100644 --- a/server/tests/src/com/vaadin/tests/design/designroot/ExtendedDesignWithAnnotation.java +++ b/server/tests/src/com/vaadin/tests/design/designroot/ExtendedDesignWithAnnotation.java @@ -15,11 +15,8 @@ */ package com.vaadin.tests.design.designroot; -import org.junit.Ignore; - import com.vaadin.ui.TextField; -@Ignore public class ExtendedDesignWithAnnotation extends DesignWithAnnotation { private TextField customField = new TextField(); diff --git a/server/tests/src/com/vaadin/tests/design/designroot/ExtendedDesignWithEmptyAnnotation.java b/server/tests/src/com/vaadin/tests/design/designroot/ExtendedDesignWithEmptyAnnotation.java index 22865b098c..ea513f6d3e 100644 --- a/server/tests/src/com/vaadin/tests/design/designroot/ExtendedDesignWithEmptyAnnotation.java +++ b/server/tests/src/com/vaadin/tests/design/designroot/ExtendedDesignWithEmptyAnnotation.java @@ -15,14 +15,11 @@ */ package com.vaadin.tests.design.designroot; -import org.junit.Ignore; - import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.Notification; import com.vaadin.ui.TextField; -@Ignore public class ExtendedDesignWithEmptyAnnotation extends DesignWithEmptyAnnotation { diff --git a/server/tests/src/com/vaadin/tests/design/designroot/ExtendedDesignWithEmptyAnnotationUI.java b/server/tests/src/com/vaadin/tests/design/designroot/ExtendedDesignWithEmptyAnnotationUI.java index 34f517d25d..1d0e8de4eb 100644 --- a/server/tests/src/com/vaadin/tests/design/designroot/ExtendedDesignWithEmptyAnnotationUI.java +++ b/server/tests/src/com/vaadin/tests/design/designroot/ExtendedDesignWithEmptyAnnotationUI.java @@ -15,12 +15,9 @@ */ package com.vaadin.tests.design.designroot; -import org.junit.Ignore; - import com.vaadin.server.VaadinRequest; import com.vaadin.ui.UI; -@Ignore public class ExtendedDesignWithEmptyAnnotationUI extends UI { @Override diff --git a/server/tests/src/com/vaadin/tests/design/nested/MyChildDesign.java b/server/tests/src/com/vaadin/tests/design/nested/MyChildDesign.java index e85c0aca5f..3b0d80c32c 100644 --- a/server/tests/src/com/vaadin/tests/design/nested/MyChildDesign.java +++ b/server/tests/src/com/vaadin/tests/design/nested/MyChildDesign.java @@ -15,8 +15,6 @@ */ package com.vaadin.tests.design.nested; -import org.junit.Ignore; - import com.vaadin.annotations.DesignRoot; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Label; @@ -27,7 +25,6 @@ import com.vaadin.ui.declarative.Design; * * @author Vaadin Ltd */ -@Ignore @DesignRoot("mychilddesign.html") public class MyChildDesign extends HorizontalLayout { public Label childLabel; diff --git a/server/tests/src/com/vaadin/tests/design/nested/MyChildDesignCustomComponent.java b/server/tests/src/com/vaadin/tests/design/nested/MyChildDesignCustomComponent.java index 94e34baea2..8402224cf9 100644 --- a/server/tests/src/com/vaadin/tests/design/nested/MyChildDesignCustomComponent.java +++ b/server/tests/src/com/vaadin/tests/design/nested/MyChildDesignCustomComponent.java @@ -15,11 +15,8 @@ */ package com.vaadin.tests.design.nested; -import org.junit.Ignore; - import com.vaadin.ui.Button; -@Ignore public class MyChildDesignCustomComponent extends Button { } diff --git a/server/tests/src/com/vaadin/tests/design/nested/MyDesignRoot.java b/server/tests/src/com/vaadin/tests/design/nested/MyDesignRoot.java index 5727322ce3..abde002ef8 100644 --- a/server/tests/src/com/vaadin/tests/design/nested/MyDesignRoot.java +++ b/server/tests/src/com/vaadin/tests/design/nested/MyDesignRoot.java @@ -15,8 +15,6 @@ */ package com.vaadin.tests.design.nested; -import org.junit.Ignore; - import com.vaadin.annotations.DesignRoot; import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.declarative.Design; @@ -26,7 +24,6 @@ import com.vaadin.ui.declarative.Design; * * @author Vaadin Ltd */ -@Ignore @DesignRoot("mydesignroot.html") public class MyDesignRoot extends VerticalLayout { // should be assigned automatically diff --git a/server/tests/src/com/vaadin/tests/design/nested/MyExtendedChildDesign.java b/server/tests/src/com/vaadin/tests/design/nested/MyExtendedChildDesign.java index 2012e4ec14..579fdfb869 100644 --- a/server/tests/src/com/vaadin/tests/design/nested/MyExtendedChildDesign.java +++ b/server/tests/src/com/vaadin/tests/design/nested/MyExtendedChildDesign.java @@ -15,9 +15,6 @@ */ package com.vaadin.tests.design.nested; -import org.junit.Ignore; - -@Ignore public class MyExtendedChildDesign extends MyChildDesign { public MyExtendedChildDesign() { super(); diff --git a/server/tests/src/com/vaadin/tests/design/nested/NestedCustomLayoutsTest.java b/server/tests/src/com/vaadin/tests/design/nested/NestedCustomLayoutsTest.java new file mode 100644 index 0000000000..beaa9519cb --- /dev/null +++ b/server/tests/src/com/vaadin/tests/design/nested/NestedCustomLayoutsTest.java @@ -0,0 +1,82 @@ +/* + * Copyright 2000-2014 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.design.nested; + +import com.vaadin.tests.design.nested.customlayouts.*; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.declarative.Design; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.junit.Test; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.greaterThan; + +/** + * Test case for nested custom layouts. The children of the custom layouts must + * not be rendered. + * + * @author Vaadin Ltd + */ +public class NestedCustomLayoutsTest { + + private static String PACKAGE_MAPPING = "com_vaadin_tests_design_nested_customlayouts:com.vaadin.tests.design.nested.customlayouts"; + + @Test + public void testNestedLayouts() throws IOException { + VerticalLayout rootLayout = createRootLayout(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + + Design.write(rootLayout, out); + Document doc = Jsoup.parse(out.toString("UTF-8")); + + assertThat(doc.head().child(0).attr("name"), is("package-mapping")); + assertThat(doc.head().child(0).attr("content"), is(PACKAGE_MAPPING)); + assertChildrenCount(doc); + } + + private VerticalLayout createRootLayout() { + VerticalLayout rootLayout = new VerticalLayout(); + rootLayout.addComponent(new CustomAbsoluteLayout()); + rootLayout.addComponent(new CustomAccordion()); + rootLayout.addComponent(new CustomCssLayout()); + rootLayout.addComponent(new CustomFormLayout()); + rootLayout.addComponent(new CustomGridLayout()); + rootLayout.addComponent(new CustomHorizontalLayout()); + rootLayout.addComponent(new CustomHorizontalSplitPanel()); + rootLayout.addComponent(new CustomPanel()); + rootLayout.addComponent(new CustomTabSheet()); + rootLayout.addComponent(new CustomVerticalLayout()); + rootLayout.addComponent(new CustomVerticalSplitPanel()); + + return rootLayout; + } + + private void assertChildrenCount(Document doc) { + Element rootNode = doc.body().child(0); + assertThat(rootNode.children().size(), greaterThan(0)); + + for (Element child : rootNode.children()) { + // make sure that the nested custom layouts do not render children + assertThat(child.children().size(), is(0)); + } + } +} diff --git a/server/tests/src/com/vaadin/tests/design/nested/ReadNestedTemplatesTest.java b/server/tests/src/com/vaadin/tests/design/nested/ReadNestedTemplatesTest.java new file mode 100644 index 0000000000..dc95306cd3 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/design/nested/ReadNestedTemplatesTest.java @@ -0,0 +1,71 @@ +/* + * Copyright 2000-2014 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.design.nested; + +import org.junit.Before; +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.core.IsNot.not; +import static org.junit.Assert.*; + +/** + * Test case for reading nested templates + * + * @since + * @author Vaadin Ltd + */ +public class ReadNestedTemplatesTest { + + private MyDesignRoot root; + + @Before + public void setUp() { + root = new MyDesignRoot(); + } + + @Test + public void rootContainsOneChild() { + assertThat(root.getComponentCount(), is(1)); + assertThat(root.iterator().next(), + instanceOf(MyExtendedChildDesign.class)); + } + + @Test + public void rootContainsTwoGrandChildren() { + assertThat(root.childDesign.getComponentCount(), is(2)); + } + + @Test + public void childComponentIsNotNull() { + assertThat(root.childDesign, is(not(nullValue()))); + } + + @Test + public void childLabelIsNotNull() { + assertThat(root.childDesign.childLabel, is(not(nullValue()))); + assertThat(root.childDesign.childLabel.getValue(), is("test content")); + } + + @Test + public void childCustomComponentsIsNotNull() { + assertThat(root.childDesign.childCustomComponent, is(not(nullValue()))); + assertThat(root.childDesign.childCustomComponent.getCaption(), + is("custom content")); + } +} diff --git a/server/tests/src/com/vaadin/tests/design/nested/TestNestedCustomLayouts.java b/server/tests/src/com/vaadin/tests/design/nested/TestNestedCustomLayouts.java deleted file mode 100644 index c71ccca85b..0000000000 --- a/server/tests/src/com/vaadin/tests/design/nested/TestNestedCustomLayouts.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2000-2014 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.design.nested; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; - -import junit.framework.TestCase; - -import org.jsoup.Jsoup; -import org.jsoup.nodes.Document; -import org.jsoup.nodes.Element; -import org.junit.Test; - -import com.vaadin.tests.design.nested.customlayouts.CustomAbsoluteLayout; -import com.vaadin.tests.design.nested.customlayouts.CustomAccordion; -import com.vaadin.tests.design.nested.customlayouts.CustomCssLayout; -import com.vaadin.tests.design.nested.customlayouts.CustomFormLayout; -import com.vaadin.tests.design.nested.customlayouts.CustomGridLayout; -import com.vaadin.tests.design.nested.customlayouts.CustomHorizontalLayout; -import com.vaadin.tests.design.nested.customlayouts.CustomHorizontalSplitPanel; -import com.vaadin.tests.design.nested.customlayouts.CustomPanel; -import com.vaadin.tests.design.nested.customlayouts.CustomTabSheet; -import com.vaadin.tests.design.nested.customlayouts.CustomVerticalLayout; -import com.vaadin.tests.design.nested.customlayouts.CustomVerticalSplitPanel; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.ui.declarative.Design; - -/** - * Test case for nested custom layouts. The children of the custom layouts must - * not be rendered. - * - * @author Vaadin Ltd - */ -public class TestNestedCustomLayouts extends TestCase { - - private static String PACKAGE_MAPPING = "com_vaadin_tests_design_nested_customlayouts:com.vaadin.tests.design.nested.customlayouts"; - - @Test - public void testNestedLayouts() throws IOException { - VerticalLayout rootLayout = new VerticalLayout(); - rootLayout.addComponent(new CustomAbsoluteLayout()); - rootLayout.addComponent(new CustomAccordion()); - rootLayout.addComponent(new CustomCssLayout()); - rootLayout.addComponent(new CustomFormLayout()); - rootLayout.addComponent(new CustomGridLayout()); - rootLayout.addComponent(new CustomHorizontalLayout()); - rootLayout.addComponent(new CustomHorizontalSplitPanel()); - rootLayout.addComponent(new CustomPanel()); - rootLayout.addComponent(new CustomTabSheet()); - rootLayout.addComponent(new CustomVerticalLayout()); - rootLayout.addComponent(new CustomVerticalSplitPanel()); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - Design.write(rootLayout, out); - Document doc = Jsoup.parse(out.toString("UTF-8")); - assertEquals("package-mapping", doc.head().child(0).attr("name")); - assertEquals(PACKAGE_MAPPING, doc.head().child(0).attr("content")); - Element rootNode = doc.body().child(0); - assertTrue("Root node must have children", - rootNode.children().size() > 0); - for (Element child : rootNode.children()) { - // make sure that the nested custom layouts do not render children - assertEquals("Child nodes must not have children", 0, child - .children().size()); - } - } -} diff --git a/server/tests/src/com/vaadin/tests/design/nested/TestReadNestedTemplates.java b/server/tests/src/com/vaadin/tests/design/nested/TestReadNestedTemplates.java deleted file mode 100644 index c1483adc8a..0000000000 --- a/server/tests/src/com/vaadin/tests/design/nested/TestReadNestedTemplates.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2000-2014 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.design.nested; - -import junit.framework.TestCase; - -/** - * Test case for reading nested templates - * - * @since - * @author Vaadin Ltd - */ -public class TestReadNestedTemplates extends TestCase { - - private MyDesignRoot root; - - @Override - protected void setUp() throws Exception { - super.setUp(); - root = new MyDesignRoot(); - } - - public void testChildren() { - assertEquals("The root layout must contain one child", 1, - root.getComponentCount()); - assertTrue(root.iterator().next() instanceof MyExtendedChildDesign); - } - - public void testGrandChildren() { - assertEquals("The root layout must have two grandchildren", 2, - root.childDesign.getComponentCount()); - } - - public void testRootComponentFields() { - assertNotNull("The child component must not be null", root.childDesign); - } - - public void testChildComponentFields() { - assertNotNull("Grandchildren must not be null", - root.childDesign.childLabel); - assertNotNull("Grandchildren must not be null", - root.childDesign.childCustomComponent); - assertEquals("child label caption must be read", "test content", - root.childDesign.childLabel.getValue()); - assertEquals("child custom component caption must be read", - "custom content", - root.childDesign.childCustomComponent.getCaption()); - } -} diff --git a/server/tests/src/com/vaadin/tests/design/nested/TestWriteNestedTemplates.java b/server/tests/src/com/vaadin/tests/design/nested/TestWriteNestedTemplates.java deleted file mode 100644 index 7fe63baa73..0000000000 --- a/server/tests/src/com/vaadin/tests/design/nested/TestWriteNestedTemplates.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2000-2014 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.design.nested; - -import junit.framework.TestCase; - -import org.jsoup.nodes.Attributes; -import org.jsoup.nodes.Element; -import org.jsoup.parser.Tag; - -import com.vaadin.ui.declarative.DesignContext; - -/** - * - * Test case for writing nested templates - * - * @author Vaadin Ltd - */ -public class TestWriteNestedTemplates extends TestCase { - - private MyDesignRoot root; - private Element design; - - @Override - protected void setUp() throws Exception { - super.setUp(); - root = new MyDesignRoot(); - design = createDesign(); - DesignContext designContext = new DesignContext(); - designContext.setRootComponent(root); - root.writeDesign(design, designContext); - } - - public void testChildRendered() { - assertEquals("Root layout must have one child", 1, design.children() - .size()); - assertEquals("com_vaadin_tests_design_nested-my-extended-child-design", - design.child(0).tagName()); - } - - public void testRootCaptionWritten() { - assertTrue("Root layout caption must be written", - design.hasAttr("caption")); - assertEquals("Root layout caption must be written", "root caption", - design.attr("caption")); - } - - public void testChildCaptionWritten() { - assertTrue("Child design caption must be written", design.child(0) - .hasAttr("caption")); - assertEquals("Child design caption must be written", "child caption", - design.child(0).attr("caption")); - } - - // The default caption is read from child template - public void testDefaultCaptionShouldNotBeWritten() { - design = createDesign(); - root.childDesign.setCaption("Default caption for child design"); - DesignContext designContext = new DesignContext(); - designContext.setRootComponent(root); - root.writeDesign(design, designContext); - assertFalse("Default caption must not be written", design.child(0) - .hasAttr("caption")); - } - - public void testChildDesignChildrenNotWrittenInRootTemplate() { - assertEquals( - "Children of the child template must not be written to root template", - 0, design.child(0).children().size()); - } - - private Element createDesign() { - return new Element(Tag.valueOf("v-vertical-layout"), "", - new Attributes()); - } -} diff --git a/server/tests/src/com/vaadin/tests/design/nested/WriteNestedTemplatesTest.java b/server/tests/src/com/vaadin/tests/design/nested/WriteNestedTemplatesTest.java new file mode 100644 index 0000000000..344cd94ac2 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/design/nested/WriteNestedTemplatesTest.java @@ -0,0 +1,89 @@ +/* + * Copyright 2000-2014 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.design.nested; + +import com.vaadin.ui.declarative.DesignContext; +import org.jsoup.nodes.Attributes; +import org.jsoup.nodes.Element; +import org.jsoup.parser.Tag; +import org.junit.Before; +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.*; + +/** + * + * Test case for writing nested templates + * + * @author Vaadin Ltd + */ +public class WriteNestedTemplatesTest { + + private MyDesignRoot root; + private Element design; + + @Before + public void setUp() { + root = new MyDesignRoot(); + design = createDesign(); + } + + private Element createDesign() { + Element design = new Element(Tag.valueOf("v-vertical-layout"), "", + new Attributes()); + + DesignContext designContext = new DesignContext(); + designContext.setRootComponent(root); + root.writeDesign(design, designContext); + + return design; + } + + @Test + public void testChildRendered() { + assertEquals("Root layout must have one child", 1, design.children() + .size()); + assertEquals("com_vaadin_tests_design_nested-my-extended-child-design", + design.child(0).tagName()); + } + + @Test + public void rootCaptionIsWritten() { + assertTrue(design.hasAttr("caption")); + assertThat(design.attr("caption"), is("root caption")); + } + + @Test + public void childCaptionIsWritten() { + assertTrue(design.child(0).hasAttr("caption")); + assertThat(design.child(0).attr("caption"), is("child caption")); + } + + // The default caption is read from child template + @Test + public void defaultCaptionIsNotOverwritten() { + root.childDesign.setCaption("Default caption for child design"); + design = createDesign(); + + assertFalse(design.child(0).hasAttr("caption")); + } + + @Test + public void childDesignChildrenIsNotWrittenInRootTemplate() { + assertThat(design.child(0).children().size(), is(0)); + } +} diff --git a/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomAbsoluteLayout.java b/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomAbsoluteLayout.java index ed2b27215e..8eef3b07a6 100644 --- a/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomAbsoluteLayout.java +++ b/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomAbsoluteLayout.java @@ -15,15 +15,12 @@ */ package com.vaadin.tests.design.nested.customlayouts; -import org.junit.Ignore; - import com.vaadin.ui.AbsoluteLayout; import com.vaadin.ui.Label; /** * @author Vaadin Ltd */ -@Ignore public class CustomAbsoluteLayout extends AbsoluteLayout { public CustomAbsoluteLayout() { this.addComponent(new Label()); diff --git a/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomAccordion.java b/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomAccordion.java index 7d45917520..93606f296c 100644 --- a/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomAccordion.java +++ b/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomAccordion.java @@ -15,15 +15,12 @@ */ package com.vaadin.tests.design.nested.customlayouts; -import org.junit.Ignore; - import com.vaadin.ui.Accordion; import com.vaadin.ui.Label; /** * @author Vaadin Ltd */ -@Ignore public class CustomAccordion extends Accordion { public CustomAccordion() { addComponent(new Label()); diff --git a/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomCssLayout.java b/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomCssLayout.java index 328a025e01..b2aaa2c015 100644 --- a/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomCssLayout.java +++ b/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomCssLayout.java @@ -15,15 +15,12 @@ */ package com.vaadin.tests.design.nested.customlayouts; -import org.junit.Ignore; - import com.vaadin.ui.CssLayout; import com.vaadin.ui.Label; /** * @author Vaadin Ltd */ -@Ignore public class CustomCssLayout extends CssLayout { public CustomCssLayout() { this.addComponent(new Label()); diff --git a/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomFormLayout.java b/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomFormLayout.java index 179b195926..66ac083c0d 100644 --- a/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomFormLayout.java +++ b/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomFormLayout.java @@ -15,15 +15,12 @@ */ package com.vaadin.tests.design.nested.customlayouts; -import org.junit.Ignore; - import com.vaadin.ui.FormLayout; import com.vaadin.ui.Label; /** * @author Vaadin Ltd */ -@Ignore public class CustomFormLayout extends FormLayout { public CustomFormLayout() { this.addComponent(new Label()); diff --git a/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomGridLayout.java b/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomGridLayout.java index 0b3b90ca1f..1059ea0e14 100644 --- a/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomGridLayout.java +++ b/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomGridLayout.java @@ -15,15 +15,12 @@ */ package com.vaadin.tests.design.nested.customlayouts; -import org.junit.Ignore; - import com.vaadin.ui.GridLayout; import com.vaadin.ui.Label; /** * @author Vaadin Ltd */ -@Ignore public class CustomGridLayout extends GridLayout { public CustomGridLayout() { this.addComponent(new Label()); diff --git a/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomHorizontalLayout.java b/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomHorizontalLayout.java index b742f7c629..482a9feb95 100644 --- a/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomHorizontalLayout.java +++ b/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomHorizontalLayout.java @@ -15,15 +15,12 @@ */ package com.vaadin.tests.design.nested.customlayouts; -import org.junit.Ignore; - import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Label; /** * @author Vaadin Ltd */ -@Ignore public class CustomHorizontalLayout extends HorizontalLayout { public CustomHorizontalLayout() { this.addComponent(new Label()); diff --git a/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomHorizontalSplitPanel.java b/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomHorizontalSplitPanel.java index deeb311858..21c8745796 100644 --- a/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomHorizontalSplitPanel.java +++ b/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomHorizontalSplitPanel.java @@ -15,15 +15,12 @@ */ package com.vaadin.tests.design.nested.customlayouts; -import org.junit.Ignore; - import com.vaadin.ui.HorizontalSplitPanel; import com.vaadin.ui.Label; /** * @author Vaadin Ltd */ -@Ignore public class CustomHorizontalSplitPanel extends HorizontalSplitPanel { public CustomHorizontalSplitPanel() { addComponent(new Label()); diff --git a/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomPanel.java b/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomPanel.java index fa7827bdfd..5841fbcfee 100644 --- a/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomPanel.java +++ b/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomPanel.java @@ -15,15 +15,12 @@ */ package com.vaadin.tests.design.nested.customlayouts; -import org.junit.Ignore; - import com.vaadin.ui.Label; import com.vaadin.ui.Panel; /** * @author Vaadin Ltd */ -@Ignore public class CustomPanel extends Panel { public CustomPanel() { setContent(new Label()); diff --git a/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomTabSheet.java b/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomTabSheet.java index 6298b67727..128de7de1f 100644 --- a/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomTabSheet.java +++ b/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomTabSheet.java @@ -15,15 +15,12 @@ */ package com.vaadin.tests.design.nested.customlayouts; -import org.junit.Ignore; - import com.vaadin.ui.Label; import com.vaadin.ui.TabSheet; /** * @author Vaadin Ltd */ -@Ignore public class CustomTabSheet extends TabSheet { public CustomTabSheet() { addComponent(new Label()); diff --git a/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomVerticalLayout.java b/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomVerticalLayout.java index 7859ae0227..3bc8fba7de 100644 --- a/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomVerticalLayout.java +++ b/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomVerticalLayout.java @@ -15,15 +15,12 @@ */ package com.vaadin.tests.design.nested.customlayouts; -import org.junit.Ignore; - import com.vaadin.ui.Label; import com.vaadin.ui.VerticalLayout; /** * @author Vaadin Ltd */ -@Ignore public class CustomVerticalLayout extends VerticalLayout { public CustomVerticalLayout() { this.addComponent(new Label()); diff --git a/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomVerticalSplitPanel.java b/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomVerticalSplitPanel.java index f6eb460c1b..486d71ea75 100644 --- a/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomVerticalSplitPanel.java +++ b/server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomVerticalSplitPanel.java @@ -15,15 +15,12 @@ */ package com.vaadin.tests.design.nested.customlayouts; -import org.junit.Ignore; - import com.vaadin.ui.Label; import com.vaadin.ui.VerticalSplitPanel; /** * @author Vaadin Ltd */ -@Ignore public class CustomVerticalSplitPanel extends VerticalSplitPanel { public CustomVerticalSplitPanel() { addComponent(new Label()); -- cgit v1.2.3