]> source.dussan.org Git - vaadin-framework.git/commitdiff
Refactor server unit tests.
authorSauli Tähkäpää <sauli@vaadin.com>
Fri, 2 Jan 2015 11:56:15 +0000 (13:56 +0200)
committerVaadin Code Review <review@vaadin.com>
Fri, 9 Jan 2015 13:35:01 +0000 (13:35 +0000)
- Renamed tests to *Test and *TestBase.
- Removed obsolete @Ignore annotations.
- Split some design tests into smaller ones.

Change-Id: I8e2a7d73ef620e584777c1e8e701917c0f69f876

42 files changed:
server/ivy.xml
server/tests/src/com/vaadin/server/VaadinGateInRequestTest.java [new file with mode: 0644]
server/tests/src/com/vaadin/server/VaadinGateInRequestTests.java [deleted file]
server/tests/src/com/vaadin/server/VaadinHttpAndPortletRequestTestBase.java [new file with mode: 0644]
server/tests/src/com/vaadin/server/VaadinHttpAndPortletRequestTests.java [deleted file]
server/tests/src/com/vaadin/server/VaadinLiferayRequestTest.java [new file with mode: 0644]
server/tests/src/com/vaadin/server/VaadinLiferayRequestTests.java [deleted file]
server/tests/src/com/vaadin/server/VaadinWebSpherePortalRequestTest.java [new file with mode: 0644]
server/tests/src/com/vaadin/server/VaadinWebSpherePortalRequestTests.java [deleted file]
server/tests/src/com/vaadin/tests/design/DesignReadInConstructor.java
server/tests/src/com/vaadin/tests/design/InvalidLayoutTemplate.java
server/tests/src/com/vaadin/tests/design/LayoutTemplate.java
server/tests/src/com/vaadin/tests/design/LocaleTest.java [new file with mode: 0644]
server/tests/src/com/vaadin/tests/design/ParseAllSupportedComponentsTest.java
server/tests/src/com/vaadin/tests/design/ParseLayoutTest.java
server/tests/src/com/vaadin/tests/design/TestLocale.java [deleted file]
server/tests/src/com/vaadin/tests/design/designroot/DesignWithAnnotation.java
server/tests/src/com/vaadin/tests/design/designroot/DesignWithEmptyAnnotation.java
server/tests/src/com/vaadin/tests/design/designroot/ExtendedDesignWithAnnotation.java
server/tests/src/com/vaadin/tests/design/designroot/ExtendedDesignWithEmptyAnnotation.java
server/tests/src/com/vaadin/tests/design/designroot/ExtendedDesignWithEmptyAnnotationUI.java
server/tests/src/com/vaadin/tests/design/nested/MyChildDesign.java
server/tests/src/com/vaadin/tests/design/nested/MyChildDesignCustomComponent.java
server/tests/src/com/vaadin/tests/design/nested/MyDesignRoot.java
server/tests/src/com/vaadin/tests/design/nested/MyExtendedChildDesign.java
server/tests/src/com/vaadin/tests/design/nested/NestedCustomLayoutsTest.java [new file with mode: 0644]
server/tests/src/com/vaadin/tests/design/nested/ReadNestedTemplatesTest.java [new file with mode: 0644]
server/tests/src/com/vaadin/tests/design/nested/TestNestedCustomLayouts.java [deleted file]
server/tests/src/com/vaadin/tests/design/nested/TestReadNestedTemplates.java [deleted file]
server/tests/src/com/vaadin/tests/design/nested/TestWriteNestedTemplates.java [deleted file]
server/tests/src/com/vaadin/tests/design/nested/WriteNestedTemplatesTest.java [new file with mode: 0644]
server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomAbsoluteLayout.java
server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomAccordion.java
server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomCssLayout.java
server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomFormLayout.java
server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomGridLayout.java
server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomHorizontalLayout.java
server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomHorizontalSplitPanel.java
server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomPanel.java
server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomTabSheet.java
server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomVerticalLayout.java
server/tests/src/com/vaadin/tests/design/nested/customlayouts/CustomVerticalSplitPanel.java

index 2901be80903fbb20a63a5057bd64f2298f938b08..b30e6a72ef1f4419bd9fe09ffb71cea9f65c3795 100644 (file)
@@ -70,6 +70,8 @@
             conf="test,ide -> default" />
         <dependency org="org.mockito" name="mockito-all" rev="1.9.5"
             conf="test,ide->default" />
+        <dependency org="org.hamcrest" name="hamcrest-all" rev="1.3"
+                    conf="test,ide->default" />
         <dependency org="org.easymock" name="easymock" rev="3.0"
             conf="test,ide-> default" transitive="true" />
         <dependency org="org.hsqldb" name="hsqldb" rev="2.2.6"
diff --git a/server/tests/src/com/vaadin/server/VaadinGateInRequestTest.java b/server/tests/src/com/vaadin/server/VaadinGateInRequestTest.java
new file mode 100644 (file)
index 0000000..eda2b3a
--- /dev/null
@@ -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.VaadinGateInRequest;
+
+public class VaadinGateInRequestTest extends
+        VaadinHttpAndPortletRequestTestBase<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/VaadinGateInRequestTests.java b/server/tests/src/com/vaadin/server/VaadinGateInRequestTests.java
deleted file mode 100644 (file)
index 4478b4c..0000000
+++ /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<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/VaadinHttpAndPortletRequestTestBase.java b/server/tests/src/com/vaadin/server/VaadinHttpAndPortletRequestTestBase.java
new file mode 100644 (file)
index 0000000..0f7cce5
--- /dev/null
@@ -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<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/VaadinHttpAndPortletRequestTests.java b/server/tests/src/com/vaadin/server/VaadinHttpAndPortletRequestTests.java
deleted file mode 100644 (file)
index a87eb18..0000000
+++ /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<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/VaadinLiferayRequestTest.java b/server/tests/src/com/vaadin/server/VaadinLiferayRequestTest.java
new file mode 100644 (file)
index 0000000..3024cd6
--- /dev/null
@@ -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<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;
+    }
+}
diff --git a/server/tests/src/com/vaadin/server/VaadinLiferayRequestTests.java b/server/tests/src/com/vaadin/server/VaadinLiferayRequestTests.java
deleted file mode 100644 (file)
index 8ccd649..0000000
+++ /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<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;
-    }
-}
diff --git a/server/tests/src/com/vaadin/server/VaadinWebSpherePortalRequestTest.java b/server/tests/src/com/vaadin/server/VaadinWebSpherePortalRequestTest.java
new file mode 100644 (file)
index 0000000..3a4c5c6
--- /dev/null
@@ -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<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;
+    }
+}
diff --git a/server/tests/src/com/vaadin/server/VaadinWebSpherePortalRequestTests.java b/server/tests/src/com/vaadin/server/VaadinWebSpherePortalRequestTests.java
deleted file mode 100644 (file)
index a1abfbd..0000000
+++ /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<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;
-    }
-}
index ce80d98324f85d07b1099ae261da3c05929cdf6e..6eccaf6a2c8d2701e27c5921e0ff2df344770463 100644 (file)
  */
 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() {
index bdfa4b47cc6740eb2402af6fd41fe48ca89cd5b1..8a2dec5a354351f96c8a3a2878b35cc3702b05a5 100644 (file)
@@ -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;
index 95f30fb728e6e46a1db20531823002b91182a149..fdfddf5c089d070649fb7737f5bc12c48c2712a5 100644 (file)
@@ -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 (file)
index 0000000..939080f
--- /dev/null
@@ -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 <body> 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
index 4f3f205631185ed40634b99bc69d1e829b6796e7..5f901cd7466ef5a1af7f59eb5fa00951cb664afa 100644 (file)
@@ -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())));
     }
 }
index c517b0e5e2d29236b9d3b3f9eee991ec2b58cc1c..70376c79f83479acbd12b9a9c32628e159895a3e 100644 (file)
@@ -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 (file)
index a4100f7..0000000
+++ /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 <body> 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
index 70809cb6947b85e33e871343d9886e3aaa1b16a0..ef9de9dcb06e42d481f6e3be25568d6a0d7a74c1 100644 (file)
@@ -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;
index f6fb928e755d85604266f88a448961467ea0709c..55fd571ee28503925a3aa9a4088a9aa788cb2f2b 100644 (file)
@@ -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;
index 14e4269e803603b1854b68e348642fe6a1814a1a..d47b4540df4af1f82641a78b042534c96830f3c3 100644 (file)
  */
 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();
 
index 22865b098c4e9af0cba45336e92a66de9e8e942d..ea513f6d3ec0856e792710b3354a763345084927 100644 (file)
  */
 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 {
 
index 34f517d25dd90aaa55b86c930614335e537098cb..1d0e8de4ebd59d110d4985280e4ed5e1d78dd332 100644 (file)
  */
 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
index e85c0aca5fcc40f7aeb3fa10c4a057c1dfdadf44..3b0d80c32c9625e2b25a7464d9093f17d60c7ffc 100644 (file)
@@ -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;
index 94e34baea26d88a55b1812e6523d4120aeab153a..8402224cf94269c27bbcea0d4fcb9066802eaace 100644 (file)
  */
 package com.vaadin.tests.design.nested;
 
-import org.junit.Ignore;
-
 import com.vaadin.ui.Button;
 
-@Ignore
 public class MyChildDesignCustomComponent extends Button {
 
 }
index 5727322ce3dc40e2a29d6ea2635f91f18c50028f..abde002ef83085abc7b142511cd90ad8247221f3 100644 (file)
@@ -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
index 2012e4ec14fa07c111a9c5b6dd3c08ecbc727e80..579fdfb8699be52460a5a1d4b50ff67b6c6dae88 100644 (file)
@@ -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 (file)
index 0000000..beaa951
--- /dev/null
@@ -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 (file)
index 0000000..dc95306
--- /dev/null
@@ -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 (file)
index c71ccca..0000000
+++ /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 (file)
index c1483ad..0000000
+++ /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 (file)
index 7fe63ba..0000000
+++ /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 (file)
index 0000000..344cd94
--- /dev/null
@@ -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));
+    }
+}
index ed2b27215e19106d7cc1845df084531ef61255af..8eef3b07a6a83d7c08bf8a92f79af3c9ea430940 100644 (file)
  */
 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());
index 7d459175202efee08005cb1799926f467d304d23..93606f296cbeadec03af5105b3f8ef568d90dcc7 100644 (file)
  */
 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());
index 328a025e0144a7bfe0a5955a9f9d79ac38c84963..b2aaa2c015d9238f5ef16a571d527edeb04906fd 100644 (file)
  */
 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());
index 179b1959262e4e380b96fcdc5bd16146f903ebe7..66ac083c0d89fc9073a0fcecb7516464996971c9 100644 (file)
  */
 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());
index 0b3b90ca1f6374bc7d4b965b0e617df1ff03cb22..1059ea0e14e873d2fbfdab50b895c45a90880750 100644 (file)
  */
 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());
index b742f7c629f8a14d2f3a80ccfe38820cd79df9af..482a9feb95b1c1391148594eda10ebdc1d9af218 100644 (file)
  */
 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());
index deeb311858a7edca5a6c390d88e5ec7a0d5ffb97..21c8745796c0db32e24816cb77453baa9ce216bc 100644 (file)
  */
 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());
index fa7827bdfd64446089321b0b4fe53df9e03ea975..5841fbcfee2404f28a06edc2e3252b2bb6c31670 100644 (file)
  */
 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());
index 6298b67727070d6664d84b760cccd00f0cef6e5a..128de7de1feee96a043981872528873329d24c7f 100644 (file)
  */
 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());
index 7859ae0227bf6edf2e4fb9c5eb6c983d4867d5df..3bc8fba7ded46180ce63ea9aa1ecf8062f9ff003 100644 (file)
  */
 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());
index f6eb460c1b243d9ed17ada76ee4942712606c3ca..486d71ea7550628332eda66890d6553df95b5e83 100644 (file)
  */
 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());