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
The following commit(s) were added to refs/heads/master by this push: new af1b512 SLING-7249 add csv output af1b512 is described below commit af1b512139845e4f18a405ed3d5568a655989dfe Author: npeltier <peltier.nico...@gmail.com> AuthorDate: Sat Nov 18 10:28:23 2017 +0100 SLING-7249 add csv output - simplify output writers hierarchy, - add csv writer --- .../org/apache/sling/pipes/CustomOutputWriter.java | 39 +++++++++ .../java/org/apache/sling/pipes/OutputWriter.java | 32 ++++++- .../org/apache/sling/pipes/internal/CsvWriter.java | 93 +++++++++++++++++++++ .../sling/pipes/internal/CustomJsonWriter.java | 97 ---------------------- .../{DefaultJsonWriter.java => JsonWriter.java} | 32 +++++-- .../sling/pipes/internal/PipeBuilderImpl.java | 5 +- .../sling/pipes/internal/PlumberServlet.java | 5 +- .../sling/pipes/internal/PlumberServletTest.java | 28 ++++--- .../apache/sling/pipes/it/PlumberServletIT.java | 11 +-- 9 files changed, 217 insertions(+), 125 deletions(-) diff --git a/src/main/java/org/apache/sling/pipes/CustomOutputWriter.java b/src/main/java/org/apache/sling/pipes/CustomOutputWriter.java new file mode 100644 index 0000000..b618aff --- /dev/null +++ b/src/main/java/org/apache/sling/pipes/CustomOutputWriter.java @@ -0,0 +1,39 @@ +/* + * 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.SlingHttpServletRequest; +import org.apache.sling.api.SlingHttpServletResponse; +import org.apache.sling.api.resource.Resource; + +import java.io.IOException; +import java.util.HashMap; + +public abstract class CustomOutputWriter extends OutputWriter { + + @Override + public void init(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException { + super.init(request, response); + + } + + @Override + public void setPipe(Pipe pipe) { + super.setPipe(pipe); + + } +} \ No newline at end of file diff --git a/src/main/java/org/apache/sling/pipes/OutputWriter.java b/src/main/java/org/apache/sling/pipes/OutputWriter.java index 090413a..a6df8fd 100644 --- a/src/main/java/org/apache/sling/pipes/OutputWriter.java +++ b/src/main/java/org/apache/sling/pipes/OutputWriter.java @@ -16,17 +16,24 @@ */ package org.apache.sling.pipes; +import org.apache.commons.lang3.StringUtils; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.SlingHttpServletResponse; import org.apache.sling.api.resource.Resource; +import org.apache.sling.pipes.internal.JsonUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.IOException; import java.io.Writer; +import java.util.HashMap; +import java.util.Map; /** * defines how pipe's output get written to a servlet response or output stream */ public abstract class OutputWriter { + Logger log = LoggerFactory.getLogger(CustomOutputWriter.class); public static final String KEY_SIZE = "size"; @@ -44,6 +51,13 @@ public abstract class OutputWriter { protected Writer writer; + public static final String PATH_KEY = "path"; + + public static final String PARAM_WRITER = "writer"; + + protected Map<String, Object> customOutputs; + + /** * * @param request current request @@ -61,6 +75,14 @@ public abstract class OutputWriter { if (request.getParameter(PARAM_SIZE) != null) { setMax(Integer.parseInt(request.getParameter(PARAM_SIZE))); } + String writerParam = request.getParameter(PARAM_WRITER); + if (StringUtils.isNotBlank(writerParam)){ + try { + customOutputs = JsonUtil.unbox(JsonUtil.parseObject(writerParam)); + } catch(Exception e){ + log.error("requested attributes can't be parsed", e); + } + } setWriter(response.getWriter()); initResponse(response); starts(); @@ -88,7 +110,7 @@ public abstract class OutputWriter { } } - /** + /**x * Set the writer * @param writer writer on which to write output */ @@ -124,6 +146,14 @@ public abstract class OutputWriter { */ public void setPipe(Pipe pipe) { this.pipe = pipe; + Resource outputs = pipe.getResource().getChild(PARAM_WRITER); + if (customOutputs == null && outputs != null ){ + customOutputs = new HashMap<>(); + customOutputs.putAll(outputs.getValueMap()); + for (String ignoredKey : BasePipe.IGNORED_PROPERTIES) { + customOutputs.remove(ignoredKey); + } + } } @Override diff --git a/src/main/java/org/apache/sling/pipes/internal/CsvWriter.java b/src/main/java/org/apache/sling/pipes/internal/CsvWriter.java new file mode 100644 index 0000000..7ca5f38 --- /dev/null +++ b/src/main/java/org/apache/sling/pipes/internal/CsvWriter.java @@ -0,0 +1,93 @@ +/* + * 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.internal; + +import org.apache.sling.api.SlingHttpServletRequest; +import org.apache.sling.api.SlingHttpServletResponse; +import org.apache.sling.api.resource.Resource; +import org.apache.sling.pipes.CustomOutputWriter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +public class CsvWriter extends CustomOutputWriter { + private static final Logger LOG = LoggerFactory.getLogger(CsvWriter.class); + + private static final String CSV_EXTENSION = "csv"; + + private static final String SEPARATOR = ","; + + private static final String NEW_LINE = "\n"; + + List<String> headers; + + @Override + public boolean handleRequest(SlingHttpServletRequest request) { + return request.getRequestPathInfo().getExtension().equals(CSV_EXTENSION); + } + + @Override + protected void initResponse(SlingHttpServletResponse response) { + response.setCharacterEncoding("utf-8"); + response.setContentType("plain/text"); + } + + @Override + public void starts() { + + } + + @Override + protected void writeItem(Resource resource) { + if (headers == null) { + headers = new ArrayList<>(); + headers.add(PATH_KEY); + if (customOutputs != null) { + headers.addAll(customOutputs.keySet()); + } + try { + writer.write(headers.stream().collect(Collectors.joining(SEPARATOR)) + NEW_LINE); + } catch (IOException e) { + LOG.error("unable to write header"); + } + } + if (headers != null){ + try { + String line = headers.stream().map(key -> key.equals(PATH_KEY) ? + resource.getPath() + : (String)pipe.getBindings().instantiateObject((String)customOutputs.get(key))) + .collect(Collectors.joining(SEPARATOR)); + writer.write(line + NEW_LINE); + } catch (IOException e) { + LOG.error("unable to write header", e); + } + } + } + + @Override + public void ends() { + try { + writer.flush(); + } catch (IOException e) { + LOG.error("unable to flush", e); + } + } +} \ No newline at end of file diff --git a/src/main/java/org/apache/sling/pipes/internal/CustomJsonWriter.java b/src/main/java/org/apache/sling/pipes/internal/CustomJsonWriter.java deleted file mode 100644 index 62df138..0000000 --- a/src/main/java/org/apache/sling/pipes/internal/CustomJsonWriter.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * 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.internal; - -import org.apache.commons.lang3.StringUtils; -import org.apache.sling.api.SlingHttpServletRequest; -import org.apache.sling.api.resource.Resource; -import org.apache.sling.api.resource.ValueMap; -import org.apache.sling.pipes.BasePipe; -import org.apache.sling.pipes.Pipe; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.json.JsonValue; -import java.io.Writer; -import java.util.HashMap; -import java.util.Map; - -/** - * writes current resource, dubbing a eventual parameter or given child resource "writer" property/value pairs, allowing - * expressions - */ -public class CustomJsonWriter extends DefaultJsonWriter { - Logger log = LoggerFactory.getLogger(CustomJsonWriter.class); - - public static final String PATH_KEY = "path"; - - public static final String PARAM_WRITER = "writer"; - - Map<String, Object> customOutputs; - - CustomJsonWriter() { - } - - CustomJsonWriter(Writer writer) { - super(writer); - } - - @Override - public boolean handleRequest(SlingHttpServletRequest request) { - String writerParam = request.getParameter(PARAM_WRITER); - if (StringUtils.isNotBlank(writerParam)){ - try { - customOutputs = JsonUtil.unbox(JsonUtil.parseObject(writerParam)); - return true; - } catch(Exception e){ - log.error("requested json writer can't be parsed", e); - } - } else { - Resource resource = request.getResource().getChild(PARAM_WRITER); - return resource != null; - } - return false; - } - - @Override - public void setPipe(Pipe pipe) { - super.setPipe(pipe); - if (customOutputs == null){ - customOutputs = new HashMap<>(); - customOutputs.putAll(pipe.getResource().getChild(PARAM_WRITER).adaptTo(ValueMap.class)); - for (String ignoredKey : BasePipe.IGNORED_PROPERTIES) { - customOutputs.remove(ignoredKey); - } - } - } - - @Override - public void writeItem(Resource resource) { - jsonWriter.writeStartObject(); - jsonWriter.write(PATH_KEY,resource.getPath()); - for (Map.Entry<String, Object> entry : customOutputs.entrySet()){ - Object o = pipe.getBindings().instantiateObject((String)entry.getValue()); - if ( o instanceof JsonValue ) { - jsonWriter.write(entry.getKey(),(JsonValue) o); - } - else { - jsonWriter.write(entry.getKey(), o.toString()); - } - } - jsonWriter.writeEnd(); - } -} \ No newline at end of file diff --git a/src/main/java/org/apache/sling/pipes/internal/DefaultJsonWriter.java b/src/main/java/org/apache/sling/pipes/internal/JsonWriter.java similarity index 66% rename from src/main/java/org/apache/sling/pipes/internal/DefaultJsonWriter.java rename to src/main/java/org/apache/sling/pipes/internal/JsonWriter.java index 3a614f7..8a69294 100644 --- a/src/main/java/org/apache/sling/pipes/internal/DefaultJsonWriter.java +++ b/src/main/java/org/apache/sling/pipes/internal/JsonWriter.java @@ -19,29 +19,33 @@ package org.apache.sling.pipes.internal; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.SlingHttpServletResponse; import org.apache.sling.api.resource.Resource; -import org.apache.sling.pipes.OutputWriter; +import org.apache.sling.pipes.CustomOutputWriter; import javax.json.Json; +import javax.json.JsonValue; import javax.json.stream.JsonGenerator; import java.io.Writer; +import java.util.Map; /** * default output writer, that outputs JSON with size and output resources' path */ -public class DefaultJsonWriter extends OutputWriter { +public class JsonWriter extends CustomOutputWriter { protected JsonGenerator jsonWriter; - DefaultJsonWriter(){ + public static final String JSON_EXTENSION = "json"; + + JsonWriter(){ } - DefaultJsonWriter(Writer writer){ + JsonWriter(Writer writer){ setWriter(writer); } @Override public boolean handleRequest(SlingHttpServletRequest request) { - return true; + return request.getRequestPathInfo().getExtension().equals(JSON_EXTENSION); } @Override @@ -59,7 +63,21 @@ public class DefaultJsonWriter extends OutputWriter { @Override public void writeItem(Resource resource) { - jsonWriter.write(resource.getPath()); + if (customOutputs == null) { + jsonWriter.write(resource.getPath()); + } else { + jsonWriter.writeStartObject(); + jsonWriter.write(PATH_KEY, resource.getPath()); + for (Map.Entry<String, Object> entry : customOutputs.entrySet()) { + Object o = pipe.getBindings().instantiateObject((String) entry.getValue()); + if (o instanceof JsonValue) { + jsonWriter.write(entry.getKey(), (JsonValue) o); + } else { + jsonWriter.write(entry.getKey(), o.toString()); + } + } + jsonWriter.writeEnd(); + } } @Override @@ -69,4 +87,4 @@ public class DefaultJsonWriter extends OutputWriter { jsonWriter.writeEnd(); jsonWriter.flush(); } -} +} \ No newline at end of file diff --git a/src/main/java/org/apache/sling/pipes/internal/PipeBuilderImpl.java b/src/main/java/org/apache/sling/pipes/internal/PipeBuilderImpl.java index a108b13..68e929f 100644 --- a/src/main/java/org/apache/sling/pipes/internal/PipeBuilderImpl.java +++ b/src/main/java/org/apache/sling/pipes/internal/PipeBuilderImpl.java @@ -24,6 +24,7 @@ import org.apache.sling.api.resource.ResourceUtil; import org.apache.sling.event.jobs.Job; import org.apache.sling.pipes.BasePipe; import org.apache.sling.pipes.ContainerPipe; +import org.apache.sling.pipes.CustomOutputWriter; import org.apache.sling.pipes.ExecutionResult; import org.apache.sling.pipes.Pipe; import org.apache.sling.pipes.PipeBuilder; @@ -335,7 +336,7 @@ public class PipeBuilderImpl implements PipeBuilder { public Pipe build(String path) throws PersistenceException { Resource pipeResource = persistStep(path, NT_SLING_FOLDER, containerStep); if (outputs != null){ - ResourceUtil.getOrCreateResource(resolver, path + "/" + CustomJsonWriter.PARAM_WRITER, outputs, NT_SLING_FOLDER, false); + ResourceUtil.getOrCreateResource(resolver, path + "/" + CustomOutputWriter.PARAM_WRITER, outputs, NT_SLING_FOLDER, false); } int index = 0; for (Step step : steps){ @@ -364,7 +365,7 @@ public class PipeBuilderImpl implements PipeBuilder { @Override public ExecutionResult run(Map bindings) throws Exception { StringWriter stringWriter = new StringWriter(); - DefaultJsonWriter writer = outputs != null ? new CustomJsonWriter(stringWriter) : new DefaultJsonWriter(stringWriter); + JsonWriter writer = new JsonWriter(stringWriter); writer.starts(); Pipe pipe = this.build(); return plumber.execute(resolver, pipe, bindings, writer , true); diff --git a/src/main/java/org/apache/sling/pipes/internal/PlumberServlet.java b/src/main/java/org/apache/sling/pipes/internal/PlumberServlet.java index 22f3fd8..a59ce8f 100644 --- a/src/main/java/org/apache/sling/pipes/internal/PlumberServlet.java +++ b/src/main/java/org/apache/sling/pipes/internal/PlumberServlet.java @@ -54,7 +54,8 @@ import java.util.Map; ServletResolverConstants.SLING_SERVLET_RESOURCE_TYPES + "=" + ChildrenPipe.RESOURCE_TYPE, ServletResolverConstants.SLING_SERVLET_METHODS + "=GET", ServletResolverConstants.SLING_SERVLET_METHODS + "=POST", - ServletResolverConstants.SLING_SERVLET_EXTENSIONS + "=json" + ServletResolverConstants.SLING_SERVLET_EXTENSIONS + "=json", + ServletResolverConstants.SLING_SERVLET_EXTENSIONS + "=csv" }) public class PlumberServlet extends SlingAllMethodsServlet { Logger log = LoggerFactory.getLogger(this.getClass()); @@ -154,7 +155,7 @@ public class PlumberServlet extends SlingAllMethodsServlet { * @throws IOException bad handling of I/O streams, */ OutputWriter getWriter(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException { - OutputWriter[] candidates = new OutputWriter[]{new CustomJsonWriter(), new DefaultJsonWriter()}; + OutputWriter[] candidates = new OutputWriter[]{new CsvWriter(), new JsonWriter()}; for (OutputWriter candidate : candidates) { if (candidate.handleRequest(request)) { candidate.init(request, response); diff --git a/src/test/java/org/apache/sling/pipes/internal/PlumberServletTest.java b/src/test/java/org/apache/sling/pipes/internal/PlumberServletTest.java index 1f9d08f..fa9564e 100644 --- a/src/test/java/org/apache/sling/pipes/internal/PlumberServletTest.java +++ b/src/test/java/org/apache/sling/pipes/internal/PlumberServletTest.java @@ -36,6 +36,7 @@ import javax.servlet.ServletException; import org.apache.commons.lang3.StringUtils; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.SlingHttpServletResponse; +import org.apache.sling.api.request.RequestPathInfo; import org.apache.sling.api.resource.PersistenceException; import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ResourceResolver; @@ -43,6 +44,7 @@ import org.apache.sling.api.resource.ValueMap; import org.apache.sling.pipes.AbstractPipeTest; import org.apache.sling.pipes.BasePipe; import org.apache.sling.pipes.ContainerPipeTest; +import org.apache.sling.pipes.CustomOutputWriter; import org.apache.sling.pipes.OutputWriter; import org.junit.Before; import org.junit.Test; @@ -97,21 +99,21 @@ public class PlumberServletTest extends AbstractPipeTest { @Test public void testDummyTreeThroughRT() throws Exception { - SlingHttpServletRequest request = mockPlumberServletRequest(context.resourceResolver(), dummyTreePath, null, null, null, null, null); + SlingHttpServletRequest request = mockPlumberServletRequest(context.resourceResolver(), "json", dummyTreePath, null, null, null, null, null); servlet.execute(request, response, false); assertDummyTree(); } @Test public void testDummyTreeThroughPlumber() throws Exception { - SlingHttpServletRequest request = mockPlumberServletRequest(context.resourceResolver(), PATH_PIPE, dummyTreePath, null, null, null, null); + SlingHttpServletRequest request = mockPlumberServletRequest(context.resourceResolver(), "json", PATH_PIPE, dummyTreePath, null, null, null, null); servlet.execute(request, response, false); assertDummyTree(); } @Test public void testWriteExecute() throws ServletException { - SlingHttpServletRequest request = mockPlumberServletRequest(context.resourceResolver(), pipedWritePath, null, null, null, null, null); + SlingHttpServletRequest request = mockPlumberServletRequest(context.resourceResolver(), "json", pipedWritePath, null, null, null, null, null); servlet.execute(request, response, true); String finalResponse = stringResponse.toString(); assertFalse("There should be a response", StringUtils.isBlank(finalResponse)); @@ -124,7 +126,7 @@ public class PlumberServletTest extends AbstractPipeTest { */ @Test public void testGetOnWriteExecute() throws ServletException { - SlingHttpServletRequest request = mockPlumberServletRequest(context.resourceResolver(), pipedWritePath, null, null, null, null, null); + SlingHttpServletRequest request = mockPlumberServletRequest(context.resourceResolver(), "json", pipedWritePath, null, null, null, null, null); boolean hasFailed = true; try { servlet.execute(request, response, false); @@ -144,7 +146,7 @@ public class PlumberServletTest extends AbstractPipeTest { String bindings = "{\"" + testBinding + "\":\"" + bindingValue + "\"}"; String respObject = "{\"" + pathLengthParam + "\":\"${path.get(\\\"dummyGrandChild\\\").length}\",\"" + testBindingLength + "\":\"${" + testBinding + ".length}\"}"; SlingHttpServletRequest request = - mockPlumberServletRequest(context.resourceResolver(), dummyTreePath, null, bindings.toString(), respObject.toString(), null, null); + mockPlumberServletRequest(context.resourceResolver(), "json", dummyTreePath, null, bindings.toString(), respObject.toString(), null, null); servlet.execute(request, response, false); assertDummyTree(); JsonObject response = Json.createReader(new StringReader(stringResponse.toString())).readObject(); @@ -152,7 +154,7 @@ public class PlumberServletTest extends AbstractPipeTest { for (int i = 0; i < array.size(); i++) { JsonObject object = array.getJsonObject(i); assertNotNull("there should be an object returned at each time", object); - String path = object.getString(CustomJsonWriter.PATH_KEY); + String path = object.getString(CustomOutputWriter.PATH_KEY); assertNotNull("the string path should be returned for each item, containing the path of the resource"); String pathLength = object.getString(pathLengthParam); assertNotNull("there should be a pathLength param, as specified in the writer", pathLength); @@ -167,32 +169,33 @@ public class PlumberServletTest extends AbstractPipeTest { @Test public void testDryRun() throws Exception { SlingHttpServletRequest dryRunRequest = - mockPlumberServletRequest(context.resourceResolver(), pipedWritePath, null, null, null, "true", null); + mockPlumberServletRequest(context.resourceResolver(), "json", pipedWritePath, null, null, null, "true", null); servlet.execute(dryRunRequest, response, true); Resource resource = context.resourceResolver().getResource("/content/fruits"); ValueMap properties = resource.adaptTo(ValueMap.class); assertFalse("property fruits shouldn't have been written", properties.containsKey("fruits")); SlingHttpServletRequest request = - mockPlumberServletRequest(context.resourceResolver(), pipedWritePath, null, null, null, "false", null); + mockPlumberServletRequest(context.resourceResolver(), "json", pipedWritePath, null, null, null, "false", null); servlet.execute(request, response, true); WritePipeTest.assertPiped(resource); } @Test public void testDummyTreeSizeLimit() throws Exception { - SlingHttpServletRequest request = mockPlumberServletRequest(context.resourceResolver(), dummyTreePath, null, null, null, null, "2"); + SlingHttpServletRequest request = mockPlumberServletRequest(context.resourceResolver(), "json", dummyTreePath, null, null, null, null, "2"); servlet.execute(request, response, false); assertDummyTree(2); } @Test public void testDummyTreeInfiniteSize() throws Exception { - SlingHttpServletRequest request = mockPlumberServletRequest(context.resourceResolver(), dummyTreePath, null, null, null, null, "-1"); + SlingHttpServletRequest request = mockPlumberServletRequest(context.resourceResolver(), "json", dummyTreePath, null, null, null, null, "-1"); servlet.execute(request, response, false); assertDummyTree(DUMMYTREE_TEST_SIZE); } public static SlingHttpServletRequest mockPlumberServletRequest(ResourceResolver resolver, + String extension, String path, String pathParam, String bindings, @@ -200,12 +203,15 @@ public class PlumberServletTest extends AbstractPipeTest { String dryRun, String size) { SlingHttpServletRequest request = mock(SlingHttpServletRequest.class); + RequestPathInfo pathInfo = mock(RequestPathInfo.class); + when(pathInfo.getExtension()).thenReturn(extension); + when(request.getRequestPathInfo()).thenReturn(pathInfo); Resource resource = resolver.getResource(path); when(request.getResourceResolver()).thenReturn(resolver); when(request.getResource()).thenReturn(resource); when(request.getParameter(PlumberServlet.PARAM_PATH)).thenReturn(pathParam); when(request.getParameter(PlumberServlet.PARAM_BINDINGS)).thenReturn(bindings); - when(request.getParameter(CustomJsonWriter.PARAM_WRITER)).thenReturn(writer); + when(request.getParameter(CustomOutputWriter.PARAM_WRITER)).thenReturn(writer); when(request.getParameter(BasePipe.DRYRUN_KEY)).thenReturn(dryRun); when(request.getParameter(OutputWriter.PARAM_SIZE)).thenReturn(size); return request; diff --git a/src/test/java/org/apache/sling/pipes/it/PlumberServletIT.java b/src/test/java/org/apache/sling/pipes/it/PlumberServletIT.java index 5ceb269..46b1fec 100644 --- a/src/test/java/org/apache/sling/pipes/it/PlumberServletIT.java +++ b/src/test/java/org/apache/sling/pipes/it/PlumberServletIT.java @@ -17,7 +17,7 @@ package org.apache.sling.pipes.it; import org.apache.commons.io.IOUtils; -import org.apache.sling.pipes.internal.DefaultJsonWriter; +import org.apache.sling.pipes.internal.JsonWriter; import org.apache.sling.pipes.internal.JsonUtil; import org.junit.Ignore; import org.junit.Test; @@ -44,7 +44,7 @@ public class PlumberServletIT extends PipesTestSupport { @Test @Ignore - public void testListComponent() throws IOException { + public void testListComponentJson() throws IOException { final String urlString = String.format("http://localhost:%s/etc/pipes-it/another-list.json", httpPort()); LOGGER.info("fetching {}", urlString); URL url = new URL(urlString); @@ -53,9 +53,10 @@ public class PlumberServletIT extends PipesTestSupport { String response = writer.toString(); LOGGER.info("retrieved following response {}", response); JsonObject main = JsonUtil.parseObject(response); - assertTrue("there should be an items key", main.containsKey(DefaultJsonWriter.KEY_ITEMS)); - assertTrue("there should be a size key", main.containsKey(DefaultJsonWriter.KEY_SIZE)); - assertEquals("there should be 2 elements", 2, main.getInt(DefaultJsonWriter.KEY_SIZE)); + assertTrue("there should be an items key", main.containsKey(JsonWriter.KEY_ITEMS)); + assertTrue("there should be a size key", main.containsKey(JsonWriter.KEY_SIZE)); + assertEquals("there should be 2 elements", 2, main.getInt(JsonWriter.KEY_SIZE)); } + } -- To stop receiving notification emails like this one, please contact ['"commits@sling.apache.org" <commits@sling.apache.org>'].