incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1231483 - in /sling/trunk/testing/tools/src: main/java/org/apache/sling/testing/tools/serversetup/ test/java/org/apache/sling/testing/tools/test/
Date Sat, 14 Jan 2012 11:53:45 GMT
Author: bdelacretaz
Date: Sat Jan 14 11:53:45 2012
New Revision: 1231483

URL: http://svn.apache.org/viewvc?rev=1231483&view=rev
Log:
SLING-2368 - add some tests

Modified:
    sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/serversetup/ServerSetup.java
    sling/trunk/testing/tools/src/test/java/org/apache/sling/testing/tools/test/ServerSetupSingletonTest.java
    sling/trunk/testing/tools/src/test/java/org/apache/sling/testing/tools/test/TestServerSetup.java
    sling/trunk/testing/tools/src/test/java/org/apache/sling/testing/tools/test/TestSetupPhase.java

Modified: sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/serversetup/ServerSetup.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/serversetup/ServerSetup.java?rev=1231483&r1=1231482&r2=1231483&view=diff
==============================================================================
--- sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/serversetup/ServerSetup.java
(original)
+++ sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/serversetup/ServerSetup.java
Sat Jan 14 11:53:45 2012
@@ -168,7 +168,7 @@ public class ServerSetup {
                     donePhases.add(id);
                 }
             } else {
-                log.info("{} ignored, not in the list of phases to run ({})", p, phasesToRun);
+                log.info("{} ignored, not in phasesToRun ({})", p, phasesToRun);
             }
         }
     }
@@ -182,6 +182,9 @@ public class ServerSetup {
         runRemainingPhases(false);
     }
     
+    /** Return a context that {@SetupPhase} can use to 
+     *  communicate among them and with the outside.
+     */
     public Map<String, Object> getContext() {
         return context;
     }
@@ -204,6 +207,9 @@ public class ServerSetup {
         failedPhases.clear();
     }
     
+    /** Return the configuration Properties that were set
+     *  by {@link #setConfig}
+     */
     public Properties getConfig() {
         return config;
     }
@@ -216,9 +222,9 @@ public class ServerSetup {
     /** Add a SetupPhase to our list. Its ID must be
      *  unique in that list.
      */
-    public void addSetupPhase(SetupPhase p) {
+    public void addSetupPhase(SetupPhase p) throws SetupException {
         if(phases.containsKey(p.getId())) {
-            throw new IllegalArgumentException("A SetupPhase with ID=" + p.getId() + " is
already in our list:" + phases.keySet());
+            throw new SetupException("A SetupPhase with ID=" + p.getId() + " is already in
our list:" + phases.keySet());
         }
         phases.put(p.getId(), p);
     }

Modified: sling/trunk/testing/tools/src/test/java/org/apache/sling/testing/tools/test/ServerSetupSingletonTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/tools/src/test/java/org/apache/sling/testing/tools/test/ServerSetupSingletonTest.java?rev=1231483&r1=1231482&r2=1231483&view=diff
==============================================================================
--- sling/trunk/testing/tools/src/test/java/org/apache/sling/testing/tools/test/ServerSetupSingletonTest.java
(original)
+++ sling/trunk/testing/tools/src/test/java/org/apache/sling/testing/tools/test/ServerSetupSingletonTest.java
Sat Jan 14 11:53:45 2012
@@ -16,8 +16,10 @@
  */
 package org.apache.sling.testing.tools.test;
 
-import static org.junit.Assert.fail;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.util.Properties;
 
@@ -41,6 +43,19 @@ public class ServerSetupSingletonTest {
         TestSetupPhase.clearExecutionLog();
         TestSetupPhase.failingPhases = "";
     }
+
+    @Test
+    public void testProperties() {
+        assertTrue(serverSetup.getConfig() == props);
+    }
+    
+    @Test
+    public void testContext() {
+        final String key = "foo";
+        assertNull(serverSetup.getContext().get(key));
+        serverSetup.getContext().put(key, this);
+        assertEquals(serverSetup.getContext().get(key), this);
+    }
     
     @Test
     public void testStartup() throws Exception {
@@ -141,4 +156,30 @@ public class ServerSetupSingletonTest {
         assertEquals("Still expecting only one startup phase to have run",
                 "four", TestSetupPhase.executionLog.toString());
     }
+    
+    @Test(expected=ServerSetup.SetupException.class)
+    public void testDuplicateStartupPhase() throws ServerSetup.SetupException {
+        serverSetup.addSetupPhase(new TestSetupPhase("two", true));
+    }
+    
+    @Test(expected=ServerSetup.SetupException.class)
+    public void testDuplicateShutdownPhase() throws ServerSetup.SetupException {
+        serverSetup.addSetupPhase(new TestSetupPhase("two", false));
+    }
+    
+    @Test
+    public void testAddPhasesLater() throws Exception {
+        props.setProperty(ServerSetup.PHASES_TO_RUN_PROP, "one, B, five, A, two");
+        serverSetup.setConfig(props);
+        serverSetup.addSetupPhase(new TestSetupPhase("A", true));
+        serverSetup.setupTestServer();
+        
+        assertEquals("Expecting all startup phases to have run",
+                "one,A,two", TestSetupPhase.executionLog.toString());
+        
+        serverSetup.addSetupPhase(new TestSetupPhase("B", false));
+        serverSetup.shutdown();
+        assertEquals("Expecting all phases to have run",
+                "one,A,two,B,five", TestSetupPhase.executionLog.toString());
+    }
 }
\ No newline at end of file

Modified: sling/trunk/testing/tools/src/test/java/org/apache/sling/testing/tools/test/TestServerSetup.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/tools/src/test/java/org/apache/sling/testing/tools/test/TestServerSetup.java?rev=1231483&r1=1231482&r2=1231483&view=diff
==============================================================================
--- sling/trunk/testing/tools/src/test/java/org/apache/sling/testing/tools/test/TestServerSetup.java
(original)
+++ sling/trunk/testing/tools/src/test/java/org/apache/sling/testing/tools/test/TestServerSetup.java
Sat Jan 14 11:53:45 2012
@@ -19,7 +19,7 @@ package org.apache.sling.testing.tools.t
 import org.apache.sling.testing.tools.serversetup.ServerSetup;
 
 public class TestServerSetup extends ServerSetup {
-    public TestServerSetup() {
+    public TestServerSetup() throws ServerSetup.SetupException {
         addSetupPhase(new TestSetupPhase("one", true));
         addSetupPhase(new TestSetupPhase("three", true));
         addSetupPhase(new TestSetupPhase("two", true));

Modified: sling/trunk/testing/tools/src/test/java/org/apache/sling/testing/tools/test/TestSetupPhase.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/tools/src/test/java/org/apache/sling/testing/tools/test/TestSetupPhase.java?rev=1231483&r1=1231482&r2=1231483&view=diff
==============================================================================
--- sling/trunk/testing/tools/src/test/java/org/apache/sling/testing/tools/test/TestSetupPhase.java
(original)
+++ sling/trunk/testing/tools/src/test/java/org/apache/sling/testing/tools/test/TestSetupPhase.java
Sat Jan 14 11:53:45 2012
@@ -47,9 +47,14 @@ class TestSetupPhase implements SetupPha
     public boolean isStartupPhase() {
         return isStartup;
     }
+    
+    @Override
+    public String toString() {
+        return getDescription();
+    }
 
     public String getDescription() {
-        return "";
+        return getClass().getSimpleName() + "(" + id + ")";
     }
 
     public String getId() {



Mime
View raw message