Hi Bertrand What is the rationale to use Strings to "configure" the TeleporterRule?
I would prefer to pass in an instance of Customizer. A LaunchpadCustomizer implementation could be provided ootb, and it could even support options. Or am I missing something? Regards Julian On Mon, Sep 21, 2015 at 5:59 PM, <bdelacre...@apache.org> wrote: > Author: bdelacretaz > Date: Mon Sep 21 15:59:51 2015 > New Revision: 1704336 > > URL: http://svn.apache.org/viewvc?rev=1704336&view=rev > Log: > SLING-5040 - client-side customizer options > > Added: > > sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/teleporter/TeleporterOptionsTest.java > Modified: > > sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/junit/teleporter/customizers/LaunchpadCustomizer.java > > sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/rules/TeleporterRule.java > > Modified: > sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/junit/teleporter/customizers/LaunchpadCustomizer.java > URL: > http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/junit/teleporter/customizers/LaunchpadCustomizer.java?rev=1704336&r1=1704335&r2=1704336&view=diff > ============================================================================== > --- > sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/junit/teleporter/customizers/LaunchpadCustomizer.java > (original) > +++ > sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/junit/teleporter/customizers/LaunchpadCustomizer.java > Mon Sep 21 15:59:51 2015 > @@ -17,8 +17,10 @@ > package org.apache.sling.junit.teleporter.customizers; > > import static org.junit.Assert.fail; > + > import org.apache.sling.commons.testing.integration.HttpTest; > import org.apache.sling.junit.rules.TeleporterRule; > +import > org.apache.sling.launchpad.webapp.integrationtest.teleporter.TeleporterOptionsTest; > import org.apache.sling.testing.teleporter.client.ClientSideTeleporter; > > /** TeleporterRule Customizer used for Sling launchpad integration tests. > @@ -29,13 +31,20 @@ public class LaunchpadCustomizer impleme > > private final static HttpTest H = new HttpTest(); > private final static int testReadyTimeout = > Integer.getInteger("ClientSideTeleporter.testReadyTimeoutSeconds",12); > + public static String PROP_OPTIONS = > ("Sling.LaunchpadCustomizer.Test.Options"); > > @Override > /** Customize the client-side TeleporterRule by first waiting > * for Sling to be ready and then setting it up with the test server > * URL, timeout etc. > */ > - public void customize(TeleporterRule t) { > + public void customize(TeleporterRule t, String options) { > + // Used to test the options mechanism > + if(TeleporterOptionsTest.OPTIONS.equals(options)) { > + throw new TeleporterOptionsTest.OptionsException(options); > + } > + > + // Setup Sling and the ClientSideTeleporter > try { > H.setUp(); > } catch(Exception e) { > > Added: > 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=1704336&view=auto > ============================================================================== > --- > sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/teleporter/TeleporterOptionsTest.java > (added) > +++ > sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/teleporter/TeleporterOptionsTest.java > Mon Sep 21 15:59:51 2015 > @@ -0,0 +1,49 @@ > +/* > + * Licensed to the Apache Software Foundation (ASF) under one or more > + * contributor license agreements. See the NOTICE file distributed with > + * this work for additional information regarding copyright ownership. > + * The ASF licenses this file to You under the Apache License, Version 2.0 > + * (the "License"); you may not use this file except in compliance with > + * the License. You may obtain a copy of the License at > + * > + * http://www.apache.org/licenses/LICENSE-2.0 > + * > + * Unless required by applicable law or agreed to in writing, software > + * distributed under the License is distributed on an "AS IS" BASIS, > + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. > + * See the License for the specific language governing permissions and > + * limitations under the License. > + */ > +package org.apache.sling.launchpad.webapp.integrationtest.teleporter; > + > +import java.util.UUID; > + > +import org.apache.sling.junit.rules.TeleporterRule; > +import org.junit.Test; > + > +import static org.junit.Assert.assertEquals; > + > +/** Test the teleporter client-side options */ > +public class TeleporterOptionsTest { > + > + public static final String OPTIONS = "TEST " + UUID.randomUUID(); > + > + @SuppressWarnings("serial") > + public static class OptionsException extends RuntimeException { > + public OptionsException(String options) { > + super(options); > + } > + } > + > + @Test > + public void testOptions() { > + try { > + // 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); > + } 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=1704336&r1=1704335&r2=1704336&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 > Mon Sep 21 15:59:51 2015 > @@ -39,7 +39,7 @@ public abstract class TeleporterRule ext > > /** Customizer is used client-side to setup the server URL and other > parameters */ > public static interface Customizer { > - void customize(TeleporterRule t); > + void customize(TeleporterRule t, String options); > } > > /** Meant to be instantiated via {@link #forClass} */ > @@ -55,15 +55,19 @@ public abstract class TeleporterRule ext > return Activator.getBundleContext() != null; > } > > - /** Build a TeleporterRule for the given class */ > + /** Build a TeleporterRule for the given class, with no client setup > options */ > public static TeleporterRule forClass(Class <?> classUnderTest) { > return forClass(classUnderTest, null); > } > > - /** Build a TeleporterRule for the given class, optionally using a > dynamically > - * instantiated Customizer if running on the client side. > + /** Build a TeleporterRule for the given class, with optional > clientSetupOptions. > + * > + * @param clientSetupOptions If supplied, the part of that string > before the first colon > + * is used as the class name of a Customizer (or shorthand for that if > it contains no dots). > + * The rest of the string is then passed to the Customizer so that it > can be used to define > + * options (which server to run the test on, etc) > */ > - public static TeleporterRule forClass(Class <?> classUnderTest, String > customizerClassName) { > + public static TeleporterRule forClass(Class <?> classUnderTest, String > clientSetupOptions) { > TeleporterRule result = null; > > if(isServerSide()) { > @@ -81,14 +85,21 @@ public abstract class TeleporterRule ext > > result.setClassUnderTest(classUnderTest); > > - if(customizerClassName != null) { > + 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); > + createInstance(Customizer.class, > customizerClassName).customize(result, customizerOptions); > } > } > > >