From 5a309d68398947f94aad5da17071319d1789d90d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Kr=C3=BCger?= <martin.krueger@rohde-schwarz.com>
Date: Fri, 7 Dec 2018 12:58:47 +0100
Subject: [PATCH] [KARAF-4095] Fix test cases

The test cases throw exceptions which are caught inside
the tested code but show up during test run. The test run succeeds
anyway.

This fix adjusts the test cases to recent changes
(8c3dda195674a2c6424be070bbba066211ab02c8). As a result the stack
traces are not present any more.
---
 .../apache/karaf/main/MainLockingTest.java    | 22 +++++++++++++++----
 .../org/apache/karaf/main/MainStartTest.java  |  6 +++++
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/main/src/test/java/org/apache/karaf/main/MainLockingTest.java b/main/src/test/java/org/apache/karaf/main/MainLockingTest.java
index 46585ec288..6362d8e57e 100644
--- a/main/src/test/java/org/apache/karaf/main/MainLockingTest.java
+++ b/main/src/test/java/org/apache/karaf/main/MainLockingTest.java
@@ -18,11 +18,8 @@
  */
 package org.apache.karaf.main;
 
-import static org.ops4j.pax.tinybundles.core.TinyBundles.withBnd;
-
 import java.io.File;
 import java.io.IOException;
-
 import org.apache.karaf.main.util.Utils;
 import org.junit.After;
 import org.junit.Assert;
@@ -34,21 +31,26 @@ import org.osgi.framework.Constants;
 import org.osgi.framework.launch.Framework;
 import org.osgi.framework.startlevel.FrameworkStartLevel;
 
+import static org.ops4j.pax.tinybundles.core.TinyBundles.withBnd;
+
 public class MainLockingTest {
     private File home;
 
     private File data;
+    private File log;
 
     @Before
     public void setUp() throws IOException {
         File basedir = new File(getClass().getClassLoader().getResource("foo").getPath()).getParentFile();
         home = new File(basedir, "test-karaf-home");
-        data = new File(home, "data");
+        data = new File(home, "data" + System.currentTimeMillis());
+        log = new File(home, "log" + System.currentTimeMillis());
 
         Utils.deleteDirectory(data);
 
         System.setProperty("karaf.home", home.toString());
         System.setProperty("karaf.data", data.toString());
+        System.setProperty("karaf.log", log.toString());
         System.setProperty("karaf.framework.factory", "org.apache.felix.framework.FrameworkFactory");
 
         System.setProperty("karaf.lock", "true");
@@ -60,6 +62,18 @@ public class MainLockingTest {
     public void tearDown() {
         home = null;
         data = null;
+        log = null;
+
+        System.clearProperty("karaf.home");
+        System.clearProperty("karaf.data");
+        System.clearProperty("karaf.log");
+        System.clearProperty("karaf.framework.factory");
+
+        System.clearProperty("karaf.lock");
+        System.clearProperty("karaf.lock.delay");
+        System.clearProperty("karaf.lock.class");
+
+        System.clearProperty("karaf.pid.file");
     }
 
     @Test
diff --git a/main/src/test/java/org/apache/karaf/main/MainStartTest.java b/main/src/test/java/org/apache/karaf/main/MainStartTest.java
index 495aee038a..23b16b7776 100644
--- a/main/src/test/java/org/apache/karaf/main/MainStartTest.java
+++ b/main/src/test/java/org/apache/karaf/main/MainStartTest.java
@@ -35,6 +35,10 @@ public class MainStartTest {
         if(main != null){
             main.destroy();
         }
+
+		System.clearProperty("karaf.home");
+		System.clearProperty("karaf.data");
+		System.clearProperty("karaf.log");
     }
 
     @Test
@@ -43,10 +47,12 @@ public class MainStartTest {
         File home = new File(basedir, "test-karaf-home");
         // generate an unique folder name to avoid conflict with folder created by other unit tests (KARAF-2558)
         File data = new File(home, "data" + System.currentTimeMillis());
+		File log = new File(home, "log" + System.currentTimeMillis());
 
 		String[] args = new String[0];
 		System.setProperty("karaf.home", home.toString());
 		System.setProperty("karaf.data", data.toString());
+		System.setProperty("karaf.log", log.toString());
 
 		main = new Main(args);
 		main.launch();
-- 
2.19.1

