]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix test broken by #16556
authorArtur Signell <artur@vaadin.com>
Mon, 8 Jun 2015 05:42:34 +0000 (08:42 +0300)
committerVaadin Code Review <review@vaadin.com>
Tue, 9 Jun 2015 08:20:36 +0000 (08:20 +0000)
Change-Id: I4e0883c58c425fc6287212a97f740016223914b5

uitest/src/com/vaadin/tests/components/FileDownloaderTest.java [deleted file]
uitest/src/com/vaadin/tests/components/FileDownloaderUI.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/FileDownloaderUITest.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java
uitest/tb2/com/vaadin/tests/components/FileDownloaderTest.html [deleted file]

diff --git a/uitest/src/com/vaadin/tests/components/FileDownloaderTest.java b/uitest/src/com/vaadin/tests/components/FileDownloaderTest.java
deleted file mode 100644 (file)
index 9eb6806..0000000
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- * Copyright 2012 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.components;
-
-import java.awt.image.BufferedImage;
-import java.io.BufferedOutputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.imageio.ImageIO;
-
-import com.vaadin.server.ClassResource;
-import com.vaadin.server.ConnectorResource;
-import com.vaadin.server.FileDownloader;
-import com.vaadin.server.FileResource;
-import com.vaadin.server.StreamResource;
-import com.vaadin.server.VaadinRequest;
-import com.vaadin.server.VaadinResponse;
-import com.vaadin.tests.components.embedded.EmbeddedPdf;
-import com.vaadin.ui.AbstractComponent;
-import com.vaadin.ui.Button;
-import com.vaadin.ui.Button.ClickEvent;
-import com.vaadin.ui.Button.ClickListener;
-import com.vaadin.ui.Component;
-import com.vaadin.ui.CssLayout;
-import com.vaadin.ui.HorizontalLayout;
-import com.vaadin.ui.Label;
-import com.vaadin.ui.Layout;
-import com.vaadin.ui.NativeButton;
-
-public class FileDownloaderTest extends AbstractTestUIWithLog {
-
-    private AbstractComponent firstDownloadComponent;
-
-    @Override
-    protected void setup(VaadinRequest request) {
-        List<Class<? extends Component>> components = new ArrayList<Class<? extends Component>>();
-        components.add(Button.class);
-        components.add(NativeButton.class);
-        components.add(CssLayout.class);
-        components.add(Label.class);
-
-        ConnectorResource resource;
-        resource = new StreamResource(new StreamResource.StreamSource() {
-
-            @Override
-            public InputStream getStream() {
-                try {
-                    BufferedImage img = getImage2("demo.png");
-                    ByteArrayOutputStream imagebuffer = new ByteArrayOutputStream();
-                    ImageIO.write(img, "png", imagebuffer);
-                    Thread.sleep(5000);
-
-                    return new ByteArrayInputStream(imagebuffer.toByteArray());
-                } catch (Exception e) {
-                    e.printStackTrace();
-                    return null;
-                }
-            }
-        }, "demo.png");
-        addComponents("Dynamic image", resource, components);
-        try {
-            File hugeFile = File.createTempFile("huge", ".txt");
-            hugeFile.deleteOnExit();
-            BufferedOutputStream os = new BufferedOutputStream(
-                    new FileOutputStream(hugeFile));
-            int writeAtOnce = 1024 * 1024;
-            byte[] b = new byte[writeAtOnce];
-            for (int i = 0; i < 5l * 1024l * 1024l; i += writeAtOnce) {
-                os.write(b);
-            }
-            os.close();
-            resource = new FileResource(hugeFile);
-            addComponents("Huge text file", resource, components);
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-        resource = new ClassResource(new EmbeddedPdf().getClass(), "test.pdf");
-        addComponents("Class resource pdf", resource, components);
-
-        Button downloadUtf8File = new Button("Download UTF-8 named file");
-        FileDownloader fd = new FileDownloader(new ClassResource(
-                new EmbeddedPdf().getClass(), "åäö-日本語.pdf"));
-        fd.setOverrideContentType(false);
-        fd.extend(downloadUtf8File);
-        addComponent(downloadUtf8File);
-
-        addComponent(new Button("Remove first download button",
-                new ClickListener() {
-
-                    @Override
-                    public void buttonClick(ClickEvent event) {
-                        Layout parent = (Layout) firstDownloadComponent
-                                .getParent();
-                        parent.removeComponent(firstDownloadComponent);
-                    }
-                }));
-        addComponent(new Button(
-                "Detach FileDownloader from first download button",
-                new ClickListener() {
-
-                    @Override
-                    public void buttonClick(ClickEvent event) {
-                        FileDownloader e = (FileDownloader) firstDownloadComponent
-                                .getExtensions().iterator().next();
-                        e.remove();
-                        log("FileDownload detached");
-                    }
-                }));
-    }
-
-    public void addComponents(String caption, ConnectorResource resource,
-            List<Class<? extends Component>> components) {
-        HorizontalLayout layout = new HorizontalLayout();
-        layout.setCaption(caption);
-        for (Class<? extends Component> cls : components) {
-            try {
-                AbstractComponent c = (AbstractComponent) cls.newInstance();
-                if (firstDownloadComponent == null) {
-                    firstDownloadComponent = c;
-                }
-
-                c.setId(cls.getName() + caption.replace(" ", ""));
-                c.setCaption(cls.getName());
-                c.setDescription(resource.getMIMEType() + " / "
-                        + resource.getClass());
-                c.setWidth("100px");
-                c.setHeight("100px");
-
-                layout.addComponent(c);
-
-                new FileDownloader(resource).extend(c);
-
-                if (c instanceof Button) {
-                    ((Button) c).addClickListener(new ClickListener() {
-
-                        @Override
-                        public void buttonClick(ClickEvent event) {
-                        }
-                    });
-                }
-            } catch (Exception e) {
-                System.err.println("Could not instatiate " + cls.getName());
-            }
-        }
-        addComponent(layout);
-    }
-
-    private static final String DYNAMIC_IMAGE_NAME = "requestImage.png";
-
-    @Override
-    public boolean handleConnectorRequest(VaadinRequest request,
-            VaadinResponse response, String path) throws IOException {
-        if (DYNAMIC_IMAGE_NAME.equals(path)) {
-            // Create an image, draw the "text" parameter to it and output it to
-            // the browser.
-            String text = request.getParameter("text");
-            if (text == null) {
-                text = DYNAMIC_IMAGE_NAME;
-            }
-            BufferedImage bi = getImage(text);
-            response.setContentType("image/png");
-            response.setHeader("Content-Disposition", "attachment; filename=\""
-                    + path + "\"");
-            ImageIO.write(bi, "png", response.getOutputStream());
-
-            return true;
-        } else {
-            return super.handleConnectorRequest(request, response, path);
-        }
-    }
-
-    private BufferedImage getImage(String text) {
-        BufferedImage bi = new BufferedImage(150, 30,
-                BufferedImage.TYPE_3BYTE_BGR);
-        bi.getGraphics()
-                .drawChars(text.toCharArray(), 0, text.length(), 10, 20);
-        return bi;
-    }
-
-    private BufferedImage getImage2(String text) {
-        BufferedImage bi = new BufferedImage(200, 200,
-                BufferedImage.TYPE_INT_RGB);
-        bi.getGraphics()
-                .drawChars(text.toCharArray(), 0, text.length(), 10, 20);
-        return bi;
-    }
-
-}
diff --git a/uitest/src/com/vaadin/tests/components/FileDownloaderUI.java b/uitest/src/com/vaadin/tests/components/FileDownloaderUI.java
new file mode 100644 (file)
index 0000000..b137908
--- /dev/null
@@ -0,0 +1,209 @@
+/*
+ * Copyright 2012 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.components;
+
+import java.awt.image.BufferedImage;
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.imageio.ImageIO;
+
+import com.vaadin.server.ClassResource;
+import com.vaadin.server.ConnectorResource;
+import com.vaadin.server.FileDownloader;
+import com.vaadin.server.FileResource;
+import com.vaadin.server.StreamResource;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.server.VaadinResponse;
+import com.vaadin.tests.components.embedded.EmbeddedPdf;
+import com.vaadin.ui.AbstractComponent;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.CssLayout;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Layout;
+import com.vaadin.ui.NativeButton;
+
+public class FileDownloaderUI extends AbstractTestUIWithLog {
+
+    private AbstractComponent firstDownloadComponent;
+
+    @Override
+    protected void setup(VaadinRequest request) {
+        List<Class<? extends Component>> components = new ArrayList<Class<? extends Component>>();
+        components.add(Button.class);
+        components.add(NativeButton.class);
+        components.add(CssLayout.class);
+        components.add(Label.class);
+
+        ConnectorResource resource;
+        resource = new StreamResource(new StreamResource.StreamSource() {
+
+            @Override
+            public InputStream getStream() {
+                try {
+                    BufferedImage img = getImage2("demo.png");
+                    ByteArrayOutputStream imagebuffer = new ByteArrayOutputStream();
+                    ImageIO.write(img, "png", imagebuffer);
+                    Thread.sleep(5000);
+
+                    return new ByteArrayInputStream(imagebuffer.toByteArray());
+                } catch (Exception e) {
+                    e.printStackTrace();
+                    return null;
+                }
+            }
+        }, "demo.png");
+        addComponents("Dynamic image", resource, components);
+        try {
+            File hugeFile = File.createTempFile("huge", ".txt");
+            hugeFile.deleteOnExit();
+            BufferedOutputStream os = new BufferedOutputStream(
+                    new FileOutputStream(hugeFile));
+            int writeAtOnce = 1024 * 1024;
+            byte[] b = new byte[writeAtOnce];
+            for (int i = 0; i < 5l * 1024l * 1024l; i += writeAtOnce) {
+                os.write(b);
+            }
+            os.close();
+            resource = new FileResource(hugeFile);
+            addComponents("Huge text file", resource, components);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        resource = new ClassResource(new EmbeddedPdf().getClass(), "test.pdf");
+        addComponents("Class resource pdf", resource, components);
+
+        Button downloadUtf8File = new Button("Download UTF-8 named file");
+        FileDownloader fd = new FileDownloader(new ClassResource(
+                new EmbeddedPdf().getClass(), "åäö-日本語.pdf"));
+        fd.setOverrideContentType(false);
+        fd.extend(downloadUtf8File);
+        addComponent(downloadUtf8File);
+
+        addComponent(new Button("Remove first download button",
+                new ClickListener() {
+
+                    @Override
+                    public void buttonClick(ClickEvent event) {
+                        Layout parent = (Layout) firstDownloadComponent
+                                .getParent();
+                        parent.removeComponent(firstDownloadComponent);
+                    }
+                }));
+        addComponent(new Button(
+                "Detach FileDownloader from first download button",
+                new ClickListener() {
+
+                    @Override
+                    public void buttonClick(ClickEvent event) {
+                        FileDownloader e = (FileDownloader) firstDownloadComponent
+                                .getExtensions().iterator().next();
+                        e.remove();
+                        log("FileDownload detached");
+                    }
+                }));
+    }
+
+    public void addComponents(String caption, ConnectorResource resource,
+            List<Class<? extends Component>> components) {
+        HorizontalLayout layout = new HorizontalLayout();
+        layout.setCaption(caption);
+        for (Class<? extends Component> cls : components) {
+            try {
+                AbstractComponent c = (AbstractComponent) cls.newInstance();
+                if (firstDownloadComponent == null) {
+                    firstDownloadComponent = c;
+                }
+
+                c.setId(cls.getName() + caption.replace(" ", ""));
+                c.setCaption(cls.getName());
+                c.setDescription(resource.getMIMEType() + " / "
+                        + resource.getClass());
+                c.setWidth("100px");
+                c.setHeight("100px");
+
+                layout.addComponent(c);
+
+                new FileDownloader(resource).extend(c);
+
+                if (c instanceof Button) {
+                    ((Button) c).addClickListener(new ClickListener() {
+
+                        @Override
+                        public void buttonClick(ClickEvent event) {
+                        }
+                    });
+                }
+            } catch (Exception e) {
+                System.err.println("Could not instatiate " + cls.getName());
+            }
+        }
+        addComponent(layout);
+    }
+
+    private static final String DYNAMIC_IMAGE_NAME = "requestImage.png";
+
+    @Override
+    public boolean handleConnectorRequest(VaadinRequest request,
+            VaadinResponse response, String path) throws IOException {
+        if (DYNAMIC_IMAGE_NAME.equals(path)) {
+            // Create an image, draw the "text" parameter to it and output it to
+            // the browser.
+            String text = request.getParameter("text");
+            if (text == null) {
+                text = DYNAMIC_IMAGE_NAME;
+            }
+            BufferedImage bi = getImage(text);
+            response.setContentType("image/png");
+            response.setHeader("Content-Disposition", "attachment; filename=\""
+                    + path + "\"");
+            ImageIO.write(bi, "png", response.getOutputStream());
+
+            return true;
+        } else {
+            return super.handleConnectorRequest(request, response, path);
+        }
+    }
+
+    private BufferedImage getImage(String text) {
+        BufferedImage bi = new BufferedImage(150, 30,
+                BufferedImage.TYPE_3BYTE_BGR);
+        bi.getGraphics()
+                .drawChars(text.toCharArray(), 0, text.length(), 10, 20);
+        return bi;
+    }
+
+    private BufferedImage getImage2(String text) {
+        BufferedImage bi = new BufferedImage(200, 200,
+                BufferedImage.TYPE_INT_RGB);
+        bi.getGraphics()
+                .drawChars(text.toCharArray(), 0, text.length(), 10, 20);
+        return bi;
+    }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/FileDownloaderUITest.java b/uitest/src/com/vaadin/tests/components/FileDownloaderUITest.java
new file mode 100644 (file)
index 0000000..73d1ba6
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * 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.components;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class FileDownloaderUITest extends MultiBrowserTest {
+
+    @Test
+    public void ensureButtonWithDownloaderCanBeRemoved() {
+        openTestURL();
+        By id = By.id("com.vaadin.ui.ButtonDynamicimage");
+        assertElementPresent(id);
+        $(ButtonElement.class).caption("Remove first download button").first()
+                .click();
+        assertElementNotPresent(id);
+    }
+
+}
index 075319103bc9c38f74d8f3e8efbf63957c703a52..2e33cc2741bf4747ac46d905cae0c13e31e19a65 100644 (file)
@@ -1044,4 +1044,25 @@ public abstract class AbstractTB3Test extends ParallelTest {
         }
         selectMenu(menuCaptions[menuCaptions.length - 1], true);
     }
+
+    /**
+     * Asserts that an element is present
+     * 
+     * @param by
+     *            the locatore for the element
+     */
+    protected void assertElementPresent(By by) {
+        Assert.assertTrue("Element is not present", isElementPresent(by));
+    }
+
+    /**
+     * Asserts that an element is not present
+     * 
+     * @param by
+     *            the locatore for the element
+     */
+    protected void assertElementNotPresent(By by) {
+        Assert.assertFalse("Element is present", isElementPresent(by));
+    }
+
 }
diff --git a/uitest/tb2/com/vaadin/tests/components/FileDownloaderTest.html b/uitest/tb2/com/vaadin/tests/components/FileDownloaderTest.html
deleted file mode 100644 (file)
index bfe8709..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head profile="http://selenium-ide.openqa.org/profiles/test-case">
-<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
-<link rel="selenium.base" href="http://arturwin.office.itmill.com:8888/" />
-<title>New Test</title>
-</head>
-<body>
-<table cellpadding="1" cellspacing="1" border="1">
-<thead>
-<tr><td rowspan="1" colspan="3">New Test</td></tr>
-</thead><tbody>
-<tr>
-       <td>open</td>
-       <td>/run/com.vaadin.tests.components.FileDownloaderTest?restartApplication</td>
-       <td></td>
-</tr>
-<tr>
-       <td>assertElementPresent</td>
-       <td>vaadin=runcomvaadintestscomponentsFileDownloaderTest::PID_Scom.vaadin.ui.ButtonDynamicimage/domChild[0]/domChild[0]</td>
-       <td></td>
-</tr>
-<tr>
-       <td>click</td>
-       <td>vaadin=runcomvaadintestscomponentsFileDownloaderTest::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[4]/VButton[0]/domChild[0]/domChild[0]</td>
-       <td></td>
-</tr>
-<tr>
-       <td>assertElementNotPresent</td>
-       <td>vaadin=runcomvaadintestscomponentsFileDownloaderTest::PID_Scom.vaadin.ui.ButtonDynamicimage/domChild[0]/domChild[0]</td>
-       <td></td>
-</tr>
-</tbody></table>
-</body>
-</html>