abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r414893 [9/11] - in /incubator/abdera/java/trunk: ./ build/ core/ core/src/ core/src/main/ core/src/main/java/ core/src/main/java/org/ core/src/main/java/org/apache/ core/src/main/java/org/apache/abdera/ core/src/main/java/org/apache/abdera...
Date Fri, 16 Jun 2006 20:10:56 GMT
Added: incubator/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/AtomConformanceTests.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/AtomConformanceTests.java?rev=414893&view=auto
==============================================================================
--- incubator/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/AtomConformanceTests.java
(added)
+++ incubator/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/AtomConformanceTests.java
Fri Jun 16 13:10:47 2006
@@ -0,0 +1,509 @@
+/*
+* 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 java.net.URI;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.abdera.model.Content;
+import org.apache.abdera.model.Div;
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+import org.apache.abdera.model.Link;
+import org.apache.abdera.model.Text;
+import org.apache.abdera.parser.Parser;
+import org.apache.axiom.om.OMElement;
+
+
+import junit.framework.TestCase;
+
+public class AtomConformanceTests extends TestCase {
+
+  private static Document<Feed> get(URI uri) {
+    try {
+      return Parser.INSTANCE.parse(uri.toURL().openStream(), uri);
+    } catch (Exception e) {}
+    return null;
+  }
+  
+  /**
+   * Test to make sure that the parser properly detects the various kinds of
+   * extended content types allowed by Atom
+   */
+  public static void testContentTypes() throws Exception {
+    URI uri = new URI("http://www.snellspace.com/public/contentsummary.xml");
+    Document<Feed> doc = get(uri);
+    Feed feed = doc.getRoot();
+    int n = 1;
+    for (Entry entry : feed.getEntries()) {
+      Content content = entry.getContentElement();
+      Text summary = entry.getSummaryElement();
+      switch (n) {
+        case 1:
+          // XML Content Type
+          assertEquals(Content.Type.XML, content.getContentType());
+          assertTrue(content.getMimeType().match("application/xml"));
+          assertEquals(Text.Type.TEXT, summary.getTextType());
+          break;
+        case 2:
+          // XML Content Type by src reference
+          assertEquals(Content.Type.XML, content.getContentType());
+          assertNotNull(content.getResolvedSrc());
+          assertEquals(Text.Type.TEXT, summary.getTextType());
+          break;
+        case 3:
+          // Text Content Type. This is really an order test,
+          // to determine how a reader selects which text to show
+          assertEquals(Content.Type.TEXT, content.getContentType());
+          assertEquals(Text.Type.TEXT, summary.getTextType());
+          break;
+        case 4:
+          // Text Content Type. This is really an order test,
+          // to determine how a reader selects which text to show
+          assertEquals(Content.Type.TEXT, content.getContentType());
+          assertEquals(Text.Type.TEXT, summary.getTextType());
+          break;
+        case 5:
+          // Embedded iCalendar
+          assertEquals(Content.Type.MEDIA, content.getContentType());
+          assertTrue(content.getMimeType().match("text/calendar"));
+          assertEquals(Text.Type.TEXT, summary.getTextType());
+          break;
+        case 6:
+          // Embedded Base64 encoded GIF
+          assertEquals(Content.Type.MEDIA, content.getContentType());
+          assertTrue(content.getMimeType().match("image/gif"));
+          assertEquals(Text.Type.TEXT, summary.getTextType());
+          break;
+      }
+      n++;
+    }
+  }
+  
+  /**
+   * Tests the parsers support for various XML Namespace options 
+   */
+  public static void testXmlNamespace() throws Exception {
+    String[] tests = {
+      "http://plasmasturm.org/attic/atom-tests/nondefaultnamespace.atom",
+      "http://plasmasturm.org/attic/atom-tests/nondefaultnamespace-xhtml.atom",
+      "http://hsivonen.iki.fi/test/unknown-namespace.atom",
+      "http://plasmasturm.org/attic/atom-tests/nondefaultnamespace-baseline.atom"
+    };
+    int n = 1;
+    for (String test : tests) {
+      URI uri = new URI(test);
+      Document<Feed> doc = get(uri);
+      assertNotNull(doc);
+      Feed feed = doc.getRoot();
+      Entry entry = feed.getEntries().get(0);
+      switch(n) {
+        case 1:
+          assertNotNull(entry.getTitleElement());
+          assertEquals(entry.getIdElement().getValue(), 
+              new URI("urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a"));
+          Content content = entry.getContentElement();
+          assertNotNull(content);
+          assertEquals(content.getContentType(), Content.Type.XHTML);
+          OMElement element = (OMElement)content;
+          OMElement div = 
+            element.getFirstChildWithName(
+              new QName("http://www.w3.org/1999/xhtml", "div"));
+          assertNotNull(div);
+          break;
+        case 2:
+          assertNotNull(entry.getTitleElement());
+          assertEquals(entry.getIdElement().getValue(), 
+              new URI("urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a"));
+          content = entry.getContentElement();
+          assertNotNull(content);
+          assertEquals(content.getContentType(), Content.Type.XHTML);
+          element = (OMElement)content;
+          div = 
+            element.getFirstChildWithName(
+              new QName("http://www.w3.org/1999/xhtml", "div"));
+          assertNotNull(div);
+          break;
+        case 3:
+          assertNotNull(entry.getTitleElement());
+          assertEquals(entry.getIdElement().getValue(), 
+              new URI("http://hsivonen.iki.fi/test/unknown-namespace.atom/entry"));
+          content = entry.getContentElement();
+          assertNotNull(content);
+          assertEquals(content.getContentType(), Content.Type.XHTML);
+          element = (OMElement)content;
+          div = 
+            element.getFirstChildWithName(
+              new QName("http://www.w3.org/1999/xhtml", "div"));
+          assertNotNull(div);
+          break;
+        case 4:
+          assertNotNull(entry.getTitleElement());
+          assertEquals(entry.getIdElement().getValue(), 
+              new URI("urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a"));
+          content = entry.getContentElement();
+          assertNotNull(content);
+          assertEquals(content.getContentType(), Content.Type.XHTML);
+          element = (OMElement)content;
+          div = 
+            element.getFirstChildWithName(
+              new QName("http://www.w3.org/1999/xhtml", "div"));
+          assertNotNull(div);
+          break;
+      }
+      n++;
+    }
+  }
+  
+  /**
+   * Test to ensure that the parser properly resolves relative URI
+   */
+  public static void testXmlBase() throws Exception {
+    //http://tbray.org/ongoing/ongoing.atom
+    URI uri = new URI("http://www.tbray.org/ongoing/ongoing.atom");
+    Document<Feed> doc = get(uri);
+    assertNotNull(doc);
+    Feed feed = doc.getRoot();
+    assertEquals(feed.getBaseUri(), new URI("http://www.tbray.org/ongoing/ongoing.atom"));
+    assertEquals(feed.getLogoElement().getResolvedValue(), new URI("http://www.tbray.org/ongoing/rsslogo.jpg"));
+    assertEquals(feed.getIconElement().getResolvedValue(),new URI("http://www.tbray.org/favicon.ico"));
   
+  }
+  
+  /**
+   * Test to ensure that the parser properly resolves relative URI
+   */
+  public static void testXmlBase2() throws Exception {
+    //http://plasmasturm.org/attic/atom-tests/xmlbase.atom
+    URI uri = new URI("http://plasmasturm.org/attic/atom-tests/xmlbase.atom");
+    URI result = new URI("http://example.org/tests/base/result.html");
+    Document<Feed> doc = get(uri);
+    assertNotNull(doc);
+    Feed feed = doc.getRoot();
+    int n = 1;
+    for (Entry entry : feed.getEntries()) {
+      switch(n) {
+        case 1:
+          assertEquals(entry.getAlternateLink().getResolvedHref(), result);
+          break;
+        case 2:
+          assertEquals(entry.getAlternateLink().getResolvedHref(), result);
+          break;
+        case 3:
+          assertEquals(entry.getAlternateLink().getResolvedHref(), result);
+          break;
+        case 4:
+          assertEquals(entry.getAlternateLink().getResolvedHref(), result);
+          break;
+        case 5:
+        case 6:
+        case 7:
+        case 8:
+        case 9:
+        case 10:
+        case 11:
+        case 12:
+        case 13:
+        case 14:
+        case 15:
+        case 16:
+          // content tests... skipping
+          // we defer the proper handling of xml:base in the content to the
+          // application using the parser. 
+          break;
+      }
+      n++;
+    }
+  }
+  
+  public static void testUpdated() throws Exception {
+    //http://intertwingly.net/testcase/updated.atom
+    //Note: This test determines whether or not applications properly
+    //      detect content changes in an atom entry based on the value
+    //      of the atom:updated.  This isn't really relevant at this 
+    //      level.  The responsibility for properly detecting modifications
+    //      belongs to the application.
+  }
+  
+  /**
+   * Test support for markup in Text constructs
+   */
+  public static void testTitle() throws Exception {
+    String[] tests = {
+      "html-cdata.atom",
+      "html-entity.atom",
+      "html-ncr.atom",
+      "text-cdata.atom",
+      "text-entity.atom",
+      "text-ncr.atom",
+      "xhtml-entity.atom",
+      "xhtml-ncr.atom"};
+    URI baseUri = new URI("http://atomtests.philringnalda.com/tests/item/title/");
+    int n = 1;
+    for (String test : tests) {
+      Document<Feed> doc = get(baseUri.resolve(test));
+      assertNotNull(doc);
+      Feed feed = doc.getRoot();
+      Entry entry = feed.getEntries().get(0);
+      assertNotNull(entry);
+      Text title = entry.getTitleElement();
+      assertNotNull(title);
+      switch(n) {
+        case 1:
+          // The parser passes escaped HTML back up to the application.
+          // is the applications responsibility to properly display it
+          String value = title.getValue();
+          assertEquals(value, "&lt;title>");
+          break;
+        case 2:
+          // The parser passes escaped HTML back up to the application.
+          // is the applications responsibility to properly display it
+          value = title.getValue();
+          assertEquals(value, "&lt;title>");
+          break;
+        case 3:
+          // The parser passes escaped HTML back up to the application.
+          // is the applications responsibility to properly display it
+          value = title.getValue();
+          assertEquals(value, "&lt;title>");          
+          break;
+        case 4:
+          value = title.getValue();
+          assertEquals(value, "<title>");          
+          break;
+        case 5:
+          value = title.getValue();
+          assertEquals(value, "<title>");
+          break;
+        case 6:
+         
+          value = title.getValue();
+          assertEquals(value, "<title>");
+          break;
+        case 7:
+          Div div = title.getValueElement();
+          assertEquals(div.getValue(), "<title>");
+          break;
+        case 8:
+          div = title.getValueElement();
+          assertEquals(div.getValue(), "<title>");
+          break;
+      }
+      n++;
+    }
+  }
+  
+  /**
+   * This tests the parsers ability to properly ignore the ordering of elements
+   * in the Atom feed/entry.  The parser should be able to properly select the
+   * requested elements regardless of the order in which they appear
+   */
+  public static void testOrder() throws Exception {
+    //http://www.snellspace.com/public/ordertest.xml
+    URI uri = new URI("http://www.snellspace.com/public/ordertest.xml");
+    Document<Feed> doc = get(uri);
+    assertNotNull(doc);
+    Feed feed = doc.getRoot();
+    List<Entry> entries = feed.getEntries();
+    int n = 1;
+    for (Entry entry : entries ) {
+      switch(n) {
+        case 1:
+          assertEquals(entry.getIdElement().getValue(), new URI("tag:example.org,2006:atom/conformance/element_order/1"));
+          assertEquals(entry.getTitleType(), Text.Type.TEXT);
+          assertEquals(entry.getSummaryType(), Text.Type.TEXT);
+          assertNotNull(entry.getUpdatedElement().getValue());
+          assertEquals(entry.getLinks(Link.REL_ALTERNATE).size(),1);
+          break;
+        case 2:
+          assertEquals(entry.getIdElement().getValue(), new URI("tag:example.org,2006:atom/conformance/element_order/2"));
+          assertEquals(entry.getTitleType(), Text.Type.TEXT);
+          assertEquals(entry.getSummaryType(), Text.Type.TEXT);
+          assertNotNull(entry.getUpdatedElement().getValue());
+          assertEquals(entry.getLinks(Link.REL_ALTERNATE).size(),1);
+          break;
+        case 3:
+          assertEquals(entry.getLinks(Link.REL_ALTERNATE).size(),2);
+          assertEquals(
+            entry.getLinks(Link.REL_ALTERNATE).get(0).getHref(), 
+            new URI("http://www.snellspace.com/public/alternate"));
+          assertEquals(
+              entry.getLinks(Link.REL_ALTERNATE).get(1).getHref(), 
+              new URI("http://www.snellspace.com/public/alternate2"));
+          break;
+        case 4:
+          assertEquals(entry.getLinks(Link.REL_ALTERNATE).size(),1);
+          assertEquals(
+              entry.getLinks(Link.REL_ALTERNATE).get(0).getHref(), 
+              new URI("http://www.snellspace.com/public/alternate"));
+          break;
+        case 5:
+          Text title = entry.getTitleElement();
+          assertEquals(entry.getTitleType(), Text.Type.TEXT);
+          String value = title.getValue();
+          assertEquals(value, "Entry with a source first");
+          assertEquals(entry.getLinks(Link.REL_ALTERNATE).size(),1);
+          assertEquals(
+              entry.getLinks(Link.REL_ALTERNATE).get(0).getHref(), 
+              new URI("http://www.snellspace.com/public/alternate"));          
+          break;
+        case 6:
+          title = entry.getTitleElement();
+          assertEquals(entry.getTitleType(), Text.Type.TEXT);
+          value = title.getValue();
+          assertEquals(value, "Entry with a source last");
+          assertEquals(entry.getLinks(Link.REL_ALTERNATE).size(),1);
+          assertEquals(
+              entry.getLinks(Link.REL_ALTERNATE).get(0).getHref(), 
+              new URI("http://www.snellspace.com/public/alternate"));
+          break;
+        case 7:
+          title = entry.getTitleElement();
+          assertEquals(entry.getTitleType(), Text.Type.TEXT);
+          value = title.getValue();
+          assertEquals(value, "Entry with a source in the middle");
+          assertEquals(entry.getLinks(Link.REL_ALTERNATE).size(),1);
+          assertEquals(
+              entry.getLinks(Link.REL_ALTERNATE).get(0).getHref(), 
+              new URI("http://www.snellspace.com/public/alternate"));          
+          break;
+        case 8:
+          title = entry.getTitleElement();
+          assertEquals(entry.getTitleType(), Text.Type.TEXT);
+          value = title.getValue();
+          assertEquals(value, "Atom elements in an extension element");
+          assertEquals(
+            entry.getIdElement().getValue(), 
+            new URI("tag:example.org,2006:atom/conformance/element_order/8"));
+          break;
+        case 9:
+          title = entry.getTitleElement();
+          assertEquals(entry.getTitleType(), Text.Type.TEXT);
+          value = title.getValue();
+          assertEquals(value, "Atom elements in an extension element");
+          assertEquals(
+            entry.getIdElement().getValue(), 
+            new URI("tag:example.org,2006:atom/conformance/element_order/9"));
+          break;
+      }
+      n++;
+    }
+  }
+  
+  /**
+   * Tests the parsers support for the various link relation types
+   */
+  public static void testLink() throws Exception {
+    //http://www.snellspace.com/public/linktests.xml
+    URI uri = new URI("http://www.snellspace.com/public/linktests.xml");
+    Document<Feed> doc = get(uri);
+    assertNotNull(doc);
+    Feed feed = doc.getRoot();
+    List<Entry> entries = feed.getEntries();
+    int n = 1;
+    for (Entry entry : entries) {
+      switch(n) {
+        case 1:
+          assertEquals(entry.getLinks(Link.REL_ALTERNATE).size(),1);
+          assertEquals(
+            entry.getLinks(Link.REL_ALTERNATE).get(0).getHref(), 
+            new URI("http://www.snellspace.com/public/linktests/alternate"));
+          break;
+        case 2:
+          assertEquals(entry.getLinks(Link.REL_ALTERNATE).size(),4);
+          assertEquals(
+              entry.getLinks(Link.REL_ALTERNATE).get(1).getHref(), 
+              new URI("http://www.snellspace.com/public/linktests/alternate"));         

+          assertEquals(
+              entry.getLinks(Link.REL_ALTERNATE).get(2).getHref(), 
+              new URI("http://www.snellspace.com/public/linktests/alternate2"));
+          break;
+        case 3:
+          assertEquals(entry.getLinks(Link.REL_ALTERNATE).size(),1);
+          assertEquals(entry.getLinks(Link.REL_ENCLOSURE).size(),1);
+          assertEquals(entry.getLinks(Link.REL_RELATED).size(),1);
+          assertEquals(entry.getLinks(Link.REL_SELF).size(),1);
+          assertEquals(entry.getLinks(Link.REL_VIA).size(),1);    
+          assertEquals(
+              entry.getLinks(Link.REL_ALTERNATE).get(0).getHref(), 
+              new URI("http://www.snellspace.com/public/linktests/alternate"));
+          assertEquals(
+              entry.getLinks(Link.REL_ENCLOSURE).get(0).getHref(), 
+              new URI("http://www.snellspace.com/public/linktests/enclosure"));
+          assertEquals(
+              entry.getLinks(Link.REL_RELATED).get(0).getHref(), 
+              new URI("http://www.snellspace.com/public/linktests/related"));
+          assertEquals(
+              entry.getLinks(Link.REL_SELF).get(0).getHref(), 
+              new URI("http://www.snellspace.com/public/linktests/self"));
+          assertEquals(
+              entry.getLinks(Link.REL_VIA).get(0).getHref(), 
+              new URI("http://www.snellspace.com/public/linktests/via"));
+          break;
+        case 4:
+          assertEquals(entry.getLinks(Link.REL_ALTERNATE).size(),2);
+          assertEquals(entry.getLinks(Link.REL_ENCLOSURE).size(),1);
+          assertEquals(entry.getLinks(Link.REL_RELATED).size(),1);
+          assertEquals(entry.getLinks(Link.REL_SELF).size(),1);
+          assertEquals(entry.getLinks(Link.REL_VIA).size(),1);          
+          assertEquals(
+              entry.getLinks(Link.REL_ALTERNATE).get(0).getHref(), 
+              new URI("http://www.snellspace.com/public/linktests/alternate"));
+          assertEquals(
+              entry.getLinks(Link.REL_ALTERNATE).get(1).getHref(), 
+              new URI("http://www.snellspace.com/public/linktests/alternate2"));
+          assertEquals(
+              entry.getLinks(Link.REL_ENCLOSURE).get(0).getHref(), 
+              new URI("http://www.snellspace.com/public/linktests/enclosure"));
+          assertEquals(
+              entry.getLinks(Link.REL_RELATED).get(0).getHref(), 
+              new URI("http://www.snellspace.com/public/linktests/related"));
+          assertEquals(
+              entry.getLinks(Link.REL_SELF).get(0).getHref(), 
+              new URI("http://www.snellspace.com/public/linktests/self"));
+          assertEquals(
+              entry.getLinks(Link.REL_VIA).get(0).getHref(), 
+              new URI("http://www.snellspace.com/public/linktests/via"));
+          break;
+        case 5:
+          assertEquals(entry.getLinks(Link.REL_ALTERNATE).size(),1);
+          assertEquals(entry.getLinks(Link.REL_LICENSE).size(),1);  
+          assertEquals(
+              entry.getLinks(Link.REL_ALTERNATE).get(0).getHref(), 
+              new URI("http://www.snellspace.com/public/linktests/alternate"));
+          assertEquals(
+              entry.getLinks(Link.REL_LICENSE).get(0).getHref(), 
+              new URI("http://www.snellspace.com/public/linktests/license"));
+          break;
+        case 6:
+          assertEquals(entry.getLinks(Link.REL_ALTERNATE).size(),1);
+          assertEquals(entry.getLinks("http://example.org").size(),1);
+          assertEquals(
+              entry.getLinks(Link.REL_ALTERNATE).get(0).getHref(), 
+              new URI("http://www.snellspace.com/public/linktests/alternate"));
+          assertEquals(
+              entry.getLinks("http://example.org").get(0).getHref(), 
+              new URI("http://www.snellspace.com/public/linktests/example"));
+          break;
+      }
+      n++;
+    }
+  }
+}

Added: incubator/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/FOMTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/FOMTest.java?rev=414893&view=auto
==============================================================================
--- incubator/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/FOMTest.java
(added)
+++ incubator/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/FOMTest.java
Fri Jun 16 13:10:47 2006
@@ -0,0 +1,247 @@
+/*
+* 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 java.io.InputStream;
+import java.io.ByteArrayOutputStream;
+import java.net.URL;
+
+import javax.xml.namespace.QName;
+
+import org.apache.abdera.factory.Factory;
+import org.apache.abdera.filter.ParseFilter;
+import org.apache.abdera.filter.TextFilter;
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Element;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.ExtensionElement;
+import org.apache.abdera.model.Feed;
+import org.apache.abdera.model.Text;
+import org.apache.abdera.parser.Parser;
+import org.apache.abdera.parser.ParserOptions;
+import org.apache.abdera.util.BlackListParseFilter;
+import org.apache.abdera.util.Constants;
+import org.apache.abdera.util.URIHelper;
+import org.apache.abdera.util.WhiteListParseFilter;
+import org.apache.abdera.xpath.XPath;
+
+
+import junit.framework.TestCase;
+
+public class FOMTest extends TestCase   {
+
+  public void testParser() throws Exception {
+    
+    InputStream in = FOMTest.class.getResourceAsStream("/simple.xml");
+    Document<Feed> doc = Parser.INSTANCE.parse(in);
+    Feed feed = doc.getRoot();
+    
+    assertEquals(feed.getTitle(),"Example Feed");
+    assertEquals(feed.getTitleType(), Text.Type.TEXT);
+    assertEquals(feed.getAlternateLink().getResolvedHref().toString(), "http://example.org/");
+    assertNotNull(feed.getUpdated());
+    assertEquals(feed.getAuthor().getName(), "John Doe");
+    assertEquals(feed.getId().toString(), "urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6");
+    
+    Entry entry = feed.getEntries().get(0);
+
+    assertEquals(entry.getTitle(),"Atom-Powered Robots Run Amok");
+    assertEquals(entry.getTitleType(), Text.Type.TEXT);
+    assertEquals(entry.getAlternateLink().getResolvedHref().toString(), "http://example.org/2003/12/13/atom03");
+    assertEquals(entry.getId().toString(),"urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a");
+    assertNotNull(entry.getUpdated());
+    assertEquals(entry.getSummary(), "Some text.");
+    assertEquals(entry.getSummaryType(), Text.Type.TEXT);
+    
+  }
+
+  public void testCreate() throws Exception {
+    Feed feed = Factory.INSTANCE.newFeed();
+    feed.setLanguage("en-US");
+    feed.setBaseUri("http://example.org");
+    
+    feed.setTitleAsText("Example Feed");
+    feed.addLink("http://example.org/");
+    feed.addAuthor("John Doe");
+    feed.setId("urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6", false);
+    feed.addContributor("Bob Jones");
+    feed.addCategory("example");
+    
+    Entry entry = feed.insertEntry();
+    entry.setTitleAsText("Atom-Powered Robots Run Amok");
+    entry.addLink("http://example.org/2003/12/13/atom03");
+    entry.setId("urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a", false);
+    entry.setSummaryAsText("Some text.");
+    
+    Entry entry2 = feed.insertEntry();
+    entry2.setTitleAsText("re: Atom-Powered Robots Run Amok");
+    entry2.addLink("/2003/12/13/atom03/1");
+    entry2.setId("urn:uuid:1225c695-cfb8-4ebb-aaaa-80cb323feb5b", false);
+    entry2.setSummaryAsText("A response");
+    entry2.addInReplyTo(entry);
+    
+    String compare = "<?xml version='1.0' encoding='UTF-8'?><a:feed xmlns:a=\"http://www.w3.org/2005/Atom\"
xml:base=\"http://example.org\" xml:lang=\"en-US\"><a:title type=\"text\">Example
Feed</a:title><a:link href=\"http://example.org/\" /><a:author><a:name>John
Doe</a:name></a:author><a:id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</a:id><a:contributor><a:name>Bob
Jones</a:name></a:contributor><a:category term=\"example\" /><a:entry><a:title
type=\"text\">re: Atom-Powered Robots Run Amok</a:title><a:link href=\"/2003/12/13/atom03/1\"
/><a:id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80cb323feb5b</a:id><a:summary type=\"text\">A
response</a:summary><thr:in-reply-to xmlns:thr=\"http://purl.org/syndication/thread/1.0\"
href=\"http://example.org/2003/12/13/atom03\" ref=\"urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a\"
/></a:entry><a:entry><a:title type=\"text\">Atom-Powered Robots Run Amok</a:title><a:link
href=\"http://example.org/2003/12/13/atom03\" /><a:id>urn:uuid:1225c695-cfb
 8-4ebb-aaaa-80da344efa6a</a:id><a:summary type=\"text\">Some text.</a:summary></a:entry></a:feed>";
+    
+    ByteArrayOutputStream out = new ByteArrayOutputStream(512);
+    feed.getDocument().writeTo(out);
+    String actual = out.toString();
+    
+    assertEquals(actual, compare);
+    
+    assertEquals(feed.getEntries().get(0).getId().toString(), "urn:uuid:1225c695-cfb8-4ebb-aaaa-80cb323feb5b");
+    assertEquals(feed.getEntries().get(1).getId().toString(), "urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a");
+    
+  }
+
+  public void testWhiteListParseFilter() throws Exception {
+    
+    ParseFilter filter = new WhiteListParseFilter();
+    filter.add(Constants.FEED);
+    filter.add(Constants.ENTRY);
+    filter.add(Constants.TITLE);
+    filter.add(Constants.ID);
+    ParserOptions options = Parser.INSTANCE.getDefaultParserOptions();
+    options.setParseFilter(filter);
+    
+    URL url = FOMTest.class.getResource("/simple.xml");
+    InputStream in = url.openStream();
+
+    Document<Feed> doc = Parser.INSTANCE.parse(in, url.toURI(), options);
+    Feed feed = doc.getRoot();
+    
+    assertEquals(feed.getTitle(),"Example Feed");
+    assertEquals(feed.getTitleType(), Text.Type.TEXT);
+    assertNull(feed.getAlternateLink());
+    assertNull(feed.getUpdated());
+    assertNull(feed.getAuthor());
+    assertEquals(feed.getId().toString(), "urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6");
+    
+    Entry entry = feed.getEntries().get(0);
+
+    assertEquals(entry.getTitle(),"Atom-Powered Robots Run Amok");
+    assertEquals(entry.getTitleType(), Text.Type.TEXT);
+    assertNull(entry.getAlternateLink());
+    assertEquals(entry.getId().toString(),"urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a");
+    assertNull(entry.getUpdated());
+    assertNull(entry.getSummary());
+    assertNull(entry.getSummaryType());
+  }
+  
+  public void testBlackListParseFilter() throws Exception {
+    
+    ParseFilter filter = new BlackListParseFilter();
+    filter.add(Constants.UPDATED);
+    ParserOptions options = Parser.INSTANCE.getDefaultParserOptions();
+    options.setParseFilter(filter);
+    
+    URL url = FOMTest.class.getResource("/simple.xml");
+    InputStream in = url.openStream();
+
+    Document<Feed> doc = Parser.INSTANCE.parse(in, url.toURI(), options);
+    Feed feed = doc.getRoot();
+    
+    assertEquals(feed.getTitle(),"Example Feed");
+    assertEquals(feed.getTitleType(), Text.Type.TEXT);
+    assertEquals(feed.getAlternateLink().getResolvedHref().toString(), "http://example.org/");
+    assertNull(feed.getUpdated());
+    assertEquals(feed.getAuthor().getName(), "John Doe");
+    assertEquals(feed.getId().toString(), "urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6");
+    
+    Entry entry = feed.getEntries().get(0);
+
+    assertEquals(entry.getTitle(),"Atom-Powered Robots Run Amok");
+    assertEquals(entry.getTitleType(), Text.Type.TEXT);
+    assertEquals(entry.getAlternateLink().getResolvedHref().toString(), "http://example.org/2003/12/13/atom03");
+    assertEquals(entry.getId().toString(),"urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a");
+    assertNull(entry.getUpdated());
+    assertEquals(entry.getSummary(), "Some text.");
+    assertEquals(entry.getSummaryType(), Text.Type.TEXT);
+
+  }
+  
+  public void testTextFilter() throws Exception {
+    
+    TextFilter filter = new TextFilter() {
+      @Override
+      public String filterText(String text, Element parent) {
+        ExtensionElement ee = (ExtensionElement) parent;
+        QName qname = ee.getQName();
+        Element elparent = parent.getParentElement();
+        if (Constants.NAME.equals(qname)) {
+          text = "Jane Doe";
+        } else if (Constants.TITLE.equals(qname) && elparent instanceof Entry) {
+          text = text.replaceAll("Amok", "Crazy");
+        }
+        return text;
+      }
+    };
+    
+    ParserOptions options = Parser.INSTANCE.getDefaultParserOptions();
+    options.setTextFilter(filter);
+    
+    URL url = FOMTest.class.getResource("/simple.xml");
+    InputStream in = url.openStream();
+    Document<Feed> doc = Parser.INSTANCE.parse(in, url.toURI(), options);
+    Feed feed = doc.getRoot();
+    
+    assertEquals(feed.getTitle(),"Example Feed");
+    assertEquals(feed.getTitleType(), Text.Type.TEXT);
+    assertEquals(feed.getAlternateLink().getResolvedHref().toString(), "http://example.org/");
+    assertNotNull(feed.getUpdated());
+    assertEquals(feed.getAuthor().getName(), "Jane Doe");
+    assertEquals(feed.getId().toString(), "urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6");
+    
+    Entry entry = feed.getEntries().get(0);
+
+    assertEquals(entry.getTitle(),"Atom-Powered Robots Run Crazy");
+    assertEquals(entry.getTitleType(), Text.Type.TEXT);
+    assertEquals(entry.getAlternateLink().getResolvedHref().toString(), "http://example.org/2003/12/13/atom03");
+    assertEquals(entry.getId().toString(),"urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a");
+    assertNotNull(entry.getUpdated());
+    assertEquals(entry.getSummary(), "Some text.");
+    assertEquals(entry.getSummaryType(), Text.Type.TEXT);
+    
+  }
+  
+  public void testXPath() throws Exception {
+    
+    InputStream in = FOMTest.class.getResourceAsStream("/simple.xml");
+    Document<Feed> doc = Parser.INSTANCE.parse(in);
+    Feed feed = doc.getRoot();
+    XPath xpath = XPath.INSTANCE;
+    assertEquals(xpath.evaluate("count(/a:feed)", feed), 1.0d);
+    assertTrue(xpath.isTrue("/a:feed/a:entry", feed));
+    assertEquals(xpath.numericValueOf("count(/a:feed)", feed), 1.0d);
+    assertEquals(xpath.valueOf("/a:feed/a:entry/a:title", feed), "Atom-Powered Robots Run
Amok");
+    assertEquals(xpath.selectNodes("/a:feed/a:entry", feed).size(), 1);
+    assertTrue(xpath.selectSingleNode("/a:feed", feed) instanceof Feed);
+    assertEquals(xpath.selectSingleNode("..", feed.getTitleElement()), feed);
+    assertEquals(xpath.selectSingleNode("ancestor::*", feed.getEntries().get(0)), feed);
+    assertEquals(xpath.valueOf("concat('The feed is is ',/a:feed/a:id)", feed), "The feed
is is urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6");
+    
+  }
+  
+  public void testUriNormalization() throws Exception {
+    String s1 = "HTTP://www.Example.ORG:80/./foo/%2d/../%2d/./foo";
+    String s2 = "HTTP://www.Example.ORG:81/./foo/%2d/../%2d/./foo";
+    assertEquals(URIHelper.normalize(s1), "http://www.example.org/foo/-/foo");
+    assertEquals(URIHelper.normalize(s2), "http://www.example.org:81/foo/-/foo");
+  }
+  
+  
+}

Added: incubator/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/FeedParserTests.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/FeedParserTests.java?rev=414893&view=auto
==============================================================================
--- incubator/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/FeedParserTests.java
(added)
+++ incubator/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/FeedParserTests.java
Fri Jun 16 13:10:47 2006
@@ -0,0 +1,111 @@
+/*
+* 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 java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.net.URI;
+
+import javax.activation.DataHandler;
+
+import org.apache.abdera.model.Content;
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+import org.apache.abdera.model.Person;
+import org.apache.abdera.parser.Parser;
+
+
+import junit.framework.TestCase;
+
+public class FeedParserTests extends TestCase {
+
+  private static URI baseURI = null;
+  
+  private static Document<Feed> get(URI uri) {
+    try {
+      return Parser.INSTANCE.parse(uri.toURL().openStream(), uri);
+    } catch (Exception e) {}
+    return null;
+  }
+  
+  @Override
+  protected void setUp() throws Exception {
+    try {
+      baseURI = new URI("http://www.feedparser.org/tests/wellformed/atom10/");
+    } catch (Exception e) {}
+    super.setUp();
+  }
+  
+  public void testAtom10Namespace() throws Exception {
+    URI uri = baseURI.resolve("atom10_namespace.xml");
+    Document doc = get(uri);
+    assertNotNull(doc);
+  }
+  
+  public void testEntryAuthorEmail() throws Exception {
+    URI uri = baseURI.resolve("entry_author_email.xml");
+    Document doc = get(uri);
+    Feed feed = (Feed) doc.getRoot();
+    Entry entry = feed.getEntries().get(0);
+    Person person = entry.getAuthor();
+    assertEquals(person.getEmailElement().getValue(), "me@example.com");
+  }
+  
+  public void testEntryAuthorName() throws Exception {
+    URI uri = baseURI.resolve("entry_author_name.xml");
+    Document doc = get(uri);
+    Feed feed = (Feed) doc.getRoot();
+    Entry entry = feed.getEntries().get(0);
+    Person person = entry.getAuthor();
+    assertEquals(person.getNameElement().getValue(), "Example author");    
+  }
+  
+  public void testEntryContentBase64() throws Exception {
+    URI uri = baseURI.resolve("entry_content_base64.xml");
+    Document doc = get(uri);
+    Feed feed = (Feed)doc.getRoot();
+    Entry entry = feed.getEntries().get(0);
+    Content mediaContent = entry.getContentElement();
+    assertEquals(mediaContent.getMimeType().toString(), "application/octet-stream");
+    DataHandler dataHandler = mediaContent.getDataHandler();
+    InputStream in = (ByteArrayInputStream) dataHandler.getContent();
+    ByteArrayOutputStream baos = new ByteArrayOutputStream();
+    int n = -1;
+    while ((n = in.read()) > -1) { baos.write(n); }
+    assertEquals(baos.toString(), "Example <b>Atom</b>");
+  }
+  
+  public void testEntryContentBase642() throws Exception {
+    URI uri = baseURI.resolve("entry_content_base64_2.xml");
+    Document doc = get(uri);
+    Feed feed = (Feed)doc.getRoot();
+    Entry entry = feed.getEntries().get(0);
+    Content mediaContent = entry.getContentElement();
+    assertEquals(mediaContent.getMimeType().toString(), "application/octet-stream");
+    DataHandler dataHandler = mediaContent.getDataHandler();
+    InputStream in = (ByteArrayInputStream) dataHandler.getContent();
+    ByteArrayOutputStream baos = new ByteArrayOutputStream();
+    int n = -1;
+    while ((n = in.read()) > -1) { baos.write(n); }
+    assertEquals(baos.toString(), "<p>History of the &lt;blink&gt; tag</p>");
+  }
+  
+  
+}



Mime
View raw message