summaryrefslogtreecommitdiffstats
path: root/src/com/vaadin/automatedtests/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/vaadin/automatedtests/util')
-rw-r--r--src/com/vaadin/automatedtests/util/DebugId.java50
-rw-r--r--src/com/vaadin/automatedtests/util/Log.java136
-rw-r--r--src/com/vaadin/automatedtests/util/MultiListener.java35
-rw-r--r--src/com/vaadin/automatedtests/util/RandomComponents.java281
-rw-r--r--src/com/vaadin/automatedtests/util/StatusServlet.java89
5 files changed, 591 insertions, 0 deletions
diff --git a/src/com/vaadin/automatedtests/util/DebugId.java b/src/com/vaadin/automatedtests/util/DebugId.java
new file mode 100644
index 0000000000..8f2390933b
--- /dev/null
+++ b/src/com/vaadin/automatedtests/util/DebugId.java
@@ -0,0 +1,50 @@
+/*
+@ITMillApache2LicenseForJavaFiles@
+ */
+
+package com.vaadin.automatedtests.util;
+
+import java.io.Serializable;
+import java.util.HashMap;
+
+import com.vaadin.ui.Component;
+
+public class DebugId implements Serializable {
+
+ private static HashMap debugIds = new HashMap();
+
+ /**
+ * Generate static debug id based on package and component type. If
+ * duplicate package, component type then number of instances count is
+ * appended to debugId.
+ *
+ * @param c
+ */
+ public static void set(Component c, String description) {
+ String debugId = "";
+
+ // add package name
+ StackTraceElement[] st = new Throwable().fillInStackTrace()
+ .getStackTrace();
+ try {
+ debugId += st[3].getClassName();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // add component type
+ debugId += c.getClass();
+
+ // add given description
+ debugId += description;
+
+ if (debugIds.containsKey(debugId)) {
+ int count = ((Integer) debugIds.get(debugId)).intValue();
+ count++;
+ debugIds.put(debugId, new Integer(count));
+ debugId = debugId + "-" + count;
+ }
+
+ c.setDebugId(debugId);
+ }
+}
diff --git a/src/com/vaadin/automatedtests/util/Log.java b/src/com/vaadin/automatedtests/util/Log.java
new file mode 100644
index 0000000000..f9948af60e
--- /dev/null
+++ b/src/com/vaadin/automatedtests/util/Log.java
@@ -0,0 +1,136 @@
+/*
+@ITMillApache2LicenseForJavaFiles@
+ */
+
+package com.vaadin.automatedtests.util;
+
+import java.io.Serializable;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+
+/**
+ *
+ * Execution output and error messages should be handled through this class. It
+ * is likely that we need these messages back to TT Server at some point just to
+ * figure out what went wrong.
+ *
+ */
+public class Log implements Serializable {
+
+ // 3 (errors only)
+ // 2 (+ warnings)
+ // 1 (+logs)
+ // 0 (all, print messages also to System.out)
+ public static final int debug = 0;
+
+ // Should class.method() and it's call times be told on debug?
+ public static final boolean showClassInformation = true;
+
+ public static DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+ public static int DEBUG = 0;
+
+ public static int LOG = 1;
+
+ public static int WARN = 2;
+
+ public static int ERROR = 3;
+
+ private static Log log;
+
+ public static HashMap classMethodCallCounter = new HashMap();
+
+ static {
+ log = new Log();
+ }
+
+ public static void reset() {
+ classMethodCallCounter = new HashMap();
+ }
+
+ public static String getNow() {
+ return df.format(new Date());
+ }
+
+ private Log() {
+ }
+
+ public static String getSource() {
+ StackTraceElement[] st = new Throwable().fillInStackTrace()
+ .getStackTrace();
+ try {
+ String key = "";
+ String methodName = st[3].getMethodName();
+ int line = st[3].getLineNumber();
+
+ String clazz = st[3].getClassName() + ".java";
+ key = "(" + clazz + ":" + line + ")" + " " + methodName;
+ Integer value = (Integer) classMethodCallCounter.get(key);
+ if (value == null) {
+ value = new Integer(1);
+ } else {
+ value = new Integer(value.intValue() + 1);
+ }
+ classMethodCallCounter.put(key, value);
+ return value.intValue() + ": " + key;
+ } catch (Exception e) {
+ return "unknown class.method";
+ }
+
+ }
+
+ public static String getClassMethodCounters() {
+ String result = "";
+ for (final Iterator it = classMethodCallCounter.keySet().iterator(); it
+ .hasNext();) {
+ String key = (String) it.next();
+ result += classMethodCallCounter.get(key) + ": " + key + "\n";
+ }
+ return result;
+ }
+
+ public void add(int type, String message) {
+ String source = getSource();
+ if (type >= debug) {
+ if (showClassInformation) {
+ System.out.println(source + ": " + message);
+ } else {
+ System.out.println(message);
+ }
+ }
+ }
+
+ public static void debug(String message) {
+ log.add(DEBUG, message);
+ }
+
+ public static void log(String message) {
+ log.add(LOG, message);
+ }
+
+ public static void warn(String message) {
+ log.add(WARN, message);
+ }
+
+ public static void error(String message) {
+ log.add(ERROR, message);
+ }
+
+ /**
+ * Simple way to check for memory consumption without profiler.
+ */
+ public static String getMemoryStatistics() {
+ // You should call gc before printing statistics (if you are not using a
+ // profiler)
+ System.gc();
+ long inUse = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime()
+ .freeMemory());
+ return "Memory:\n" + inUse + " (Used)\n"
+ + Runtime.getRuntime().totalMemory() + " (Total)\n"
+ + Runtime.getRuntime().freeMemory() + " (Free)\n";
+
+ }
+}
diff --git a/src/com/vaadin/automatedtests/util/MultiListener.java b/src/com/vaadin/automatedtests/util/MultiListener.java
new file mode 100644
index 0000000000..5f7df2ab99
--- /dev/null
+++ b/src/com/vaadin/automatedtests/util/MultiListener.java
@@ -0,0 +1,35 @@
+/*
+@ITMillApache2LicenseForJavaFiles@
+ */
+
+package com.vaadin.automatedtests.util;
+
+import com.vaadin.data.Container.ItemSetChangeEvent;
+import com.vaadin.data.Container.ItemSetChangeListener;
+import com.vaadin.data.Container.PropertySetChangeEvent;
+import com.vaadin.data.Container.PropertySetChangeListener;
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.data.Property.ValueChangeListener;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+
+public class MultiListener implements Button.ClickListener,
+ PropertySetChangeListener, ItemSetChangeListener, ValueChangeListener {
+
+ public void buttonClick(ClickEvent event) {
+ Log.debug("ClickEvent from " + event.getButton().getCaption());
+ }
+
+ public void containerPropertySetChange(PropertySetChangeEvent event) {
+ Log.debug("containerPropertySetChange from " + event.getContainer());
+ }
+
+ public void containerItemSetChange(ItemSetChangeEvent event) {
+ Log.debug("containerItemSetChange from " + event.getContainer());
+ }
+
+ public void valueChange(ValueChangeEvent event) {
+ Log.debug("valueChange from " + event.getProperty());
+ }
+
+}
diff --git a/src/com/vaadin/automatedtests/util/RandomComponents.java b/src/com/vaadin/automatedtests/util/RandomComponents.java
new file mode 100644
index 0000000000..8ddafaf62b
--- /dev/null
+++ b/src/com/vaadin/automatedtests/util/RandomComponents.java
@@ -0,0 +1,281 @@
+/*
+@ITMillApache2LicenseForJavaFiles@
+ */
+
+package com.vaadin.automatedtests.util;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Random;
+
+import com.vaadin.automatedtests.ComponentsInTable;
+import com.vaadin.data.Container.ItemSetChangeListener;
+import com.vaadin.data.Container.PropertySetChangeListener;
+import com.vaadin.data.Property.ValueChangeListener;
+import com.vaadin.demo.featurebrowser.ButtonExample;
+import com.vaadin.demo.featurebrowser.ClientCachingExample;
+import com.vaadin.demo.featurebrowser.ComboBoxExample;
+import com.vaadin.demo.featurebrowser.EmbeddedBrowserExample;
+import com.vaadin.demo.featurebrowser.LabelExample;
+import com.vaadin.demo.featurebrowser.LayoutExample;
+import com.vaadin.demo.featurebrowser.NotificationExample;
+import com.vaadin.demo.featurebrowser.RichTextExample;
+import com.vaadin.demo.featurebrowser.SelectExample;
+import com.vaadin.demo.featurebrowser.TableExample;
+import com.vaadin.demo.featurebrowser.TreeExample;
+import com.vaadin.demo.featurebrowser.ValueInputExample;
+import com.vaadin.demo.featurebrowser.WindowingExample;
+import com.vaadin.terminal.ExternalResource;
+import com.vaadin.terminal.ThemeResource;
+import com.vaadin.ui.AbstractComponent;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.ComponentContainer;
+import com.vaadin.ui.DateField;
+import com.vaadin.ui.Embedded;
+import com.vaadin.ui.GridLayout;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Link;
+import com.vaadin.ui.OrderedLayout;
+import com.vaadin.ui.Panel;
+import com.vaadin.ui.Select;
+import com.vaadin.ui.TabSheet;
+import com.vaadin.ui.TextField;
+
+public class RandomComponents implements Serializable {
+
+ private Random rand = null;
+
+ private static Date date = new Date(2002, 2, 3, 4, 5, 6);
+
+ public RandomComponents() {
+ // Always use the same seed, used to ensure deterministic behaviour
+ rand = new Random(1);
+ }
+
+ /**
+ * Get random component container
+ *
+ * @param caption
+ * @return
+ */
+ public ComponentContainer getRandomComponentContainer(String caption) {
+ ComponentContainer result = null;
+ final int randint = rand.nextInt(5);
+ switch (randint) {
+
+ case 0:
+ result = new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL);
+ ((OrderedLayout) result).setCaption("OrderedLayout_horizontal_"
+ + caption);
+ break;
+ case 1:
+ result = new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL);
+ ((OrderedLayout) result).setCaption("OrderedLayout_vertical_"
+ + caption);
+ break;
+ case 2:
+ GridLayout gl;
+ if (rand.nextInt(1) > 0) {
+ gl = new GridLayout();
+ } else {
+ gl = new GridLayout(rand.nextInt(3) + 1, rand.nextInt(3) + 1);
+ }
+ gl.setCaption("GridLayout_" + caption);
+ gl.setDescription(gl.getCaption());
+ for (int x = 0; x < gl.getColumns(); x++) {
+ for (int y = 0; y < gl.getRows(); y++) {
+ // gl.addComponent(getExamplePicture("x=" + x + ", y=" + y),
+ // x, y);
+ gl.addComponent(new Label("x=" + x + ", y=" + y));
+ }
+ }
+ result = gl;
+ break;
+ case 3:
+ result = new Panel();
+ ((Panel) result).setCaption("Panel_" + caption);
+ break;
+ case 4:
+ final TabSheet ts = new TabSheet();
+ ts.setCaption("TabSheet_" + caption);
+ // randomly select one of the tabs
+ final int selectedTab = rand.nextInt(3);
+ final ArrayList tabs = new ArrayList();
+ for (int i = 0; i < 3; i++) {
+ String tabCaption = "tab" + i;
+ if (selectedTab == i) {
+ tabCaption = "tabX";
+ }
+ tabs.add(new OrderedLayout());
+ ts.addTab((ComponentContainer) tabs.get(tabs.size() - 1),
+ tabCaption, null);
+ }
+ ts.setSelectedTab((ComponentContainer) tabs.get(selectedTab));
+ result = ts;
+ break;
+ }
+
+ return result;
+ }
+
+ public AbstractComponent getRandomComponent(int caption) {
+ AbstractComponent result = null;
+ int randint = rand.nextInt(23);
+ MultiListener l = new MultiListener();
+ switch (randint) {
+ case 0:
+ // Label
+ result = new Label();
+ result.setCaption("Label component " + caption);
+ result.setDebugId(result.getCaption());
+ break;
+ case 1:
+ // Button
+ result = new Button();
+ result.setCaption("Button component " + caption);
+ result.setDebugId(result.getCaption());
+ // some listeners
+ ((Button) result).addListener((Button.ClickListener) l);
+ break;
+ case 2:
+ // TextField
+ result = new TextField();
+ result.setCaption("TextField component " + caption);
+ result.setDebugId(result.getCaption());
+ break;
+ case 3:
+ // Select
+ result = new Select("Select component " + caption);
+ result.setCaption("Select component " + caption);
+ result.setDebugId(result.getCaption());
+ result.setImmediate(true);
+ ((Select) result).setNewItemsAllowed(true);
+ // items
+ ((Select) result).addItem("first");
+ ((Select) result).addItem("first");
+ ((Select) result).addItem("first");
+ ((Select) result).addItem("second");
+ ((Select) result).addItem("third");
+ ((Select) result).addItem("fourth");
+ // some listeners
+ ((Select) result).addListener((ValueChangeListener) l);
+ ((Select) result).addListener((PropertySetChangeListener) l);
+ ((Select) result).addListener((ItemSetChangeListener) l);
+ break;
+ case 4:
+ // Link
+ result = new Link("", new ExternalResource("http://www.itmill.com"));
+ result.setCaption("Link component " + caption);
+ break;
+ case 5:
+ // Link
+ result = new Panel();
+ result.setCaption("Panel component " + caption);
+ ((Panel) result)
+ .addComponent(new Label(
+ "Panel is a container for other components, by default it draws a frame around it's "
+ + "extremities and may have a caption to clarify the nature of the contained components' purpose."
+ + " Panel contains an layout where the actual contained components are added, "
+ + "this layout may be switched on the fly."));
+ ((Panel) result).setWidth(250);
+ break;
+ case 6:
+ // Datefield
+ result = new DateField();
+ ((DateField) result).setStyleName("calendar");
+ ((DateField) result).setValue(date);
+ result.setCaption("Calendar component " + caption);
+ result.setDebugId(result.getCaption());
+ break;
+ case 7:
+ // Datefield
+ result = new DateField();
+ ((DateField) result).setValue(date);
+ result.setCaption("Calendar component " + caption);
+ result.setDebugId(result.getCaption());
+ break;
+ case 8:
+ result = new OrderedLayout();
+ ((OrderedLayout) result).addComponent(new ButtonExample());
+ break;
+ case 9:
+ result = new OrderedLayout();
+ ((OrderedLayout) result).addComponent(new ClientCachingExample());
+ break;
+ case 10:
+ result = new OrderedLayout();
+ ((OrderedLayout) result).addComponent(new ComboBoxExample());
+ break;
+ case 11:
+ result = new OrderedLayout();
+ ((OrderedLayout) result).addComponent(new EmbeddedBrowserExample());
+ break;
+ case 12:
+ result = new OrderedLayout();
+ ((OrderedLayout) result).addComponent(new EmbeddedBrowserExample());
+ break;
+ case 13:
+ result = new OrderedLayout();
+ ((OrderedLayout) result).addComponent(new LabelExample());
+ break;
+ case 14:
+ result = new OrderedLayout();
+ ((OrderedLayout) result).addComponent(new LayoutExample());
+ break;
+ case 15:
+ result = new OrderedLayout();
+ ((OrderedLayout) result).addComponent(new NotificationExample());
+ break;
+ case 16:
+ result = new OrderedLayout();
+ ((OrderedLayout) result).addComponent(new RichTextExample());
+ break;
+ case 17:
+ result = new OrderedLayout();
+ ((OrderedLayout) result).addComponent(new SelectExample());
+ break;
+ case 18:
+ result = new OrderedLayout();
+ ((OrderedLayout) result).addComponent(new ValueInputExample());
+ break;
+ case 19:
+ result = new OrderedLayout();
+ ((OrderedLayout) result).addComponent(new WindowingExample());
+ break;
+ case 20:
+ result = new OrderedLayout();
+ ((OrderedLayout) result).addComponent(new TreeExample());
+ break;
+ case 21:
+ result = new OrderedLayout();
+ ((OrderedLayout) result).addComponent(new TableExample());
+ break;
+ case 22:
+ result = new OrderedLayout();
+ ((OrderedLayout) result)
+ .addComponent(new ComponentsInTable(4, 1000));
+ break;
+ }
+
+ return result;
+ }
+
+ /**
+ * Add demo components to given container
+ *
+ * @param container
+ */
+ public void fillLayout(ComponentContainer container, int numberOfComponents) {
+ for (int i = 0; i < numberOfComponents; i++) {
+ container.addComponent(getRandomComponent(i));
+ }
+ }
+
+ public AbstractComponent getExamplePicture(String caption) {
+ final ThemeResource res = new ThemeResource("test.png");
+ final Embedded em = new Embedded("Embedded " + caption, res);
+ return em;
+ }
+
+}
diff --git a/src/com/vaadin/automatedtests/util/StatusServlet.java b/src/com/vaadin/automatedtests/util/StatusServlet.java
new file mode 100644
index 0000000000..c0b3c7c118
--- /dev/null
+++ b/src/com/vaadin/automatedtests/util/StatusServlet.java
@@ -0,0 +1,89 @@
+/*
+@ITMillApache2LicenseForJavaFiles@
+ */
+
+package com.vaadin.automatedtests.util;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+@SuppressWarnings("serial")
+public class StatusServlet extends HttpServlet {
+
+ public static DateFormat dfHuman = new SimpleDateFormat(
+ "yyyy-MM-dd HH:mm:ss");
+
+ /**
+ * Version number of this release. For example "5.0.0".
+ */
+ public static final String VERSION;
+
+ /**
+ * Major version number. For example 5 in 5.1.0.
+ */
+ public static final int VERSION_MAJOR;
+
+ /**
+ * Minor version number. For example 1 in 5.1.0.
+ */
+ public static final int VERSION_MINOR;
+
+ /**
+ * Builds number. For example 0-custom_tag in 5.0.0-custom_tag.
+ */
+ public static final String VERSION_BUILD;
+
+ /* Initialize version numbers from string replaced by build-script. */
+ static {
+ if ("@VERSION@".equals("@" + "VERSION" + "@")) {
+ VERSION = "5.9.9-INTERNAL-NONVERSIONED-DEBUG-BUILD";
+ } else {
+ VERSION = "@VERSION@";
+ }
+ final String[] digits = VERSION.split("\\.");
+ VERSION_MAJOR = Integer.parseInt(digits[0]);
+ VERSION_MINOR = Integer.parseInt(digits[1]);
+ VERSION_BUILD = digits[2];
+ }
+
+ @Override
+ public void init(javax.servlet.ServletConfig servletConfig)
+ throws javax.servlet.ServletException {
+ super.init(servletConfig);
+ }
+
+ @Override
+ protected void service(HttpServletRequest request,
+ HttpServletResponse response) throws ServletException, IOException {
+ Writer w = response.getWriter();
+
+ // not cacheable
+ response.setHeader("Cache-Control", "no-cache");
+ response.setHeader("Pragma", "no-cache");
+ response.setDateHeader("Expires", 0);
+ response.setContentType("text/html");
+
+ String p = "";
+ p += "<p>StatusServlet " + dfHuman.format(new Date()) + "</p>";
+ for (int i = 0; i < 30; i++) {
+ System.gc();
+ }
+ long inUse = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime()
+ .freeMemory());
+ p += "<p>Memory:<br />\n<memused>" + inUse
+ + "</memused> (Used)<br />\n" + "<memtotal>"
+ + Runtime.getRuntime().totalMemory()
+ + "<memtotal> (Total)<br />\n" + "<memfree>"
+ + Runtime.getRuntime().freeMemory() + "<memfree> (Free)</p>\n";
+
+ w.write("<html>\n" + p + "</html>\n");
+ }
+}