You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by np...@apache.org on 2018/01/16 11:39:35 UTC

[sling-org-apache-sling-pipes] branch master updated (01b37fc -> 0e76739)

This is an automated email from the ASF dual-hosted git repository.

npeltier pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-pipes.git.


    from 01b37fc  Merge branch 'master' of github.com:apache/sling-org-apache-sling-pipes
     new 4c31425  SLING-7314 add dryRun handling for path pipe
     new 0e76739  SLING-7314 fix dryRun

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 pom.xml                                            |  2 +-
 src/main/java/org/apache/sling/pipes/BasePipe.java | 17 +++++----
 .../org/apache/sling/pipes/internal/PathPipe.java  |  5 ++-
 .../java/org/apache/sling/pipes/BasePipeTest.java  | 42 ++++++++++++++++++++++
 .../org/apache/sling/pipes/PipeBuilderTest.java    | 15 ++++++--
 5 files changed, 71 insertions(+), 10 deletions(-)
 create mode 100644 src/test/java/org/apache/sling/pipes/BasePipeTest.java

-- 
To stop receiving notification emails like this one, please contact
['"commits@sling.apache.org" <co...@sling.apache.org>'].

[sling-org-apache-sling-pipes] 02/02: SLING-7314 fix dryRun

Posted by np...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

npeltier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-pipes.git

commit 0e767394a0f1c42bcecdbb7406fc47c1bb976f71
Author: Nicolas Peltier <pe...@gmail.com>
AuthorDate: Tue Jan 16 11:20:29 2018 +0100

    SLING-7314 fix dryRun
    
    - add unit tests in base pipe & pipe builder tests,
    - ensure dryRun is false only if there is nothing or false value as boolean or text
---
 pom.xml                                            |  2 +-
 src/main/java/org/apache/sling/pipes/BasePipe.java | 17 +++++----
 .../java/org/apache/sling/pipes/BasePipeTest.java  | 42 ++++++++++++++++++++++
 .../org/apache/sling/pipes/PipeBuilderTest.java    | 15 ++++++--
 4 files changed, 67 insertions(+), 9 deletions(-)

diff --git a/pom.xml b/pom.xml
index df7fbec..26a41d4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -24,7 +24,7 @@
   <parent>
     <groupId>org.apache.sling</groupId>
     <artifactId>sling</artifactId>
-    <version>31</version>
+    <version>32</version>
     <relativePath />
   </parent>
 
diff --git a/src/main/java/org/apache/sling/pipes/BasePipe.java b/src/main/java/org/apache/sling/pipes/BasePipe.java
index 4099315..e816e24 100644
--- a/src/main/java/org/apache/sling/pipes/BasePipe.java
+++ b/src/main/java/org/apache/sling/pipes/BasePipe.java
@@ -43,7 +43,7 @@ public class BasePipe implements Pipe {
     public static final String PN_STATUS_MODIFIED = "statusModified";
     public static final String STATUS_STARTED = "started";
     public static final String STATUS_FINISHED = "finished";
-    protected static final String DRYRUN_EXPR = "${" + DRYRUN_KEY + "}";
+    protected static final String DRYRUN_EXPR = String.format("${%s}", DRYRUN_KEY);
 
     protected ResourceResolver resolver;
     protected ValueMap properties;
@@ -56,7 +56,6 @@ public class BasePipe implements Pipe {
     // used by pipes using complex JCR configurations
     public static final List<String> IGNORED_PROPERTIES = Arrays.asList(new String[]{"jcr:lastModified", "jcr:primaryType", "jcr:created", "jcr:createdBy"});
 
-
     protected Boolean dryRunObject;
 
     @Override
@@ -97,11 +96,18 @@ public class BasePipe implements Pipe {
     @Override
     public boolean isDryRun() {
         if (dryRunObject == null) {
+            dryRunObject = false;
             Object run =  bindings.isBindingDefined(DRYRUN_KEY) ? bindings.instantiateObject(DRYRUN_EXPR) : false;
-            dryRunObject =  run != null && run instanceof Boolean ? (Boolean)run : false;
+            if (run != null) {
+                dryRunObject = true;
+                if (run instanceof Boolean){
+                    dryRunObject = (Boolean)run;
+                } else if (run instanceof String && String.format("%s", Boolean.FALSE).equals(run)){
+                    dryRunObject = false;
+                }
+            }
         }
-        boolean dryRun = dryRunObject != null ? dryRunObject : false;
-        return dryRun;
+        return dryRunObject;
     }
 
     @Override
@@ -170,7 +176,6 @@ public class BasePipe implements Pipe {
         return resource;
     }
 
-
     @Override
     public Object getOutputBinding() {
         if (parent != null){
diff --git a/src/test/java/org/apache/sling/pipes/BasePipeTest.java b/src/test/java/org/apache/sling/pipes/BasePipeTest.java
new file mode 100644
index 0000000..d5a3194
--- /dev/null
+++ b/src/test/java/org/apache/sling/pipes/BasePipeTest.java
@@ -0,0 +1,42 @@
+/*
+ * 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.pipes;
+
+import org.apache.sling.api.resource.PersistenceException;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class BasePipeTest extends AbstractPipeTest {
+
+    protected BasePipe resetDryRun(Object value) throws PersistenceException {
+        BasePipe basePipe = (BasePipe)plumber.newPipe(context.resourceResolver()).echo("blah").build();
+        basePipe.bindings.addBinding(BasePipe.DRYRUN_KEY, value);
+        return basePipe;
+    }
+
+    @Test
+    public void dryRunTest() throws Exception {
+        assertFalse("Is dry run should be false with flag set to text false", resetDryRun("false").isDryRun());
+        assertFalse("Is dry run should be false with flag set to boolean false", resetDryRun(false).isDryRun());
+        assertFalse("Is dry run should be true with no dry run flag", resetDryRun(null).isDryRun());
+        assertTrue("Is dry run should be true with flag set to boolean true", resetDryRun(true).isDryRun());
+        assertTrue("Is dry run should be true with flag set to text true", resetDryRun("true").isDryRun());
+        assertTrue("Is dry run should be true with flag set to something that is not false or 'false'", resetDryRun("other").isDryRun());
+    }
+}
\ No newline at end of file
diff --git a/src/test/java/org/apache/sling/pipes/PipeBuilderTest.java b/src/test/java/org/apache/sling/pipes/PipeBuilderTest.java
index 205f9dc..45f8a43 100644
--- a/src/test/java/org/apache/sling/pipes/PipeBuilderTest.java
+++ b/src/test/java/org/apache/sling/pipes/PipeBuilderTest.java
@@ -30,6 +30,7 @@ import java.util.Map;
 import java.util.stream.Collectors;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
@@ -38,8 +39,8 @@ public class PipeBuilderTest extends AbstractPipeTest {
     public void simpleBuild() throws Exception {
         PipeBuilder rmBuilder = plumber.newPipe(context.resourceResolver());
         Pipe rmPipe = rmBuilder.echo(PATH_APPLE).rm().build();
-        assertNotNull(" a pipe should be built", rmPipe);
-        //we rebuild pipe out of created pipe path, execute it, and test correct output (= correct pipe built)
+        assertNotNull(" a basePipe should be built", rmPipe);
+        //we rebuild basePipe out of created basePipe path, execute it, and test correct output (= correct basePipe built)
         testOneResource(rmPipe.getResource().getPath(), PATH_FRUITS);
     }
 
@@ -53,6 +54,16 @@ public class PipeBuilderTest extends AbstractPipeTest {
     }
 
     @Test
+    public void dryRun() throws Exception {
+        String lemonPath = "/content/fruits/lemon";
+        PipeBuilder lemonBuilder = plumber.newPipe(context.resourceResolver());
+        ExecutionResult result = lemonBuilder.mkdir(lemonPath).runWith("dryRun", true);
+        assertFalse("returned set should not contain lemon path with dryRun=true(boolean)", result.getCurrentPathSet().contains(lemonPath));
+        ExecutionResult textResult = lemonBuilder.mkdir(lemonPath).runWith("dryRun", "true");
+        assertFalse("returned set should not contain lemon path with dryRun=true(text)", textResult.getCurrentPathSet().contains(lemonPath));
+    }
+
+    @Test
     public void confBuild() throws Exception {
         PipeBuilder writeBuilder = plumber.newPipe(context.resourceResolver());
         writeBuilder.echo(PATH_APPLE).write("tested", true, "working", true).run();

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-pipes] 01/02: SLING-7314 add dryRun handling for path pipe

Posted by np...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

npeltier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-pipes.git

commit 4c3142554145e52d005410af756087c711f6bb1a
Author: npeltier <pe...@gmail.com>
AuthorDate: Mon Jan 15 22:47:47 2018 +0100

    SLING-7314 add dryRun handling for path pipe
---
 src/main/java/org/apache/sling/pipes/internal/PathPipe.java | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/sling/pipes/internal/PathPipe.java b/src/main/java/org/apache/sling/pipes/internal/PathPipe.java
index 795dfae..6e4918c 100644
--- a/src/main/java/org/apache/sling/pipes/internal/PathPipe.java
+++ b/src/main/java/org/apache/sling/pipes/internal/PathPipe.java
@@ -70,7 +70,10 @@ public class PathPipe extends BasePipe {
         String expression = getExpr();
         try {
             String path = expression.startsWith(SLASH) ? expression : getInput().getPath() + SLASH + expression;
-            output = Collections.singleton(ResourceUtil.getOrCreateResource(resolver, path, resourceType, intermediateType, autosave)).iterator();
+            logger.info("creating path {}", path);
+            if (!isDryRun()) {
+                output = Collections.singleton(ResourceUtil.getOrCreateResource(resolver, path, resourceType, intermediateType, autosave)).iterator();
+            }
         } catch (PersistenceException e){
             logger.error ("Not able to create path {}", expression, e);
         }

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.