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/22 15:38:50 UTC
[sling-org-apache-sling-pipes] 01/01: SLING-7251 fixing olli's
comments
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 8e5a5f092765a86314bd8e51dc992e4c5c2018d8
Author: Nicolas Peltier <pe...@gmail.com>
AuthorDate: Mon Jan 22 16:36:58 2018 +0100
SLING-7251 fixing olli's comments
- use class for parsing json,
- added more detailed ACLs
---
.../apache/sling/pipes/it/PipesTestSupport.java | 6 +++++-
.../apache/sling/pipes/it/PlumberServletIT.java | 23 +++++++++++++---------
2 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/src/test/java/org/apache/sling/pipes/it/PipesTestSupport.java b/src/test/java/org/apache/sling/pipes/it/PipesTestSupport.java
index 5b69c5d..52cd271 100644
--- a/src/test/java/org/apache/sling/pipes/it/PipesTestSupport.java
+++ b/src/test/java/org/apache/sling/pipes/it/PipesTestSupport.java
@@ -79,7 +79,11 @@ public abstract class PipesTestSupport extends TestSupport {
.put("path", "/etc/pipes-it")
.asOption(),
factoryConfiguration("org.apache.sling.jcr.repoinit.RepositoryInitializer")
- .put("scripts", new String[]{"create service user sling-pipes\n\n set ACL for sling-pipes\n\n allow jcr:all on /\n\n end"})
+ .put("scripts", new String[]{"create service user sling-pipes\n\n set ACL for sling-pipes\n\n" +
+ " allow jcr:all on /content" +
+ "\n\n allow jcr:all on /var" +
+ "\n\n allow jcr:read on /" +
+ "\n\n end"})
.asOption(),
factoryConfiguration("org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.amended")
.put("user.mapping", new String[]{"org.apache.sling.pipes=sling-pipes"})
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 9fc8e83..28d696a 100644
--- a/src/test/java/org/apache/sling/pipes/it/PlumberServletIT.java
+++ b/src/test/java/org/apache/sling/pipes/it/PlumberServletIT.java
@@ -17,10 +17,10 @@
package org.apache.sling.pipes.it;
import java.io.IOException;
-import java.util.HashMap;
+import java.util.ArrayList;
import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
+import com.google.gson.reflect.TypeToken;
import org.jsoup.Jsoup;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -30,28 +30,33 @@ import org.ops4j.pax.exam.spi.reactors.PerClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
@RunWith(PaxExam.class)
@ExamReactorStrategy(PerClass.class)
public class PlumberServletIT extends PipesTestSupport {
- private final GsonBuilder gsonBuilder = new GsonBuilder();
private static final Logger LOGGER = LoggerFactory.getLogger(PlumberServletIT.class);
+ /**
+ * Java type for parsing the json
+ */
+ class ExpectedResponse {
+ int size;
+ ArrayList<String> items;
+ }
+
@Test
public void testListComponentJson() throws IOException {
final String url = String.format("http://localhost:%s/etc/pipes-it/another-list.json", httpPort());
LOGGER.info("fetching {}", url);
final String response = Jsoup.connect(url).header("Authorization", basicAuthorizationHeader(ADMIN_CREDENTIALS)).ignoreContentType(true).execute().body();
LOGGER.info("retrieved following response {}", response);
- final Gson gson = gsonBuilder.create();
- final HashMap main = gson.fromJson(response, HashMap.class);
- assertTrue("there should be an items key", main.containsKey("items"));
- assertTrue("there should be a size key", main.containsKey("size"));
- assertEquals("there should be 2 elements", 2, ((Double) main.get("size")).intValue());
+ final ExpectedResponse json = (new Gson()).fromJson(response, new TypeToken<ExpectedResponse>(){}.getType());
+ assertEquals("there should be 2 elements", 2, json.size);
+ assertArrayEquals("should be fruits array", new String[] {"/content/fruits/apple", "/content/fruits/banana"}, json.items.toArray());
}
}
--
To stop receiving notification emails like this one, please contact
npeltier@apache.org.