felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From santil...@apache.org
Subject svn commit: r438864 - in /incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/test/java: FelixLauncher.java org/apache/felix/jmood/FelixLauncher.java org/apache/felix/jmood/core/TestHarness.java
Date Thu, 31 Aug 2006 11:23:42 GMT
Author: santillan
Date: Thu Aug 31 04:23:42 2006
New Revision: 438864

URL: http://svn.apache.org/viewvc?rev=438864&view=rev
Log:
Refactored to make the TestHarness use the launcher.

Added:
    incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/test/java/org/apache/felix/jmood/FelixLauncher.java
      - copied, changed from r438554, incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/test/java/FelixLauncher.java
Removed:
    incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/test/java/FelixLauncher.java
Modified:
    incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/test/java/org/apache/felix/jmood/core/TestHarness.java

Copied: incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/test/java/org/apache/felix/jmood/FelixLauncher.java
(from r438554, incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/test/java/FelixLauncher.java)
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/test/java/org/apache/felix/jmood/FelixLauncher.java?p2=incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/test/java/org/apache/felix/jmood/FelixLauncher.java&p1=incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/test/java/FelixLauncher.java&r1=438554&r2=438864&rev=438864&view=diff
==============================================================================
--- incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/test/java/FelixLauncher.java
(original)
+++ incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/test/java/org/apache/felix/jmood/FelixLauncher.java
Thu Aug 31 04:23:42 2006
@@ -1,3 +1,4 @@
+package org.apache.felix.jmood;
 /*
  *   Copyright 2005 The Apache Software Foundation
  *
@@ -15,7 +16,9 @@
  *
  */
 
+import java.io.BufferedReader;
 import java.io.File;
+import java.io.InputStreamReader;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -31,19 +34,21 @@
 public class FelixLauncher {
 
     private MutablePropertyResolver props;
-	private Felix fw;
-	private List<String> bundles;
-	private List<String> packages;
+	private Felix framework;
+	private List bundles;
+	private List packages;
+	private File cacheDir;
 	public FelixLauncher() {
         super();
-    	File cacheDir=new File("./cache");
-    	clearCache(cacheDir);
+    	cacheDir = new File("./cache");
+    	System.out.println(cacheDir.getAbsolutePath());
+		clearCache(cacheDir);
     	cacheDir.mkdir();
         
-        fw = new Felix();
+        framework = new Felix();
 		Map m=new HashMap();
-		bundles=new ArrayList<String>();
-		packages=new ArrayList<String>();
+		bundles=new ArrayList();
+		packages=new ArrayList();
 
         props = new MutablePropertyResolverImpl(m);
         props.put("felix.cache.profiledir", cacheDir.getAbsolutePath());
@@ -59,22 +64,36 @@
 	}
 	public void start(){
 		StringBuffer autostart=new StringBuffer();
-		for (String bundle : bundles){
+		for (int i=0; i<bundles.size(); i++){
+			String bundle=(String)bundles.get(i);
 			autostart.append(bundle).append(" ");
 		}
 		props.put("felix.auto.start.1", autostart.toString());
-		StringBuffer spkg=new StringBuffer(packages.get(0));
+		StringBuffer spkg=new StringBuffer((String)packages.get(0));
 		packages.remove(0);
-		for(String pkg : packages){
+		for (int i=0; i<packages.size(); i++){
+			String pkg=(String)packages.get(i);
 			spkg.append(", "+pkg);
 		}
 		
 		
         props.put(Constants.FRAMEWORK_SYSTEMPACKAGES, spkg.toString());
 
-        fw.start(props,null);
+        framework.start(props,null);
+	}
+	public void blockingStart() throws Exception{
+		this.start();
+        int to=0;
+        while(framework.getStatus()!=Felix.RUNNING_STATUS) {
+            Thread.sleep(10);
+            to++;
+            if(to>100) throw new Exception("timeout");
+        }
 
-		
+	}
+	public void shutdown(){
+		framework.shutdown();
+		clearCache(cacheDir);
 	}
 
 	private void clearCache(File cacheDir) {
@@ -82,13 +101,17 @@
 			System.out.println("not valid cache");
 			return;
 		}
-		for(File f: cacheDir.listFiles())
-		recursiveDelete(f);
+		File[] files=cacheDir.listFiles();
+		for(int i=0; i<files.length; i++){
+			recursiveDelete(files[i]);
+		}
 	}
 	private void recursiveDelete(File file){
 	   if(file.isDirectory()){
-		   for(File f: file.listFiles()){
-			   recursiveDelete(f);
+			File[] files=file.listFiles();
+			for(int i=0; i<files.length; i++){
+				File f=files[i];	
+				recursiveDelete(f);
 		   }
 	   }
 	   file.delete();
@@ -96,7 +119,9 @@
 	private boolean isCache(File cacheDir){
 		if(!cacheDir.exists()||!cacheDir.isDirectory()) return false;
 		else{
-			for(String name :cacheDir.list()){
+			String[] names=cacheDir.list();
+			for(int i=0;i<names.length;i++){
+				String name=names[i];
 				if(!name.startsWith("bundle")) return false;
 			}
 			return true;
@@ -125,4 +150,7 @@
         launcher.addPackage("javax.script");
     	launcher.start();
     }
+	public Felix getFramework() {
+		return framework;
+	}
 }

Modified: incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/test/java/org/apache/felix/jmood/core/TestHarness.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/test/java/org/apache/felix/jmood/core/TestHarness.java?rev=438864&r1=438863&r2=438864&view=diff
==============================================================================
--- incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/test/java/org/apache/felix/jmood/core/TestHarness.java
(original)
+++ incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/test/java/org/apache/felix/jmood/core/TestHarness.java
Thu Aug 31 04:23:42 2006
@@ -16,139 +16,36 @@
  */
 
 package org.apache.felix.jmood.core;
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Vector;
-import java.util.logging.Logger;
-
-import javax.management.Attribute;
-import javax.management.AttributeList;
-import javax.management.MBeanServerConnection;
-import javax.management.ObjectName;
-import javax.management.remote.JMXConnectorFactory;
-import javax.management.remote.JMXServiceURL;
-
 import junit.framework.TestCase;
 
-import org.apache.felix.framework.Felix;
-import org.apache.felix.framework.util.MutablePropertyResolver;
-import org.apache.felix.framework.util.MutablePropertyResolverImpl;
-import org.osgi.framework.Constants;
-
-public class TestHarness /*extends TestCase*/ {
-//	private MBeanServerConnection server;
-//	private String url="service:jmx:rmi:///jndi/rmi://localhost:1199/server";
-//	private static Logger l=Logger.getLogger(TestHarness.class.getPackage().getName());
-//    private String BUNDLE_URL;
-//    private String CACHE_DIR;
-//    Felix fw;
-
-	public TestHarness() {
-//        super();
-//        BUNDLE_URL="file:\""+System.getProperty("user.dir")+"\"/dist/jmoodr4.jar";
-//        CACHE_DIR=System.getProperty("user.dir")+File.separator+"felix";
-		// TODO Auto-generated constructor stub
-	}
+import org.apache.felix.jmood.FelixLauncher;
 
+public class TestHarness extends TestCase {
+	private FelixLauncher launcher;
 	protected void setUp() throws Exception {
-//        super.setUp();
-//        fw=new Felix();
-//        Map m=new HashMap();
-//        StringBuffer spkg=new StringBuffer("org.osgi.framework, org.osgi.util.tracker,
org.osgi.service.log, org.osgi.service.packageadmin, org.osgi.service.startlevel");
-//        spkg.append(", org.osgi.service.permissionadmin");
-//        spkg.append(", org.osgi.service.useradmin");
-//        spkg.append(", org.osgi.service.cm");
-//        spkg.append(", javax.management");
-//        spkg.append(", javax.management.remote");
-//
-//        MutablePropertyResolver props=new MutablePropertyResolverImpl(m);
-//        props.put("felix.auto.start.1", BUNDLE_URL);
-//        //props.put("felix.embedded.execution", "true");
-//        props.put("felix.cache.dir", CACHE_DIR);
-//        props.put("felix.cache.profile", "test");
-//        props.put(Constants.FRAMEWORK_SYSTEMPACKAGES, spkg.toString());
-//        fw.start(props,null);
-//        int to=0;
-//        while(fw.getStatus()!=Felix.RUNNING_STATUS) {
-//            l.info("waiting for felix to be running");
-//            Thread.sleep(10);
-//            to++;
-//            if(to>100) throw new Exception("timeout");
-//        }
-//        boolean connected=false;
-//        to=0;
-//        while(!connected) {
-//        try {
-//            Thread.sleep(10);
-//		server=JMXConnectorFactory.connect(new JMXServiceURL(url)).getMBeanServerConnection();
-//        connected=true;
-//        to++;
-//        if(to>100) throw new Exception("timeout");
-//        } catch(IOException ioe) {}
-//        }
+		//ISSUE: this is not a unit test, but maven runs it as one
+		//before it builds the jar
+        super.setUp();
+        launcher=new FelixLauncher();
+        String jmood="file:target/org.apache.felix.jmood-0.8.0-SNAPSHOT.jar";
+        launcher.addBundle(jmood);
+        launcher.addPackage("org.osgi.framework");
+        launcher.addPackage("org.osgi.util.tracker");
+        launcher.addPackage("org.osgi.service.log");
+        launcher.addPackage("org.osgi.service.packageadmin");
+        launcher.addPackage("org.osgi.service.startlevel");
+        launcher.addPackage("org.osgi.service.permissionadmin");
+        launcher.addPackage("org.osgi.service.useradmin");
+        launcher.addPackage("org.osgi.service.cm");
+        launcher.addPackage("javax.management");
+        launcher.addPackage("javax.management.remote");
+        launcher.blockingStart();
 	}
-
 	protected void tearDown() throws Exception {
-//		super.tearDown();
-//        fw.shutdown();
-//        fw=null;
-//        
-//        File cache=new File(CACHE_DIR);
-//        if (!deleteFile(cache)) l.severe("could not delete cache");
-//        else {
-//            l.info("JUNIT: deleted chache dir: "+CACHE_DIR);
-//        }
-	}
-    private boolean deleteFile(File f) {
-    	return false;
-//        if(f.isDirectory()) {
-//            File[] children=f.listFiles();
-//            for (int i = 0; i < children.length; i++) {
-//                if(!deleteFile(children[i])) l.severe("could not delete "+children[i].getName());
-//            }
-//        }
-//        return f.delete();
-    }
-	protected MBeanServerConnection getServer(){
-		return null;
-//		return server;
+		super.tearDown();
+		launcher.shutdown();
 	}
-
-	public void testAttributes(ObjectName oname, Class mbeanClass) throws Exception {
-//		Class clazz=mbeanClass;
-//		Method[] methods=clazz.getMethods();
-//		Vector atts=new Vector();
-//		for (int i = 0; i < methods.length; i++) {
-//			String name=methods[i].getName();
-//			l.info("mbean method:"+ name);
-//			if (methods[i].getGenericParameterTypes().length!=0) continue;
-//			if(name.startsWith("get")){
-//				char c=name.charAt(3);
-//				if (Character.isLowerCase(c)) continue;
-//				String at=Character.toString(c)+name.substring(4);
-//				atts.add(at);
-//				l.info("attribute name:"+at);
-//			}else if (name.startsWith("is")){
-//				char c=name.charAt(2);
-//				if (Character.isLowerCase(c)) continue;
-//				String at=Character.toString(c)+name.substring(3);
-//				atts.add(at);
-//				l.info("attribute name:"+at);
-//			}
-//		}
-//		String[] attnames=(String[])atts.toArray(new String[atts.size()]);
-//		AttributeList list=getServer().getAttributes(oname,attnames);
-//		assertTrue("expected atts != retrieved atts: "+list.size()+"!="+attnames.length,attnames.length==list.size());
-//		Iterator it=list.iterator();
-//		while(it.hasNext()){
-//			Attribute at=(Attribute)it.next();
-//			l.info(at.getName()+": "+at.getValue());
-//		}
-//		
+	public void testDummy() {
+		//to avoid test not found assertion error
 	}
-
 }



Mime
View raw message