diff options
author | Johannes Dahlström <johannes.dahlstrom@vaadin.com> | 2012-01-16 07:01:28 +0000 |
---|---|---|
committer | Johannes Dahlström <johannes.dahlstrom@vaadin.com> | 2012-01-16 07:01:28 +0000 |
commit | 326ccadd49971a36bcf4c356f114eba70a4e337f (patch) | |
tree | 7756dead0ad908b23911030464fe308f5929be3d /tests/testbench | |
parent | c661750fbc7149becd34548ac3a0a844df39b3b7 (diff) | |
download | vaadin-framework-326ccadd49971a36bcf4c356f114eba70a4e337f.tar.gz vaadin-framework-326ccadd49971a36bcf4c356f114eba70a4e337f.zip |
Merged #8105 Compile core files and test files to separate folders
svn changeset:22636/svn branch:6.8
Diffstat (limited to 'tests/testbench')
-rw-r--r-- | tests/testbench/com/vaadin/launcher/util/BrowserLauncher.java | 127 | ||||
-rw-r--r-- | tests/testbench/com/vaadin/tests/Components.java | 17 | ||||
-rw-r--r-- | tests/testbench/com/vaadin/tests/VaadinClasses.java | 235 |
3 files changed, 135 insertions, 244 deletions
diff --git a/tests/testbench/com/vaadin/launcher/util/BrowserLauncher.java b/tests/testbench/com/vaadin/launcher/util/BrowserLauncher.java new file mode 100644 index 0000000000..55692cb251 --- /dev/null +++ b/tests/testbench/com/vaadin/launcher/util/BrowserLauncher.java @@ -0,0 +1,127 @@ +/*
+@VaadinApache2LicenseForJavaFiles@
+ */
+
+package com.vaadin.launcher.util;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+/**
+ * This class opens default browser for DemoLauncher class. Default browser is
+ * detected by the operating system.
+ *
+ */
+public class BrowserLauncher {
+
+ /**
+ * Open browser on specified URL.
+ *
+ * @param url
+ */
+ public static void openBrowser(String url) {
+
+ final Runtime runtime = Runtime.getRuntime();
+ boolean started = false;
+
+ final String os = System.getProperty("os.name", "windows")
+ .toLowerCase();
+
+ // Linux
+ if (os.indexOf("linux") >= 0) {
+ // See if the default browser is Konqueror by resolving the symlink.
+ boolean isDefaultKonqueror = false;
+ try {
+ // Find out the location of the x-www-browser link from path.
+ Process process = runtime.exec("which x-www-browser");
+ BufferedInputStream ins = new BufferedInputStream(
+ process.getInputStream());
+ BufferedReader bufreader = new BufferedReader(
+ new InputStreamReader(ins));
+ String defaultLinkPath = bufreader.readLine();
+ ins.close();
+
+ // The path is null if the link did not exist.
+ if (defaultLinkPath != null) {
+ // See if the default browser is Konqueror.
+ File file = new File(defaultLinkPath);
+ String canonical = file.getCanonicalPath();
+ if (canonical.indexOf("konqueror") != -1) {
+ isDefaultKonqueror = true;
+ }
+ }
+ } catch (IOException e1) {
+ // The symlink was probably not found, so this is ok.
+ }
+
+ // Try x-www-browser, which is symlink to the default browser,
+ // except if we found that it is Konqueror.
+ if (!started && !isDefaultKonqueror) {
+ try {
+ runtime.exec("x-www-browser " + url);
+ started = true;
+ } catch (final IOException e) {
+ }
+ }
+
+ // Try firefox
+ if (!started) {
+ try {
+ runtime.exec("firefox " + url);
+ started = true;
+ } catch (final IOException e) {
+ }
+ }
+
+ // Try mozilla
+ if (!started) {
+ try {
+ runtime.exec("mozilla " + url);
+ started = true;
+ } catch (final IOException e) {
+ }
+ }
+
+ // Try konqueror
+ if (!started) {
+ try {
+ runtime.exec("konqueror " + url);
+ started = true;
+ } catch (final IOException e) {
+ }
+ }
+ }
+
+ // OS X
+ if (os.indexOf("mac os x") >= 0) {
+
+ // Try open
+ if (!started) {
+ try {
+ runtime.exec("open " + url);
+ started = true;
+ } catch (final IOException e) {
+ }
+ }
+ }
+
+ // Try cmd /start command on windows
+ if (os.indexOf("win") >= 0) {
+ if (!started) {
+ try {
+ runtime.exec("cmd /c start " + url);
+ started = true;
+ } catch (final IOException e) {
+ }
+ }
+ }
+
+ if (!started) {
+ System.out.println("Failed to open browser. Please go to " + url);
+ }
+ }
+
+}
diff --git a/tests/testbench/com/vaadin/tests/Components.java b/tests/testbench/com/vaadin/tests/Components.java index 6987c04a54..d7bc18e2f6 100644 --- a/tests/testbench/com/vaadin/tests/Components.java +++ b/tests/testbench/com/vaadin/tests/Components.java @@ -32,7 +32,7 @@ import com.vaadin.ui.Window; public class Components extends Application {
private static final Object CAPTION = "c";
- private Map<Class<? extends AbstractComponentTest<?>>, String> tests = new HashMap<Class<? extends AbstractComponentTest<?>>, String>();
+ private Map<Class<? extends AbstractComponentTest>, String> tests = new HashMap<Class<? extends AbstractComponentTest>, String>();
private Tree naviTree;
private HorizontalSplitPanel sp;
private Window mainWindow;
@@ -41,10 +41,9 @@ public class Components extends Application { private List<Class<? extends Component>> componentsWithoutTests = new ArrayList<Class<? extends Component>>();
{
- for (Class<? extends AbstractComponentTest<?>> c : VaadinClasses
- .getBasicComponentTests()) {
+ for (Class<?> c : VaadinClasses.getBasicComponentTests()) {
String testClass = c.getSimpleName();
- tests.put(c, testClass);
+ tests.put((Class<? extends AbstractComponentTest>) c, testClass);
}
List<Class<? extends Component>> componentsWithoutTest = VaadinClasses
@@ -171,7 +170,7 @@ public class Components extends Application { hc.setItemSorter(sorter);
naviTree.addContainerProperty(CAPTION, String.class, "");
naviTree.setItemCaptionPropertyId(CAPTION);
- for (Class<? extends AbstractComponentTest<?>> cls : tests.keySet()) {
+ for (Class<? extends AbstractComponentTest> cls : tests.keySet()) {
addTreeItem(cls);
}
hc.sort(new Object[] { CAPTION }, new boolean[] { true });
@@ -226,13 +225,13 @@ public class Components extends Application { }
@SuppressWarnings("unchecked")
- private void addTreeItem(Class<? extends AbstractComponentTest<?>> cls) {
+ private void addTreeItem(Class<? extends AbstractComponentTest> cls) {
String name = tests.get(cls);
if (name == null) {
name = cls.getSimpleName();
}
- Class<? extends AbstractComponentTest<?>> superClass = (Class<? extends AbstractComponentTest<?>>) cls
+ Class<? extends AbstractComponentTest> superClass = (Class<? extends AbstractComponentTest>) cls
.getSuperclass();
// This cast is needed only to make compilation through Ant work ..
@@ -249,9 +248,9 @@ public class Components extends Application { }
protected Component createTestComponent(
- Class<? extends AbstractComponentTest<?>> cls) {
+ Class<? extends AbstractComponentTest> cls) {
try {
- AbstractComponentTest<?> t = cls.newInstance();
+ AbstractComponentTest t = cls.newInstance();
t.init();
ComponentContainer c = t.getMainWindow().getContent();
t.getMainWindow().setContent(null);
diff --git a/tests/testbench/com/vaadin/tests/VaadinClasses.java b/tests/testbench/com/vaadin/tests/VaadinClasses.java deleted file mode 100644 index 0f4e2ff4da..0000000000 --- a/tests/testbench/com/vaadin/tests/VaadinClasses.java +++ /dev/null @@ -1,235 +0,0 @@ -package com.vaadin.tests; - -import java.io.File; -import java.io.IOException; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.net.JarURLConnection; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.Enumeration; -import java.util.List; -import java.util.jar.JarEntry; - -import org.junit.Test; - -import com.vaadin.Application; -import com.vaadin.tests.components.AbstractComponentTest; -import com.vaadin.ui.Component; -import com.vaadin.ui.ComponentContainer; -import com.vaadin.ui.CustomComponent; -import com.vaadin.ui.DragAndDropWrapper; -import com.vaadin.ui.HorizontalSplitPanel; -import com.vaadin.ui.LoginForm; -import com.vaadin.ui.PopupView; -import com.vaadin.ui.SplitPanel; -import com.vaadin.ui.VerticalSplitPanel; -import com.vaadin.ui.Window; - -@SuppressWarnings("deprecation") -public class VaadinClasses { - - public static void main(String[] args) { - System.out.println("ComponentContainers"); - System.out.println("==================="); - for (Class<? extends ComponentContainer> c : getComponentContainers()) { - System.out.println(c.getName()); - } - System.out.println(); - System.out.println("Components"); - System.out.println("=========="); - for (Class<? extends Component> c : getComponents()) { - System.out.println(c.getName()); - } - System.out.println(); - System.out.println("Server side classes"); - System.out.println("==================="); - for (Class<?> c : getAllServerSideClasses()) { - System.out.println(c.getName()); - } - } - - public static List<Class<? extends Component>> getComponents() { - try { - return findClasses(Component.class, "com.vaadin.ui"); - } catch (IOException e) { - e.printStackTrace(); - return null; - } - } - - public static List<Class<? extends Object>> getAllServerSideClasses() { - try { - return findClassesNoTests(Object.class, "com.vaadin", new String[] { - "com.vaadin.tests", "com.vaadin.terminal.gwt.client" }); - } catch (IOException e) { - e.printStackTrace(); - return null; - } - } - - public static List<Class<? extends ComponentContainer>> getComponentContainers() { - try { - return findClasses(ComponentContainer.class, "com.vaadin.ui"); - } catch (IOException e) { - e.printStackTrace(); - return null; - } - } - - public static List<Class<? extends ComponentContainer>> getComponentContainersSupportingAddRemoveComponent() { - List<Class<? extends ComponentContainer>> classes = getComponentContainers(); - classes.remove(PopupView.class); - classes.remove(CustomComponent.class); - classes.remove(DragAndDropWrapper.class); - classes.remove(CustomComponent.class); - classes.remove(LoginForm.class); - - return classes; - } - - public static List<Class<? extends ComponentContainer>> getComponentContainersSupportingUnlimitedNumberOfComponents() { - List<Class<? extends ComponentContainer>> classes = getComponentContainersSupportingAddRemoveComponent(); - classes.remove(SplitPanel.class); - classes.remove(VerticalSplitPanel.class); - classes.remove(HorizontalSplitPanel.class); - classes.remove(Window.class); - - return classes; - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - public static List<Class<? extends AbstractComponentTest<?>>> getBasicComponentTests() { - try { - return (List) findClasses(AbstractComponentTest.class, - "com.vaadin.tests.components"); - } catch (IOException e) { - e.printStackTrace(); - return null; - } - - } - - private static <T> List<Class<? extends T>> findClasses(Class<T> baseClass, - String basePackage) throws IOException { - return findClasses(baseClass, basePackage, new String[] {}); - } - - private static <T> List<Class<? extends T>> findClasses(Class<T> baseClass, - String basePackage, String[] ignoredPackages) throws IOException { - List<Class<? extends T>> classes = new ArrayList<Class<? extends T>>(); - String basePackageDirName = "/" + basePackage.replace('.', '/'); - URL location = Application.class.getResource(basePackageDirName); - if (location.getProtocol().equals("file")) { - try { - File f = new File(location.toURI()); - if (!f.exists()) { - throw new IOException("Directory " + f.toString() - + " does not exist"); - } - findPackages(f, basePackage, baseClass, classes, - ignoredPackages); - } catch (URISyntaxException e) { - throw new IOException(e.getMessage()); - } - } else if (location.getProtocol().equals("jar")) { - JarURLConnection juc = (JarURLConnection) location.openConnection(); - findPackages(juc, basePackage, baseClass, classes); - } - - Collections.sort(classes, new Comparator<Class<? extends T>>() { - - public int compare(Class<? extends T> o1, Class<? extends T> o2) { - return o1.getName().compareTo(o2.getName()); - } - - }); - return classes; - } - - private static <T> List<Class<? extends T>> findClassesNoTests( - Class<T> baseClass, String basePackage, String[] ignoredPackages) - throws IOException { - List<Class<? extends T>> classes = findClasses(baseClass, basePackage, - ignoredPackages); - List<Class<? extends T>> classesNoTests = new ArrayList<Class<? extends T>>(); - for (Class<? extends T> clazz : classes) { - if (!clazz.getName().contains("Test")) { - boolean testPresent = false; - for (Method method : clazz.getMethods()) { - if (method.isAnnotationPresent(Test.class)) { - testPresent = true; - break; - } - } - if (!testPresent) { - classesNoTests.add(clazz); - } - } - } - return classesNoTests; - } - - private static <T> void findPackages(JarURLConnection juc, - String javaPackage, Class<T> baseClass, - Collection<Class<? extends T>> result) throws IOException { - String prefix = "com/vaadin/ui"; - Enumeration<JarEntry> ent = juc.getJarFile().entries(); - while (ent.hasMoreElements()) { - JarEntry e = ent.nextElement(); - if (e.getName().endsWith(".class") - && e.getName().startsWith(prefix)) { - String fullyQualifiedClassName = e.getName().replace('/', '.') - .replace(".class", ""); - addClassIfMatches(result, fullyQualifiedClassName, baseClass); - } - } - } - - private static <T> void findPackages(File parent, String javaPackage, - Class<T> baseClass, Collection<Class<? extends T>> result, - String[] ignoredPackages) { - for (String ignoredPackage : ignoredPackages) { - if (javaPackage.equals(ignoredPackage)) { - return; - } - } - - for (File file : parent.listFiles()) { - if (file.isDirectory()) { - findPackages(file, javaPackage + "." + file.getName(), - baseClass, result, ignoredPackages); - } else if (file.getName().endsWith(".class")) { - String fullyQualifiedClassName = javaPackage + "." - + file.getName().replace(".class", ""); - addClassIfMatches(result, fullyQualifiedClassName, baseClass); - } - } - - } - - @SuppressWarnings("unchecked") - private static <T> void addClassIfMatches( - Collection<Class<? extends T>> result, - String fullyQualifiedClassName, Class<T> baseClass) { - try { - // Try to load the class - - Class<?> c = Class.forName(fullyQualifiedClassName); - if (baseClass.isAssignableFrom(c) - && !Modifier.isAbstract(c.getModifiers())) { - result.add((Class<? extends T>) c); - } - } catch (Exception e) { - // Could ignore that class cannot be loaded - e.printStackTrace(); - } catch (LinkageError e) { - // Ignore. Client side classes will at least throw LinkageErrors - } - - } -} |