You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2013/05/05 17:40:35 UTC

svn commit: r1479341 - in /felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-bad-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/bad/test: Common.java TestBadLFCCallback.java TestBadLFCController.java TestBadServiceDependencies.java

Author: clement
Date: Sun May  5 15:40:34 2013
New Revision: 1479341

URL: http://svn.apache.org/r1479341
Log:
Refactor tests

Modified:
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-bad-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/bad/test/Common.java
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-bad-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/bad/test/TestBadLFCCallback.java
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-bad-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/bad/test/TestBadLFCController.java
    felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-bad-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/bad/test/TestBadServiceDependencies.java

Modified: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-bad-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/bad/test/Common.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-bad-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/bad/test/Common.java?rev=1479341&r1=1479340&r2=1479341&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-bad-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/bad/test/Common.java (original)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-bad-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/bad/test/Common.java Sun May  5 15:40:34 2013
@@ -19,222 +19,13 @@
 
 package org.apache.felix.ipojo.runtime.bad.test;
 
-import ch.qos.logback.classic.Level;
-import ch.qos.logback.classic.Logger;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.filefilter.TrueFileFilter;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.Configuration;
-import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.junit.PaxExam;
-import org.ops4j.pax.exam.options.CompositeOption;
-import org.ops4j.pax.exam.options.DefaultCompositeOption;
-import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
-import org.ops4j.pax.exam.spi.reactors.PerClass;
-import org.ops4j.pax.tinybundles.core.TinyBundle;
-import org.ops4j.pax.tinybundles.core.TinyBundles;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-import org.ow2.chameleon.testing.helpers.IPOJOHelper;
-import org.ow2.chameleon.testing.helpers.OSGiHelper;
-import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
-import org.slf4j.LoggerFactory;
-
-import javax.inject.Inject;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import static org.ops4j.pax.exam.CoreOptions.*;
+import org.ow2.chameleon.testing.helpers.BaseTest;
 
 /**
  * Bootstrap the test from this project
  */
-@RunWith(PaxExam.class)
-@ExamReactorStrategy(PerClass.class)
-public class Common {
-
-    @Inject
-    BundleContext bc;
-
-    OSGiHelper osgiHelper;
-    IPOJOHelper ipojoHelper;
-
-    Bundle testedBundle;
-
-    @Configuration
-    public Option[] config() throws MalformedURLException {
-        Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
-        root.setLevel(Level.INFO);
-
-        return options(
-                ipojoBundles(),
-                junitBundles(),
-                testedBundle(),
-                systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN")
-        );
-    }
-
-    @Before
-    public void commonSetUp() throws InterruptedException {
-        osgiHelper = new OSGiHelper(bc);
-        ipojoHelper = new IPOJOHelper(bc);
-
-        testedBundle = osgiHelper.getBundle("test.bundle");
-
-        // Dump OSGi Framework information
-        String vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VENDOR);
-        if (vendor == null) {
-            vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_SYMBOLICNAME);
-        }
-        String version = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VERSION);
-        System.out.println("OSGi Framework : " + vendor + " - " + version);
-
-        waitForStability(bc);
-
-    }
-
-    @After
-    public void commonTearDown() {
-        ipojoHelper.dispose();
-        osgiHelper.dispose();
-    }
-
-    public CompositeOption ipojoBundles() {
-        return new DefaultCompositeOption(
-                mavenBundle("org.apache.felix", "org.apache.felix.ipojo").versionAsInProject(),
-                mavenBundle("org.ow2.chameleon.testing", "osgi-helpers").versionAsInProject());
-    }
-
-    public Option testedBundle() throws MalformedURLException {
-        File out = new File("target/tested/bundle.jar");
-
-        TinyBundle tested = TinyBundles.bundle();
-
-        // We look inside target/classes to find the class and resources
-        File classes = new File("target/classes");
-        Collection<File> files = FileUtils.listFilesAndDirs(classes, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
-        List<File> services = new ArrayList<File>();
-        for (File file : files) {
-            if (file.isDirectory()) {
-                // By convention we export of .services and .service package
-                if (file.getName().endsWith("services") || file.getName().endsWith("service")) {
-                    services.add(file);
-                }
-            } else {
-                // We need to compute the path
-                String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() + 1);
-                tested.add(path, file.toURI().toURL());
-                System.out.println(file.getName() + " added to " + path);
-            }
-        }
-
-        String export = "";
-        for (File file : services) {
-            if (export.length() > 0) {
-                export += ", ";
-            }
-            String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() + 1);
-            String packageName = path.replace('/', '.');
-            export += packageName;
-        }
-
-        System.out.println("Exported packages : " + export);
-
-        InputStream inputStream = tested
-                .set(Constants.BUNDLE_SYMBOLICNAME, "test.bundle")
-                .set(Constants.IMPORT_PACKAGE, "*")
-                .set(Constants.EXPORT_PACKAGE, export)
-                .build(IPOJOStrategy.withiPOJO(new File("src/main/resources")));
-
-        try {
-            FileUtils.copyInputStreamToFile(inputStream, out);
-            return bundle(out.toURI().toURL().toExternalForm());
-        } catch (MalformedURLException e) {
-            throw new RuntimeException("Cannot compute the url of the manipulated bundle");
-        } catch (IOException e) {
-            throw new RuntimeException("Cannot write of the manipulated bundle");
-        }
-    }
-
-    /**
-     * Waits for stability:
-     * <ul>
-     * <li>all bundles are activated
-     * <li>service count is stable
-     * </ul>
-     * If the stability can't be reached after a specified time,
-     * the method throws a {@link IllegalStateException}.
-     * @param context the bundle context
-     * @throws IllegalStateException when the stability can't be reach after a several attempts.
-     */
-    private void waitForStability(BundleContext context) throws IllegalStateException {
-        // Wait for bundle initialization.
-        boolean bundleStability = getBundleStability(context);
-        int count = 0;
-        while (!bundleStability && count < 500) {
-            try {
-                Thread.sleep(5);
-            } catch (InterruptedException e) {
-                // Interrupted
-            }
-            count++;
-            bundleStability = getBundleStability(context);
-        }
-
-        if (count == 500) {
-            for (Bundle bundle : bc.getBundles()) {
-                System.out.println("Bundle " + bundle.getSymbolicName() + " - " + bundle.getState());
-            }
-            System.err.println("Bundle stability isn't reached after 500 tries");
-            throw new IllegalStateException("Cannot reach the bundle stability");
-        }
-
-        boolean serviceStability = false;
-        count = 0;
-        int count1 = 0;
-        int count2 = 0;
-        while (! serviceStability && count < 500) {
-            try {
-                ServiceReference[] refs = context.getServiceReferences((String) null, null);
-                count1 = refs.length;
-                Thread.sleep(500);
-                refs = context.getServiceReferences((String) null, null);
-                count2 = refs.length;
-                serviceStability = count1 == count2;
-            } catch (Exception e) {
-                System.err.println(e);
-                serviceStability = false;
-                // Nothing to do, while recheck the condition
-            }
-            count++;
-        }
+public class Common extends BaseTest {
 
-        if (count == 500) {
-            System.err.println("Service stability isn't reached after 500 tries (" + count1 + " != " + count2);
-            throw new IllegalStateException("Cannot reach the service stability");
-        }
-    }
+    // Nothing to customize.
 
-    /**
-     * Are bundle stables.
-     * @param bc the bundle context
-     * @return <code>true</code> if every bundles are activated.
-     */
-    private boolean getBundleStability(BundleContext bc) {
-        boolean stability = true;
-        Bundle[] bundles = bc.getBundles();
-        for (Bundle bundle : bundles) {
-            stability = stability && (bundle.getState() == Bundle.ACTIVE);
-        }
-        return stability;
-    }
 }

Modified: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-bad-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/bad/test/TestBadLFCCallback.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-bad-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/bad/test/TestBadLFCCallback.java?rev=1479341&r1=1479340&r2=1479341&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-bad-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/bad/test/TestBadLFCCallback.java (original)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-bad-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/bad/test/TestBadLFCCallback.java Sun May  5 15:40:34 2013
@@ -115,7 +115,7 @@ public class TestBadLFCCallback extends 
     }
 
     private Element getManipulationForComponent() {
-        String header = testedBundle.getHeaders().get("iPOJO-Components");
+        String header = getTestBundle().getHeaders().get("iPOJO-Components");
         Element elem = null;
         try {
             elem = ManifestMetadataParser.parseHeaderMetadata(header);
@@ -200,7 +200,7 @@ public class TestBadLFCCallback extends 
     @Test
     public void testBadMethod() {
         try {
-            ComponentFactory cf = new ComponentFactory(testedBundle.getBundleContext(), getBadMethod());
+            ComponentFactory cf = new ComponentFactory(getTestBundle().getBundleContext(), getBadMethod());
             cf.start();
             ComponentInstance ci = cf.createComponentInstance(props);
             if (ci.isStarted()) {
@@ -221,7 +221,7 @@ public class TestBadLFCCallback extends 
     @Test
     public void testBadMethod2() {
         try {
-            ComponentFactory cf = new ComponentFactory(testedBundle.getBundleContext(), getBadMethod2());
+            ComponentFactory cf = new ComponentFactory(getTestBundle().getBundleContext(), getBadMethod2());
             cf.start();
             ComponentInstance ci = cf.createComponentInstance(props);
             ci.stop();

Modified: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-bad-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/bad/test/TestBadLFCController.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-bad-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/bad/test/TestBadLFCController.java?rev=1479341&r1=1479340&r2=1479341&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-bad-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/bad/test/TestBadLFCController.java (original)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-bad-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/bad/test/TestBadLFCController.java Sun May  5 15:40:34 2013
@@ -53,7 +53,7 @@ public class TestBadLFCController extend
     }
 
     private Element getManipulationForComponent(String comp_name) {
-        String header = testedBundle.getHeaders().get("iPOJO-Components");
+        String header = getTestBundle().getHeaders().get("iPOJO-Components");
         Element elem = null;
         try {
             elem = ManifestMetadataParser.parseHeaderMetadata(header);

Modified: felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-bad-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/bad/test/TestBadServiceDependencies.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-bad-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/bad/test/TestBadServiceDependencies.java?rev=1479341&r1=1479340&r2=1479341&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-bad-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/bad/test/TestBadServiceDependencies.java (original)
+++ felix/trunk/ipojo/runtime/core-it/src/it/ipojo-core-bad-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/bad/test/TestBadServiceDependencies.java Sun May  5 15:40:34 2013
@@ -116,7 +116,7 @@ public class TestBadServiceDependencies 
     }
 
     private Element getManipulationForComponent() {
-        String header = testedBundle.getHeaders().get("iPOJO-Components");
+        String header = getTestBundle().getHeaders().get("iPOJO-Components");
         Element elem = null;
         try {
             elem = ManifestMetadataParser.parse(header);