- Renamed tests to *Test and *TestBase.
- Removed obsolete @Ignore annotations.
- Split some design tests into smaller ones.
Change-Id: I8e2a7d73ef620e584777c1e8e701917c0f69f876
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"
--- /dev/null
+/*
+ * 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;
+ }
+}
+++ /dev/null
-/*
- * 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;
- }
-}
--- /dev/null
+/*
+ * 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));
+ }
+}
+++ /dev/null
-/*
- * 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));
- }
-}
--- /dev/null
+/*
+ * 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;
+ }
+}
+++ /dev/null
-/*
- * 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;
- }
-}
--- /dev/null
+/*
+ * 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;
+ }
+}
+++ /dev/null
-/*
- * 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;
- }
-}
*/
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() {
*/
package com.vaadin.tests.design;
-import org.junit.Ignore;
-
import com.vaadin.ui.Button;
import com.vaadin.ui.NativeButton;
import com.vaadin.ui.TextField;
* @since
* @author Vaadin Ltd
*/
-@Ignore
public class InvalidLayoutTemplate extends VerticalLayout {
private NativeButton firstButton;
private NativeButton secondButton;
*/
package com.vaadin.tests.design;
-import org.junit.Ignore;
-
import com.vaadin.ui.Button;
import com.vaadin.ui.NativeButton;
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
--- /dev/null
+/*
+ * 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
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())));
}
}
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
* @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" };
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");
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));
+ }
}
+++ /dev/null
-/*
- * 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
*/
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;
import com.vaadin.ui.declarative.Design;
@DesignRoot("DesignWithEmptyAnnotation.html")
-@Ignore
public class DesignWithAnnotation extends VerticalLayout {
public Button ok;
*/
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;
import com.vaadin.ui.declarative.Design;
@DesignRoot
-@Ignore
public class DesignWithEmptyAnnotation extends VerticalLayout {
protected Button ok;
*/
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();
*/
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 {
*/
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
*/
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;
*
* @author Vaadin Ltd
*/
-@Ignore
@DesignRoot("mychilddesign.html")
public class MyChildDesign extends HorizontalLayout {
public Label childLabel;
*/
package com.vaadin.tests.design.nested;
-import org.junit.Ignore;
-
import com.vaadin.ui.Button;
-@Ignore
public class MyChildDesignCustomComponent extends Button {
}
*/
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;
*
* @author Vaadin Ltd
*/
-@Ignore
@DesignRoot("mydesignroot.html")
public class MyDesignRoot extends VerticalLayout {
// should be assigned automatically
*/
package com.vaadin.tests.design.nested;
-import org.junit.Ignore;
-
-@Ignore
public class MyExtendedChildDesign extends MyChildDesign {
public MyExtendedChildDesign() {
super();
--- /dev/null
+/*
+ * 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));
+ }
+ }
+}
--- /dev/null
+/*
+ * 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"));
+ }
+}
+++ /dev/null
-/*
- * 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());
- }
- }
-}
+++ /dev/null
-/*
- * 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());
- }
-}
+++ /dev/null
-/*
- * 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());
- }
-}
--- /dev/null
+/*
+ * 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));
+ }
+}
*/
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());
*/
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());
*/
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());
*/
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());
*/
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());
*/
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());
*/
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());
*/
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());
*/
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());
*/
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());
*/
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());