From e64b3c7fec3b91f865a0802f60516c59c9938481 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Fri, 19 Sep 2008 18:01:29 +0000 Subject: [PATCH] (non fonctionning) OSGi tests git-svn-id: https://svn.argeo.org/slc/trunk@1602 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- sandbox/argeo.slc.jemmytest/.classpath | 2 +- sandbox/argeo.slc.jemmytest/build.properties | 5 + sandbox/argeo.slc.jemmytest/pom.xml | 93 +++++---- .../autoui/swingtest/rmi/AutoUiContext.java | 7 - .../autoui/swingtest/rmi/AutoUiServer.java | 8 - .../swingtest/rmi/AutoUiServerImpl.java | 55 ------ .../slc/autoui/swingtest/rmi/AutoUiTask.java | 7 - .../slc/jemmytest/JemmyTestActivator.java | 35 ++++ .../java/org/argeo/slc/jemmytest/Main.java | 185 ++++++++++++++++++ .../ui}/SwingTestUi.java | 2 +- .../JemmyRemoteTest.java | 3 +- .../SwingTestJemmy.java | 7 +- 12 files changed, 287 insertions(+), 122 deletions(-) create mode 100644 sandbox/argeo.slc.jemmytest/build.properties delete mode 100644 sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/autoui/swingtest/rmi/AutoUiContext.java delete mode 100644 sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/autoui/swingtest/rmi/AutoUiServer.java delete mode 100644 sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/autoui/swingtest/rmi/AutoUiServerImpl.java delete mode 100644 sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/autoui/swingtest/rmi/AutoUiTask.java create mode 100644 sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/jemmytest/JemmyTestActivator.java create mode 100644 sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/jemmytest/Main.java rename sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/{autoui/swingtest => jemmytest/ui}/SwingTestUi.java (97%) rename sandbox/argeo.slc.jemmytest/src/test/java/org/argeo/slc/{autoui/swingtest => jemmytest}/JemmyRemoteTest.java (97%) rename sandbox/argeo.slc.jemmytest/src/test/java/org/argeo/slc/{autoui/swingtest => jemmytest}/SwingTestJemmy.java (83%) 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/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/autoui/swingtest/SwingTestUi.java b/sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/jemmytest/ui/SwingTestUi.java similarity index 97% rename from sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/autoui/swingtest/SwingTestUi.java rename to sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/jemmytest/ui/SwingTestUi.java index e29f2dd07..91dfd126e 100644 --- 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/jemmytest/ui/SwingTestUi.java @@ -1,4 +1,4 @@ -package org.argeo.slc.autoui.swingtest; +package org.argeo.slc.jemmytest.ui; import java.awt.GridLayout; import java.awt.event.ActionEvent; 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/jemmytest/JemmyRemoteTest.java similarity index 97% rename from sandbox/argeo.slc.jemmytest/src/test/java/org/argeo/slc/autoui/swingtest/JemmyRemoteTest.java rename to sandbox/argeo.slc.jemmytest/src/test/java/org/argeo/slc/jemmytest/JemmyRemoteTest.java index 48bec9c49..b7de73f8b 100644 --- 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/jemmytest/JemmyRemoteTest.java @@ -1,4 +1,4 @@ -package org.argeo.slc.autoui.swingtest; +package org.argeo.slc.jemmytest; import java.io.Serializable; import java.rmi.registry.LocateRegistry; @@ -7,6 +7,7 @@ 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; 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/jemmytest/SwingTestJemmy.java similarity index 83% rename from sandbox/argeo.slc.jemmytest/src/test/java/org/argeo/slc/autoui/swingtest/SwingTestJemmy.java rename to sandbox/argeo.slc.jemmytest/src/test/java/org/argeo/slc/jemmytest/SwingTestJemmy.java index 023968c14..5de37ba17 100644 --- 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/jemmytest/SwingTestJemmy.java @@ -1,16 +1,15 @@ -package org.argeo.slc.autoui.swingtest; +package org.argeo.slc.jemmytest; import junit.framework.TestCase; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +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); +// private final static Log log = LogFactory.getLog(SwingTestJemmy.class); public void testSimple() throws Exception { // Start application -- 2.39.2