abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r1173209 [44/49] - in /abdera/abdera2: ./ .settings/ activities/ activities/src/ activities/src/main/ activities/src/main/java/ activities/src/main/java/org/ activities/src/main/java/org/apache/ activities/src/main/java/org/apache/abdera2/ ...
Date Tue, 20 Sep 2011 15:57:20 GMT
Added: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/ext/sharing/SharingTest.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/test/src/main/java/org/apache/abdera2/test/ext/sharing/SharingTest.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/test/src/main/java/org/apache/abdera2/test/ext/sharing/SharingTest.java (added)
+++ abdera/abdera2/test/src/main/java/org/apache/abdera2/test/ext/sharing/SharingTest.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,261 @@
+/*
+ * 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.abdera2.test.ext.sharing;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.StringReader;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.ext.sharing.Conflicts;
+import org.apache.abdera2.ext.sharing.History;
+import org.apache.abdera2.ext.sharing.Related;
+import org.apache.abdera2.ext.sharing.Sharing;
+import org.apache.abdera2.ext.sharing.SharingHelper;
+import org.apache.abdera2.ext.sharing.Sync;
+import org.apache.abdera2.ext.sharing.Unpublished;
+import org.apache.abdera2.ext.sharing.SharingHelper.ConflictResolver;
+import org.apache.abdera2.factory.Factory;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Entry;
+import org.apache.abdera2.model.Feed;
+import org.junit.Test;
+import org.apache.abdera2.common.date.DateTime;
+
+public class SharingTest {
+
+    @Test
+    public void testSharingFactory() throws Exception {
+        Abdera abdera = Abdera.getInstance();
+        Factory factory = abdera.getFactory();
+        Conflicts conflicts = factory.newElement(SharingHelper.SSE_CONFLICTS);
+        assertNotNull(conflicts);
+        History history = factory.newElement(SharingHelper.SSE_HISTORY);
+        assertNotNull(history);
+        Related related = factory.newElement(SharingHelper.SSE_RELATED);
+        assertNotNull(related);
+        Sharing sharing = factory.newElement(SharingHelper.SSE_SHARING);
+        assertNotNull(sharing);
+        Sync sync = factory.newElement(SharingHelper.SSE_SYNC);
+        assertNotNull(sync);
+        Unpublished unpub = factory.newElement(SharingHelper.SSE_UNPUBLISHED);
+        assertNotNull(unpub);
+    }
+
+    @Test
+    public void testSimpleExample() throws Exception {
+
+        String ex =
+            "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<feed xmlns=\"http://www.w3.org/2005/Atom\" "
+                + "xmlns:sx=\"http://feedsync.org/2007/feedsync\">"
+                + "<title>To Do List</title>"
+                + "<subtitle>A list of items to do</subtitle>"
+                + "<link rel=\"self\" href=\"http://example.com/partial.xml\"/>"
+                + "<author>"
+                + "<name>Ray Ozzie</name>"
+                + "</author>"
+                + "<updated>2005-05-21T11:43:33Z</updated>"
+                + "<id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0aaa</id>"
+                + "<sx:sharing since=\"2005-02-13T18:30:02Z\" "
+                + "until=\"2005-05-23T18:30:02Z\" >"
+                + "<sx:related link=\"http://example.com/all.xml\" type=\"complete\" />"
+                + "<sx:related link=\"http://example.com/B.xml\" type=\"aggregated\" "
+                + "title=\"To Do List (Jacks Copy)\" />"
+                + "</sx:sharing>"
+                + "<entry>"
+                + "<title>Buy groceries</title>"
+                + "<content>Get milk, eggs, butter and bread</content>"
+                + "<id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0aa0</id>"
+                + "<author>"
+                + "<name>Ray Ozzie</name>"
+                + "</author>"
+                + "<updated>2005-05-21T11:43:33Z</updated>"
+                + "<sx:sync id=\"item 1_myapp_2005-05-21T11:43:33Z\" updates=\"3\">"
+                + "<sx:history sequence=\"3\" when=\"2005-05-21T11:43:33Z\" by=\"JEO2000\"/>"
+                + "<sx:history sequence=\"2\" when=\"2005-05-21T10:43:33Z\" by=\"REO1750\"/>"
+                + "<sx:history sequence=\"1\" when=\"2005-05-21T09:43:33Z\" by=\"REO1750\"/>"
+                + "</sx:sync>"
+                + "</entry></feed>";
+
+        StringReader rdr = new StringReader(ex);
+        Abdera abdera = Abdera.getInstance();
+        Document<Feed> doc = abdera.getParser().parse(rdr);
+        Feed feed = doc.getRoot();
+        assertTrue(SharingHelper.hasSharing(feed));
+
+        Sharing sharing = SharingHelper.getSharing(feed, false);
+        assertNotNull(sharing);
+
+        Date since = DateTime.parse("2005-02-13T18:30:02Z");
+        Date until = DateTime.parse("2005-05-23T18:30:02Z");
+
+        assertEquals(since, sharing.getSince());
+        assertEquals(until, sharing.getUntil());
+
+        assertEquals(2, sharing.getRelated().size());
+
+        Related rel = sharing.getRelated().get(0);
+        assertEquals("http://example.com/all.xml", rel.getLink().toString());
+        assertEquals(Related.Type.COMPLETE, rel.getType());
+
+        rel = sharing.getRelated().get(1);
+        assertEquals("http://example.com/B.xml", rel.getLink().toString());
+        assertEquals(Related.Type.AGGREGATED, rel.getType());
+
+        Entry entry = feed.getEntries().get(0);
+        Sync sync = SharingHelper.getSync(entry, false);
+        assertNotNull(sync);
+        assertEquals("item 1_myapp_2005-05-21T11:43:33Z", sync.getId());
+        assertEquals(3, sync.getUpdates());
+
+        assertEquals(3, sync.getHistory().size());
+
+        Date d1 = DateTime.parse("2005-05-21T11:43:33Z");
+        Date d2 = DateTime.parse("2005-05-21T10:43:33Z");
+        Date d3 = DateTime.parse("2005-05-21T09:43:33Z");
+
+        History history = sync.getHistory().get(0);
+        assertEquals(3, history.getSequence());
+        assertEquals(d1, history.getWhen());
+        assertEquals("JEO2000", history.getBy());
+
+        history = sync.getHistory().get(1);
+        assertEquals(2, history.getSequence());
+        assertEquals(d2, history.getWhen());
+        assertEquals("REO1750", history.getBy());
+
+        history = sync.getHistory().get(2);
+        assertEquals(1, history.getSequence());
+        assertEquals(d3, history.getWhen());
+        assertEquals("REO1750", history.getBy());
+    }
+
+    @Test
+    public void testCreateOperation() throws Exception {
+        Abdera abdera = Abdera.getInstance();
+        Entry entry = SharingHelper.createEntry(abdera, "jms");
+        Sync sync = SharingHelper.getSync(entry, false);
+        assertNotNull(sync);
+        assertNotNull(sync.getId());
+        assertEquals(1, sync.getUpdates());
+        assertEquals(1, sync.getHistory().size());
+        History history = sync.getTopmostHistory();
+        assertEquals(1, history.getSequence());
+        assertEquals("jms", history.getBy());
+    }
+
+    @Test
+    public void testUpdateOperation() throws Exception {
+        Abdera abdera = Abdera.getInstance();
+        Entry entry = SharingHelper.createEntry(abdera, "jms");
+        SharingHelper.updateEntry(entry, "jms");
+        Sync sync = SharingHelper.getSync(entry, false);
+        assertNotNull(sync);
+        assertNotNull(sync.getId());
+        assertEquals(2, sync.getUpdates());
+        assertEquals(2, sync.getHistory().size());
+        History history = sync.getTopmostHistory();
+        assertEquals(2, history.getSequence());
+        assertEquals("jms", history.getBy());
+    }
+
+    @Test
+    public void testDeleteOperation() throws Exception {
+        Abdera abdera = Abdera.getInstance();
+        Entry entry = SharingHelper.createEntry(abdera, "jms");
+        Sync sync = SharingHelper.getSync(entry, false);
+        assertNotNull(sync);
+        assertFalse(sync.isDeleted());
+        SharingHelper.deleteEntry(entry, "jms");
+        sync = SharingHelper.getSync(entry, false);
+        assertNotNull(sync);
+        assertTrue(sync.isDeleted());
+        assertNotNull(sync.getId());
+        assertEquals(2, sync.getUpdates());
+        assertEquals(2, sync.getHistory().size());
+        History history = sync.getTopmostHistory();
+        assertEquals(2, history.getSequence());
+        assertEquals("jms", history.getBy());
+    }
+
+    @Test
+    public void testConflict() throws Exception {
+
+        Abdera abdera = Abdera.getInstance();
+        Feed f1 = abdera.newFeed();
+        Feed f2 = abdera.newFeed();
+        Entry e1 = SharingHelper.createEntry(abdera, "jms", f1);
+        Entry e2 = SharingHelper.createEntry(abdera, "jms", f2);
+        Sync s1 = SharingHelper.getSync(e1, false);
+        Sync s2 = SharingHelper.getSync(e2, false);
+        s2.setId(s1.getId());
+        SharingHelper.updateEntry(e1, "bob");
+        SharingHelper.updateEntry(e2, "jms");
+
+        SharingHelper.mergeFeeds(f1, f2);
+
+        assertEquals(1, f2.getEntries().size());
+        Entry entry = f2.getEntries().get(0);
+        Sync sync = SharingHelper.getSync(entry);
+        Conflicts conflicts = sync.getConflicts();
+        assertNotNull(conflicts);
+        assertEquals(1, conflicts.getEntries().size());
+        Entry conflict = conflicts.getEntries().get(0);
+        assertNotNull(conflict);
+
+        ConflictResolver r = new ConflictResolver() {
+            public Entry resolve(Entry entry, List<Entry> conflicts) {
+                Sync sync = SharingHelper.getSync(entry, false);
+                Conflicts c = sync.getConflicts(false);
+                if (c != null)
+                    c.discard();
+                return entry; // take the latest
+            }
+        };
+
+        entry = SharingHelper.resolveConflicts(entry, r, "jms");
+        sync = SharingHelper.getSync(entry);
+        conflicts = sync.getConflicts();
+        assertNull(conflicts);
+        assertEquals(4, sync.getHistory().size());
+
+    }
+
+    @Test
+    public void testUnpublish() throws Exception {
+
+        Abdera abdera = Abdera.getInstance();
+        Feed feed = abdera.newFeed();
+        Entry entry = feed.addEntry();
+        assertEquals(1, feed.getEntries().size());
+        entry = SharingHelper.unpublish(entry);
+        assertEquals(0, feed.getEntries().size());
+        Unpublished unpub = SharingHelper.getUnpublished(feed);
+        assertEquals(1, unpub.getEntries().size());
+        SharingHelper.republish(entry);
+        unpub = SharingHelper.getUnpublished(feed);
+        assertEquals(0, unpub.getEntries().size());
+        assertEquals(1, feed.getEntries().size());
+    }
+}

Propchange: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/ext/sharing/SharingTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/ext/thread/ThreadTest.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/test/src/main/java/org/apache/abdera2/test/ext/thread/ThreadTest.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/test/src/main/java/org/apache/abdera2/test/ext/thread/ThreadTest.java (added)
+++ abdera/abdera2/test/src/main/java/org/apache/abdera2/test/ext/thread/ThreadTest.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,51 @@
+/*
+ * 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.abdera2.test.ext.thread;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.ext.thread.InReplyTo;
+import org.apache.abdera2.ext.thread.ThreadConstants;
+import org.apache.abdera2.ext.thread.ThreadHelper;
+import org.apache.abdera2.factory.Factory;
+import org.apache.abdera2.model.Entry;
+import org.junit.Test;
+
+public class ThreadTest {
+
+    @Test
+    public void testThread() throws Exception {
+
+        Abdera abdera = Abdera.getInstance();
+        Factory factory = abdera.getFactory();
+        Entry e1 = factory.newEntry();
+        Entry e2 = factory.newEntry();
+
+        e1.setId("tag:example.org,2006:first");
+        e2.setId("tag:example.org,2006:second");
+
+        ThreadHelper.addInReplyTo(e2, e1); // e2 is a response to e1
+        assertNotNull(e2.getExtension(ThreadConstants.IN_REPLY_TO));
+        InReplyTo irt = e2.getExtension(ThreadConstants.IN_REPLY_TO);
+        assertEquals(e1.getId(), irt.getRef());
+
+    }
+
+}

Propchange: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/ext/thread/ThreadTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/factory/FactoryTest.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/test/src/main/java/org/apache/abdera2/test/factory/FactoryTest.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/test/src/main/java/org/apache/abdera2/test/factory/FactoryTest.java (added)
+++ abdera/abdera2/test/src/main/java/org/apache/abdera2/test/factory/FactoryTest.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,97 @@
+package org.apache.abdera2.test.factory;
+
+import static org.junit.Assert.assertNotNull;
+
+import javax.xml.namespace.QName;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.model.Content;
+import org.apache.abdera2.model.Element;
+import org.apache.abdera2.model.Entry;
+import org.apache.abdera2.model.ExtensibleElementWrapper;
+import org.apache.abdera2.model.Text;
+import org.apache.abdera2.common.Constants;
+import org.apache.abdera2.common.anno.Namespace;
+import org.apache.abdera2.ext.thread.Total;
+import org.apache.abdera2.factory.AbstractExtensionFactory;
+import org.apache.abdera2.factory.AbstractExtensionFactory.Impls;
+import org.apache.abdera2.factory.AbstractExtensionFactory.Impl;
+import org.apache.abdera2.factory.Factory;
+import org.junit.Test;
+
+public class FactoryTest {
+
+  @Test
+  public void factoryTest() {
+    Abdera abdera = Abdera.getInstance();
+    Factory factory = abdera.getFactory();
+    assertNotNull(factory.newEntry());
+    assertNotNull(factory.newAuthor());
+    assertNotNull(factory.newCategories());
+    assertNotNull(factory.newCategory());
+    assertNotNull(factory.newCollection());
+    assertNotNull(factory.newContent());
+    assertNotNull(factory.newContent(Content.Type.TEXT));
+    assertNotNull(factory.newContributor());
+    assertNotNull(factory.newControl());
+    assertNotNull(factory.newDefaultGenerator());
+    assertNotNull(factory.newDiv());
+    assertNotNull(factory.newDocument());
+    assertNotNull(factory.newEdited());
+    assertNotNull(factory.newElement(Constants.ENTRY));
+    assertNotNull(factory.newElement(Entry.class));
+    assertNotNull(factory.newEmail());
+    assertNotNull(factory.newExtensionElement(Total.class));
+    assertNotNull(factory.newExtensionElement(new QName("a","b")));
+    assertNotNull(factory.newFeed());
+    assertNotNull(factory.newGenerator());
+    assertNotNull(factory.newIcon());
+    assertNotNull(factory.newID());
+    assertNotNull(factory.newLink());
+    assertNotNull(factory.newLogo());
+    assertNotNull(factory.newName());
+    assertNotNull(factory.newParser());
+    assertNotNull(factory.newPublished());
+    assertNotNull(factory.newRights());
+    assertNotNull(factory.newRights(Text.Type.TEXT));
+    assertNotNull(factory.newService());
+    assertNotNull(factory.newSource());
+    assertNotNull(factory.newSubtitle());
+    assertNotNull(factory.newSummary());
+    assertNotNull(factory.newTitle());
+    assertNotNull(factory.newUpdated());
+    assertNotNull(factory.newUri());
+    assertNotNull(factory.newUuidUri());
+    assertNotNull(factory.newWorkspace());
+    assertNotNull(factory.listExtensionFactories());
+    
+  }
+  
+  @Test
+  public void extensionFactoryTest() {
+    Abdera abdera = Abdera.getInstance();
+    Factory factory = abdera.getFactory();
+    TestExtensionFactory tef = new TestExtensionFactory();
+    factory.registerExtension(tef);
+    TestExtension te = factory.newExtensionElement(TestExtension.class);
+    assertNotNull(te);
+    
+    Entry entry = abdera.newEntry();
+    te = entry.addExtension(TestExtension.class);
+    assertNotNull(te);
+  }
+  
+  @Namespace({"foo","b"})
+  @Impls(@Impl(TestExtension.class))
+  public static class TestExtensionFactory extends AbstractExtensionFactory {}
+
+  @org.apache.abdera2.common.anno.QName(value="a",ns="b")  
+  public static class TestExtension extends ExtensibleElementWrapper{
+    public TestExtension(Element internal) {
+      super(internal);
+    }
+    public TestExtension(Factory factory, QName qname) {
+      super(factory, qname);
+    }
+  }
+}

Propchange: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/factory/FactoryTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/EncodingTest.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/EncodingTest.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/EncodingTest.java (added)
+++ abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/EncodingTest.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,135 @@
+/*
+ * 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.abdera2.test.parser;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+import java.io.StringReader;
+import java.util.Date;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.common.io.Compression;
+import org.apache.abdera2.common.io.Compression.CompressionCodec;
+import org.apache.abdera2.model.Content;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Element;
+import org.apache.abdera2.model.Entry;
+import org.apache.abdera2.parser.Parser;
+import org.apache.abdera2.parser.ParserOptions;
+import org.apache.abdera2.writer.WriterOptions;
+import org.junit.Test;
+
+public class EncodingTest {
+
+    @Test
+    public void testContentEncoding() throws Exception {
+        Abdera abdera = Abdera.getInstance();
+        Entry entry = abdera.newEntry();
+        entry.setId("http://example.com/entry/1");
+        entry.setTitle("Whatever");
+        entry.setUpdated(new Date());
+        Content content = entry.getFactory().newContent(Content.Type.XML);
+        String s = "<x>" + new Character((char)224) + "</x>";
+        content.setValue(s);
+        content.setMimeType("application/xml+whatever");
+        entry.setContentElement(content);
+        assertNotNull(entry.getContent());
+        assertEquals(s, entry.getContent());
+    }
+
+    /**
+     * Passes if the test does not throw a parse exception
+     */
+    @Test
+    public void testCompressionCodec() throws Exception {
+        Abdera abdera = Abdera.getInstance();
+        Entry entry = abdera.newEntry();
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        OutputStream cout = Compression.wrap(out, new CompressionCodec[] {CompressionCodec.GZIP});
+        entry.writeTo(cout);
+        cout.close();
+        byte[] bytes = out.toByteArray();
+        ByteArrayInputStream in = new ByteArrayInputStream(bytes);
+        Parser parser = abdera.getParser();
+        ParserOptions options = parser.getDefaultParserOptions();
+        options.setCompressionCodecs(CompressionCodec.GZIP);
+        Document<Entry> doc = abdera.getParser().parse(in, null, options);
+        entry = doc.getRoot();
+    }
+
+    /**
+     * Passes if the test does not throw a parse exception
+     */
+    @Test
+    public void testXMLRestrictedChar() throws Exception {
+        String s = "<?xml version='1.1'?><t t='\u007f' />";
+        Abdera abdera = Abdera.getInstance();
+        Parser parser = abdera.getParser();
+        ParserOptions options = parser.getDefaultParserOptions();
+        options.setFilterRestrictedCharacters(true);
+        Document<Element> doc = parser.parse(new StringReader(s), null, options);
+        doc.getRoot().toString();
+    }
+
+    /**
+     * Passes if the test does not throw a parse exception
+     */
+    @Test
+    public void testXMLRestrictedChar2() throws Exception {
+        String s = "<?xml version='1.0'?><t t='\u0002' />";
+        Abdera abdera = Abdera.getInstance();
+        Parser parser = abdera.getParser();
+        ParserOptions options = parser.getDefaultParserOptions();
+        options.setFilterRestrictedCharacters(true);
+        options.setCharset("UTF-8");
+        Document<Element> doc = parser.parse(new ByteArrayInputStream(s.getBytes("UTF-8")), null, options);
+        doc.getRoot().toString();
+    }
+
+    /**
+     * Passes if the test does not throw any exceptions
+     */
+    @Test
+    public void testWriterOptions() throws Exception {
+        Abdera abdera = Abdera.getInstance();
+        Entry entry = abdera.newEntry();
+        entry.setTitle("1");
+
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        WriterOptions writeoptions = entry.getDefaultWriterOptions();
+        writeoptions.setCompressionCodecs(CompressionCodec.DEFLATE);
+        writeoptions.setCharset("UTF-16");
+        writeoptions.setAutoClose(true);
+        entry.getDocument().writeTo(out, writeoptions);
+        out.close();
+
+        byte[] bytes = out.toByteArray();
+
+        ByteArrayInputStream in = new ByteArrayInputStream(bytes);
+        Parser parser = abdera.getParser();
+        ParserOptions options = parser.getDefaultParserOptions();
+        options.setCompressionCodecs(CompressionCodec.DEFLATE);
+        Document<Entry> doc = abdera.getParser().parse(in, null, options);
+
+        doc.getRoot().toString();
+    }
+}

Propchange: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/EncodingTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/ParserTest.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/ParserTest.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/ParserTest.java (added)
+++ abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/ParserTest.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,57 @@
+package org.apache.abdera2.test.parser;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.StringReader;
+
+import javax.xml.namespace.QName;
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Element;
+import org.apache.abdera2.parser.Parser;
+import org.apache.abdera2.parser.ParserFactory;
+import org.apache.abdera2.parser.ParserOptions;
+import org.apache.abdera2.parser.filter.BlackListParseFilter;
+import org.junit.Test;
+
+public class ParserTest {
+
+  @Test
+  public void testParser() {
+    String s = "<a><b/>\u0000<c/></a>";
+    Abdera abdera = Abdera.getInstance();
+    Parser parser = abdera.getParser();
+    assertNotNull(parser);
+    ParserOptions options = parser.getDefaultParserOptions();
+    options.setFilterRestrictedCharacters(true);// invalid xml char will be filtered 
+    assertNotNull(options);
+    Document<Element> doc = parser.parse(new StringReader(s),options);
+    assertNotNull(doc);
+    Element root = doc.getRoot();
+    assertNotNull(root);
+    assertEquals("a", root.getQName().getLocalPart());
+    
+    Element d = root.getFirstChild();
+    assertEquals("b", d.getQName().getLocalPart());
+    
+    // Test Parse Filtering
+    BlackListParseFilter filter = new BlackListParseFilter();
+    filter.add(new QName("b"));
+    options.setParseFilter(filter);
+    
+    doc = parser.parse(new StringReader(s),options);
+    root = doc.getRoot();
+    Element c = root.getFirstChild();
+    assertEquals("c", c.getQName().getLocalPart());
+  }
+  
+  @Test
+  public void testParserFactory() {
+    Abdera abdera = Abdera.getInstance();
+    ParserFactory pf = abdera.getParserFactory();
+    Parser parser = pf.getParser("html");
+    assertNotNull(parser);
+  }
+  
+}

Propchange: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/ParserTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/ServiceDocumentTest.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/ServiceDocumentTest.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/ServiceDocumentTest.java (added)
+++ abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/ServiceDocumentTest.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,82 @@
+/*
+ * 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.abdera2.test.parser;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.StringWriter;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.factory.Factory;
+import org.apache.abdera2.model.Collection;
+import org.apache.abdera2.model.Service;
+import org.apache.abdera2.model.Workspace;
+import org.apache.abdera2.parser.axiom.FOMMultipartCollection;
+import org.junit.Test;
+
+public class ServiceDocumentTest {
+
+    /**
+     * Test whether the Service Document includes <accept> for collections.
+     */
+    @Test
+    public void testCollectionAccepts() throws Exception {
+        Abdera abdera = Abdera.getInstance();
+        Factory factory = abdera.getFactory();
+        Service svc = factory.newService();
+        Workspace ws = svc.addWorkspace("test-ws");
+        Collection coll = ws.addCollection("test-coll", ws.getTitle() + "/test-coll");
+        coll.setAcceptsEntry();
+        assertTrue("Collection does not accept entries.", coll.acceptsEntry());
+        coll.addAccepts("application/apples");
+        assertTrue("Collection does not accept apples.", coll.accepts("application/apples"));
+        StringWriter sw = new StringWriter();
+        svc.writeTo(sw);
+        // System.out.println(sw);
+        String s = sw.toString();
+        assertTrue("Service document does not specify acceptance of entries.", s
+            .contains("application/atom+xml; type=entry"));
+        assertTrue("Service document does not specify acceptance of apples.", s.contains("application/apples"));
+    }
+
+    /**
+     * Test whether the <accept> element includes the multipart attribute.
+     */
+    @Test
+    public void testCollectionAcceptsMultipart() throws Exception {
+        Abdera abdera = Abdera.getInstance();
+        Factory factory = abdera.getFactory();
+        Service svc = factory.newService();
+        Workspace ws = svc.addWorkspace("test-ws");
+        FOMMultipartCollection coll =
+            (FOMMultipartCollection)ws.addMultipartCollection("test multipart coll", "/test-coll");
+        coll.setAcceptsEntry();
+        coll.addAccepts("image/*", "multipart-related");
+
+        assertTrue("Collection does not accept entries.", coll.acceptsEntry());
+        assertTrue("Collection does not accept multipart related images", coll.acceptsMultipart("image/*"));
+
+        StringWriter sw = new StringWriter();
+        svc.writeTo(sw);
+
+        String s = sw.toString();
+        assertTrue("Service document does not specify acceptance of entries.", s
+            .contains("application/atom+xml; type=entry"));
+        assertTrue("Service document does not specify acceptance of apples.", s.contains("image/*"));
+    }
+}

Propchange: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/ServiceDocumentTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/axiom/AtomConformanceTest.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/axiom/AtomConformanceTest.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/axiom/AtomConformanceTest.java (added)
+++ abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/axiom/AtomConformanceTest.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,338 @@
+/*
+ * 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.abdera2.test.parser.axiom;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.abdera2.common.iri.IRI;
+import org.apache.abdera2.model.Content;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Entry;
+import org.apache.abdera2.model.Feed;
+import org.apache.abdera2.model.Link;
+import org.apache.abdera2.model.Text;
+import org.apache.axiom.om.OMElement;
+import org.junit.Test;
+
+public class AtomConformanceTest extends BaseParserTestCase {
+
+    /**
+     * Test to make sure that the parser properly detects the various kinds of extended content types allowed by Atom
+     */
+    @Test
+    public void testContentTypes() throws Exception {
+        IRI uri = new IRI("http://www.snellspace.com/public/contentsummary.xml");
+        Document<Feed> doc = parse(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
+     */
+    @Test
+    public void testXmlNamespace() throws Exception {
+        String[] tests =
+            {"http://www.snellspace.com/public/nondefaultnamespace.xml",
+             "http://www.snellspace.com/public/nondefaultnamespace2.xml",
+             "http://www.snellspace.com/public/nondefaultnamespace3.xml"};
+        int n = 1;
+        for (String test : tests) {
+            IRI uri = new IRI(test);
+            Document<Feed> doc = parse(uri);
+            assertNotNull(doc);
+            Feed feed = doc.getRoot();
+            Entry entry = feed.getEntries().get(0);
+            switch (n) {
+                case 1:
+                    assertNotNull(entry.getTitleElement());
+                    assertEquals(new IRI("tag:example.org,2007:bar"), entry.getIdElement().getValue());
+                    Text summary = entry.getSummaryElement();
+                    assertNotNull(summary);
+                    assertEquals(Text.Type.XHTML, summary.getTextType());
+                    OMElement element = (OMElement)summary;
+                    OMElement div = element.getFirstChildWithName(new QName("http://www.w3.org/1999/xhtml", "div"));
+                    assertNotNull(div);
+                    break;
+                case 2:
+                    assertNotNull(entry.getTitleElement());
+                    assertEquals(new IRI("tag:example.org,2007:bar"), entry.getIdElement().getValue());
+                    summary = entry.getSummaryElement();
+                    assertNotNull(summary);
+                    assertEquals(Text.Type.XHTML, summary.getTextType());
+                    element = (OMElement)summary;
+                    div = element.getFirstChildWithName(new QName("http://www.w3.org/1999/xhtml", "div"));
+                    assertNotNull(div);
+                    break;
+                case 3:
+                    assertNotNull(entry.getTitleElement());
+                    assertEquals(new IRI("tag:example.org,2007:bar"), entry.getIdElement().getValue());
+                    summary = entry.getSummaryElement();
+                    assertNotNull(summary);
+                    assertEquals(Text.Type.XHTML, summary.getTextType());
+                    element = (OMElement)summary;
+                    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
+     */
+    @Test
+    public void testXmlBase() throws Exception {
+        IRI uri = new IRI("http://www.snellspace.com/public/xmlbase.xml");
+        Document<Feed> doc = parse(uri);
+        assertNotNull(doc);
+        Feed feed = doc.getRoot();
+        assertEquals(new IRI("http://www.snellspace.com/public/xmlbase.xml"), feed.getBaseUri());
+        assertEquals(new IRI("http://www.snellspace.com/public/atom-logo.png"), feed.getLogoElement()
+            .getResolvedValue());
+        assertEquals(new IRI("http://www.snellspace.com/public/atom-icon.png"), feed.getIconElement()
+            .getResolvedValue());
+
+        Entry entry = feed.getEntries().get(0);
+        assertEquals("http://www.snellspace.com/wp", entry.getAlternateLinkResolvedHref().toString());
+    }
+
+    /**
+     * 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
+     */
+    @Test
+    public void testOrder() throws Exception {
+        // http://www.snellspace.com/public/ordertest.xml
+        IRI uri = new IRI("http://www.snellspace.com/public/ordertest.xml");
+        Document<Feed> doc = parse(uri);
+        assertNotNull(doc);
+        Feed feed = doc.getRoot();
+        List<Entry> entries = feed.getEntries();
+        int n = 1;
+        for (Entry entry : entries) {
+            switch (n) {
+                case 1:
+                    assertEquals(new IRI("tag:example.org,2006:atom/conformance/element_order/1"), entry.getIdElement()
+                        .getValue());
+                    assertEquals(Text.Type.TEXT, entry.getTitleType());
+                    assertEquals(Text.Type.TEXT, entry.getSummaryType());
+                    assertNotNull(entry.getUpdatedElement().getValue());
+                    assertEquals(1, entry.getLinks(Link.REL_ALTERNATE).size());
+                    break;
+                case 2:
+                    assertEquals(new IRI("tag:example.org,2006:atom/conformance/element_order/2"), entry.getIdElement()
+                        .getValue());
+                    assertEquals(Text.Type.TEXT, entry.getTitleType());
+                    assertEquals(Text.Type.TEXT, entry.getSummaryType());
+                    assertNotNull(entry.getUpdatedElement().getValue());
+                    assertEquals(1, entry.getLinks(Link.REL_ALTERNATE).size());
+                    break;
+                case 3:
+                    assertEquals(2, entry.getLinks(Link.REL_ALTERNATE).size());
+                    assertEquals(new IRI("http://www.snellspace.com/public/alternate"), entry
+                        .getLinks(Link.REL_ALTERNATE).get(0).getHref());
+                    assertEquals(new IRI("http://www.snellspace.com/public/alternate2"), entry
+                        .getLinks(Link.REL_ALTERNATE).get(1).getHref());
+                    break;
+                case 4:
+                    assertEquals(1, entry.getLinks(Link.REL_ALTERNATE).size());
+                    assertEquals(new IRI("http://www.snellspace.com/public/alternate"), entry
+                        .getLinks(Link.REL_ALTERNATE).get(0).getHref());
+                    break;
+                case 5:
+                    Text title = entry.getTitleElement();
+                    assertEquals(Text.Type.TEXT, entry.getTitleType());
+                    String value = title.getValue();
+                    assertEquals("Entry with a source first", value);
+                    assertEquals(1, entry.getLinks(Link.REL_ALTERNATE).size());
+                    assertEquals(new IRI("http://www.snellspace.com/public/alternate"), entry
+                        .getLinks(Link.REL_ALTERNATE).get(0).getHref());
+                    break;
+                case 6:
+                    title = entry.getTitleElement();
+                    assertEquals(Text.Type.TEXT, entry.getTitleType());
+                    value = title.getValue();
+                    assertEquals("Entry with a source last", value);
+                    assertEquals(1, entry.getLinks(Link.REL_ALTERNATE).size());
+                    assertEquals(new IRI("http://www.snellspace.com/public/alternate"), entry
+                        .getLinks(Link.REL_ALTERNATE).get(0).getHref());
+                    break;
+                case 7:
+                    title = entry.getTitleElement();
+                    assertEquals(Text.Type.TEXT, entry.getTitleType());
+                    value = title.getValue();
+                    assertEquals("Entry with a source in the middle", value);
+                    assertEquals(1, entry.getLinks(Link.REL_ALTERNATE).size());
+                    assertEquals(new IRI("http://www.snellspace.com/public/alternate"), entry
+                        .getLinks(Link.REL_ALTERNATE).get(0).getHref());
+                    break;
+                case 8:
+                    title = entry.getTitleElement();
+                    assertEquals(Text.Type.TEXT, entry.getTitleType());
+                    value = title.getValue();
+                    assertEquals("Atom elements in an extension element", value);
+                    assertEquals(new IRI("tag:example.org,2006:atom/conformance/element_order/8"), entry.getIdElement()
+                        .getValue());
+                    break;
+                case 9:
+                    title = entry.getTitleElement();
+                    assertEquals(Text.Type.TEXT, entry.getTitleType());
+                    value = title.getValue();
+                    assertEquals("Atom elements in an extension element", value);
+                    assertEquals(new IRI("tag:example.org,2006:atom/conformance/element_order/9"), entry.getIdElement()
+                        .getValue());
+                    break;
+            }
+            n++;
+        }
+    }
+
+    /**
+     * Tests the parsers support for the various link relation types
+     */
+    @Test
+    public void testLink() throws Exception {
+        // http://www.snellspace.com/public/linktests.xml
+        IRI uri = new IRI("http://www.snellspace.com/public/linktests.xml");
+        Document<Feed> doc = parse(uri);
+        assertNotNull(doc);
+        Feed feed = doc.getRoot();
+        List<Entry> entries = feed.getEntries();
+        int n = 1;
+        for (Entry entry : entries) {
+            switch (n) {
+                case 1:
+                    assertEquals(1, entry.getLinks(Link.REL_ALTERNATE).size());
+                    assertEquals(new IRI("http://www.snellspace.com/public/linktests/alternate"), entry
+                        .getLinks(Link.REL_ALTERNATE).get(0).getHref());
+                    break;
+                case 2:
+                    assertEquals(4, entry.getLinks(Link.REL_ALTERNATE).size());
+                    assertEquals(new IRI("http://www.snellspace.com/public/linktests/alternate"), entry
+                        .getLinks(Link.REL_ALTERNATE).get(1).getHref());
+                    assertEquals(new IRI("http://www.snellspace.com/public/linktests/alternate2"), entry
+                        .getLinks(Link.REL_ALTERNATE).get(2).getHref());
+                    break;
+                case 3:
+                    assertEquals(1, entry.getLinks(Link.REL_ALTERNATE).size());
+                    assertEquals(1, entry.getLinks(Link.REL_ENCLOSURE).size());
+                    assertEquals(1, entry.getLinks(Link.REL_RELATED).size());
+                    assertEquals(1, entry.getLinks(Link.REL_SELF).size());
+                    assertEquals(1, entry.getLinks(Link.REL_VIA).size());
+                    assertEquals(new IRI("http://www.snellspace.com/public/linktests/alternate"), entry
+                        .getLinks(Link.REL_ALTERNATE).get(0).getHref());
+                    assertEquals(new IRI("http://www.snellspace.com/public/linktests/enclosure"), entry
+                        .getLinks(Link.REL_ENCLOSURE).get(0).getHref());
+                    assertEquals(new IRI("http://www.snellspace.com/public/linktests/related"), entry
+                        .getLinks(Link.REL_RELATED).get(0).getHref());
+                    assertEquals(new IRI("http://www.snellspace.com/public/linktests/self"), entry
+                        .getLinks(Link.REL_SELF).get(0).getHref());
+                    assertEquals(new IRI("http://www.snellspace.com/public/linktests/via"), entry
+                        .getLinks(Link.REL_VIA).get(0).getHref());
+                    break;
+                case 4:
+                    assertEquals(2, entry.getLinks(Link.REL_ALTERNATE).size());
+                    assertEquals(1, entry.getLinks(Link.REL_ENCLOSURE).size());
+                    assertEquals(1, entry.getLinks(Link.REL_RELATED).size());
+                    assertEquals(1, entry.getLinks(Link.REL_SELF).size());
+                    assertEquals(1, entry.getLinks(Link.REL_VIA).size());
+                    assertEquals(new IRI("http://www.snellspace.com/public/linktests/alternate"), entry
+                        .getLinks(Link.REL_ALTERNATE).get(0).getHref());
+                    assertEquals(new IRI("http://www.snellspace.com/public/linktests/alternate2"), entry
+                        .getLinks(Link.REL_ALTERNATE).get(1).getHref());
+                    assertEquals(new IRI("http://www.snellspace.com/public/linktests/enclosure"), entry
+                        .getLinks(Link.REL_ENCLOSURE).get(0).getHref());
+                    assertEquals(new IRI("http://www.snellspace.com/public/linktests/related"), entry
+                        .getLinks(Link.REL_RELATED).get(0).getHref());
+                    assertEquals(new IRI("http://www.snellspace.com/public/linktests/self"), entry
+                        .getLinks(Link.REL_SELF).get(0).getHref());
+                    assertEquals(new IRI("http://www.snellspace.com/public/linktests/via"), entry
+                        .getLinks(Link.REL_VIA).get(0).getHref());
+                    break;
+                case 5:
+                    assertEquals(1, entry.getLinks(Link.REL_ALTERNATE).size());
+                    assertEquals(1, entry.getLinks(Link.REL_LICENSE).size());
+                    assertEquals(new IRI("http://www.snellspace.com/public/linktests/alternate"), entry
+                        .getLinks(Link.REL_ALTERNATE).get(0).getHref());
+                    assertEquals(new IRI("http://www.snellspace.com/public/linktests/license"), entry
+                        .getLinks(Link.REL_LICENSE).get(0).getHref());
+                    break;
+                case 6:
+                    assertEquals(1, entry.getLinks(Link.REL_ALTERNATE).size());
+                    assertEquals(1, entry.getLinks("http://example.org").size());
+                    assertEquals(new IRI("http://www.snellspace.com/public/linktests/alternate"), entry
+                        .getLinks(Link.REL_ALTERNATE).get(0).getHref());
+                    assertEquals(new IRI("http://www.snellspace.com/public/linktests/example"), entry
+                        .getLinks("http://example.org").get(0).getHref());
+                    break;
+            }
+            n++;
+        }
+    }
+}

Propchange: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/axiom/AtomConformanceTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/axiom/BaseParserTestCase.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/axiom/BaseParserTestCase.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/axiom/BaseParserTestCase.java (added)
+++ abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/axiom/BaseParserTestCase.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,52 @@
+/*
+ * 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.abdera2.test.parser.axiom;
+
+import java.io.InputStream;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.common.iri.IRI;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Element;
+import org.apache.abdera2.parser.Parser;
+
+public abstract class BaseParserTestCase {
+
+    private static Abdera abdera = Abdera.getInstance();
+
+    protected static Parser getParser() {
+        return abdera.getParser();
+    }
+
+    protected static <T extends Element> Document<T> parse(IRI uri) {
+        try {
+            String uriStr = uri.toString();
+            String path = uriStr.substring(uriStr.indexOf("//") + 1);
+            InputStream stream = BaseParserTestCase.class.getResourceAsStream(path);
+            return getParser().parse(stream, uri.toString());
+        } catch (Exception e) {
+            // when getting it local fails, fall back to getting it from the server
+            try {
+                return getParser().parse(uri.toURL().openStream(), uri.toString());
+            } catch (Exception ex) {
+            }
+        }
+        return null;
+    }
+
+}

Propchange: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/axiom/BaseParserTestCase.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/axiom/ConcurrencyTest.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/axiom/ConcurrencyTest.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/axiom/ConcurrencyTest.java (added)
+++ abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/axiom/ConcurrencyTest.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,83 @@
+/*
+ * 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.abdera2.test.parser.axiom;
+
+import static org.junit.Assert.fail;
+
+import java.io.InputStream;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.model.Content;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Entry;
+import org.apache.abdera2.parser.Parser;
+import org.junit.Test;
+
+/**
+ * Test possible concurrency issues.
+ * 
+ * @version $Id: ConcurrencyTest.java 951666 2010-06-05 07:44:32Z antelder $
+ */
+public class ConcurrencyTest {
+
+    private static final int N_THREADS = 100;
+
+    /**
+     * Test for a concurrency issue that caused a ConcurrentModificationException in Abdera 0.1.0 but seems to be fixed
+     * in 0.2. We leave the test here to prevent possible regressions.
+     */
+    @Test
+    public void testSetContentMT() throws Exception {
+        Thread t[] = new Thread[N_THREADS];
+        final boolean failed[] = new boolean[t.length];
+        for (int i = 0; i < t.length; ++i) {
+            final int j = i;
+            failed[i] = false;
+            Runnable r = new Runnable() {
+                public void run() {
+                    try {
+                        setContent();
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                        failed[j] = true;
+                        fail(e.toString());
+                    }
+                }
+            };
+            t[i] = new Thread(r);
+            t[i].start();
+        }
+        for (int i = 0; i < t.length; ++i) {
+            t[i].join();
+            if (failed[i]) {
+                fail("Thread " + t[i] + " failed.");
+            }
+        }
+    }
+
+    private void setContent() throws Exception {
+        Parser parser = Abdera.getInstance().create(Parser.class);
+        InputStream is = ParserTest.class.getResourceAsStream("/entry.xml");
+        Document<Entry> doc = parser.parse(is);
+        Entry entry = doc.getRoot();
+        Content content = entry.getFactory().newContent(Content.Type.XML);
+        content.setValue("<some><xml>document</xml></some>");
+        content.setMimeType("application/xml");
+        entry.setContentElement(content);
+    }
+}

Propchange: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/axiom/ConcurrencyTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/axiom/EntryLinkTest.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/axiom/EntryLinkTest.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/axiom/EntryLinkTest.java (added)
+++ abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/axiom/EntryLinkTest.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,61 @@
+/*
+ * 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.abdera2.test.parser.axiom;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.factory.Factory;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Entry;
+import org.apache.abdera2.model.Feed;
+import org.apache.abdera2.model.Link;
+import org.apache.abdera2.parser.Parser;
+import org.junit.Test;
+
+public class EntryLinkTest {
+
+    /**
+     * Link in entry disappears after adding entry to a feed.
+     * 
+     * @see https://issues.apache.org/jira/browse/ABDERA-70 FOM Objects should automatically complete the parse when
+     *      modifications are made
+     */
+    @Test
+    public void testEntryLinkInFeed() throws Exception {
+        Abdera abdera = org.apache.abdera2.Abdera.getInstance();
+        Factory factory = abdera.getFactory();
+        Feed feed = factory.newFeed();
+        feed.setTitle("Test");
+        feed.setId("http://example.com/feed");
+        Parser parser = abdera.getParser();
+        Document<Entry> doc = parser.parse(this.getClass().getResourceAsStream("/entry.xml"));
+        Entry entry = doc.getRoot();
+
+        Link link = factory.newLink();
+        link.setHref(entry.getId().toString());
+        link.setRel(Link.REL_EDIT);
+        entry.addLink(link);
+        assertNotNull("Link is null", entry.getLink(Link.REL_EDIT));
+        feed.addEntry(entry);
+        assertNotNull("Link is null", entry.getLink(Link.REL_EDIT));
+        for (Entry e : feed.getEntries()) {
+            assertNotNull("Link is null", e.getLink(Link.REL_EDIT));
+        }
+    }
+}

Propchange: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/axiom/EntryLinkTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/axiom/FOMDivTest.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/axiom/FOMDivTest.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/axiom/FOMDivTest.java (added)
+++ abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/axiom/FOMDivTest.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,28 @@
+package org.apache.abdera2.test.parser.axiom;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.InputStream;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Entry;
+import org.apache.abdera2.model.Text;
+import org.junit.Test;
+
+public class FOMDivTest {
+    
+    @Test
+    public void getInternalValueWithUtf8Characters (){
+        Abdera abdera = Abdera.getInstance();
+        InputStream in = FOMTest.class.getResourceAsStream("/utf8characters.xml");
+        Document<Entry> doc = abdera.getParser().parse(in);
+        Entry entry = doc.getRoot();
+
+        assertEquals("Item", entry.getTitle());
+        assertEquals(Text.Type.TEXT, entry.getTitleType());
+        String value = entry.getContentElement().getValue();
+        assertTrue(value.contains("\u0200\u0201"));
+    }
+}

Propchange: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/axiom/FOMDivTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message