You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by cs...@apache.org on 2013/11/12 14:44:36 UTC

svn commit: r1541060 - in /karaf/trunk/itests/src/test/java/org/apache/karaf/itests: KarafTestSupport.java features/StandardFeaturesTest.java

Author: cschneider
Date: Tue Nov 12 13:44:36 2013
New Revision: 1541060

URL: http://svn.apache.org/r1541060
Log:
Make sure uninstall also removes dependent features in tests

Modified:
    karaf/trunk/itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java
    karaf/trunk/itests/src/test/java/org/apache/karaf/itests/features/StandardFeaturesTest.java

Modified: karaf/trunk/itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java
URL: http://svn.apache.org/viewvc/karaf/trunk/itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java?rev=1541060&r1=1541059&r2=1541060&view=diff
==============================================================================
--- karaf/trunk/itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java (original)
+++ karaf/trunk/itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java Tue Nov 12 13:44:36 2013
@@ -66,6 +66,8 @@ import org.osgi.framework.FrameworkUtil;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
 import org.osgi.util.tracker.ServiceTracker;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class KarafTestSupport {
 
@@ -75,7 +77,9 @@ public class KarafTestSupport {
 
     static final Long COMMAND_TIMEOUT = 10000L;
     static final Long SERVICE_TIMEOUT = 30000L;
-    
+
+    private static Logger LOG = LoggerFactory.getLogger(KarafTestSupport.class);
+
     @Rule
     public KarafTestWatcher baseTestWatcher = new KarafTestWatcher();
 
@@ -356,11 +360,36 @@ public class KarafTestSupport {
         assertFeatureInstalled(feature);
     }
     
-    protected void installAssertAndUninstallFeature(String feature) throws Exception {
-        featureService.installFeature(feature);
-        assertFeatureInstalled(feature);
-        featureService.uninstallFeature(feature);
+    protected void installAssertAndUninstallFeature(String... feature) throws Exception {
+    	Set<Feature> featuresBefore = new HashSet<Feature>(Arrays.asList(featureService.listInstalledFeatures()));
+    	for (String curFeature : feature) {
+    		featureService.installFeature(curFeature);
+            assertFeatureInstalled(curFeature);			
+		}
+        uninstallNewFeatures(featuresBefore);
     }
+
+    /**
+     * The feature service does not uninstall feature dependencies when uninstalling a single feature.
+     * So we need to make sure we uninstall all features that were newly installed.
+     * 
+     * @param featuresBefore
+     * @throws Exception
+     */
+	private void uninstallNewFeatures(Set<Feature> featuresBefore)
+			throws Exception {
+		Feature[] features = featureService.listInstalledFeatures();
+        for (Feature curFeature : features) {
+			if (!featuresBefore.contains(curFeature)) {
+				try {
+					System.out.println("Uninstalling " + curFeature.getName());
+					featureService.uninstallFeature(curFeature.getName(), curFeature.getVersion());
+				} catch (Exception e) {
+					LOG.error(e.getMessage(), e);
+				}
+			}
+		}
+	}
     
     protected void close(Closeable closeAble) {
     	if (closeAble != null) {

Modified: karaf/trunk/itests/src/test/java/org/apache/karaf/itests/features/StandardFeaturesTest.java
URL: http://svn.apache.org/viewvc/karaf/trunk/itests/src/test/java/org/apache/karaf/itests/features/StandardFeaturesTest.java?rev=1541060&r1=1541059&r2=1541060&view=diff
==============================================================================
--- karaf/trunk/itests/src/test/java/org/apache/karaf/itests/features/StandardFeaturesTest.java (original)
+++ karaf/trunk/itests/src/test/java/org/apache/karaf/itests/features/StandardFeaturesTest.java Tue Nov 12 13:44:36 2013
@@ -30,13 +30,8 @@ public class StandardFeaturesTest extend
 	 * @throws Exception
 	 */
 	public void checkInteractionOfHttpAndAriesAnnotationFeature() throws Exception {
-		featureService.installFeature("pax-http");
-		try {
-			installAssertAndUninstallFeature("aries-annotation");
-		} finally {
-        	featureService.uninstallFeature("pax-http");
-        	featureService.uninstallFeature("pax-jetty");
-        }
+		installAssertAndUninstallFeature("aries-annotation", "pax-http");
+		installAssertAndUninstallFeature("aries-annotation", "pax-http");
     }
 
     @Test
@@ -72,18 +67,11 @@ public class StandardFeaturesTest extend
     @Test
     public void installHttpFeature() throws Exception {
         installAssertAndUninstallFeature("http");
-        
-        // TODO: Check why uninstalling http does not uninstall pax-http
-        featureService.uninstallFeature("pax-http");
     }
 
     @Test
     public void installHttpWhiteboardFeature() throws Exception {
         installAssertAndUninstallFeature("http-whiteboard");
-        
-        // TODO: Check why uninstalling http does not uninstall pax-http-whiteboard
-        featureService.uninstallFeature("pax-http-whiteboard");
-        featureService.uninstallFeature("pax-http");
     }
 
     @Test