You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ni...@apache.org on 2014/06/09 17:11:03 UTC

svn commit: r1601404 - /tika/trunk/tika-bundle/src/test/java/org/apache/tika/bundle/BundleIT.java

Author: nick
Date: Mon Jun  9 15:11:03 2014
New Revision: 1601404

URL: http://svn.apache.org/r1601404
Log:
Add a tests that ensures that the Tika Bundles are found + started, and clarify a bit why the detectors test should work but isn't

Modified:
    tika/trunk/tika-bundle/src/test/java/org/apache/tika/bundle/BundleIT.java

Modified: tika/trunk/tika-bundle/src/test/java/org/apache/tika/bundle/BundleIT.java
URL: http://svn.apache.org/viewvc/tika/trunk/tika-bundle/src/test/java/org/apache/tika/bundle/BundleIT.java?rev=1601404&r1=1601403&r2=1601404&view=diff
==============================================================================
--- tika/trunk/tika-bundle/src/test/java/org/apache/tika/bundle/BundleIT.java (original)
+++ tika/trunk/tika-bundle/src/test/java/org/apache/tika/bundle/BundleIT.java Mon Jun  9 15:11:03 2014
@@ -48,6 +48,7 @@ import org.ops4j.pax.exam.CoreOptions;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.Configuration;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.xml.sax.ContentHandler;
 
@@ -55,8 +56,6 @@ import org.xml.sax.ContentHandler;
 public class BundleIT {
     private final File TARGET = new File("target");
     
-    private TestingServiceLoader nonOSGiLoader = new TestingServiceLoader();
-    
     @Configuration
     public Option[] configuration() throws IOException, URISyntaxException {
         File base = new File(TARGET, "test-bundles");
@@ -67,6 +66,23 @@ public class BundleIT {
     }
     
     @Test
+    public void testBundleLoaded(BundleContext bc) throws Exception {
+        boolean hasCore = false, hasBundle = false;
+        for (Bundle b : bc.getBundles()) {
+            if ("org.apache.tika.core".equals(b.getSymbolicName())) {
+                hasCore = true;
+                assertEquals("Core not activated", Bundle.ACTIVE, b.getState());
+            }
+            if ("org.apache.tika.bundle".equals(b.getSymbolicName())) {
+                hasBundle = true;
+                assertEquals("Bundle not activated", Bundle.ACTIVE, b.getState());
+            }
+        }
+        assertTrue("Core bundle not found", hasCore);
+        assertTrue("Bundle bundle not found", hasBundle);
+    }
+    
+    @Test
     public void testBundleDetection(BundleContext bc) throws Exception {
         Tika tika = new Tika();
 
@@ -88,16 +104,17 @@ public class BundleIT {
     @Ignore // TODO Fix this test
     @Test
     public void testBundleDetectors(BundleContext bc) throws Exception {
-        // Get the non-OSGi detectors
-        List<String> nonOSGiDetectors =
-                nonOSGiLoader.identifyStaticServiceProviders(Detector.class);
+        // Get the raw detectors list
+        // TODO Why is this not finding the detector service resource files?
+        TestingServiceLoader loader = new TestingServiceLoader();
+        List<String> rawDetectors = loader.identifyStaticServiceProviders(Detector.class);
         
         // Check we did get a few, just in case...
-        assertNotNull(nonOSGiDetectors);
-        assertTrue("Should have several non-OSGi detectors, found " + nonOSGiDetectors.size(),
-                   nonOSGiDetectors.size() > 3);
+        assertNotNull(rawDetectors);
+        assertTrue("Should have several Detector names, found " + rawDetectors.size(),
+                rawDetectors.size() > 3);
         
-        // Get the ones found within OSGi
+        // Get the classes found within OSGi
         DefaultDetector detector = new DefaultDetector();
         Set<String> osgiDetectors = new HashSet<String>();
         for (Detector d : detector.getDetectors()) {
@@ -105,7 +122,7 @@ public class BundleIT {
         }
         
         // Check that OSGi didn't miss any
-        for (String detectorName : nonOSGiDetectors) {
+        for (String detectorName : rawDetectors) {
             if (!osgiDetectors.contains(detectorName)) {
                 fail("Detector " + detectorName + 
                      " not found within OSGi Detector list: " + osgiDetectors);
@@ -167,7 +184,7 @@ public class BundleIT {
      */
     private static class TestingServiceLoader extends ServiceLoader {
         private TestingServiceLoader() {
-            super(TikaConfig.class.getClassLoader());
+            super();
         }
         public <T> List<String> identifyStaticServiceProviders(Class<T> iface) {
             return super.identifyStaticServiceProviders(iface);