You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ss...@apache.org on 2017/03/02 17:34:32 UTC
svn commit: r1785169 - in /sling/trunk/bundles/extensions/fsresource: ./
src/main/java/org/apache/sling/fsprovider/internal/
src/main/java/org/apache/sling/fsprovider/internal/mapper/
src/main/java/org/apache/sling/fsprovider/internal/parser/ src/test/...
Author: sseifert
Date: Thu Mar 2 17:34:31 2017
New Revision: 1785169
URL: http://svn.apache.org/viewvc?rev=1785169&view=rev
Log:
SLING-6440 switch to fscontentparser
rename "Filesystem" to "File System"
update to latest parent
Added:
sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtil.java (with props)
sling/trunk/bundles/extensions/fsresource/src/test/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtilTest.java (with props)
Removed:
sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParser.java
sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/parser/JcrXmlFileParser.java
sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/parser/JcrXmlValueConverter.java
sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/parser/JsonFileParser.java
sling/trunk/bundles/extensions/fsresource/src/test/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserTest.java
sling/trunk/bundles/extensions/fsresource/src/test/java/org/apache/sling/fsprovider/internal/parser/JcrXmlFileParserTest.java
sling/trunk/bundles/extensions/fsresource/src/test/java/org/apache/sling/fsprovider/internal/parser/JcrXmlValueConverterTest.java
Modified:
sling/trunk/bundles/extensions/fsresource/pom.xml
sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java
sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileResource.java
sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/mapper/ValueMapUtil.java
sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileCache.java
sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileTypes.java
sling/trunk/bundles/extensions/fsresource/src/test/java/org/apache/sling/fsprovider/internal/JcrXmlContentTest.java
sling/trunk/bundles/extensions/fsresource/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java
Modified: sling/trunk/bundles/extensions/fsresource/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/fsresource/pom.xml?rev=1785169&r1=1785168&r2=1785169&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/fsresource/pom.xml (original)
+++ sling/trunk/bundles/extensions/fsresource/pom.xml Thu Mar 2 17:34:31 2017
@@ -22,7 +22,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>29</version>
+ <version>30-SNAPSHOT</version>
<relativePath />
</parent>
@@ -30,10 +30,9 @@
<packaging>bundle</packaging>
<version>1.2.3-SNAPSHOT</version>
- <name>Apache Sling Filesystem Resource Provider</name>
+ <name>Apache Sling File System Resource Provider</name>
<description>
- Provides a ResourceProvider implementation supporting filesystem
- based resources.
+ Provides a ResourceProvider implementation supporting file system based resources.
</description>
<scm>
@@ -61,33 +60,14 @@
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
- <executions>
- <!-- Configure extra execution of 'manifest' in process-classes phase to make sure SCR metadata is generated before unit test runs -->
- <execution>
- <id>scr-metadata</id>
- <goals>
- <goal>manifest</goal>
- </goals>
- <configuration>
- <supportIncrementalBuild>true</supportIncrementalBuild>
- </configuration>
- </execution>
- </executions>
<configuration>
- <!-- Export SCR metadata to classpath to have them available in unit tests -->
- <exportScr>true</exportScr>
<instructions>
- <!-- Embed Apache Johnzon -->
+ <!-- Embed Apache Johnzon and fscontentparser -->
<Embed-Dependency>
johnzon-core;scope=compile;inline=false,
- geronimo-json_1.0_spec;scope=compile;inline=false
+ geronimo-json_1.0_spec;scope=compile;inline=false,
+ org.apache.sling.fscontentparser;scope=compile;inline=false
</Embed-Dependency>
- <!-- Embed the nessecary parts of the jackrabbit-jcr-commons bundle as described in http://njbartlett.name/2014/05/26/static-linking.html -->
- <Conditional-Package>org.apache.jackrabbit.util</Conditional-Package>
- <Import-Package>
- !org.apache.jackrabbit.*,
- *
- </Import-Package>
</instructions>
</configuration>
</plugin>
@@ -152,18 +132,18 @@
<scope>compile</scope>
</dependency>
<dependency>
- <groupId>org.apache.jackrabbit</groupId>
- <artifactId>jackrabbit-jcr-commons</artifactId>
- <version>2.8.0</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
<groupId>org.apache.sling</groupId>
<artifactId>adapter-annotations</artifactId>
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.fscontentparser</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
Modified: sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java?rev=1785169&r1=1785168&r2=1785169&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java (original)
+++ sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java Thu Mar 2 17:34:31 2017
@@ -63,7 +63,7 @@ import org.osgi.service.metatype.annotat
service=ResourceProvider.class,
configurationPolicy=ConfigurationPolicy.REQUIRE,
property={
- Constants.SERVICE_DESCRIPTION + "=Sling Filesystem Resource Provider",
+ Constants.SERVICE_DESCRIPTION + "=Sling File System Resource Provider",
Constants.SERVICE_VENDOR + "=The Apache Software Foundation"
})
@Designate(ocd=FsResourceProvider.Config.class, factory=true)
@@ -74,7 +74,7 @@ public final class FsResourceProvider ex
*/
public static final String RESOURCE_METADATA_FILE_DIRECTORY = ":org.apache.sling.fsprovider.file.directory";
- @ObjectClassDefinition(name = "Apache Sling Filesystem Resource Provider",
+ @ObjectClassDefinition(name = "Apache Sling File System Resource Provider",
description = "Configure an instance of the filesystem " +
"resource provider in terms of provider root and filesystem location")
public @interface Config {
@@ -83,8 +83,8 @@ public final class FsResourceProvider ex
* files and folders mapped into the resource tree (value is
* "provider.file").
*/
- @AttributeDefinition(name = "Filesystem Root",
- description = "Filesystem directory mapped to the virtual " +
+ @AttributeDefinition(name = "File System Root",
+ description = "File system directory mapped to the virtual " +
"resource tree. This property must not be an empty string. If the path is " +
"relative it is resolved against sling.home or the current working directory. " +
"The path may be a file or folder. If the path does not address an existing " +
Modified: sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileResource.java?rev=1785169&r1=1785168&r2=1785169&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileResource.java (original)
+++ sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileResource.java Thu Mar 2 17:34:31 2017
@@ -82,7 +82,7 @@ public final class FileResource extends
private static final Logger log = LoggerFactory.getLogger(FileResource.class);
/**
- * Creates an instance of this Filesystem resource.
+ * Creates an instance of this File system resource.
*
* @param resolver The owning resource resolver
* @param resourcePath The resource path in the resource tree
Modified: sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/mapper/ValueMapUtil.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/mapper/ValueMapUtil.java?rev=1785169&r1=1785168&r2=1785169&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/mapper/ValueMapUtil.java (original)
+++ sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/mapper/ValueMapUtil.java Thu Mar 2 17:34:31 2017
@@ -22,8 +22,6 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
-import javax.jcr.nodetype.NodeType;
-
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.wrappers.ValueMapDecorator;
@@ -55,11 +53,6 @@ final class ValueMapUtil {
}
}
- // fallback to default jcr:primaryType is none is set
- if (!props.containsKey("jcr:primaryType")) {
- props.put("jcr:primaryType", NodeType.NT_UNSTRUCTURED);
- }
-
return new ValueMapDecorator(props);
}
Modified: sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileCache.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileCache.java?rev=1785169&r1=1785168&r2=1785169&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileCache.java (original)
+++ sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileCache.java Thu Mar 2 17:34:31 2017
@@ -57,7 +57,7 @@ public final class ContentFileCache {
content = contentCache.get(path);
}
if (content == null) {
- content = ContentFileParser.parse(file);
+ content = ContentFileParserUtil.parse(file);
if (content == null) {
content = NULL_MAP;
}
Added: sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtil.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtil.java?rev=1785169&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtil.java (added)
+++ sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtil.java Thu Mar 2 17:34:31 2017
@@ -0,0 +1,79 @@
+/*
+ * 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.fsprovider.internal.parser;
+
+import static org.apache.sling.fsprovider.internal.parser.ContentFileTypes.JCR_XML_SUFFIX;
+import static org.apache.sling.fsprovider.internal.parser.ContentFileTypes.JSON_SUFFIX;
+
+import java.io.File;
+import java.util.Map;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.sling.fscontentparser.ContentFileExtension;
+import org.apache.sling.fscontentparser.ContentFileParser;
+import org.apache.sling.fscontentparser.ContentFileParserFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Parses files that contains content fragments (e.g. JSON, JCR XML).
+ */
+class ContentFileParserUtil {
+
+ private static final Logger log = LoggerFactory.getLogger(ContentFileParserUtil.class);
+
+ private static final ContentFileParser JSON_PARSER;
+ static {
+ // workaround for JsonProvider classloader issue until https://issues.apache.org/jira/browse/GERONIMO-6560 is fixed
+ ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(ContentFileParserUtil.class.getClassLoader());
+ JSON_PARSER = ContentFileParserFactory.create(ContentFileExtension.JSON);
+ }
+ finally {
+ Thread.currentThread().setContextClassLoader(oldClassLoader);
+ }
+ }
+ private static final ContentFileParser JCR_XML_PARSER = ContentFileParserFactory.create(ContentFileExtension.JCR_XML);
+
+ private ContentFileParserUtil() {
+ // static methods only
+ }
+
+ /**
+ * Parse content from file.
+ * @param file File. Type is detected automatically.
+ * @return Content or null if content could not be parsed.
+ */
+ public static Map<String,Object> parse(File file) {
+ try {
+ if (StringUtils.endsWith(file.getName(), JSON_SUFFIX)) {
+ return JSON_PARSER.parse(file);
+ }
+ else if (StringUtils.endsWith(file.getName(), JCR_XML_SUFFIX)) {
+ return JCR_XML_PARSER.parse(file);
+ }
+ }
+ catch (Throwable ex) {
+ log.warn("Error parsing content from " + file.getPath(), ex);
+ }
+ return null;
+ }
+
+}
Propchange: sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtil.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtil.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Thu Mar 2 17:34:31 2017
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author
Propchange: sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtil.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileTypes.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileTypes.java?rev=1785169&r1=1785168&r2=1785169&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileTypes.java (original)
+++ sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileTypes.java Thu Mar 2 17:34:31 2017
@@ -18,6 +18,8 @@
*/
package org.apache.sling.fsprovider.internal.parser;
+import org.apache.sling.fscontentparser.ContentFileExtension;
+
/**
* Content file types.
*/
@@ -26,12 +28,12 @@ public final class ContentFileTypes {
/**
* JSON content files.
*/
- public static final String JSON_SUFFIX = ".json";
+ public static final String JSON_SUFFIX = "." + ContentFileExtension.JSON;
/**
* JCR XML content files.
*/
- public static final String JCR_XML_SUFFIX = ".jcr.xml";
+ public static final String JCR_XML_SUFFIX = "." + ContentFileExtension.JCR_XML;
private ContentFileTypes() {
// static methods only
Modified: sling/trunk/bundles/extensions/fsresource/src/test/java/org/apache/sling/fsprovider/internal/JcrXmlContentTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/fsresource/src/test/java/org/apache/sling/fsprovider/internal/JcrXmlContentTest.java?rev=1785169&r1=1785168&r2=1785169&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/fsresource/src/test/java/org/apache/sling/fsprovider/internal/JcrXmlContentTest.java (original)
+++ sling/trunk/bundles/extensions/fsresource/src/test/java/org/apache/sling/fsprovider/internal/JcrXmlContentTest.java Thu Mar 2 17:34:31 2017
@@ -90,7 +90,7 @@ public class JcrXmlContentTest {
}
@Test
- public void testJsonContent_Root() {
+ public void testContent_Root() {
Resource underTest = fsroot.getChild("folder3/content");
assertNotNull(underTest);
assertEquals("app:Page", underTest.getValueMap().get("jcr:primaryType", String.class));
@@ -99,7 +99,7 @@ public class JcrXmlContentTest {
}
@Test
- public void testJsonContent_Level1() {
+ public void testContent_Level1() {
Resource underTest = fsroot.getChild("folder3/content/jcr:content");
assertNotNull(underTest);
assertEquals("app:PageContent", underTest.getValueMap().get("jcr:primaryType", String.class));
@@ -108,7 +108,7 @@ public class JcrXmlContentTest {
}
@Test
- public void testJsonContent_Level3() {
+ public void testContent_Level3() {
Resource underTest = fsroot.getChild("folder3/content/jcr:content/content/contentheadline");
assertNotNull(underTest);
assertEquals("nt:unstructured", underTest.getValueMap().get("jcr:primaryType", String.class));
@@ -117,7 +117,7 @@ public class JcrXmlContentTest {
}
@Test
- public void testJsonContent_Datatypes() {
+ public void testContent_Datatypes() {
Resource underTest = fsroot.getChild("folder3/content/jcr:content");
ValueMap props = underTest.getValueMap();
@@ -131,7 +131,7 @@ public class JcrXmlContentTest {
}
@Test
- public void testJsonContent_InvalidPath() {
+ public void testContent_InvalidPath() {
Resource underTest = fsroot.getChild("folder2/content/jcr:content/xyz");
assertNull(underTest);
}
Modified: sling/trunk/bundles/extensions/fsresource/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/fsresource/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java?rev=1785169&r1=1785168&r2=1785169&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/fsresource/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java (original)
+++ sling/trunk/bundles/extensions/fsresource/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java Thu Mar 2 17:34:31 2017
@@ -42,6 +42,7 @@ import javax.jcr.nodetype.NodeType;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.fscontentparser.ParserOptions;
import org.apache.sling.fsprovider.internal.TestUtils.RegisterFsResourcePlugin;
import org.apache.sling.hamcrest.ResourceMatchers;
import org.apache.sling.testing.mock.sling.ResourceResolverType;
@@ -99,7 +100,7 @@ public class JsonContentTest {
}
@Test
- public void testJsonContent_Root() {
+ public void testContent_Root() {
Resource underTest = fsroot.getChild("folder2/content");
assertNotNull(underTest);
assertEquals("app:Page", underTest.getValueMap().get("jcr:primaryType", String.class));
@@ -108,7 +109,7 @@ public class JsonContentTest {
}
@Test
- public void testJsonContent_Level1() {
+ public void testContent_Level1() {
Resource underTest = fsroot.getChild("folder2/content/jcr:content");
assertNotNull(underTest);
assertEquals("app:PageContent", underTest.getValueMap().get("jcr:primaryType", String.class));
@@ -118,7 +119,7 @@ public class JsonContentTest {
}
@Test
- public void testJsonContent_Level5() {
+ public void testContent_Level5() {
Resource underTest = fsroot.getChild("folder2/content/jcr:content/par/image/file/jcr:content");
assertNotNull(underTest);
assertEquals("nt:resource", underTest.getValueMap().get("jcr:primaryType", String.class));
@@ -126,7 +127,7 @@ public class JsonContentTest {
}
@Test
- public void testJsonContent_Datatypes() {
+ public void testContent_Datatypes() {
Resource underTest = fsroot.getChild("folder2/content/toolbar/profiles/jcr:content");
ValueMap props = underTest.getValueMap();
@@ -140,7 +141,7 @@ public class JsonContentTest {
}
@Test
- public void testJsonContent_Datatypes_JCR() throws RepositoryException {
+ public void testContent_Datatypes_JCR() throws RepositoryException {
Resource underTest = fsroot.getChild("folder2/content/toolbar/profiles/jcr:content");
ValueMap props = underTest.getValueMap();
Node node = underTest.adaptTo(Node.class);
@@ -218,11 +219,11 @@ public class JsonContentTest {
@Test
public void testFallbackNodeType() throws RepositoryException {
Resource underTest = fsroot.getChild("folder2/content/jcr:content/par/title_2");
- assertEquals(NodeType.NT_UNSTRUCTURED, underTest.adaptTo(Node.class).getPrimaryNodeType().getName());
+ assertEquals(ParserOptions.DEFAULT_PRIMARY_TYPE, underTest.adaptTo(Node.class).getPrimaryNodeType().getName());
}
@Test
- public void testJsonContent_InvalidPath() {
+ public void testContent_InvalidPath() {
Resource underTest = fsroot.getChild("folder2/content/jcr:content/xyz");
assertNull(underTest);
}
Added: sling/trunk/bundles/extensions/fsresource/src/test/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtilTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/fsresource/src/test/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtilTest.java?rev=1785169&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/fsresource/src/test/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtilTest.java (added)
+++ sling/trunk/bundles/extensions/fsresource/src/test/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtilTest.java Thu Mar 2 17:34:31 2017
@@ -0,0 +1,66 @@
+/*
+ * 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.fsprovider.internal.parser;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.io.File;
+import java.util.Map;
+
+import org.junit.Test;
+
+public class ContentFileParserUtilTest {
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testParseJson() {
+ File file = new File("src/test/resources/fs-test/folder2/content.json");
+ Map<String,Object> content = ContentFileParserUtil.parse(file);
+ assertNotNull(content);
+ assertEquals("app:Page", content.get("jcr:primaryType"));
+ assertEquals("app:PageContent", ((Map<String,Object>)content.get("jcr:content")).get("jcr:primaryType"));
+ }
+
+ @Test
+ public void testParseInvalidJson() {
+ File file = new File("src/test/resources/invalid-test/invalid.json");
+ Map<String,Object> content = ContentFileParserUtil.parse(file);
+ assertNull(content);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testParseJcrXml() {
+ File file = new File("src/test/resources/fs-test/folder3/content.jcr.xml");
+ Map<String,Object> content = ContentFileParserUtil.parse(file);
+ assertNotNull(content);
+ assertEquals("app:Page", content.get("jcr:primaryType"));
+ assertEquals("app:PageContent", ((Map<String,Object>)content.get("jcr:content")).get("jcr:primaryType"));
+ }
+
+ @Test
+ public void testParseInvalidJcrXml() {
+ File file = new File("src/test/resources/invalid-test/invalid.jcr.xml");
+ Map<String,Object> content = ContentFileParserUtil.parse(file);
+ assertNull(content);
+ }
+
+}
Propchange: sling/trunk/bundles/extensions/fsresource/src/test/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtilTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/bundles/extensions/fsresource/src/test/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtilTest.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Thu Mar 2 17:34:31 2017
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author
Propchange: sling/trunk/bundles/extensions/fsresource/src/test/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtilTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain