abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1372057 - in /abdera/java/trunk/parser/src/test: java/org/apache/abdera/test/parser/stax/ParserOptionsTest.java java/org/apache/abdera/test/parser/stax/SimpleParseFilter.java resources/parseroptionstest.xml
Date Sun, 12 Aug 2012 08:11:50 GMT
Author: veithen
Date: Sun Aug 12 08:11:50 2012
New Revision: 1372057

URL: http://svn.apache.org/viewvc?rev=1372057&view=rev
Log:
Added a unit test to test various parser options for which there was no test coverage yet.

Added:
    abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/ParserOptionsTest.java
  (with props)
    abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/SimpleParseFilter.java
  (with props)
    abdera/java/trunk/parser/src/test/resources/parseroptionstest.xml   (with props)

Added: abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/ParserOptionsTest.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/ParserOptionsTest.java?rev=1372057&view=auto
==============================================================================
--- abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/ParserOptionsTest.java
(added)
+++ abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/ParserOptionsTest.java
Sun Aug 12 08:11:50 2012
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera.test.parser.stax;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.filter.ParseFilter;
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Feed;
+import org.apache.abdera.parser.Parser;
+import org.apache.abdera.parser.ParserOptions;
+import org.junit.Test;
+
+public class ParserOptionsTest {
+    private static final Abdera abdera = new Abdera();
+    
+    @Test
+    public void testIgnoreComments() {
+        Parser parser = abdera.getParser();
+        ParserOptions options = parser.getDefaultParserOptions();
+        ParseFilter filter = new SimpleParseFilter();
+        filter.setIgnoreComments(true);
+        options.setParseFilter(filter);
+        Document<Feed> doc = parser.parse(ParserOptionsTest.class.getResourceAsStream(
+                "/parseroptionstest.xml"), options);
+        assertTrue(abdera.getXPath().selectNodes("//comment()", doc).isEmpty());
+    }
+    
+    @Test
+    public void testIgnoreProcessingInstructions() {
+        Parser parser = abdera.getParser();
+        ParserOptions options = parser.getDefaultParserOptions();
+        ParseFilter filter = new SimpleParseFilter();
+        filter.setIgnoreProcessingInstructions(true);
+        options.setParseFilter(filter);
+        Document<Feed> doc = parser.parse(ParserOptionsTest.class.getResourceAsStream(
+                "/parseroptionstest.xml"), options);
+        assertTrue(abdera.getXPath().selectNodes("//processing-instruction()", doc).isEmpty());
+    }
+    
+    @Test
+    public void testIgnoreWhitespace() {
+        Parser parser = abdera.getParser();
+        ParserOptions options = parser.getDefaultParserOptions();
+        ParseFilter filter = new SimpleParseFilter();
+        filter.setIgnoreWhitespace(true);
+        options.setParseFilter(filter);
+        Document<Feed> doc = parser.parse(ParserOptionsTest.class.getResourceAsStream(
+                "/parseroptionstest.xml"), options);
+        assertEquals("", doc.getRoot().getEntries().get(0).getSummary());
+    }
+}

Propchange: abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/ParserOptionsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/SimpleParseFilter.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/SimpleParseFilter.java?rev=1372057&view=auto
==============================================================================
--- abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/SimpleParseFilter.java
(added)
+++ abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/SimpleParseFilter.java
Sun Aug 12 08:11:50 2012
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera.test.parser.stax;
+
+import javax.xml.namespace.QName;
+
+import org.apache.abdera.util.filter.AbstractParseFilter;
+
+public class SimpleParseFilter extends AbstractParseFilter {
+    private static final long serialVersionUID = -7037334325964942488L;
+
+    public boolean acceptable(QName qname) {
+        return true;
+    }
+
+    public boolean acceptable(QName qname, QName attribute) {
+        return true;
+    }
+}

Propchange: abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/SimpleParseFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: abdera/java/trunk/parser/src/test/resources/parseroptionstest.xml
URL: http://svn.apache.org/viewvc/abdera/java/trunk/parser/src/test/resources/parseroptionstest.xml?rev=1372057&view=auto
==============================================================================
--- abdera/java/trunk/parser/src/test/resources/parseroptionstest.xml (added)
+++ abdera/java/trunk/parser/src/test/resources/parseroptionstest.xml Sun Aug 12 08:11:50
2012
@@ -0,0 +1,12 @@
+<?xml version="1.0" ?>
+<feed xmlns="http://www.w3.org/2005/Atom">
+    <!-- comment -->
+    <?pi processing instruction?>
+    <entry>
+        <title>Atom-Powered Robots Run Amok</title>
+        <link href="http://example.org/2003/12/13/atom03"/>
+        <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
+        <updated>2003-12-13T18:30:02Z</updated>
+        <summary>      </summary>
+    </entry>
+</feed>
\ No newline at end of file

Propchange: abdera/java/trunk/parser/src/test/resources/parseroptionstest.xml
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message