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 2017/08/29 19:55:37 UTC
svn commit: r1806636 - in /sling/trunk/contrib/extensions/sling-pipes/src:
main/java/org/apache/sling/pipes/ main/java/org/apache/sling/pipes/internal/
test/java/org/apache/sling/pipes/
test/java/org/apache/sling/pipes/internal/ test/java/org/apache/sl...
Author: npeltier
Date: Tue Aug 29 19:55:37 2017
New Revision: 1806636
URL: http://svn.apache.org/viewvc?rev=1806636&view=rev
Log:
SLING-7013 pipe builder api updates
- make with extensible,
- add async run & binding run,
- move filter api to grep,
- remove exception throwing from the api, when it will never happen,
- add some integration tests,
- fix a specific case of reference call through pipebuilder (container -> reference -> container -> pipe)
Added:
sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/internal/ReferencePipeTest.java
- copied, changed from r1806595, sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/ReferencePipeTest.java
sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/it/PipeBuilderIT.java
Removed:
sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/ReferencePipeTest.java
Modified:
sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/ContainerPipe.java
sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/PipeBuilder.java
sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/Plumber.java
sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/ReferencePipe.java
sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/internal/PipeBuilderImpl.java
sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/internal/PlumberImpl.java
sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/PipeBuilderTest.java
sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/internal/PathPipeTest.java
sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/it/PipesTestSupport.java
sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/it/PlumberTestIT.java
Modified: sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/ContainerPipe.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/ContainerPipe.java?rev=1806636&r1=1806635&r2=1806636&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/ContainerPipe.java (original)
+++ sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/ContainerPipe.java Tue Aug 29 19:55:37 2017
@@ -77,6 +77,14 @@ public class ContainerPipe extends BaseP
}
@Override
+ public void setBindings(PipeBindings bindings) {
+ this.bindings = bindings;
+ for (Pipe pipe : pipeList){
+ pipe.setBindings(bindings);
+ }
+ }
+
+ @Override
public Iterator<Resource> getOutput() {
return new ContainerResourceIterator(this);
}
Modified: sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/PipeBuilder.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/PipeBuilder.java?rev=1806636&r1=1806635&r2=1806636&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/PipeBuilder.java (original)
+++ sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/PipeBuilder.java Tue Aug 29 19:55:37 2017
@@ -17,7 +17,9 @@
package org.apache.sling.pipes;
import org.apache.sling.api.resource.PersistenceException;
+import org.apache.sling.event.jobs.Job;
+import java.util.Map;
import java.util.Set;
/**
@@ -42,7 +44,7 @@ public interface PipeBuilder {
* attach a write pipe to the current context
* @param conf configuration parameters
* @return updated instance of PipeBuilder
- * @throws IllegalAccessException in case it's called in a bad time
+ * @throws IllegalAccessException in case it's called with bad configuration
*/
PipeBuilder write(Object... conf) throws IllegalAccessException;
@@ -50,15 +52,15 @@ public interface PipeBuilder {
* attach a filter pipe to the current context
* @param conf configuration parameters
* @return updated instance of PipeBuilder
- * @throws IllegalAccessException in case it's called in a bad time
+ * @throws IllegalAccessException in case it's called with bad configuration
*/
- PipeBuilder filter(Object... conf) throws IllegalAccessException;
+ PipeBuilder grep(Object... conf) throws IllegalAccessException;
/**
* attach an authorizable pipe to the current context
* @param conf configuration key value pairs for authorizable (see pipe's doc)
* @return updated instance of PipeBuilder
- * @throws IllegalAccessException in case it's called in a bad time
+ * @throws IllegalAccessException in case it's called with bad configuration
*/
PipeBuilder auth(Object... conf) throws IllegalAccessException;
@@ -66,17 +68,15 @@ public interface PipeBuilder {
* attach a xpath pipe to the current context
* @param expr xpath expression
* @return updated instance of PipeBuilder
- * @throws IllegalAccessException in case it's called in a bad time
*/
- PipeBuilder xpath(String expr) throws IllegalAccessException;
+ PipeBuilder xpath(String expr);
/**
* attach a sling query pipe to the current context
* @param expr sling query expression
* @return updated instance of PipeBuilder
- * @throws IllegalAccessException in case it's called in a bad time
*/
- PipeBuilder $(String expr) throws IllegalAccessException;
+ PipeBuilder $(String expr);
/**
* attach a rm pipe to the current context
@@ -88,32 +88,28 @@ public interface PipeBuilder {
* attach a json pipe to the current context
* @param expr json expr or URL
* @return updated instance of PipeBuilder
- * @throws IllegalAccessException in case it's called in a bad time
*/
- PipeBuilder json(String expr) throws IllegalAccessException;
+ PipeBuilder json(String expr);
/**
* Attach a path pipe to the current context
* @param expr path to create
* @return updated instance of PipeBuilder
- * @throws IllegalAccessException in case it's called in a bad time
*/
- PipeBuilder mkdir(String expr) throws IllegalAccessException;
+ PipeBuilder mkdir(String expr);
/**
* attach a base pipe to the current context
* @param path pipe path
* @return updated instance of PipeBuilder
- * @throws IllegalAccessException in case it's called in a bad time
*/
- PipeBuilder echo(String path) throws IllegalAccessException;
+ PipeBuilder echo(String path);
/**
* attach a traverse pipe to the current context
- * @return
- * @throws IllegalAccessException
+ * @return updated instance of PipeBuilder
*/
- PipeBuilder traverse() throws IllegalAccessException;
+ PipeBuilder traverse();
/**
* attach a parent pipe to the current context
@@ -123,12 +119,11 @@ public interface PipeBuilder {
/**
* parameterized current pipe in the context
- * @param param key (property name) of the property
- * @param value value of te property
+ * @param params key value pair of parameters
* @return updated instance of PipeBuilder
- * @throws IllegalAccessException in case it's called in a bad time
+ * @throws IllegalAccessException in case it's called before a pipe is configured, or with wrong # of arguments
*/
- PipeBuilder with(String param, Object value) throws IllegalAccessException;
+ PipeBuilder with(Object... params) throws IllegalAccessException;
/**
* set an expr configuration to the current pipe in the context
@@ -142,7 +137,7 @@ public interface PipeBuilder {
* sets a pipe name, important in case you want to reuse it in another expression
* @param name to overwrite default binding name (otherwise it will be "one", "two", ...)
* @return updated instance of PipeBuilder
- * @throws IllegalAccessException in case it's called in a bad time
+ * @throws IllegalAccessException in case it's called before a pipe is configured
*/
PipeBuilder name(String name) throws IllegalAccessException;
@@ -150,7 +145,7 @@ public interface PipeBuilder {
* set a path configuration to the current pipe in the context
* @param value path value
* @return updated instance of PipeBuilder
- * @throws IllegalAccessException in case it's called in a bad time
+ * @throws IllegalAccessException in case it's called before a pipe is configured
*/
PipeBuilder path(String value) throws IllegalAccessException;
@@ -175,4 +170,20 @@ public interface PipeBuilder {
* @throws Exception exceptions thrown by the build or the pipe execution itself
*/
Set<String> run() throws Exception;
+
+ /**
+ * allow execution of a pipe, with more parameter
+ * @param bindings additional bindings
+ * @return set of resource path, output of the pipe execution
+ * @throws Exception in case something goes wrong with pipe execution
+ */
+ Set<String> run(Map bindings) throws Exception;
+
+ /**
+ * run a pipe asynchronously
+ * @param bindings additional bindings for the execution (can be null)
+ * @return registered job for the pipe execution
+ * @throws PersistenceException in case something goes wrong in the job creation
+ */
+ Job runAsync(Map bindings) throws PersistenceException;
}
Modified: sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/Plumber.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/Plumber.java?rev=1806636&r1=1806635&r2=1806636&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/Plumber.java (original)
+++ sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/Plumber.java Tue Aug 29 19:55:37 2017
@@ -98,7 +98,7 @@ public interface Plumber {
* @param resolver resource resolver that will be used for building the pipe
* @return instance of PipeBuilder
*/
- PipeBuilder getBuilder(ResourceResolver resolver);
+ PipeBuilder newPipe(ResourceResolver resolver);
/**
* returns true if the pipe is considered to be running
Modified: sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/ReferencePipe.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/ReferencePipe.java?rev=1806636&r1=1806635&r2=1806636&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/ReferencePipe.java (original)
+++ sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/ReferencePipe.java Tue Aug 29 19:55:37 2017
@@ -53,6 +53,11 @@ public class ReferencePipe extends BaseP
}
@Override
+ public PipeBindings getBindings() {
+ return reference.getBindings();
+ }
+
+ @Override
public Iterator<Resource> getOutput() {
return reference.getOutput();
}
Modified: sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/internal/PipeBuilderImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/internal/PipeBuilderImpl.java?rev=1806636&r1=1806635&r2=1806636&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/internal/PipeBuilderImpl.java (original)
+++ sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/internal/PipeBuilderImpl.java Tue Aug 29 19:55:37 2017
@@ -21,6 +21,7 @@ import org.apache.sling.api.resource.Per
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
+import org.apache.sling.event.jobs.Job;
import org.apache.sling.pipes.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -72,9 +73,24 @@ public class PipeBuilderImpl implements
return this;
}
+ /**
+ * internal utility to glob pipe configuration & expression configuration
+ * @param type pipe type
+ * @param expr expression
+ * @return updated instance of PipeBuilder
+ */
+ protected PipeBuilder pipeWithExpr(String type, String expr){
+ try {
+ pipe(type).expr(expr);
+ } catch (IllegalAccessException e){
+ logger.error("exception while configuring {}", type, e);
+ }
+ return this;
+ }
+
@Override
public PipeBuilder mv(String expr) {
- return pipe(MovePipe.RESOURCE_TYPE);
+ return pipeWithExpr(MovePipe.RESOURCE_TYPE, expr);
}
@Override
@@ -83,7 +99,7 @@ public class PipeBuilderImpl implements
}
@Override
- public PipeBuilder filter(Object... conf) throws IllegalAccessException {
+ public PipeBuilder grep(Object... conf) throws IllegalAccessException {
return pipe(FilterPipe.RESOURCE_TYPE).conf(conf);
}
@@ -93,13 +109,13 @@ public class PipeBuilderImpl implements
}
@Override
- public PipeBuilder xpath(String expr) throws IllegalAccessException {
- return pipe(XPathPipe.RESOURCE_TYPE).expr(expr);
+ public PipeBuilder xpath(String expr) {
+ return pipeWithExpr(XPathPipe.RESOURCE_TYPE, expr);
}
@Override
- public PipeBuilder $(String expr) throws IllegalAccessException {
- return pipe(SlingQueryPipe.RESOURCE_TYPE).expr(expr);
+ public PipeBuilder $(String expr) {
+ return pipeWithExpr(SlingQueryPipe.RESOURCE_TYPE, expr);
}
@Override
@@ -113,18 +129,23 @@ public class PipeBuilderImpl implements
}
@Override
- public PipeBuilder json(String expr) throws IllegalAccessException {
- return pipe(JsonPipe.RESOURCE_TYPE).expr(expr);
+ public PipeBuilder json(String expr) {
+ return pipeWithExpr(JsonPipe.RESOURCE_TYPE, expr);
}
@Override
- public PipeBuilder mkdir(String expr) throws IllegalAccessException {
- return pipe(PathPipe.RESOURCE_TYPE).expr(expr);
+ public PipeBuilder mkdir(String expr) {
+ return pipeWithExpr(PathPipe.RESOURCE_TYPE, expr);
}
@Override
- public PipeBuilder echo(String path) throws IllegalAccessException {
- return pipe(BasePipe.RESOURCE_TYPE).path(path);
+ public PipeBuilder echo(String path) {
+ try {
+ pipe(BasePipe.RESOURCE_TYPE).path(path);
+ } catch(IllegalAccessException e){
+ logger.error("error when calling echo {}", path, e);
+ }
+ return this;
}
@Override
@@ -143,9 +164,37 @@ public class PipeBuilderImpl implements
}
@Override
- public PipeBuilder with(String param, Object value) throws IllegalAccessException {
+ public PipeBuilder with(Object... params) throws IllegalAccessException {
+ return writeToCurrentStep(null, params);
+ }
+
+ @Override
+ public PipeBuilder conf(Object... properties) throws IllegalAccessException {
+ return writeToCurrentStep(Pipe.NN_CONF, properties);
+ }
+
+ /**
+ * Add some configurations to current's Step node defined by name (if null, will be step's properties)
+ * @param name name of the configuration node, can be null in which case it's the subpipe itself
+ * @param params key/value pair list of configuration
+ * @return updated instance of PipeBuilder
+ * @throws IllegalAccessException in case configuration is wrong
+ */
+ protected PipeBuilder writeToCurrentStep(String name, Object... params) throws IllegalAccessException {
checkCurrentStep();
- currentStep.properties.put(param, value);
+ if (params.length % 2 > 0){
+ throw new IllegalArgumentException("there should be an even number of arguments");
+ }
+ Map props = name != null ? currentStep.confs.get(name) : currentStep.properties;
+ if (props == null){
+ props = new HashMap();
+ if (name != null){
+ currentStep.confs.put(name, props);
+ }
+ }
+ for (int i = 0; i < params.length; i += 2){
+ props.put(params[i], params[i + 1]);
+ }
return this;
}
@@ -166,18 +215,6 @@ public class PipeBuilderImpl implements
return this;
}
- @Override
- public PipeBuilder conf(Object... properties) throws IllegalAccessException {
- checkCurrentStep();
- if (properties.length % 2 > 0){
- throw new IllegalArgumentException("there should be an even number of arguments");
- }
- for (int i = 0; i < properties.length; i += 2){
- currentStep.conf.put(properties[i], properties[i + 1]);
- }
- return this;
- }
-
/**
* build a time + random based path under /var/pipes
* @return full path of future Pipe
@@ -188,6 +225,18 @@ public class PipeBuilderImpl implements
+ UUID.randomUUID().toString();
}
+ /**
+ * Create a configuration resource
+ * @param resolver current resolver
+ * @param path path of the resource
+ * @param type type of the node to be created
+ * @param data map of properties to add
+ * @throws PersistenceException in case configuration resource couldn't be persisted
+ */
+ protected void createResource(ResourceResolver resolver, String path, String type, Map data) throws PersistenceException {
+ ResourceUtil.getOrCreateResource(resolver, path, data, type, false);
+ }
+
@Override
public Pipe build() throws PersistenceException {
String rootPath = buildPipePath();
@@ -197,11 +246,11 @@ public class PipeBuilderImpl implements
String name = StringUtils.isNotBlank(step.name) ? step.name : DEFAULT_NAMES.length > index ? DEFAULT_NAMES[index] : Integer.toString(index);
index++;
String subPipePath = rootPath + "/" + Pipe.NN_CONF + "/" + name;
- ResourceUtil.getOrCreateResource(resolver, subPipePath, step.properties, NT_SLING_ORDERED_FOLDER, false);
+ createResource(resolver, subPipePath, NT_SLING_ORDERED_FOLDER, step.properties);
logger.debug("built subpipe {}", subPipePath);
- if (!step.conf.isEmpty()){
- ResourceUtil.getOrCreateResource(resolver, subPipePath + "/" + Pipe.NN_CONF, step.conf, NT_SLING_FOLDER, false);
- logger.debug("built subpipe {}'s conf node", subPipePath);
+ for (Map.Entry<String, Map> entry : step.confs.entrySet()){
+ createResource(resolver, subPipePath + "/" + entry.getKey(), NT_SLING_FOLDER, entry.getValue());
+ logger.debug("built subpipe {}'s {} node", subPipePath, entry.getKey());
}
}
resolver.commit();
@@ -211,8 +260,19 @@ public class PipeBuilderImpl implements
@Override
public Set<String> run() throws Exception {
+ return run(null);
+ }
+
+ @Override
+ public Set<String> run(Map bindings) throws Exception {
+ Pipe pipe = this.build();
+ return plumber.execute(resolver, pipe, bindings, new NopWriter() , true);
+ }
+
+ @Override
+ public Job runAsync(Map bindings) throws PersistenceException {
Pipe pipe = this.build();
- return plumber.execute(resolver, pipe, null, new NopWriter(), true);
+ return plumber.executeAsync(resolver, pipe.getResource().getPath(), bindings);
}
/**
@@ -221,10 +281,9 @@ public class PipeBuilderImpl implements
public class Step {
String name;
Map properties;
- Map conf;
+ Map<String, Map> confs = new HashMap<>();
Step(String type){
properties = new HashMap();
- conf = new HashMap();
properties.put(SLING_RESOURCE_TYPE_PROPERTY, type);
}
}
Modified: sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/internal/PlumberImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/internal/PlumberImpl.java?rev=1806636&r1=1806635&r2=1806636&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/internal/PlumberImpl.java (original)
+++ sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/internal/PlumberImpl.java Tue Aug 29 19:55:37 2017
@@ -271,7 +271,7 @@ public class PlumberImpl implements Plum
}
@Override
- public PipeBuilder getBuilder(ResourceResolver resolver) {
+ public PipeBuilder newPipe(ResourceResolver resolver) {
PipeBuilder builder = new PipeBuilderImpl(resolver, this);
return builder;
}
Modified: sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/PipeBuilderTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/PipeBuilderTest.java?rev=1806636&r1=1806635&r2=1806636&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/PipeBuilderTest.java (original)
+++ sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/PipeBuilderTest.java Tue Aug 29 19:55:37 2017
@@ -19,6 +19,8 @@ package org.apache.sling.pipes;
import org.apache.sling.api.resource.ValueMap;
import org.junit.Test;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Set;
import static org.junit.Assert.*;
@@ -26,7 +28,7 @@ import static org.junit.Assert.*;
public class PipeBuilderTest extends AbstractPipeTest {
@Test
public void simpleBuild() throws Exception {
- PipeBuilder rmBuilder = plumber.getBuilder(context.resourceResolver());
+ 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)
@@ -36,7 +38,7 @@ public class PipeBuilderTest extends Abs
@Test
public void run() throws Exception {
String lemonPath = "/content/fruits/lemon";
- PipeBuilder lemonBuilder = plumber.getBuilder(context.resourceResolver());
+ PipeBuilder lemonBuilder = plumber.newPipe(context.resourceResolver());
Set<String> paths = lemonBuilder.mkdir(lemonPath).run();
assertTrue("returned set should contain lemon path", paths.contains(lemonPath));
assertNotNull("there should be a lemon created", context.resourceResolver().getResource(lemonPath));
@@ -44,7 +46,7 @@ public class PipeBuilderTest extends Abs
@Test
public void confBuild() throws Exception {
- PipeBuilder writeBuilder = plumber.getBuilder(context.resourceResolver());
+ PipeBuilder writeBuilder = plumber.newPipe(context.resourceResolver());
writeBuilder.echo(PATH_APPLE).write("tested", true, "working", true).run();
ValueMap properties = context.resourceResolver().getResource(PATH_APPLE).adaptTo(ValueMap.class);
assertTrue("properties should have been written", properties.get("tested", false) && properties.get("working", false));
@@ -52,11 +54,11 @@ public class PipeBuilderTest extends Abs
@Test
public void bindings() throws Exception {
- PipeBuilder defaultNames = plumber.getBuilder(context.resourceResolver());
+ PipeBuilder defaultNames = plumber.newPipe(context.resourceResolver());
Set<String> paths = defaultNames
.echo(PATH_FRUITS)
.$("nt:unstructured")
- .filter("slingPipesFilter_test","${two.worm}")
+ .grep("slingPipesFilter_test","${two.worm}")
.$("nt:unstructured#isnota")
.$("nt:unstructured").name("thing")
.write("jcr:path", "${path.thing}").run();
@@ -71,4 +73,11 @@ public class PipeBuilderTest extends Abs
}
}
+ @Test
+ public void additionalBindings() throws Exception {
+ Map bindings = new HashMap<>();
+ bindings.put("testedPath", PATH_FRUITS);
+ Set<String> paths = plumber.newPipe(context.resourceResolver()).echo("${testedPath}").run(bindings);
+ assertTrue("paths should contain implemented testedPath", paths.contains(PATH_FRUITS));
+ }
}
\ No newline at end of file
Modified: sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/internal/PathPipeTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/internal/PathPipeTest.java?rev=1806636&r1=1806635&r2=1806636&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/internal/PathPipeTest.java (original)
+++ sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/internal/PathPipeTest.java Tue Aug 29 19:55:37 2017
@@ -34,7 +34,7 @@ public class PathPipeTest extends Abstra
@Test
public void modifiesContent() throws IllegalAccessException, PersistenceException {
- Pipe pipe = plumber.getBuilder(context.resourceResolver())
+ Pipe pipe = plumber.newPipe(context.resourceResolver())
.mkdir(PATH_FRUITS + "/whatever")
.build();
assertTrue("path pipe should be considered as modifying the content", pipe.modifiesContent());
@@ -43,7 +43,7 @@ public class PathPipeTest extends Abstra
@Test
public void getClassicOutput() throws Exception {
ResourceResolver resolver = context.resourceResolver();
- plumber.getBuilder(resolver).mkdir(WATERMELON_FULL_PATH).run();
+ plumber.newPipe(resolver).mkdir(WATERMELON_FULL_PATH).run();
resolver.revert();
assertNotNull("Resource should be here & saved", resolver.getResource(WATERMELON_FULL_PATH));
}
@@ -51,7 +51,7 @@ public class PathPipeTest extends Abstra
@Test
public void getRelativePath() throws Exception {
ResourceResolver resolver = context.resourceResolver();
- plumber.getBuilder(resolver).echo(PATH_FRUITS).mkdir(WATERMELON).run();
+ plumber.newPipe(resolver).echo(PATH_FRUITS).mkdir(WATERMELON).run();
assertNotNull("Resource should be here & saved", resolver.getResource(WATERMELON_FULL_PATH));
}
}
\ No newline at end of file
Copied: sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/internal/ReferencePipeTest.java (from r1806595, sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/ReferencePipeTest.java)
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/internal/ReferencePipeTest.java?p2=sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/internal/ReferencePipeTest.java&p1=sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/ReferencePipeTest.java&r1=1806595&r2=1806636&rev=1806636&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/ReferencePipeTest.java (original)
+++ sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/internal/ReferencePipeTest.java Tue Aug 29 19:55:37 2017
@@ -14,13 +14,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.sling.pipes;
+package org.apache.sling.pipes.internal;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import org.apache.sling.api.resource.ResourceUtil;
+import org.apache.sling.pipes.AbstractPipeTest;
+import org.apache.sling.pipes.Pipe;
+import org.apache.sling.pipes.ReferencePipe;
import org.junit.Before;
import org.junit.Test;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
/**
* testing references
*/
@@ -49,6 +58,20 @@ public class ReferencePipeTest extends
@Test
public void testValueBinding() throws Exception {
testOneResource(PATH_PIPE + "/isAppleWormy", PATH_APPLE);
- assertFalse("Banana should be filtered out", getOutput(PATH_PIPE + "/isBananaWormy").hasNext());
+ }
+
+ @Test
+ public void testBuilderWithAdditionalBinding() throws Exception {
+ String newFruit = "watermelon";
+ String newPath = PATH_FRUITS + "/" + newFruit;
+ ResourceUtil.getOrCreateResource(context.resourceResolver(), newPath, "nt:unstructured", "nt:unstructured", true);
+ Map bindings = new HashMap();
+ bindings.put("fruit", newFruit);
+ Pipe pipe = plumber.newPipe(context.resourceResolver()).echo(PATH_FRUITS + "/${fruit}").build();
+ Set<String> paths = plumber.newPipe(context.resourceResolver())
+ .pipe(ReferencePipe.RESOURCE_TYPE)
+ .expr(pipe.getResource().getPath())
+ .run(bindings);
+ assertTrue("paths should contain new path", paths.contains(newPath));
}
}
\ No newline at end of file
Added: sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/it/PipeBuilderIT.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/it/PipeBuilderIT.java?rev=1806636&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/it/PipeBuilderIT.java (added)
+++ sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/it/PipeBuilderIT.java Tue Aug 29 19:55:37 2017
@@ -0,0 +1,112 @@
+/*
+ * 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.it;
+
+import org.apache.commons.collections.IteratorUtils;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.pipes.Pipe;
+import org.apache.sling.pipes.ReferencePipe;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jcr.query.Query;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * testing explicitly the pipe builder
+ */
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class PipeBuilderIT extends PipesTestSupport {
+ private static final Logger LOGGER = LoggerFactory.getLogger(PlumberTestIT.class);
+
+ @Test
+ public void traverseTest() throws Exception {
+ final String CONTENT = "/content/traverse/test";
+ try (ResourceResolver resolver = resolver()) {
+ mkdir(resolver, CONTENT);
+ Set<String> results = plumber.newPipe(resolver).echo(CONTENT).traverse().run();
+ LOGGER.info("Following results are found {}", results);
+ assertTrue("should contain former test", results.contains(CONTENT));
+ }
+ }
+
+ @Test
+ public void mvTest() throws Exception {
+ final String CONTENT = "/content/mv/" + NN_TEST;
+ final String TARGET = "/content/target";
+ final String TARGET_PATH = TARGET + "/" + NN_TEST;
+ try (ResourceResolver resolver = resolver()) {
+ mkdir(resolver, CONTENT);
+ mkdir(resolver, TARGET);
+ Set<String> results = plumber.newPipe(resolver).echo(CONTENT).mv(TARGET_PATH).run();
+ LOGGER.info("Following results are found {}", results);
+ assertTrue("mv return should be the moved item", results.contains(TARGET_PATH));
+ }
+ }
+
+ @Test
+ @Ignore //for some reason xpath doesn't seem to run
+ public void xpathTest() throws Exception {
+ final String ROOT = "/content/xpath";
+ final int NB_ITEMS = 10;
+ try (ResourceResolver resolver = resolver()) {
+ for (int i = 0; i < NB_ITEMS; i ++){
+ plumber.newPipe(resolver).mkdir(ROOT + "/" + i + "/" + NN_TEST).write("xpathTestStatus","testing").run();
+ }
+ String query = "/jcr:root" + ROOT +"//element(*,nt:unstructured)[@xpathTestStatus]";
+ Set<String> results = plumber.newPipe(resolver).xpath(query).run();
+ Iterator<Resource> resources = resolver.findResources(query, Query.XPATH);
+ LOGGER.info("found through normal request {}", IteratorUtils.toList(resources));
+ LOGGER.info("Following results are found through pipe {}", results);
+ assertEquals("xpath should return as many items as the ones we wrote", NB_ITEMS, results.size());
+ }
+ }
+
+ @Test
+ public void referenceWithBindings() throws Exception {
+ final String ROOT = "/content/reference";
+ try (ResourceResolver resolver = resolver()) {
+ Pipe pipe = plumber.newPipe(resolver).mkdir(ROOT + "/test-${testedBinding}").write("jcr:title","${testedBinding}").build();
+ for (int i = 0; i < 10; i ++) {
+ Map bindings = new HashMap();
+ bindings.put("testedBinding", i);
+ plumber.newPipe(resolver).pipe(ReferencePipe.RESOURCE_TYPE).expr(pipe.getResource().getPath()).run(bindings);
+ }
+ Set<String> results = plumber.newPipe(resolver).echo(ROOT).traverse().run();
+ LOGGER.info("Following results are found {}", results);
+ assertEquals("we should have root and implemented children", 11, results.size());
+ }
+ }
+
+
+}
Modified: sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/it/PipesTestSupport.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/it/PipesTestSupport.java?rev=1806636&r1=1806635&r2=1806636&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/it/PipesTestSupport.java (original)
+++ sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/it/PipesTestSupport.java Tue Aug 29 19:55:37 2017
@@ -21,6 +21,7 @@ package org.apache.sling.pipes.it;
import javax.inject.Inject;
import org.apache.sling.api.resource.LoginException;
+import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.pipes.Plumber;
@@ -41,6 +42,8 @@ import static org.ops4j.pax.exam.cm.Conf
public abstract class PipesTestSupport extends TestSupport {
+ protected static final String NN_TEST = "test";
+
@Inject
@Filter(timeout = 3000000)
protected Plumber plumber;
@@ -63,6 +66,10 @@ public abstract class PipesTestSupport e
};
}
+ protected void mkdir(ResourceResolver resolver, String path) throws Exception {
+ plumber.newPipe(resolver).mkdir(path).run();
+ }
+
protected Option launchpad() {
final int httpPort = findFreePort();
final String workingDirectory = workingDirectory();
Modified: sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/it/PlumberTestIT.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/it/PlumberTestIT.java?rev=1806636&r1=1806635&r2=1806636&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/it/PlumberTestIT.java (original)
+++ sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/it/PlumberTestIT.java Tue Aug 29 19:55:37 2017
@@ -25,10 +25,6 @@ import org.junit.runner.RunWith;
import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
import org.ops4j.pax.exam.spi.reactors.PerClass;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Set;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -36,15 +32,13 @@ import static org.junit.Assert.assertTru
@RunWith(PaxExam.class)
@ExamReactorStrategy(PerClass.class)
public class PlumberTestIT extends PipesTestSupport {
- private static final Logger LOGGER = LoggerFactory.getLogger(PlumberTestIT.class);
public static final String ROOT = "/content/my";
- public static final String NN_TEST = "test";
public static final String TEST_PATH = ROOT + "/" + NN_TEST;
@Test
public void simpleTest() throws Exception {
try (ResourceResolver resolver = resolver()) {
- plumber.getBuilder(resolver)
+ plumber.newPipe(resolver)
.mkdir(ROOT)
.write(NN_TEST, true)
.run();
@@ -54,14 +48,4 @@ public class PlumberTestIT extends Pipes
}
}
- @Test
- public void traverseTest() throws Exception {
- try (ResourceResolver resolver = resolver()) {
- plumber.getBuilder(resolver).mkdir(ROOT).run();
- Set<String> results = plumber.getBuilder(resolver).echo(ROOT).traverse().run();
- LOGGER.info("Following results are found {}", results);
- assertTrue("should contain former test", results.contains(ROOT));
- }
- }
-
}