You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ra...@apache.org on 2019/07/22 09:50:46 UTC

[sling-org-apache-sling-contentparser-xml] 02/06: SLING-8570 - Extract a generic Content Parser API from org.apache.sling.jcr.contentparser with pluggable implementations

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

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

commit 7179289cfce7392f09bdb7f61f9208fb64bb18a6
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Mon Jul 15 12:02:03 2019 +0200

    SLING-8570 - Extract a generic Content Parser API from org.apache.sling.jcr.contentparser with pluggable implementations
    
    * added parser for JCR-flavoured XML
    * made the ParserHelper compatible with both Java 8 and Java 11
    * reduced the number of dependencies for all modules
---
 pom.xml                                            | 27 ----------
 .../xml/internal/XmlContentParserTest.java         | 62 ++++++++++++----------
 2 files changed, 34 insertions(+), 55 deletions(-)

diff --git a/pom.xml b/pom.xml
index d2063ac..b9a0237 100644
--- a/pom.xml
+++ b/pom.xml
@@ -50,12 +50,6 @@
             <scope>provided</scope>
         </dependency>
         <dependency>
-            <groupId>commons-io</groupId>
-            <artifactId>commons-io</artifactId>
-            <version>2.6</version>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
             <groupId>org.apache.commons</groupId>
             <artifactId>commons-lang3</artifactId>
             <version>3.8</version>
@@ -67,21 +61,6 @@
             <scope>provided</scope>
         </dependency>
         <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.service.component</artifactId>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.framework</artifactId>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.slf4j</groupId>
-            <artifactId>slf4j-api</artifactId>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.contentparser.testutils</artifactId>
             <version>0.9.0-SNAPSHOT</version>
@@ -92,11 +71,5 @@
             <artifactId>junit</artifactId>
             <scope>test</scope>
         </dependency>
-        <dependency>
-            <groupId>com.google.guava</groupId>
-            <artifactId>guava</artifactId>
-            <version>15.0</version>
-            <scope>test</scope>
-        </dependency>
     </dependencies>
 </project>
diff --git a/src/test/java/org/apache/sling/contentparser/xml/internal/XmlContentParserTest.java b/src/test/java/org/apache/sling/contentparser/xml/internal/XmlContentParserTest.java
index 111ac73..5da18c3 100644
--- a/src/test/java/org/apache/sling/contentparser/xml/internal/XmlContentParserTest.java
+++ b/src/test/java/org/apache/sling/contentparser/xml/internal/XmlContentParserTest.java
@@ -20,20 +20,21 @@ package org.apache.sling.contentparser.xml.internal;
 
 import java.io.File;
 import java.math.BigDecimal;
+import java.util.Arrays;
 import java.util.Calendar;
+import java.util.Collections;
+import java.util.HashSet;
 import java.util.Map;
 import java.util.TimeZone;
 
 import org.apache.sling.contentparser.api.ContentParser;
 import org.apache.sling.contentparser.api.ParseException;
 import org.apache.sling.contentparser.api.ParserOptions;
+import org.apache.sling.contentparser.testutils.TestUtils;
 import org.apache.sling.contentparser.testutils.mapsupport.ContentElement;
 import org.junit.Before;
 import org.junit.Test;
 
-import com.google.common.collect.ImmutableSet;
-
-import static org.apache.sling.contentparser.testutils.TestUtils.parse;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
@@ -52,16 +53,17 @@ public class XmlContentParserTest {
 
     @Test
     public void testPageJcrPrimaryType() throws Exception {
-        ContentElement content = parse(underTest, file);
+        ContentElement content = TestUtils.parse(underTest, file);
 
         assertEquals("app:Page", content.getProperties().get("jcr:primaryType"));
     }
 
     @Test
     public void testDataTypes() throws Exception {
-        ContentElement content = parse(underTest, file);
-
-        Map<String, Object> props = content.getChild("toolbar/profiles/jcr:content").getProperties();
+        ContentElement content = TestUtils.parse(underTest, file);
+        ContentElement child = content.getChild("toolbar/profiles/jcr:content");
+        assertNotNull("Expected child at path toolbar/profiles/jcr:content", child);
+        Map<String, Object> props = child.getProperties();
         assertEquals(true, props.get("hideInNav"));
 
         assertEquals(1234567890123L, props.get("longProp"));
@@ -75,17 +77,19 @@ public class XmlContentParserTest {
 
     @Test
     public void testContentProperties() throws Exception {
-        ContentElement content = parse(underTest, file);
-
-        Map<String, Object> props = content.getChild("jcr:content/header").getProperties();
+        ContentElement content = TestUtils.parse(underTest, file);
+        ContentElement child = content.getChild("jcr:content/header");
+        assertNotNull("Expected child at jcr:content/header", child);
+        Map<String, Object> props = child.getProperties();
         assertEquals("/content/dam/sample/header.png", props.get("imageReference"));
     }
 
     @Test
     public void testCalendar() throws Exception {
-        ContentElement content = parse(underTest, new ParserOptions().detectCalendarValues(true), file);
-
-        Map<String, Object> props = content.getChild("jcr:content").getProperties();
+        ContentElement content = TestUtils.parse(underTest, new ParserOptions().detectCalendarValues(true), file);
+        ContentElement child = content.getChild("jcr:content");
+        assertNotNull("Expected child at jcr:content", child);
+        Map<String, Object> props = child.getProperties();
 
         Calendar calendar = (Calendar) props.get("app:lastModified");
         assertNotNull(calendar);
@@ -103,11 +107,10 @@ public class XmlContentParserTest {
 
     @Test
     public void testUTF8Chars() throws Exception {
-
-        ContentElement content = parse(underTest, file);
-
-        Map<String, Object> props = content.getChild("jcr:content").getProperties();
-
+        ContentElement content = TestUtils.parse(underTest, file);
+        ContentElement child = content.getChild("jcr:content");
+        assertNotNull("Expected child at jcr:content", child);
+        Map<String, Object> props = child.getProperties();
         assertEquals("äöü߀", props.get("utf8Property"));
     }
 
@@ -115,7 +118,7 @@ public class XmlContentParserTest {
     public void testParseInvalidJson() throws Exception {
         file = new File("src/test/resources/invalid-test/invalid.json");
 
-        ContentElement content = parse(underTest, file);
+        ContentElement content = TestUtils.parse(underTest, file);
         assertNull(content);
     }
 
@@ -123,34 +126,37 @@ public class XmlContentParserTest {
     public void testParseInvalidJsonWithObjectList() throws Exception {
         file = new File("src/test/resources/invalid-test/contentWithObjectList.json");
 
-        ContentElement content = parse(underTest, file);
+        ContentElement content = TestUtils.parse(underTest, file);
         assertNull(content);
     }
 
     @Test
     public void testIgnoreResourcesProperties() throws Exception {
-        ContentElement content = parse(underTest,  new ParserOptions().ignoreResourceNames(ImmutableSet.of("header", "newslist"))
-                .ignorePropertyNames(ImmutableSet.of("jcr:title")), file);
+        ContentElement content = TestUtils.parse(underTest,
+                new ParserOptions().ignoreResourceNames(Collections.unmodifiableSet(new HashSet<>(Arrays.asList("header", "newslist"))))
+                        .ignorePropertyNames(Collections.unmodifiableSet(new HashSet<>(Arrays.asList("jcr:title")))), file);
         ContentElement child = content.getChild("jcr:content");
+        assertNotNull("Expected child at jcr:content", child);
+        Map<String, Object> props = child.getProperties();
 
-        assertEquals("Sample Homepage", child.getProperties().get("pageTitle"));
-        assertNull(child.getProperties().get("jcr:title"));
+        assertEquals("Sample Homepage", props.get("pageTitle"));
+        assertEquals("abc", props.get("refpro1"));
+        assertEquals("def", props.get("pathprop1"));
+        assertNull(props.get("jcr:title"));
 
         assertNull(child.getChildren().get("header"));
         assertNull(child.getChildren().get("newslist"));
         assertNotNull(child.getChildren().get("lead"));
-
-        assertEquals("abc", child.getProperties().get("refpro1"));
-        assertEquals("def", child.getProperties().get("pathprop1"));
     }
 
     @Test
     public void testGetChild() throws Exception {
 
-        ContentElement content = parse(underTest, file);
+        ContentElement content = TestUtils.parse(underTest, file);
         assertNull(content.getName());
 
         ContentElement deepChild = content.getChild("jcr:content/par/image/file/jcr:content");
+        assertNotNull("Expected a child at path jcr:content/par/image/file/jcr:content", deepChild);
         assertEquals("jcr:content", deepChild.getName());
         assertEquals("nt:resource", deepChild.getProperties().get("jcr:primaryType"));