Author: bdelacretaz
Date: Mon Mar 2 10:46:25 2009
New Revision: 749266
URL: http://svn.apache.org/viewvc?rev=749266&view=rev
Log:
SLING-857 - test case for XmlReader using an XSLT transform contributed by
Vidar S. Ramdal, thanks!
Added:
incubator/sling/trunk/bundles/jcr/contentloader/src/test/java/org/apache/sling/jcr/contentloader/internal/readers/
incubator/sling/trunk/bundles/jcr/contentloader/src/test/java/org/apache/sling/jcr/contentloader/internal/readers/XmlReaderTest.java
(with props)
incubator/sling/trunk/bundles/jcr/contentloader/src/test/resources/
incubator/sling/trunk/bundles/jcr/contentloader/src/test/resources/reader/
incubator/sling/trunk/bundles/jcr/contentloader/src/test/resources/reader/sample.xml
(with props)
incubator/sling/trunk/bundles/jcr/contentloader/src/test/resources/reader/sample.xsl
(with props)
Added:
incubator/sling/trunk/bundles/jcr/contentloader/src/test/java/org/apache/sling/jcr/contentloader/internal/readers/XmlReaderTest.java
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/jcr/contentloader/src/test/java/org/apache/sling/jcr/contentloader/internal/readers/XmlReaderTest.java?rev=749266&view=auto
==============================================================================
---
incubator/sling/trunk/bundles/jcr/contentloader/src/test/java/org/apache/sling/jcr/contentloader/internal/readers/XmlReaderTest.java
(added)
+++
incubator/sling/trunk/bundles/jcr/contentloader/src/test/java/org/apache/sling/jcr/contentloader/internal/readers/XmlReaderTest.java
Mon Mar 2 10:46:25 2009
@@ -0,0 +1,76 @@
+/*
+ * 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.jcr.contentloader.internal.readers;
+
+import junit.framework.TestCase;
+import org.apache.sling.jcr.contentloader.internal.ContentCreator;
+
+import javax.jcr.RepositoryException;
+import java.io.File;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+
+/**
+ * Test the XmlReader with an XSLT transform
+ */
+public class XmlReaderTest extends TestCase {
+
+ public void testXmlReader() throws Exception {
+ XmlReader reader = new XmlReader();
+ File file = new File("src/test/resources/reader/sample.xml");
+ final URL testdata = file.toURI().toURL();
+ final MockContentCreator creator = new MockContentCreator();
+ reader.parse(testdata, creator);
+ assertEquals("Did not create expected number of nodes", 1,
creator.size());
+ }
+
+ @SuppressWarnings("serial")
+ private static class MockContentCreator extends ArrayList<String>
implements ContentCreator {
+
+ public MockContentCreator() {
+ }
+
+ public void createNode(String name, String primaryNodeType, String[]
mixinNodeTypes) throws RepositoryException {
+ this.add(name);
+ }
+
+ public void finishNode() throws RepositoryException {
+ }
+
+ public void createProperty(String name, int propertyType, String
value) throws RepositoryException {
+ }
+
+ public void createProperty(String name, int propertyType, String[]
values) throws RepositoryException {
+ }
+
+ public void createProperty(String name, Object value) throws
RepositoryException {
+ }
+
+ public void createProperty(String name, Object[] values) throws
RepositoryException {
+ }
+
+ public void createFileAndResourceNode(String name, InputStream data,
String mimeType, long lastModified) throws RepositoryException {
+ }
+
+ public boolean switchCurrentNode(String subPath, String newNodeType)
throws RepositoryException {
+ return true;
+ }
+ }
+}
Propchange:
incubator/sling/trunk/bundles/jcr/contentloader/src/test/java/org/apache/sling/jcr/contentloader/internal/readers/XmlReaderTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/sling/trunk/bundles/jcr/contentloader/src/test/java/org/apache/sling/jcr/contentloader/internal/readers/XmlReaderTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Added:
incubator/sling/trunk/bundles/jcr/contentloader/src/test/resources/reader/sample.xml
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/jcr/contentloader/src/test/resources/reader/sample.xml?rev=749266&view=auto
==============================================================================
---
incubator/sling/trunk/bundles/jcr/contentloader/src/test/resources/reader/sample.xml
(added)
+++
incubator/sling/trunk/bundles/jcr/contentloader/src/test/resources/reader/sample.xml
Mon Mar 2 10:46:25 2009
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+
+
+<!--
+ This needs to be transformed by sample.xsl
+ to create valid node/propertie structures
+ that the standard XML importer can accept.
+-->
+<?xml-stylesheet type="text/xsl" href="sample.xsl"?>
+<pages>
+ <page name="firstpage">
+ <content>some text</content>
+ </page>
+</pages>
\ No newline at end of file
Propchange:
incubator/sling/trunk/bundles/jcr/contentloader/src/test/resources/reader/sample.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added:
incubator/sling/trunk/bundles/jcr/contentloader/src/test/resources/reader/sample.xsl
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/jcr/contentloader/src/test/resources/reader/sample.xsl?rev=749266&view=auto
==============================================================================
---
incubator/sling/trunk/bundles/jcr/contentloader/src/test/resources/reader/sample.xsl
(added)
+++
incubator/sling/trunk/bundles/jcr/contentloader/src/test/resources/reader/sample.xsl
Mon Mar 2 10:46:25 2009
@@ -0,0 +1,58 @@
+<?xml version="1.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.
+-->
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+ <xsl:output indent="yes" />
+
+ <xsl:template match="/">
+ <xsl:apply-templates select="pages/page"/>
+ </xsl:template>
+
+ <xsl:template match="page">
+ <node>
+ <name><xsl:value-of select="@name"/></name>
+ <primaryNodeType>nt:unstructured</primaryNodeType>
+ <mixinNodeTypes/>
+ <properties>
+ <xsl:call-template name="property">
+ <xsl:with-param name="name">content</xsl:with-param>
+ <xsl:with-param name="value"><xsl:value-of
select="content"/></xsl:with-param>
+ </xsl:call-template>
+ <xsl:call-template name="property">
+ <xsl:with-param
name="name">sling:resourceType</xsl:with-param>
+ <xsl:with-param name="value">page</xsl:with-param>
+ </xsl:call-template>
+ </properties>
+ </node>
+ </xsl:template>
+
+ <xsl:template name="property">
+ <xsl:param name="name"/>
+ <xsl:param name="value"/>
+ <property>
+ <name><xsl:value-of select="$name"/></name>
+ <type>String</type>
+ <value><xsl:value-of select="$value"/></value>
+ </property>
+ </xsl:template>
+
+</xsl:stylesheet>
\ No newline at end of file
Propchange:
incubator/sling/trunk/bundles/jcr/contentloader/src/test/resources/reader/sample.xsl
------------------------------------------------------------------------------
svn:eol-style = native