From: Mathieu Baudier Date: Sun, 21 Sep 2008 10:22:23 +0000 (+0000) Subject: Restructure Jemmy tests prototype X-Git-Tag: argeo-slc-2.1.7~2580 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;ds=sidebyside;h=3921e17b95b0d4f390f990c3ee59d36976f6dbf7;hp=e64b3c7fec3b91f865a0802f60516c59c9938481;p=gpl%2Fargeo-slc.git Restructure Jemmy tests prototype git-svn-id: https://svn.argeo.org/slc/trunk@1603 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/org.argeo.slc.autoui/pom.xml b/org.argeo.slc.autoui/pom.xml index 14d16f270..9722210ba 100644 --- a/org.argeo.slc.autoui/pom.xml +++ b/org.argeo.slc.autoui/pom.xml @@ -31,9 +31,6 @@ org.argeo.slc.autoui.* - - org.argeo.slc.jemmytest.ui.*;resolution=optional - + + org.apache.felix org.apache.felix.main - --> + \ No newline at end of file diff --git a/org.argeo.slc.autoui/src/main/java/org/argeo/slc/autoui/AutoUiActivator.java b/org.argeo.slc.autoui/src/main/java/org/argeo/slc/autoui/AutoUiActivator.java index 463a10bf3..cc78b2911 100644 --- a/org.argeo.slc.autoui/src/main/java/org/argeo/slc/autoui/AutoUiActivator.java +++ b/org.argeo.slc.autoui/src/main/java/org/argeo/slc/autoui/AutoUiActivator.java @@ -1,8 +1,5 @@ package org.argeo.slc.autoui; -import java.util.Properties; - -import org.argeo.slc.autoui.internal.AutoUiApplicationJemmy; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; @@ -10,12 +7,6 @@ public class AutoUiActivator implements BundleActivator { public void start(BundleContext context) throws Exception { stdOut("AutoUi started"); - Properties properties = new Properties(); - AutoUiApplicationJemmy applicationJemmy = new AutoUiApplicationJemmy(); - context.registerService(AutoUiApplication.class.getName(), - applicationJemmy, properties); - context.registerService(Runnable.class.getName(), applicationJemmy, - properties); } public void stop(BundleContext context) throws Exception { diff --git a/org.argeo.slc.autoui/src/main/java/org/argeo/slc/autoui/Main.java b/org.argeo.slc.autoui/src/main/java/org/argeo/slc/autoui/Main.java new file mode 100644 index 000000000..638ba01de --- /dev/null +++ b/org.argeo.slc.autoui/src/main/java/org/argeo/slc/autoui/Main.java @@ -0,0 +1,201 @@ +package org.argeo.slc.autoui; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.apache.felix.framework.Felix; +import org.apache.felix.framework.cache.BundleCache; +import org.apache.felix.framework.util.FelixConstants; +import org.apache.felix.framework.util.StringMap; +import org.apache.felix.main.AutoActivator; +import org.netbeans.jemmy.ClassReference; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; +import org.osgi.framework.ServiceReference; + +public class Main { + + /** + * @param args + */ + public static void main(String[] args) { + try { + // Create a temporary bundle cache directory and + // make sure to clean it up on exit. + final File cachedir = File.createTempFile( + "felix.example.servicebased", null); + cachedir.delete(); + Runtime.getRuntime().addShutdownHook(new Thread() { + public void run() { + deleteFileOrDir(cachedir); + } + }); + + String mavenBase = "file:/home/mbaudier/.m2/repository/"; + String uiPackage = "org.argeo.slc.testui"; + Map configMap = new StringMap(false); + configMap + .put( + Constants.FRAMEWORK_SYSTEMPACKAGES, + "org.osgi.framework; version=1.4.0," + + "org.osgi.service.packageadmin; version=1.2.0," + + "org.osgi.service.startlevel; version=1.1.0," + + "org.osgi.service.url; version=1.0.0," + + "org.osgi.util.tracker; version=1.3.3," + /*+ "org.apache.felix.example.servicebased.host.service; version=1.0.0,"*/ + + "org.argeo.slc.autoui; version=0.10.3.SNAPSHOT," + + uiPackage+"," + + "javax.swing"); + configMap + .put( + AutoActivator.AUTO_START_PROP + ".1", + mavenBase + + "org/apache/felix/org.apache.felix.shell/1.0.2/org.apache.felix.shell-1.0.2.jar " + + mavenBase + + "org/apache/felix/org.apache.felix.shell.tui/1.0.2/org.apache.felix.shell.tui-1.0.2.jar " + + mavenBase + + "org/argeo/dep/jemmy/org.argeo.dep.jemmy.nb61/0.2.0/org.argeo.dep.jemmy.nb61-0.2.0.jar " + + mavenBase + + "org/argeo/slc/sandbox/org.argeo.slc.sandbox.jemmytest/0.1.1-SNAPSHOT/org.argeo.slc.sandbox.jemmytest-0.1.1-SNAPSHOT.jar"); + configMap.put(FelixConstants.LOG_LEVEL_PROP, "1"); + configMap.put(BundleCache.CACHE_PROFILE_DIR_PROP, cachedir + .getAbsolutePath()); + + // Create list to hold custom framework activators. + List list = new ArrayList(); + // Add activator to process auto-start/install properties. + list.add(new AutoActivator(configMap)); + // Add our own activator. + list.add(new AutoUiActivator()); + + BundleContext context = null; + try { + // Now create an instance of the framework. + Felix felix = new Felix(configMap, list); + felix.start(); + + context = felix.getBundleContext(); + + // Bundle jemmyTestBundle = context + // .installBundle(mavenBase + // + + // "org/argeo/slc/sandbox/org.argeo.slc.sandbox.jemmytest/0.1.1-SNAPSHOT/org.argeo.slc.sandbox.jemmytest-0.1.1-SNAPSHOT.jar"); + // jemmyTestBundle.start(); + + } catch (Exception ex) { + System.err.println("Could not create framework: " + ex); + ex.printStackTrace(); + System.exit(-1); + } + + + // Start UI + String className = "org.argeo.slc.testui.SwingTestUi"; + //String className = SwingTestUi.class.getName(); + // String[] args = {}; + // SwingTestUi.main(args); + // Start application + ClassReference classReference = new ClassReference(className); + String[] uiArgs = { "noExitOnClose" }; + classReference.startApplication(uiArgs); + + + + ServiceReference ref = context + .getServiceReference("org.argeo.slc.autoui.AutoUiApplication"); +// ServiceReference ref = context +// .getServiceReference("java.lang.Runnable"); + Object service = context.getService(ref); + AutoUiActivator.stdOut("service=" + service.getClass()); + AutoUiApplication app = (AutoUiApplication) service; + app.execute(null); + // app.execute(null); + + + } catch (Exception e) { + e.printStackTrace(); + System.exit(-1); + } + + // Felix felix; + // // JemmyTestActivator activator; + // + // // Create a case-insensitive configuration property map. + // Map configMap = new StringMap(false); + // // Configure the Felix instance to be embedded. + // configMap.put(FelixConstants.EMBEDDED_EXECUTION_PROP, "true"); + // // Add core OSGi packages to be exported from the class path + // // via the system bundle. + // configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES, + // "org.osgi.framework; version=1.3.0," + // + "org.osgi.service.packageadmin; version=1.2.0," + // + "org.osgi.service.startlevel; version=1.0.0," + // + "org.osgi.service.url; version=1.0.0"); + // // Explicitly specify the directory to use for caching bundles. + // configMap.put(BundleCache.CACHE_PROFILE_DIR_PROP, "target/cache"); + // + // try { + // // Create host activator; + // // activator = new JemmyTestActivator(); + // List list = new ArrayList(); + // // list.add(activator); + // list.add(new Activator()); + // list.add(new org.apache.felix.shell.impl.Activator()); + // list.add(new org.apache.felix.bundlerepository.Activator()); + // + // // Now create an instance of the framework with + // // our configuration properties and activator. + // felix = new Felix(configMap, list); + // + // // Now start Felix instance. + // felix.start(); + // + // Bundle jemmyBundle = felix + // .getBundleContext() + // .installBundle( + // "file:/home/mbaudier/.m2/repository/org/argeo/dep/jemmy/org.argeo.dep.jemmy.nb61/0.2.0/org.argeo.dep.jemmy.nb61-0.2.0.jar"); + // jemmyBundle.start(); + // // + // // Bundle autoUiBundle = felix + // // .getBundleContext() + // // .installBundle( + // // + // "reference:file:/home/mbaudier/dev/src/slc/org.argeo.slc.autoui/"); + // // autoUiBundle.start(); + // + // Bundle[] bundles = felix.getBundleContext().getBundles(); + // for (int i = 0; i < bundles.length; i++) { + // Bundle bundle = bundles[i]; + // System.out.println("" + bundle.getBundleId() + "\t" + // + bundle.getSymbolicName() + "\t" + bundle.getState() + // + "\t" + bundle.getLocation()); + // } + // + // // felix.stop(); + // } catch (Exception ex) { + // System.err.println("Could not create framework: " + ex); + // ex.printStackTrace(); + // } + // + } + + /** + * Utility method used to delete the profile directory when run as a + * stand-alone application. + * + * @param file + * The file to recursively delete. + */ + private static void deleteFileOrDir(File file) { + if (file.isDirectory()) { + File[] childs = file.listFiles(); + for (int i = 0; i < childs.length; i++) { + deleteFileOrDir(childs[i]); + } + } + file.delete(); + } + +} diff --git a/org.argeo.slc.autoui/src/main/java/org/argeo/slc/autoui/internal/AutoUiApplicationJemmy.java b/org.argeo.slc.autoui/src/main/java/org/argeo/slc/autoui/internal/AutoUiApplicationJemmy.java deleted file mode 100644 index d22074226..000000000 --- a/org.argeo.slc.autoui/src/main/java/org/argeo/slc/autoui/internal/AutoUiApplicationJemmy.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.argeo.slc.autoui.internal; - -import org.argeo.slc.autoui.AutoUiActivator; -import org.argeo.slc.autoui.AutoUiApplication; -import org.netbeans.jemmy.ClassReference; -import org.netbeans.jemmy.operators.JButtonOperator; -import org.netbeans.jemmy.operators.JFrameOperator; -import org.netbeans.jemmy.operators.JLabelOperator; - -public class AutoUiApplicationJemmy implements AutoUiApplication { - public void run() { - try { - execute(new Object()); - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException("Could not execute as Runnable", e); - } - } - - public Object execute(Object object) throws Exception { - - String className = "org.argeo.slc.jemmytest.ui.SwingTestUi"; - // String[] args = {}; - // SwingTestUi.main(args); - // Start application - ClassReference classReference = new ClassReference(className); - String[] args = { "noExitOnClose" }; - classReference.startApplication(args); - - // Find components - JFrameOperator jFrameOperator = new JFrameOperator("HelloWorldSwing"); - JButtonOperator jButtonOperator = new JButtonOperator(jFrameOperator, - "Button"); - JLabelOperator jLabelOperator = new JLabelOperator(jFrameOperator, - "Hello World"); - - // Execute actions - jButtonOperator.push(); - - // Performs checks - String textAfterPush = jLabelOperator.getText(); - AutoUiActivator.stdOut("textAfterPush=" + textAfterPush); - - return null; - } - -} diff --git a/sandbox/argeo.slc.jemmytest/pom.xml b/sandbox/argeo.slc.jemmytest/pom.xml index 673bd0f8e..8797af113 100644 --- a/sandbox/argeo.slc.jemmytest/pom.xml +++ b/sandbox/argeo.slc.jemmytest/pom.xml @@ -20,8 +20,11 @@ ${pom.artifactId} + + org.argeo.slc.jemmytest.JemmyTestActivator + - !org.apache.felix.*,* + !org.apache.felix.*,*,javax.swing.* org.argeo.slc.jemmytest.* @@ -67,6 +70,10 @@ org.apache.felix org.osgi.core + + org.apache.felix + org.apache.felix.main + @@ -74,7 +81,6 @@ org.argeo.dep.jemmy org.argeo.dep.jemmy.nb61 0.2.0 - test junit diff --git a/sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/jemmytest/AutoUiApplicationJemmy.java b/sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/jemmytest/AutoUiApplicationJemmy.java new file mode 100644 index 000000000..d15b4fef7 --- /dev/null +++ b/sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/jemmytest/AutoUiApplicationJemmy.java @@ -0,0 +1,40 @@ +package org.argeo.slc.jemmytest; + +import org.argeo.slc.autoui.AutoUiActivator; +import org.argeo.slc.autoui.AutoUiApplication; +import org.netbeans.jemmy.ClassReference; +import org.netbeans.jemmy.operators.JButtonOperator; +import org.netbeans.jemmy.operators.JFrameOperator; +import org.netbeans.jemmy.operators.JLabelOperator; + +public class AutoUiApplicationJemmy implements AutoUiApplication { + public void run() { + try { + execute(new Object()); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Could not execute as Runnable" + + e.getMessage()); + } + } + + public Object execute(Object object) throws Exception { + + // Find components + JFrameOperator jFrameOperator = new JFrameOperator("HelloWorldSwing"); + JButtonOperator jButtonOperator = new JButtonOperator(jFrameOperator, + "Button"); + JLabelOperator jLabelOperator = new JLabelOperator(jFrameOperator, + "Hello World"); + + // Execute actions + jButtonOperator.push(); + + // Performs checks + String textAfterPush = jLabelOperator.getText(); + AutoUiActivator.stdOut("textAfterPush=" + textAfterPush); + + return null; + } + +} diff --git a/sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/jemmytest/JemmyTestActivator.java b/sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/jemmytest/JemmyTestActivator.java index 6047f83d6..f33855fbc 100644 --- a/sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/jemmytest/JemmyTestActivator.java +++ b/sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/jemmytest/JemmyTestActivator.java @@ -1,5 +1,8 @@ package org.argeo.slc.jemmytest; +import java.util.Properties; + +import org.argeo.slc.autoui.AutoUiApplication; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceEvent; @@ -9,6 +12,12 @@ public class JemmyTestActivator implements BundleActivator, ServiceListener { public void start(BundleContext context) throws Exception { stdOut("JemmyTest started"); + Properties properties = new Properties(); + AutoUiApplicationJemmy applicationJemmy = new AutoUiApplicationJemmy(); + context.registerService(AutoUiApplication.class.getName(), + applicationJemmy, properties); + context.registerService(Runnable.class.getName(), applicationJemmy, + properties); // ServiceReference ref = context // .getServiceReference("org.argeo.slc.autoui.AutoUiApplication"); diff --git a/sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/jemmytest/ui/SwingTestUi.java b/sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/jemmytest/ui/SwingTestUi.java deleted file mode 100644 index 91dfd126e..000000000 --- a/sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/jemmytest/ui/SwingTestUi.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.argeo.slc.jemmytest.ui; - -import java.awt.GridLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.JButton; -import javax.swing.JFrame; -import javax.swing.JLabel; - -public class SwingTestUi { - private static void createAndShowGUI(boolean exitOnClose) { - // Create and set up the window. - JFrame frame = new JFrame("HelloWorldSwing"); - if (exitOnClose) - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - - frame.getContentPane().setLayout(new GridLayout(2, 1)); - - // Add the ubiquitous "Hello World" label. - final JLabel label = new JLabel("Hello World"); - frame.getContentPane().add(label); - - final JButton button = new JButton("Button"); - frame.getContentPane().add(button); - button.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - label.setText("Pressed!!"); - } - }); - - // Display the window. - frame.pack(); - frame.setVisible(true); - } - - public static void main(String[] args) { - boolean noExitOnClose = false; - for (int i = 0; i < args.length; i++) { - if (args[i].equals("noExitOnClose")) { - noExitOnClose = true; - } - } - - final boolean exitOnClose = !noExitOnClose; - javax.swing.SwingUtilities.invokeLater(new Runnable() { - public void run() { - createAndShowGUI(exitOnClose); - } - }); - } - -} diff --git a/sandbox/argeo.slc.testui/.classpath b/sandbox/argeo.slc.testui/.classpath new file mode 100644 index 000000000..30a18728e --- /dev/null +++ b/sandbox/argeo.slc.testui/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/sandbox/argeo.slc.testui/.project b/sandbox/argeo.slc.testui/.project new file mode 100644 index 000000000..6b8609fcc --- /dev/null +++ b/sandbox/argeo.slc.testui/.project @@ -0,0 +1,17 @@ + + + argeo.slc.testui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/sandbox/argeo.slc.testui/.settings/org.eclipse.jdt.core.prefs b/sandbox/argeo.slc.testui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..897ca45f9 --- /dev/null +++ b/sandbox/argeo.slc.testui/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +#Sat Sep 20 12:22:38 GMT+02:00 2008 +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.3 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.1 +org.eclipse.jdt.core.compiler.problem.enumIdentifier=ignore +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=ignore +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled +org.eclipse.jdt.core.compiler.source=1.3 +eclipse.preferences.version=1 diff --git a/sandbox/argeo.slc.testui/src/main/java/org/argeo/slc/testui/SwingTestUi.java b/sandbox/argeo.slc.testui/src/main/java/org/argeo/slc/testui/SwingTestUi.java new file mode 100644 index 000000000..4ff18c746 --- /dev/null +++ b/sandbox/argeo.slc.testui/src/main/java/org/argeo/slc/testui/SwingTestUi.java @@ -0,0 +1,53 @@ +package org.argeo.slc.testui; + +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; + +public class SwingTestUi { + private static void createAndShowGUI(boolean exitOnClose) { + // Create and set up the window. + JFrame frame = new JFrame("HelloWorldSwing"); + if (exitOnClose) + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + frame.getContentPane().setLayout(new GridLayout(2, 1)); + + // Add the ubiquitous "Hello World" label. + final JLabel label = new JLabel("Hello World"); + frame.getContentPane().add(label); + + final JButton button = new JButton("Button"); + frame.getContentPane().add(button); + button.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + label.setText("Pressed!!"); + } + }); + + // Display the window. + frame.pack(); + frame.setVisible(true); + } + + public static void main(String[] args) { + boolean noExitOnClose = false; + for (int i = 0; i < args.length; i++) { + if (args[i].equals("noExitOnClose")) { + noExitOnClose = true; + } + } + + final boolean exitOnClose = !noExitOnClose; + javax.swing.SwingUtilities.invokeLater(new Runnable() { + public void run() { + createAndShowGUI(exitOnClose); + } + }); + } + +}