sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dul...@apache.org
Subject svn commit: r1777550 - in /sling/trunk/testing/junit/rules: ./ src/main/java/org/apache/sling/testing/junit/rules/ src/main/java/org/apache/sling/testing/junit/rules/instance/
Date Fri, 06 Jan 2017 09:44:51 GMT
Author: dulvac
Date: Fri Jan  6 09:44:50 2017
New Revision: 1777550

URL: http://svn.apache.org/viewvc?rev=1777550&view=rev
Log:
SLING-6431

Modified:
    sling/trunk/testing/junit/rules/pom.xml
    sling/trunk/testing/junit/rules/src/main/java/org/apache/sling/testing/junit/rules/RemoteLogDumperRule.java
    sling/trunk/testing/junit/rules/src/main/java/org/apache/sling/testing/junit/rules/SlingRule.java
    sling/trunk/testing/junit/rules/src/main/java/org/apache/sling/testing/junit/rules/instance/AbstractInstance.java
    sling/trunk/testing/junit/rules/src/main/java/org/apache/sling/testing/junit/rules/instance/Instance.java

Modified: sling/trunk/testing/junit/rules/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/rules/pom.xml?rev=1777550&r1=1777549&r2=1777550&view=diff
==============================================================================
--- sling/trunk/testing/junit/rules/pom.xml (original)
+++ sling/trunk/testing/junit/rules/pom.xml Fri Jan  6 09:44:50 2017
@@ -23,7 +23,7 @@
     <parent>
         <groupId>org.apache.sling</groupId>
         <artifactId>sling</artifactId>
-        <version>26</version>
+        <version>28</version>
         <relativePath />
     </parent>
 
@@ -87,7 +87,7 @@
         </dependency>
         <dependency>
             <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.core</artifactId>
+            <artifactId>osgi.core</artifactId>
         </dependency>
        <dependency>
             <groupId>org.apache.felix</groupId>

Modified: sling/trunk/testing/junit/rules/src/main/java/org/apache/sling/testing/junit/rules/RemoteLogDumperRule.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/rules/src/main/java/org/apache/sling/testing/junit/rules/RemoteLogDumperRule.java?rev=1777550&r1=1777549&r2=1777550&view=diff
==============================================================================
--- sling/trunk/testing/junit/rules/src/main/java/org/apache/sling/testing/junit/rules/RemoteLogDumperRule.java
(original)
+++ sling/trunk/testing/junit/rules/src/main/java/org/apache/sling/testing/junit/rules/RemoteLogDumperRule.java
Fri Jan  6 09:44:50 2017
@@ -26,6 +26,7 @@ import org.apache.sling.testing.clients.
 import org.apache.sling.testing.clients.SlingHttpResponse;
 import org.apache.sling.testing.clients.interceptors.TestDescriptionHolder;
 import org.apache.sling.testing.clients.util.URLParameterBuilder;
+import org.apache.sling.testing.junit.rules.instance.Instance;
 import org.junit.rules.TestWatcher;
 import org.junit.runner.Description;
 import org.junit.runners.model.Statement;
@@ -38,12 +39,14 @@ import static org.apache.sling.testing.c
  * remote server and dumps them locally upon test failure. This simplifies determining failure
  * cause by providing all required data locally. This would be specially useful when running
test
  * in CI server where server logs gets cluttered with all other test executions
+ * Can be constructed either with a {@link SlingClient} or with a {@link Instance}
  *
  * <pre>
  *     public class LoginTestIT {
  *
  *     &#064;Rule
  *     public TestRule logDumper = new RemoteLogDumperRule(slingClient);
+ *     // OR public TestRule logDumper = new RemoteLogDumperRule(myInstance);
  *
  *     &#064;Test
  *     public void remoteLogin() {
@@ -60,25 +63,35 @@ public class RemoteLogDumperRule extends
      */
     static final String SERVLET_PATH = "/system/sling/testlog";
 
-    private SlingClient slingClient;
+    private SlingClient slingClient = null;
+    private Instance instance = null;
 
-    public RemoteLogDumperRule(){
+    public RemoteLogDumperRule() {
+    }
 
+    public RemoteLogDumperRule (Instance instance) {
+        this.instance = instance;
     }
 
     public RemoteLogDumperRule(SlingClient slingClient) {
         this.slingClient = slingClient;
     }
 
+    public RemoteLogDumperRule setSlingClient(SlingClient slingClient) {
+        this.slingClient = slingClient;
+        return this;
+    }
+
+    public RemoteLogDumperRule setInstance(Instance instance) {
+        this.instance = instance;
+        return this;
+    }
+
     @Override
     public Statement apply(Statement base, Description description) {
         return super.apply(base, description);
     }
 
-    public void setSlingClient(SlingClient slingClient) {
-        this.slingClient = slingClient;
-    }
-
     @Override
     protected void finished(Description description) {
         TestDescriptionHolder.removeClassName();
@@ -87,6 +100,10 @@ public class RemoteLogDumperRule extends
 
     @Override
     protected void starting(Description description) {
+        // Get the client from an Instance if it was passed in this way
+        if (null == this.slingClient && null != instance) {
+            this.slingClient = instance.getAdminClient();
+        }
         TestDescriptionHolder.setClassName(description.getClassName());
         TestDescriptionHolder.setMethodName(description.getMethodName());
     }

Modified: sling/trunk/testing/junit/rules/src/main/java/org/apache/sling/testing/junit/rules/SlingRule.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/rules/src/main/java/org/apache/sling/testing/junit/rules/SlingRule.java?rev=1777550&r1=1777549&r2=1777550&view=diff
==============================================================================
--- sling/trunk/testing/junit/rules/src/main/java/org/apache/sling/testing/junit/rules/SlingRule.java
(original)
+++ sling/trunk/testing/junit/rules/src/main/java/org/apache/sling/testing/junit/rules/SlingRule.java
Fri Jan  6 09:44:50 2017
@@ -17,6 +17,7 @@
 package org.apache.sling.testing.junit.rules;
 
 import org.apache.sling.testing.junit.rules.category.FailingTest;
+import org.apache.sling.testing.junit.rules.instance.Instance;
 import org.junit.rules.RuleChain;
 import org.junit.rules.TestRule;
 import org.junit.runner.Description;
@@ -25,9 +26,12 @@ import org.junit.runners.model.Statement
 /**
  * Sling Rule that wraps all the Rules (at method level) useful when running a Sling Integration
Test.
  * Can be used in any junit test using the @Rule annotation
- * I chains: {@link TestTimeout}, {@link TestDescriptionRule}, {@link TestStickyCookieRule},
{@link FilterRule}
+ * It chains: {@link TestTimeout}, {@link TestDescriptionRule}, {@link TestStickyCookieRule},
{@link FilterRule}
  */
 public class SlingRule implements TestRule {
+
+    private Instance[] instances;
+
     /** Rule to define the max timeout for all the tests */
     public final TestTimeout testTimeoutRule = new TestTimeout();
 
@@ -41,10 +45,18 @@ public class SlingRule implements TestRu
     public final TestDescriptionRule testDescriptionRule = new TestDescriptionRule();
 
     /** Main RuleChain describing the order of execution of all the rules */
-    protected TestRule ruleChain = RuleChain.outerRule(testTimeoutRule)
-            .around(testStickySessionRule)
-            .around(filterRule)
-            .around(testDescriptionRule);
+    protected RuleChain ruleChain = RuleChain.outerRule(testTimeoutRule);
+
+    public SlingRule(Instance... instances) {
+        this.instances = instances;
+        this.ruleChain = ruleChain.around(testStickySessionRule)
+                .around(filterRule)
+                .around(testDescriptionRule);
+        // Configure all rules that need an instance (where you can get a client from)
+        for (Instance instance : instances) {
+            this.ruleChain = ruleChain.around(new RemoteLogDumperRule(instance));
+        }
+    }
 
     @Override
     public Statement apply(Statement base, Description description) {

Modified: sling/trunk/testing/junit/rules/src/main/java/org/apache/sling/testing/junit/rules/instance/AbstractInstance.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/rules/src/main/java/org/apache/sling/testing/junit/rules/instance/AbstractInstance.java?rev=1777550&r1=1777549&r2=1777550&view=diff
==============================================================================
--- sling/trunk/testing/junit/rules/src/main/java/org/apache/sling/testing/junit/rules/instance/AbstractInstance.java
(original)
+++ sling/trunk/testing/junit/rules/src/main/java/org/apache/sling/testing/junit/rules/instance/AbstractInstance.java
Fri Jan  6 09:44:50 2017
@@ -19,12 +19,19 @@ package org.apache.sling.testing.junit.r
 
 import org.apache.sling.testing.clients.SlingClient;
 import org.apache.sling.testing.clients.instance.InstanceConfiguration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.lang.reflect.Constructor;
 import java.net.URI;
 
 public abstract class AbstractInstance implements Instance {
 
+    private static final Logger LOG = LoggerFactory.getLogger(AbstractInstance.class);
+
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public <T extends SlingClient> T getClient(Class<T> clientClass, String user,
String pass) {
         InstanceConfiguration configuration = getConfiguration();
@@ -48,9 +55,23 @@ public abstract class AbstractInstance i
         return client;
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public <T extends SlingClient> T getAdminClient(Class<T> clientClass) {
-        return getClient(clientClass, "admin", "admin");
+        return getClient(clientClass, getConfiguration().getAdminUser(), getConfiguration().getAdminPassword());
     }
 
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public SlingClient getAdminClient() {
+       return getAdminClient(SlingClient.class);
+    }
+
+
+
 }

Modified: sling/trunk/testing/junit/rules/src/main/java/org/apache/sling/testing/junit/rules/instance/Instance.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/rules/src/main/java/org/apache/sling/testing/junit/rules/instance/Instance.java?rev=1777550&r1=1777549&r2=1777550&view=diff
==============================================================================
--- sling/trunk/testing/junit/rules/src/main/java/org/apache/sling/testing/junit/rules/instance/Instance.java
(original)
+++ sling/trunk/testing/junit/rules/src/main/java/org/apache/sling/testing/junit/rules/instance/Instance.java
Fri Jan  6 09:44:50 2017
@@ -18,6 +18,7 @@ package org.apache.sling.testing.junit.r
 
 import org.apache.sling.testing.clients.SlingClient;
 import org.apache.sling.testing.clients.instance.InstanceConfiguration;
+import org.apache.sling.testing.clients.instance.InstanceSetup;
 import org.junit.rules.TestRule;
 
 public interface Instance extends TestRule {
@@ -28,8 +29,35 @@ public interface Instance extends TestRu
 
     InstanceConfiguration getConfiguration();
 
+    /**
+     * Return <strong>a new client</strong> pointing to the instance corresponding
to this {{AbstractInstance}}
+     *
+     * @param clientClass the class of the returned client
+     * @param user the username used in the client
+     * @param pass the password used in the client
+     * @param <T> the type of the returned client
+     * @return a new client extending {{SlingClient}}
+     */
     <T extends SlingClient> T getClient(Class<T> clientClass, String user, String
pass);
 
+    /**
+     * Return <strong>a new client</strong> pointing to the instance corresponding
to this {{AbstractInstance}},
+     * with the admin user and password.
+     * See {@link InstanceSetup#INSTANCE_CONFIG_ADMINUSER} and {@link InstanceSetup#INSTANCE_CONFIG_ADMINPASSWORD}
+     *
+     * @return a new {{SlingClient}}
+     */
+    SlingClient getAdminClient();
+
+    /**
+     * Return <strong>a new client</strong> pointing to the instance corresponding
to this {{AbstractInstance}},
+     * with the admin user and password.
+     * See {@link InstanceSetup#INSTANCE_CONFIG_ADMINUSER} and {@link InstanceSetup#INSTANCE_CONFIG_ADMINPASSWORD}
+     *
+     * @param clientClass the class of the returned client
+     * @param <T> the class of the returned client
+     * @return a new client extending on {{SlingClient}}
+     */
     <T extends SlingClient> T getAdminClient(Class<T> clientClass);
 
 }



Mime
View raw message