]> source.dussan.org Git - vaadin-framework.git/commitdiff
Tests for CustomLayout
authorArtur Signell <artur@vaadin.com>
Wed, 4 Apr 2012 20:37:18 +0000 (23:37 +0300)
committerArtur Signell <artur@vaadin.com>
Wed, 4 Apr 2012 21:09:53 +0000 (00:09 +0300)
tests/testbench/com/vaadin/tests/components/customcomponent/CustomLayoutUsingTemplate.java [new file with mode: 0644]
tests/testbench/com/vaadin/tests/components/customcomponent/CustomLayoutUsingTheme.java [new file with mode: 0644]
tests/testbench/com/vaadin/tests/components/customcomponent/template.html [new file with mode: 0644]
tests/testbench/com/vaadin/tests/layouts/CssLayoutCustomCss.java

diff --git a/tests/testbench/com/vaadin/tests/components/customcomponent/CustomLayoutUsingTemplate.java b/tests/testbench/com/vaadin/tests/components/customcomponent/CustomLayoutUsingTemplate.java
new file mode 100644 (file)
index 0000000..44c35ef
--- /dev/null
@@ -0,0 +1,59 @@
+package com.vaadin.tests.components.customcomponent;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.CustomLayout;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.TextField;
+
+public class CustomLayoutUsingTemplate extends TestBase implements
+        ClickListener {
+
+    CustomLayout layout;
+
+    @Override
+    protected void setup() {
+        String thisPackage = CustomLayoutUsingTemplate.class.getName().replace(
+                '.', '/');
+        thisPackage = thisPackage.replaceAll(
+                CustomLayoutUsingTemplate.class.getSimpleName() + "$", "");
+        String template = thisPackage + "template.html";
+        InputStream is = getClassLoader().getResourceAsStream(template);
+        try {
+            layout = new CustomLayout(is);
+            layout.addComponent(new Button(
+                    "Click to add a TextField to second location", this),
+                    "location1");
+            addComponent(layout);
+        } catch (IOException e) {
+            addComponent(new Label(e.getMessage()));
+            e.printStackTrace();
+        } finally {
+            try {
+                is.close();
+            } catch (IOException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+        }
+    }
+
+    @Override
+    protected String getDescription() {
+        return "Test for using a CustomLayout with a template read from an input stream and passed through the state";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return null;
+    }
+
+    public void buttonClick(ClickEvent event) {
+        layout.addComponent(new TextField("A text field!"), "location2");
+    }
+}
diff --git a/tests/testbench/com/vaadin/tests/components/customcomponent/CustomLayoutUsingTheme.java b/tests/testbench/com/vaadin/tests/components/customcomponent/CustomLayoutUsingTheme.java
new file mode 100644 (file)
index 0000000..e8df335
--- /dev/null
@@ -0,0 +1,59 @@
+package com.vaadin.tests.components.customcomponent;
+
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.tests.util.LoremIpsum;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.CustomLayout;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.NativeButton;
+import com.vaadin.ui.TextField;
+import com.vaadin.ui.VerticalLayout;
+
+public class CustomLayoutUsingTheme extends TestBase implements ClickListener {
+
+    private CustomLayout layout;
+
+    @Override
+    protected void setup() {
+        setTheme("tests-tickets");
+        layout = new CustomLayout("Ticket1775.html");
+        addComponent(layout);
+        layout.addComponent(new TextField("Username"), "loginUser");
+        layout.addComponent(new TextField("Password"), "loginPassword");
+        layout.addComponent(new Button("Login"), "loginButton");
+
+        VerticalLayout menu = new VerticalLayout();
+        menu.addComponent(new Button("Set main to label", new ClickListener() {
+
+            public void buttonClick(ClickEvent event) {
+                layout.addComponent(new Label(LoremIpsum.get(200)), "main");
+            }
+        }));
+        menu.addComponent(new Button("Set main to huge NativeButton",
+                new ClickListener() {
+
+                    public void buttonClick(ClickEvent event) {
+                        layout.addComponent(new NativeButton(
+                                "This is it, the main!"), "main");
+                    }
+                }));
+        layout.addComponent(menu, "menu");
+    }
+
+    @Override
+    protected String getDescription() {
+        return "Test for using a CustomLayout with a template read from an input stream and passed through the state";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return null;
+    }
+
+    public void buttonClick(ClickEvent event) {
+        layout.addComponent(new TextField("A text field!"), "location2");
+    }
+
+}
diff --git a/tests/testbench/com/vaadin/tests/components/customcomponent/template.html b/tests/testbench/com/vaadin/tests/components/customcomponent/template.html
new file mode 100644 (file)
index 0000000..fa02305
--- /dev/null
@@ -0,0 +1,4 @@
+<b>Contents</b>
+<div location="location1">This is where the first component goes</div>
+<div style="width: 500px; border: 1 px solid blue; margin: 10px;" location="location2">This is where the second component goes</div>
+<b>End of template</b>
\ No newline at end of file
index 5ddf196bcc628c4e051357c5aa42bda8cecdbfcf..0e2d57010103fa77f7aedd462767925f5fb00246 100644 (file)
@@ -31,10 +31,13 @@ public class CssLayoutCustomCss extends TestBase implements ClickListener {
         layout.setSizeFull();
         addComponent(layout);
 
-        layout.addComponent(createButton("color:red"));
+        Button red, green;
+        layout.addComponent(red = createButton("color:red"));
         layout.addComponent(createButton("color: blue"));
-        layout.addComponent(createButton("color: green"));
+        layout.addComponent(green = createButton("color: green"));
 
+        red.click();
+        green.click();
         layout.addComponent(createMarginsToggle());
     }
 
@@ -51,7 +54,7 @@ public class CssLayoutCustomCss extends TestBase implements ClickListener {
         return cb;
     }
 
-    private Component createButton(String string) {
+    private Button createButton(String string) {
         NativeButton button = new NativeButton(string);
         css.put(button, string);
         button.addListener(this);