aboutsummaryrefslogtreecommitdiffstats
path: root/server/tests/src
diff options
context:
space:
mode:
authorJohannes Dahlström <johannesd@vaadin.com>2015-03-31 15:41:46 +0300
committerJohannes Dahlström <johannesd@vaadin.com>2015-04-07 15:21:50 +0300
commit8664c97c7bb6fb36b2ebbe3849b51ec00e052e24 (patch)
tree31451d8bf956cb2bfb686857f27f12e54703f67d /server/tests/src
parent0f1dcd23a0bffae76fc312d95d7b64bf7861df88 (diff)
downloadvaadin-framework-8664c97c7bb6fb36b2ebbe3849b51ec00e052e24.tar.gz
vaadin-framework-8664c97c7bb6fb36b2ebbe3849b51ec00e052e24.zip
Fix declarative support for Window (#17314)
Change-Id: If89a46a4c08ec1491eb00a2f2b8580fb3ef785fc
Diffstat (limited to 'server/tests/src')
-rw-r--r--server/tests/src/com/vaadin/tests/design/DeclarativeTestBase.java8
-rw-r--r--server/tests/src/com/vaadin/tests/design/DeclarativeTestBaseBase.java23
-rw-r--r--server/tests/src/com/vaadin/tests/design/DesignFormatterTest.java27
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/window/WindowDeclarativeTest.java153
4 files changed, 201 insertions, 10 deletions
diff --git a/server/tests/src/com/vaadin/tests/design/DeclarativeTestBase.java b/server/tests/src/com/vaadin/tests/design/DeclarativeTestBase.java
index cba981c947..10f1e5c711 100644
--- a/server/tests/src/com/vaadin/tests/design/DeclarativeTestBase.java
+++ b/server/tests/src/com/vaadin/tests/design/DeclarativeTestBase.java
@@ -24,6 +24,7 @@ import java.util.Map;
import org.junit.Assert;
+import com.vaadin.shared.Connector;
import com.vaadin.ui.Component;
import com.vaadin.ui.Flash;
@@ -59,6 +60,11 @@ public abstract class DeclarativeTestBase<T extends Component> extends
if (readMethod == null || writeMethod == null) {
continue;
}
+ if (Connector.class.isAssignableFrom(c)
+ && readMethod.getName().equals("getParent")) {
+ // Hack to break cycles in the connector hierarchy
+ continue;
+ }
try {
c.getDeclaredMethod(readMethod.getName());
} catch (Exception e) {
@@ -99,7 +105,6 @@ public abstract class DeclarativeTestBase<T extends Component> extends
}
}
});
-
}
@Override
@@ -118,5 +123,4 @@ public abstract class DeclarativeTestBase<T extends Component> extends
}
return comp;
}
-
}
diff --git a/server/tests/src/com/vaadin/tests/design/DeclarativeTestBaseBase.java b/server/tests/src/com/vaadin/tests/design/DeclarativeTestBaseBase.java
index b2da98bd30..4cb627d035 100644
--- a/server/tests/src/com/vaadin/tests/design/DeclarativeTestBaseBase.java
+++ b/server/tests/src/com/vaadin/tests/design/DeclarativeTestBaseBase.java
@@ -84,12 +84,21 @@ public abstract class DeclarativeTestBaseBase<T extends Component> {
return;
}
- if (o1 instanceof Collection && o2 instanceof Collection) {
-
- } else {
+ if (!(o1 instanceof Collection && o2 instanceof Collection)) {
Assert.assertEquals(o1.getClass(), o2.getClass());
}
+ if (o1 instanceof Object[]) {
+ Object[] a1 = ((Object[]) o1);
+ Object[] a2 = ((Object[]) o2);
+ Assert.assertEquals(message + ": array length", a1.length,
+ a2.length);
+ for (int i = 0; i < a1.length; i++) {
+ assertEquals(message, a1[i], a2[i]);
+ }
+ return;
+ }
+
List<EqualsAsserter<Object>> comparators = getComparators(o1);
if (!comparators.isEmpty()) {
for (EqualsAsserter<Object> ec : comparators) {
@@ -126,7 +135,9 @@ public abstract class DeclarativeTestBaseBase<T extends Component> {
protected abstract <TT> EqualsAsserter<TT> getComparator(Class<TT> c);
private boolean isVaadin(Class<?> c) {
- return c.getPackage().getName().startsWith("com.vaadin");
+ return c.getPackage() != null
+ && c.getPackage().getName().startsWith("com.vaadin");
+
}
public void testRead(String design, T expected) {
@@ -149,6 +160,10 @@ public abstract class DeclarativeTestBaseBase<T extends Component> {
Assert.assertEquals(comparable, produced);
}
+ protected Element createElement(Component c) {
+ return new DesignContext().createElement(c);
+ }
+
private String elementToHtml(Element producedElem) {
StringBuilder stringBuilder = new StringBuilder();
elementToHtml(producedElem, stringBuilder);
diff --git a/server/tests/src/com/vaadin/tests/design/DesignFormatterTest.java b/server/tests/src/com/vaadin/tests/design/DesignFormatterTest.java
index 9b01188aea..681b9d80a3 100644
--- a/server/tests/src/com/vaadin/tests/design/DesignFormatterTest.java
+++ b/server/tests/src/com/vaadin/tests/design/DesignFormatterTest.java
@@ -24,10 +24,14 @@ import java.util.Date;
import java.util.HashSet;
import java.util.TimeZone;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import com.vaadin.data.util.converter.Converter.ConversionException;
import com.vaadin.event.ShortcutAction;
+import com.vaadin.event.ShortcutAction.KeyCode;
+import com.vaadin.event.ShortcutAction.ModifierKey;
import com.vaadin.server.ExternalResource;
import com.vaadin.server.FileResource;
import com.vaadin.server.Resource;
@@ -203,10 +207,8 @@ public class DesignFormatterTest {
@Test
public void testShortcutActionNoCaption() {
- ShortcutAction action = new ShortcutAction(null,
- ShortcutAction.KeyCode.D, new int[] {
- ShortcutAction.ModifierKey.ALT,
- ShortcutAction.ModifierKey.CTRL });
+ ShortcutAction action = new ShortcutAction(null, KeyCode.D, new int[] {
+ ModifierKey.ALT, ModifierKey.CTRL });
String formatted = formatter.format(action);
assertEquals("alt-ctrl-d", formatted);
@@ -216,6 +218,23 @@ public class DesignFormatterTest {
}
@Test
+ public void testInvalidShortcutAction() {
+ assertInvalidShortcut("-");
+ assertInvalidShortcut("foo");
+ assertInvalidShortcut("atl-ctrl");
+ assertInvalidShortcut("-a");
+ }
+
+ protected void assertInvalidShortcut(String shortcut) {
+ try {
+ formatter.parse(shortcut, ShortcutAction.class);
+ Assert.fail("Invalid shortcut '" + shortcut + "' should throw");
+ } catch (ConversionException e) {
+ // expected
+ }
+ }
+
+ @Test
public void testTimeZone() {
TimeZone zone = TimeZone.getTimeZone("GMT+2");
String formatted = formatter.format(zone);
diff --git a/server/tests/src/com/vaadin/tests/server/component/window/WindowDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/window/WindowDeclarativeTest.java
new file mode 100644
index 0000000000..1ab0011442
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/server/component/window/WindowDeclarativeTest.java
@@ -0,0 +1,153 @@
+/*
+ * 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.server.component.window;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.event.ShortcutAction.KeyCode;
+import com.vaadin.event.ShortcutAction.ModifierKey;
+import com.vaadin.shared.ui.window.WindowMode;
+import com.vaadin.shared.ui.window.WindowRole;
+import com.vaadin.tests.design.DeclarativeTestBase;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Window;
+import com.vaadin.ui.declarative.DesignException;
+
+/**
+ * Tests declarative support for implementations of {@link Window}.
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public class WindowDeclarativeTest extends DeclarativeTestBase<Window> {
+
+ @Test
+ public void testDefault() {
+ String design = "<v-window>";
+
+ Window expected = new Window();
+
+ testRead(design, expected);
+ testWrite(design, expected);
+ }
+
+ @Test
+ public void testFeatures() {
+
+ String design = "<v-window position='100,100' window-mode='maximized' "
+ + "center modal=true resizable=false resize-lazy=true closable=false draggable=false "
+ + "close-shortcut='ctrl-alt-escape' "
+ + "assistive-prefix='Hello' assistive-postfix='World' assistive-role='alertdialog' "
+ + "tab-stop-enabled=true "
+ + "tab-stop-top-assistive-text='Do not move above the window' "
+ + "tab-stop-bottom-assistive-text='End of window'>"
+ + "</v-window>";
+
+ Window expected = new Window();
+
+ expected.setPositionX(100);
+ expected.setPositionY(100);
+ expected.setWindowMode(WindowMode.MAXIMIZED);
+
+ expected.center();
+ expected.setModal(!expected.isModal());
+ expected.setResizable(!expected.isResizable());
+ expected.setResizeLazy(!expected.isResizeLazy());
+ expected.setClosable(!expected.isClosable());
+ expected.setDraggable(!expected.isDraggable());
+
+ expected.setCloseShortcut(KeyCode.ESCAPE, ModifierKey.CTRL,
+ ModifierKey.ALT);
+
+ expected.setAssistivePrefix("Hello");
+ expected.setAssistivePostfix("World");
+ expected.setAssistiveRole(WindowRole.ALERTDIALOG);
+ expected.setTabStopEnabled(!expected.isTabStopEnabled());
+ expected.setTabStopTopAssistiveText("Do not move above the window");
+ expected.setTabStopBottomAssistiveText("End of window");
+
+ testRead(design, expected);
+ testWrite(design, expected);
+ }
+
+ @Test
+ public void testInvalidPosition() {
+ assertInvalidPosition("");
+ assertInvalidPosition("1");
+ assertInvalidPosition("100,100.1");
+ assertInvalidPosition("x");
+ assertInvalidPosition("2,foo");
+ // Should be invalid, not checked currently
+ // assertInvalidPosition("1,2,3");
+ }
+
+ protected void assertInvalidPosition(String position) {
+ try {
+ read("<v-window position='" + position + "'>");
+ Assert.fail("Invalid position '" + position + "' should throw");
+ } catch (Exception e) {
+ // expected
+ }
+ }
+
+ @Test
+ public void testChildContent() {
+
+ String design = "<v-window>" + createElement(new Button("OK"))
+ + "</v-window>";
+
+ Window expected = new Window();
+ expected.setContent(new Button("OK"));
+
+ testRead(design, expected);
+ testWrite(design, expected);
+ }
+
+ @Test(expected = DesignException.class)
+ public void testMultipleContentChildren() {
+
+ String design = "<v-window>" + createElement(new Label("Hello"))
+ + createElement(new Button("OK")) + "</v-window>";
+
+ read(design);
+ }
+
+ @Test
+ public void testAssistiveDescription() {
+
+ Label assistive1 = new Label("Assistive text");
+ Label assistive2 = new Label("More assistive text");
+
+ String design = "<v-window>"
+ + createElement(assistive1).attr(":assistive-description", "")
+ + createElement(new Button("OK"))
+ + createElement(assistive2).attr(":assistive-description", "");
+
+ Window expected = new Window();
+ expected.setContent(new Button("OK"));
+ expected.setAssistiveDescription(assistive1, assistive2);
+
+ testRead(design, expected);
+
+ String written = "<v-window>" + createElement(new Button("OK"))
+ + createElement(assistive1).attr(":assistive-description", "")
+ + createElement(assistive2).attr(":assistive-description", "");
+
+ testWrite(written, expected);
+ }
+}