karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pie...@apache.org
Subject svn commit: r1442064 - /karaf/trunk/instance/core/src/test/java/org/apache/karaf/instance/core/internal/InstanceServiceImplTest.java
Date Mon, 04 Feb 2013 10:08:00 GMT
Author: pieber
Date: Mon Feb  4 10:08:00 2013
New Revision: 1442064

URL: http://svn.apache.org/viewvc?rev=1442064&view=rev
Log:
[KARAF-2158] Test InstanceServiceImplTest#testToSimulateRenameInstanceByExternalProcess fails
when run isolated (thanks to Christoph Gritschenberger for the patch)

Signed-off-by: Andreas Pieber <anpieber@gmail.com>

Modified:
    karaf/trunk/instance/core/src/test/java/org/apache/karaf/instance/core/internal/InstanceServiceImplTest.java

Modified: karaf/trunk/instance/core/src/test/java/org/apache/karaf/instance/core/internal/InstanceServiceImplTest.java
URL: http://svn.apache.org/viewvc/karaf/trunk/instance/core/src/test/java/org/apache/karaf/instance/core/internal/InstanceServiceImplTest.java?rev=1442064&r1=1442063&r2=1442064&view=diff
==============================================================================
--- karaf/trunk/instance/core/src/test/java/org/apache/karaf/instance/core/internal/InstanceServiceImplTest.java
(original)
+++ karaf/trunk/instance/core/src/test/java/org/apache/karaf/instance/core/internal/InstanceServiceImplTest.java
Mon Feb  4 10:08:00 2013
@@ -25,57 +25,68 @@ import java.io.OutputStream;
 import java.util.Arrays;
 import java.util.Properties;
 
-import junit.framework.TestCase;
-
 import org.apache.karaf.instance.core.Instance;
 import org.apache.karaf.instance.core.InstanceSettings;
-import org.apache.karaf.instance.core.internal.InstanceServiceImpl;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.junit.rules.TestName;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class InstanceServiceImplTest {
 
-public class InstanceServiceImplTest extends TestCase {
+    @Rule
+    public TestName name = new TestName();
+
+    @Rule
+    public TemporaryFolder tempFolder = new TemporaryFolder();
+
+    @BeforeClass
+    public static void setUpClass() throws Exception {
+        String buildDirectory = ClassLoader.getSystemResource("etc/startup.properties").getFile()
+                .replace("etc/startup.properties", "");
+        System.setProperty("karaf.base", buildDirectory);
+    }
 
+    @Test
     public void testHandleFeatures() throws Exception {
         InstanceServiceImpl as = new InstanceServiceImpl();
-        
-        File f = File.createTempFile(getName(), ".test");
+
+        File f = tempFolder.newFile(getName() + ".test");
+        Properties p = new Properties();
+        p.put("featuresBoot", "abc,def ");
+        p.put("featuresRepositories", "somescheme://xyz");
+        OutputStream os = new FileOutputStream(f);
         try {
-            Properties p = new Properties();
-            p.put("featuresBoot", "abc,def ");
-            p.put("featuresRepositories", "somescheme://xyz");
-            OutputStream os = new FileOutputStream(f);
-            try {
-                p.store(os, "Test comment");
-            } finally {
-                os.close();
-            }
-            
-            InstanceSettings s = new InstanceSettings(8122, 1122, 44444, null, null, null,
Arrays.asList("test"));
-            as.addFeaturesFromSettings(f, s);
-            
-            Properties p2 = new Properties();
-            InputStream is = new FileInputStream(f);
-            try {
-                p2.load(is);
-            } finally {
-                is.close();
-            }
-            assertEquals(2, p2.size());
-            assertEquals("abc,def,ssh,test", p2.get("featuresBoot"));
-            assertEquals("somescheme://xyz", p2.get("featuresRepositories"));
+            p.store(os, "Test comment");
         } finally {
-            f.delete();
+            os.close();
         }
+
+        InstanceSettings s = new InstanceSettings(8122, 1122, 44444, null, null, null, Arrays.asList("test"));
+        as.addFeaturesFromSettings(f, s);
+
+        Properties p2 = new Properties();
+        InputStream is = new FileInputStream(f);
+        try {
+            p2.load(is);
+        } finally {
+            is.close();
+        }
+        assertEquals(2, p2.size());
+        assertEquals("abc,def,ssh,test", p2.get("featuresBoot"));
+        assertEquals("somescheme://xyz", p2.get("featuresRepositories"));
     }
 
-    /**
-     * Ensure the instance:create generates all the required configuration files
-     * //TODO: fix this test so it can run in an IDE
-     */
+    @Test
     public void testConfigurationFiles() throws Exception {
         InstanceServiceImpl service = new InstanceServiceImpl();
-        service.setStorageLocation(new File("target/instances/" + System.currentTimeMillis()));
+        service.setStorageLocation(tempFolder.newFolder("instances"));
 
-        System.setProperty("karaf.base", new File("target/test-classes/").getAbsolutePath());
-        
         InstanceSettings settings = new InstanceSettings(8122, 1122, 44444, getName(), null,
null, null);
         Instance instance = service.createInstance(getName(), settings, true);
 
@@ -97,11 +108,10 @@ public class InstanceServiceImplTest ext
      * Test the renaming of an existing instance.
      * </p>
      */
+    @Test
     public void testRenameInstance() throws Exception {
         InstanceServiceImpl service = new InstanceServiceImpl();
-        service.setStorageLocation(new File("target/instances/" + System.currentTimeMillis()));
-
-        System.setProperty("karaf.base", new File("target/test-classes/").getAbsolutePath());
+        service.setStorageLocation(tempFolder.newFolder("instances"));
 
         InstanceSettings settings = new InstanceSettings(8122, 1122, 44444, getName(), null,
null, null);
         service.createInstance(getName(), settings, true);
@@ -110,15 +120,15 @@ public class InstanceServiceImplTest ext
         assertNotNull(service.getInstance(getName() + "b"));
     }
 
-
     /**
      * <p>
      * Test the renaming of an existing instance.
      * </p>
      */
+    @Test
     public void testToSimulateRenameInstanceByExternalProcess() throws Exception {
         InstanceServiceImpl service = new InstanceServiceImpl();
-        File storageLocation = new File("target/instances/" + System.currentTimeMillis());
+        File storageLocation = tempFolder.newFolder("instances");
         service.setStorageLocation(storageLocation);
 
         InstanceSettings settings = new InstanceSettings(8122, 1122, 44444, getName(), null,
null, null);
@@ -139,6 +149,10 @@ public class InstanceServiceImplTest ext
         assertNotNull(service.getInstance(getName() + "b"));
     }
 
+    private String getName() {
+        return name.getMethodName();
+    }
+
     private void saveStorage(Properties props, File location, String comment) throws IOException
{
         OutputStream os = null;
         try {



Mime
View raw message