sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1704485 - in /sling/trunk: launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/teleporter/ testing/junit/core/src/main/java/org/apache/sling/junit/rules/ testing/junit/teleporter/src/main/java/org/ap...
Date Tue, 22 Sep 2015 08:55:58 GMT
Author: bdelacretaz
Date: Tue Sep 22 08:55:54 2015
New Revision: 1704485

URL: http://svn.apache.org/viewvc?rev=1704485&view=rev
Log:
SLING-5040 - call the Customizer lazily

Modified:
    sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/teleporter/TeleporterOptionsTest.java
    sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/rules/TeleporterRule.java
    sling/trunk/testing/junit/teleporter/src/main/java/org/apache/sling/testing/teleporter/client/ClientSideTeleporter.java

Modified: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/teleporter/TeleporterOptionsTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/teleporter/TeleporterOptionsTest.java?rev=1704485&r1=1704484&r2=1704485&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/teleporter/TeleporterOptionsTest.java
(original)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/teleporter/TeleporterOptionsTest.java
Tue Sep 22 08:55:54 2015
@@ -42,7 +42,8 @@ public class TeleporterOptionsTest {
             // The TeleporterRule options are usually meant to select which
             // server to run the tests on, for example - here we just verify
             // that the LaunchpadCustomizer gets our options
-            TeleporterRule.forClass(getClass(), "Launchpad:" + OPTIONS);
+            final TeleporterRule r = TeleporterRule.forClass(getClass(), "Launchpad:" + OPTIONS);
+            r.apply(null,  null);
             fail("Expecting an OptionsException");
         } catch(OptionsException oex) {
             assertEquals(OPTIONS, oex.getMessage());

Modified: sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/rules/TeleporterRule.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/rules/TeleporterRule.java?rev=1704485&r1=1704484&r2=1704485&view=diff
==============================================================================
--- sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/rules/TeleporterRule.java
(original)
+++ sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/rules/TeleporterRule.java
Tue Sep 22 08:55:54 2015
@@ -41,6 +41,7 @@ public abstract class TeleporterRule ext
     public static interface Customizer {
         void customize(TeleporterRule t, String options);
     }
+    private String clientSetupOptions;
 
     /** Meant to be instantiated via {@link #forClass} */
     protected TeleporterRule() {
@@ -72,7 +73,6 @@ public abstract class TeleporterRule ext
         
         if(isServerSide()) {
             result = new ServerSideTeleporter();
-            result.setClassUnderTest(classUnderTest);
         } else {
             // Client-side. Instantiate the class dynamically to 
             // avoid bringing its dependencies into this module when
@@ -82,29 +82,34 @@ public abstract class TeleporterRule ext
             } catch(Exception e) {
                 throw new RuntimeException("Unable to instantiate Teleporter client " + CLIENT_CLASS,
e);
             }
-            
-            result.setClassUnderTest(classUnderTest);
-            
-            if(clientSetupOptions != null && !clientSetupOptions.isEmpty()) {
-                String customizerClassName = clientSetupOptions;
-                String customizerOptions = "";
-                final int firstColon = clientSetupOptions.indexOf(":");
-                if(firstColon > 0) {
-                    customizerClassName = clientSetupOptions.substring(0, firstColon);
-                    customizerOptions = clientSetupOptions.substring(firstColon + 1);
-                }
-                // If a short name is used, transform it using our pattern. Simplifies referring
-                // to these customizers in test code, without having to make the customizer
-                // classes accessible to this bundle
-                if(!customizerClassName.contains(".")) {
-                    customizerClassName = CUSTOMIZER_PATTERN.replace("<NAME>", customizerClassName);
-                }
-                createInstance(Customizer.class, customizerClassName).customize(result, customizerOptions);
-            }
         }
         
+        result.clientSetupOptions = clientSetupOptions;
+        result.setClassUnderTest(classUnderTest);
         return result;
     }
+
+    /** Use a Customizer, if one was defined, to customize this Rule */
+    protected void customize() {
+        // As with the client-side rule implementation, instantiate our Customizer
+        // dynamically to avoid requiring its class on the server side.
+        if(!isServerSide() && (clientSetupOptions != null) && !clientSetupOptions.isEmpty())
{
+            String customizerClassName = clientSetupOptions;
+            String customizerOptions = "";
+            final int firstColon = clientSetupOptions.indexOf(":");
+            if(firstColon > 0) {
+                customizerClassName = clientSetupOptions.substring(0, firstColon);
+                customizerOptions = clientSetupOptions.substring(firstColon + 1);
+            }
+            // If a short name is used, transform it using our pattern. Simplifies referring
+            // to these customizers in test code, without having to make the customizer
+            // classes accessible to this bundle
+            if(!customizerClassName.contains(".")) {
+                customizerClassName = CUSTOMIZER_PATTERN.replace("<NAME>", customizerClassName);
+            }
+            createInstance(Customizer.class, customizerClassName).customize(this, customizerOptions);
+        }
+    }
     
     @SuppressWarnings("unchecked")
     protected static <T> T createInstance(Class<T> objectClass, String className)
{

Modified: sling/trunk/testing/junit/teleporter/src/main/java/org/apache/sling/testing/teleporter/client/ClientSideTeleporter.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/teleporter/src/main/java/org/apache/sling/testing/teleporter/client/ClientSideTeleporter.java?rev=1704485&r1=1704484&r2=1704485&view=diff
==============================================================================
--- sling/trunk/testing/junit/teleporter/src/main/java/org/apache/sling/testing/teleporter/client/ClientSideTeleporter.java
(original)
+++ sling/trunk/testing/junit/teleporter/src/main/java/org/apache/sling/testing/teleporter/client/ClientSideTeleporter.java
Tue Sep 22 08:55:54 2015
@@ -95,6 +95,8 @@ public class ClientSideTeleporter extend
     
     @Override
     public Statement apply(final Statement base, final Description description) {
+        customize();
+        
         if(baseUrl == null) {
             fail("base URL is not set");
         }



Mime
View raw message