From: Mathieu Baudier Date: Fri, 19 Sep 2008 18:01:29 +0000 (+0000) Subject: (non fonctionning) OSGi tests X-Git-Tag: argeo-slc-2.1.7~2581 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=e64b3c7fec3b91f865a0802f60516c59c9938481;p=gpl%2Fargeo-slc.git (non fonctionning) OSGi tests git-svn-id: https://svn.argeo.org/slc/trunk@1602 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/sandbox/argeo.slc.jemmytest/.classpath b/sandbox/argeo.slc.jemmytest/.classpath index bddeaab31..cad23f086 100644 --- a/sandbox/argeo.slc.jemmytest/.classpath +++ b/sandbox/argeo.slc.jemmytest/.classpath @@ -3,7 +3,7 @@ - + diff --git a/sandbox/argeo.slc.jemmytest/build.properties b/sandbox/argeo.slc.jemmytest/build.properties new file mode 100644 index 000000000..528985695 --- /dev/null +++ b/sandbox/argeo.slc.jemmytest/build.properties @@ -0,0 +1,5 @@ +source.. = src/main/java/,\ + src/test/resources/,\ + src/test/java/ +bin.includes = META-INF/,\ + . diff --git a/sandbox/argeo.slc.jemmytest/pom.xml b/sandbox/argeo.slc.jemmytest/pom.xml index ff6769a0b..673bd0f8e 100644 --- a/sandbox/argeo.slc.jemmytest/pom.xml +++ b/sandbox/argeo.slc.jemmytest/pom.xml @@ -2,14 +2,37 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 - org.argeo.slc - slc-jemmy - SLC Jemmy + org.argeo.slc.sandbox + org.argeo.slc.sandbox.jemmytest + SLC Sandbox JemmyTest 0.1.1-SNAPSHOT - + bundle - + + org.apache.felix + maven-bundle-plugin + 1.4.3 + true + + META-INF + + + ${pom.artifactId} + + + !org.apache.felix.*,* + + + org.argeo.slc.jemmytest.* + + + + + org.apache.maven.plugins maven-compiler-plugin @@ -36,46 +59,40 @@ - org.netbeans - jemmy - 2.2.7.5 + org.argeo.slc + org.argeo.slc.autoui + 0.10.3-SNAPSHOT + + + org.apache.felix + org.osgi.core + + + + + + org.argeo.dep.jemmy + org.argeo.dep.jemmy.nb61 + 0.2.0 + test junit junit 3.8.2 + test + - commons-logging - commons-logging - 1.1.1 - - - log4j - log4j - 1.2.15 - - - com.sun.jmx - jmxri - - - com.sun.jdmk - jmxtools - - - javax.mail - mail - - - javax.jms - jms - - + org.apache.felix + org.apache.felix.main + 1.2.1 - - - - + + + argeo + http://www.argeo.org/maven/argeo + + \ No newline at end of file diff --git a/sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/autoui/swingtest/SwingTestUi.java b/sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/autoui/swingtest/SwingTestUi.java deleted file mode 100644 index e29f2dd07..000000000 --- a/sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/autoui/swingtest/SwingTestUi.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.argeo.slc.autoui.swingtest; - -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.jemmytest/src/main/java/org/argeo/slc/autoui/swingtest/rmi/AutoUiContext.java b/sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/autoui/swingtest/rmi/AutoUiContext.java deleted file mode 100644 index 868a0c927..000000000 --- a/sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/autoui/swingtest/rmi/AutoUiContext.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.argeo.slc.autoui.swingtest.rmi; - -public interface AutoUiContext { - public Object getLocalRef(String key); - - public void setLocalRef(String key, Object ref); -} diff --git a/sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/autoui/swingtest/rmi/AutoUiServer.java b/sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/autoui/swingtest/rmi/AutoUiServer.java deleted file mode 100644 index 089e6f88e..000000000 --- a/sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/autoui/swingtest/rmi/AutoUiServer.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.argeo.slc.autoui.swingtest.rmi; - -import java.rmi.Remote; -import java.rmi.RemoteException; - -public interface AutoUiServer extends Remote { - public Object executeTask(AutoUiTask task) throws RemoteException; -} diff --git a/sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/autoui/swingtest/rmi/AutoUiServerImpl.java b/sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/autoui/swingtest/rmi/AutoUiServerImpl.java deleted file mode 100644 index b32b23771..000000000 --- a/sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/autoui/swingtest/rmi/AutoUiServerImpl.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.argeo.slc.autoui.swingtest.rmi; - -import java.rmi.Naming; -import java.rmi.RemoteException; -import java.rmi.registry.LocateRegistry; -import java.rmi.registry.Registry; -import java.rmi.server.UnicastRemoteObject; -import java.util.Map; -import java.util.TreeMap; - -public class AutoUiServerImpl extends UnicastRemoteObject implements - AutoUiServer, AutoUiContext { - private Map map = new TreeMap(); - - public AutoUiServerImpl() throws RemoteException { - super(); - } - - public Object executeTask(AutoUiTask task) throws RemoteException { - try { - return task.execute(this); - } catch (Exception e) { - throw new RemoteException("Coul not execute task.", e); - } - } - - public Object getLocalRef(String key) { - return map.get(key); - } - - public void setLocalRef(String key, Object ref) { - map.put(key, ref); - } - - public static void main(String[] args) { - if (System.getSecurityManager() == null) { - System.setSecurityManager(new SecurityManager()); - } - try { - String name = "AutoUiServer"; - AutoUiServer engine = new AutoUiServerImpl(); - // AutoUiServer stub = (AutoUiServer) UnicastRemoteObject - // .exportObject(engine, 0); - // Registry registry = LocateRegistry.getRegistry(); - // registry.rebind(name, stub); - Naming.rebind(name, engine); - System.out.println("AutoUiServer bound"); - - } catch (Exception e) { - System.err.println("AutoUiServer exception:"); - e.printStackTrace(); - } - - } -} diff --git a/sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/autoui/swingtest/rmi/AutoUiTask.java b/sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/autoui/swingtest/rmi/AutoUiTask.java deleted file mode 100644 index 86dcc1f08..000000000 --- a/sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/autoui/swingtest/rmi/AutoUiTask.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.argeo.slc.autoui.swingtest.rmi; - -import java.io.Serializable; - -public interface AutoUiTask extends Serializable { - public Object execute(AutoUiContext context) throws Exception; -} 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 new file mode 100644 index 000000000..6047f83d6 --- /dev/null +++ b/sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/jemmytest/JemmyTestActivator.java @@ -0,0 +1,35 @@ +package org.argeo.slc.jemmytest; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceEvent; +import org.osgi.framework.ServiceListener; + +public class JemmyTestActivator implements BundleActivator, ServiceListener { + + public void start(BundleContext context) throws Exception { + stdOut("JemmyTest started"); + +// ServiceReference ref = context +// .getServiceReference("org.argeo.slc.autoui.AutoUiApplication"); +// Object service = context.getService(ref); +// // JemmyTestActivator.stdOut("service=" + service.getClass()); +// AutoUiApplication app = (AutoUiApplication) service; +// app.execute(null); + + } + + public void stop(BundleContext context) throws Exception { + stdOut("JemmyTest stopped"); + } + + public void serviceChanged(ServiceEvent serviceEvent) { + stdOut("serviceEvent=" + serviceEvent); + + } + + public static void stdOut(Object obj) { + System.out.println(obj); + } + +} diff --git a/sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/jemmytest/Main.java b/sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/jemmytest/Main.java new file mode 100644 index 000000000..45d02e7f4 --- /dev/null +++ b/sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/jemmytest/Main.java @@ -0,0 +1,185 @@ +package org.argeo.slc.jemmytest; + +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.osgi.framework.Bundle; +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/"; + + 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,"*/ + + "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/org.argeo.slc.autoui/0.10.3-SNAPSHOT/org.argeo.slc.autoui-0.10.3-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 JemmyTestActivator()); + + 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); + } + +// ServiceReference ref = context +// .getServiceReference("org.argeo.slc.autoui.AutoUiApplication"); + ServiceReference ref = context + .getServiceReference("java.lang.Runnable"); + Object service = context.getService(ref); + JemmyTestActivator.stdOut("service=" + service.getClass()); + Runnable app = (Runnable) service; + app.run(); + // 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/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 new file mode 100644 index 000000000..91dfd126e --- /dev/null +++ b/sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/jemmytest/ui/SwingTestUi.java @@ -0,0 +1,53 @@ +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.jemmytest/src/test/java/org/argeo/slc/autoui/swingtest/JemmyRemoteTest.java b/sandbox/argeo.slc.jemmytest/src/test/java/org/argeo/slc/autoui/swingtest/JemmyRemoteTest.java deleted file mode 100644 index 48bec9c49..000000000 --- a/sandbox/argeo.slc.jemmytest/src/test/java/org/argeo/slc/autoui/swingtest/JemmyRemoteTest.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.argeo.slc.autoui.swingtest; - -import java.io.Serializable; -import java.rmi.registry.LocateRegistry; -import java.rmi.registry.Registry; - -import org.argeo.slc.autoui.swingtest.rmi.AutoUiContext; -import org.argeo.slc.autoui.swingtest.rmi.AutoUiServer; -import org.argeo.slc.autoui.swingtest.rmi.AutoUiTask; -import org.netbeans.jemmy.ClassReference; -import org.netbeans.jemmy.operators.JButtonOperator; -import org.netbeans.jemmy.operators.JFrameOperator; -import org.netbeans.jemmy.operators.JLabelOperator; - -import junit.framework.TestCase; - -public class JemmyRemoteTest extends TestCase implements Serializable { - static final long serialVersionUID = 1l; - - public void testRemote() throws Exception { - if (System.getSecurityManager() == null) { - System.setSecurityManager(new SecurityManager()); - } - String name = "AutoUiServer"; - Registry registry = LocateRegistry.getRegistry("localhost"); - AutoUiServer server = (AutoUiServer) registry.lookup(name); - AutoUiTask startFrame = new AutoUiTask() { - static final long serialVersionUID = 1l; - - public Object execute(AutoUiContext context) throws Exception { - // Start application - ClassReference classReference = new ClassReference( - SwingTestUi.class.getName()); - 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"); - - context.setLocalRef("label", jLabelOperator); - context.setLocalRef("button", jButtonOperator); - return null; - } - - }; - - AutoUiTask pushButton = new AutoUiTask() { - static final long serialVersionUID = 1l; - - public Object execute(AutoUiContext context) throws Exception { - JButtonOperator jButtonOperator = (JButtonOperator) context - .getLocalRef("button"); - JLabelOperator jLabelOperator = (JLabelOperator) context - .getLocalRef("label"); - - // Execute actions - jButtonOperator.push(); - - // Performs checks - String textAfterPush = jLabelOperator.getText(); - Boolean pressed = new Boolean(textAfterPush.equals("Pressed!!")); - return pressed; - } - - }; - - server.executeTask(startFrame); - Boolean pressed = (Boolean) server.executeTask(pushButton); - assertTrue("Has been pressed", pressed.booleanValue()); - } - - public static void main(String[] args){ - try { - JemmyRemoteTest jemmyRemoteTest = new JemmyRemoteTest(); - jemmyRemoteTest.testRemote(); - } catch (Exception e) { - e.printStackTrace(); - } - } -} diff --git a/sandbox/argeo.slc.jemmytest/src/test/java/org/argeo/slc/autoui/swingtest/SwingTestJemmy.java b/sandbox/argeo.slc.jemmytest/src/test/java/org/argeo/slc/autoui/swingtest/SwingTestJemmy.java deleted file mode 100644 index 023968c14..000000000 --- a/sandbox/argeo.slc.jemmytest/src/test/java/org/argeo/slc/autoui/swingtest/SwingTestJemmy.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.argeo.slc.autoui.swingtest; - -import junit.framework.TestCase; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -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 SwingTestJemmy extends TestCase { - private final static Log log = LogFactory.getLog(SwingTestJemmy.class); - - public void testSimple() throws Exception { - // Start application - ClassReference classReference = new ClassReference(SwingTestUi.class - .getName()); - 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(); - assertEquals("Pressed!!", textAfterPush); - - // Clean up - jFrameOperator.close(); - } - -} diff --git a/sandbox/argeo.slc.jemmytest/src/test/java/org/argeo/slc/jemmytest/JemmyRemoteTest.java b/sandbox/argeo.slc.jemmytest/src/test/java/org/argeo/slc/jemmytest/JemmyRemoteTest.java new file mode 100644 index 000000000..b7de73f8b --- /dev/null +++ b/sandbox/argeo.slc.jemmytest/src/test/java/org/argeo/slc/jemmytest/JemmyRemoteTest.java @@ -0,0 +1,86 @@ +package org.argeo.slc.jemmytest; + +import java.io.Serializable; +import java.rmi.registry.LocateRegistry; +import java.rmi.registry.Registry; + +import org.argeo.slc.autoui.swingtest.rmi.AutoUiContext; +import org.argeo.slc.autoui.swingtest.rmi.AutoUiServer; +import org.argeo.slc.autoui.swingtest.rmi.AutoUiTask; +import org.argeo.slc.jemmytest.ui.SwingTestUi; +import org.netbeans.jemmy.ClassReference; +import org.netbeans.jemmy.operators.JButtonOperator; +import org.netbeans.jemmy.operators.JFrameOperator; +import org.netbeans.jemmy.operators.JLabelOperator; + +import junit.framework.TestCase; + +public class JemmyRemoteTest extends TestCase implements Serializable { + static final long serialVersionUID = 1l; + + public void testRemote() throws Exception { + if (System.getSecurityManager() == null) { + System.setSecurityManager(new SecurityManager()); + } + String name = "AutoUiServer"; + Registry registry = LocateRegistry.getRegistry("localhost"); + AutoUiServer server = (AutoUiServer) registry.lookup(name); + AutoUiTask startFrame = new AutoUiTask() { + static final long serialVersionUID = 1l; + + public Object execute(AutoUiContext context) throws Exception { + // Start application + ClassReference classReference = new ClassReference( + SwingTestUi.class.getName()); + 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"); + + context.setLocalRef("label", jLabelOperator); + context.setLocalRef("button", jButtonOperator); + return null; + } + + }; + + AutoUiTask pushButton = new AutoUiTask() { + static final long serialVersionUID = 1l; + + public Object execute(AutoUiContext context) throws Exception { + JButtonOperator jButtonOperator = (JButtonOperator) context + .getLocalRef("button"); + JLabelOperator jLabelOperator = (JLabelOperator) context + .getLocalRef("label"); + + // Execute actions + jButtonOperator.push(); + + // Performs checks + String textAfterPush = jLabelOperator.getText(); + Boolean pressed = new Boolean(textAfterPush.equals("Pressed!!")); + return pressed; + } + + }; + + server.executeTask(startFrame); + Boolean pressed = (Boolean) server.executeTask(pushButton); + assertTrue("Has been pressed", pressed.booleanValue()); + } + + public static void main(String[] args){ + try { + JemmyRemoteTest jemmyRemoteTest = new JemmyRemoteTest(); + jemmyRemoteTest.testRemote(); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/sandbox/argeo.slc.jemmytest/src/test/java/org/argeo/slc/jemmytest/SwingTestJemmy.java b/sandbox/argeo.slc.jemmytest/src/test/java/org/argeo/slc/jemmytest/SwingTestJemmy.java new file mode 100644 index 000000000..5de37ba17 --- /dev/null +++ b/sandbox/argeo.slc.jemmytest/src/test/java/org/argeo/slc/jemmytest/SwingTestJemmy.java @@ -0,0 +1,39 @@ +package org.argeo.slc.jemmytest; + +import junit.framework.TestCase; + +import org.argeo.slc.jemmytest.ui.SwingTestUi; +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 SwingTestJemmy extends TestCase { +// private final static Log log = LogFactory.getLog(SwingTestJemmy.class); + + public void testSimple() throws Exception { + // Start application + ClassReference classReference = new ClassReference(SwingTestUi.class + .getName()); + 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(); + assertEquals("Pressed!!", textAfterPush); + + // Clean up + jFrameOperator.close(); + } + +}