abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r1173209 [47/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
Propchange: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/axiom/FeedValidatorTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/axiom/ParserTest.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/axiom/ParserTest.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/axiom/ParserTest.java (added)
+++ abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/axiom/ParserTest.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,101 @@
+/*
+ * 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.assertTrue;
+
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Entry;
+import org.apache.abdera2.model.Feed;
+import org.apache.abdera2.model.Service;
+import org.apache.abdera2.parser.Parser;
+import org.junit.Test;
+
+public class ParserTest {
+
+    private static Abdera abdera = Abdera.getInstance();
+
+    private static Parser getParser() {
+        return abdera.getParser();
+    }
+
+    @Test
+    public void testParse() throws Exception {
+
+        Document<Feed> feedDoc = getParser().parse(ParserTest.class.getResourceAsStream("/simpleFeed.xml"));
+        assertTrue(feedDoc.getRoot() instanceof Feed);
+        assertEquals("utf-8", feedDoc.getCharset());
+
+        Document<Entry> entryDoc = getParser().parse(ParserTest.class.getResourceAsStream("/simpleEntry.xml"));
+        assertTrue(entryDoc.getRoot() instanceof Entry);
+        assertEquals("utf-8", entryDoc.getCharset());
+
+        Document<Service> serviceDoc = getParser().parse(ParserTest.class.getResourceAsStream("/simpleService.xml"));
+        assertTrue(serviceDoc.getRoot() instanceof Service);
+        assertEquals("utf-8", serviceDoc.getCharset());
+
+    }
+
+    @Test
+    public void testParseReader() throws Exception {
+
+        InputStream is = ParserTest.class.getResourceAsStream("/simpleFeed.xml");
+        Document<Feed> feedDoc = getParser().parse(new InputStreamReader(is), getResourceName("/simpleEntry.xml"));
+        assertTrue(feedDoc.getRoot() instanceof Feed);
+        assertEquals("utf-8", feedDoc.getCharset());
+
+        is = ParserTest.class.getResourceAsStream("/simpleEntry.xml");
+        Document<Entry> entryDoc = getParser().parse(new InputStreamReader(is), getResourceName("/simpleEntry.xml"));
+        assertTrue(entryDoc.getRoot() instanceof Entry);
+        assertEquals("utf-8", entryDoc.getCharset());
+
+        is = ParserTest.class.getResourceAsStream("/simpleService.xml");
+        Document<Service> serviceDoc =
+            getParser().parse(new InputStreamReader(is), getResourceName("/simpleEntry.xml"));
+        assertTrue(serviceDoc.getRoot() instanceof Service);
+        assertEquals("utf-8", serviceDoc.getCharset());
+
+    }
+
+    private static String getResourceName(String name) {
+        return ParserTest.class.getResource(name).toExternalForm().replaceAll(" ", "%20");
+    }
+
+    /**
+     * Test for ABDERA-22.
+     * 
+     * @see https://issues.apache.org/jira/browse/ABDERA-22
+     */
+    @Test
+    public void testParseReaderNoBase() throws Exception {
+
+        InputStream is = ParserTest.class.getResourceAsStream("/simpleEntry.xml");
+        Reader reader = new InputStreamReader(is);
+        Document<Entry> entryDoc = getParser().parse(reader);
+        assertTrue(entryDoc.getRoot() instanceof Entry);
+        assertEquals("utf-8", entryDoc.getCharset());
+
+    }
+
+}

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

Added: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/axiom/XhtmlTest.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/axiom/XhtmlTest.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/axiom/XhtmlTest.java (added)
+++ abdera/abdera2/test/src/main/java/org/apache/abdera2/test/parser/axiom/XhtmlTest.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,65 @@
+/*
+ * 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 org.apache.abdera2.Abdera;
+import org.apache.abdera2.model.Content;
+import org.apache.abdera2.model.Div;
+import org.apache.abdera2.model.Element;
+import org.apache.abdera2.model.Entry;
+import org.junit.Test;
+
+public class XhtmlTest {
+
+    @Test
+    public void testXhtml() throws Exception {
+
+        Abdera abdera = Abdera.getInstance();
+        Entry entry = abdera.newEntry();
+        entry.setContentAsXhtml("<p>Test</p>");
+        assertNotNull(entry.getContent());
+        assertEquals(Content.Type.XHTML, entry.getContentType());
+        Element el = entry.getContentElement().getValueElement();
+        assertTrue(el instanceof Div);
+
+        entry = abdera.newEntry();
+        entry.setContent("<a><b><c/></b></a>", Content.Type.XML);
+        assertNotNull(entry.getContent());
+        assertEquals(Content.Type.XML, entry.getContentType());
+        assertNotNull(entry.getContentElement().getValueElement());
+
+    }
+
+    @Test
+    public void testSpecialCharacters() {
+        Abdera abdera = Abdera.getInstance();
+        Entry entry = abdera.newEntry();
+        entry.setContentAsXhtml("<p>&Auml;sthetik</p>");
+        assertNotNull(entry.getContent());
+        assertEquals(Content.Type.XHTML, entry.getContentType());
+        Element el = entry.getContentElement().getValueElement();
+        char umlaut = ((Element)el.getFirstChild()).getText().charAt(0);
+        // hexadecimal value of &Auml; is U+00C4
+        assertEquals("c4", Integer.toHexString(umlaut));
+    }
+
+}

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

Added: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/protocol/error/ErrorTest.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/test/src/main/java/org/apache/abdera2/test/protocol/error/ErrorTest.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/test/src/main/java/org/apache/abdera2/test/protocol/error/ErrorTest.java (added)
+++ abdera/abdera2/test/src/main/java/org/apache/abdera2/test/protocol/error/ErrorTest.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,18 @@
+package org.apache.abdera2.test.protocol.error;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.protocol.error.Error;
+import org.apache.abdera2.protocol.error.AbderaProtocolException;
+import org.junit.Test;
+
+public class ErrorTest {
+
+  @Test(expected=AbderaProtocolException.class)
+  public void errorTest() {
+    Abdera abdera = Abdera.getInstance();
+    Error error = Error.create(abdera,10,"foo");
+    AbderaProtocolException pe = new AbderaProtocolException(error);
+    throw pe;
+  }
+  
+}

Propchange: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/protocol/error/ErrorTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/protocol/pusher/PusherTest.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/test/src/main/java/org/apache/abdera2/test/protocol/pusher/PusherTest.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/test/src/main/java/org/apache/abdera2/test/protocol/pusher/PusherTest.java (added)
+++ abdera/abdera2/test/src/main/java/org/apache/abdera2/test/protocol/pusher/PusherTest.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,45 @@
+package org.apache.abdera2.test.protocol.pusher;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+
+import org.apache.abdera2.common.pusher.ChannelManager;
+import org.apache.abdera2.common.pusher.Listener;
+import org.apache.abdera2.common.pusher.Pusher;
+import org.apache.abdera2.common.pusher.Receiver;
+import org.apache.abdera2.common.pusher.SimpleChannelManager;
+import org.junit.Test;
+
+public class PusherTest {
+
+  @Test
+  public void pusherTest() throws Exception {
+    final ChannelManager cm = new SimpleChannelManager();
+    Executor exec = Executors.newCachedThreadPool();
+    final CountDownLatch latch = new CountDownLatch(3);
+    exec.execute(
+      new Runnable() {
+        public void run() {
+          Receiver<String> r = cm.getReceiver("foo");
+          r.startListening(
+            new Listener<String>() {
+              public void beforeItems() {}
+              public void onItem(String t) {
+                latch.countDown();
+              }
+              public void afterItems() {}
+            }
+          );
+        }
+      }
+    );
+    Pusher<String> pusher = cm.getPusher("foo");
+    pusher.push("a");
+    pusher.push("b");
+    pusher.push("c");
+    latch.await();
+    cm.shutdown();
+  }
+  
+}

Propchange: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/protocol/pusher/PusherTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/security/DigitalSignatureTest.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/test/src/main/java/org/apache/abdera2/test/security/DigitalSignatureTest.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/test/src/main/java/org/apache/abdera2/test/security/DigitalSignatureTest.java (added)
+++ abdera/abdera2/test/src/main/java/org/apache/abdera2/test/security/DigitalSignatureTest.java Tue Sep 20 15:56:46 2011
@@ -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.abdera2.test.security;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.security.KeyStore;
+import java.security.PrivateKey;
+import java.security.cert.X509Certificate;
+
+import javax.xml.namespace.QName;
+
+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.security.Security;
+import org.apache.abdera2.security.Signature;
+import org.apache.abdera2.security.SignatureOptions;
+import org.junit.Test;
+
+public class DigitalSignatureTest {
+
+    private static final String keystoreFile = "/key.jks";
+    private static final String keystoreType = "JKS";
+    private static final String keystorePass = "testing";
+    private static final String privateKeyAlias = "James";
+    private static final String privateKeyPass = "testing";
+    private static final String certificateAlias = "James";
+
+    @Test
+    public void testSignEntry() throws Exception {
+
+        // Initialize the keystore
+        KeyStore ks = KeyStore.getInstance(keystoreType);
+        assertNotNull(ks);
+
+        InputStream in = DigitalSignatureTest.class.getResourceAsStream(keystoreFile);
+        assertNotNull(in);
+
+        ks.load(in, keystorePass.toCharArray());
+        PrivateKey signingKey = (PrivateKey)ks.getKey(privateKeyAlias, privateKeyPass.toCharArray());
+        X509Certificate cert = (X509Certificate)ks.getCertificate(certificateAlias);
+        assertNotNull(signingKey);
+        assertNotNull(cert);
+
+        // Create the entry to sign
+        Abdera abdera = Abdera.getInstance();
+        Security absec = new Security(abdera);
+        Factory factory = abdera.getFactory();
+
+        Entry entry = factory.newEntry();
+        entry.setId("http://example.org/foo/entry");
+        entry.setUpdated(new java.util.Date());
+        entry.setTitle("This is an entry");
+        entry.setContentAsXhtml("This <b>is</b> <i>markup</i>");
+        entry.addAuthor("James");
+        entry.addLink("http://www.example.org");
+
+        // Prepare the digital signature options
+        Signature sig = absec.getSignature();
+        SignatureOptions options = sig.getDefaultSignatureOptions();
+        options.setCertificate(cert);
+        options.setSigningKey(signingKey);
+
+        // Sign the entry
+        entry = sig.sign(entry, options);
+        assertNotNull(entry.getFirstChild(new QName("http://www.w3.org/2000/09/xmldsig#", "Signature")));
+
+        X509Certificate[] certs = sig.getValidSignatureCertificates(entry, options);
+        assertNotNull(certs);
+        assertEquals(1, certs.length);
+        assertEquals("CN=James M Snell, OU=WebAhead, O=IBM, L=Hanford, ST=California, C=US", certs[0].getSubjectDN()
+            .getName());
+
+        // Check the round trip
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        entry.writeTo(out); // do not use the pretty writer, it will break the signature
+        ByteArrayInputStream bais = new ByteArrayInputStream(out.toByteArray());
+        Document<Entry> entry_doc = abdera.getParser().parse(bais);
+        entry = entry_doc.getRoot();
+        assertTrue(sig.verify(entry, null)); // the signature better still be valid
+
+        entry.setTitle("Change the title");
+
+        assertFalse(sig.verify(entry, null)); // the signature better be invalid
+
+    }
+
+}

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

Added: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/security/EncryptionTest.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/test/src/main/java/org/apache/abdera2/test/security/EncryptionTest.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/test/src/main/java/org/apache/abdera2/test/security/EncryptionTest.java (added)
+++ abdera/abdera2/test/src/main/java/org/apache/abdera2/test/security/EncryptionTest.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,96 @@
+/*
+ * 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.security;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.security.Provider;
+
+import javax.crypto.KeyGenerator;
+import javax.crypto.SecretKey;
+import javax.xml.namespace.QName;
+
+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.security.Security;
+import org.apache.abdera2.security.Encryption;
+import org.apache.abdera2.security.EncryptionOptions;
+import org.junit.Test;
+
+public class EncryptionTest {
+
+    /**
+     * The bouncy castle JCE provider is required to run this test
+     */
+    @Test
+    public void testEncryption() throws Exception {
+
+        Abdera abdera = Abdera.getInstance();
+
+        try {
+            String jce =
+                abdera.getConfiguration().getConfigurationOption("jce.provider",
+                                                                 "org.bouncycastle.jce.provider.BouncyCastleProvider");
+            Class<?> provider = Class.forName(jce);
+            Provider p = (Provider)provider.newInstance();
+            java.security.Security.addProvider(p);
+        } catch (Exception e) {
+            // the configured jce provider is not available, try to proceed anyway
+        }
+
+        // Generate Encryption Key
+        String jceAlgorithmName = "AES";
+        KeyGenerator keyGenerator = KeyGenerator.getInstance(jceAlgorithmName);
+        keyGenerator.init(128);
+        SecretKey key = keyGenerator.generateKey();
+
+        // Create the entry to encrypt
+        Security absec = new Security(abdera);
+        Factory factory = abdera.getFactory();
+
+        Entry entry = factory.newEntry();
+        entry.setId("http://example.org/foo/entry");
+        entry.setUpdated(new java.util.Date());
+        entry.setTitle("This is an entry");
+        entry.setContentAsXhtml("This <b>is</b> <i>markup</i>");
+        entry.addAuthor("James");
+        entry.addLink("http://www.example.org");
+
+        // Prepare the encryption options
+        Encryption enc = absec.getEncryption();
+        EncryptionOptions options = enc.getDefaultEncryptionOptions();
+        options.setDataEncryptionKey(key);
+
+        // Encrypt the document using the generated key
+        Document<?> enc_doc = enc.encrypt(entry.getDocument(), options);
+
+        assertEquals(new QName("http://www.w3.org/2001/04/xmlenc#", "EncryptedData"), enc_doc.getRoot().getQName());
+
+        // Decrypt the document using the generated key
+        Document<Entry> entry_doc = enc.decrypt(enc_doc, options);
+
+        assertTrue(entry_doc.getRoot() instanceof Entry);
+
+        assertEquals("http://example.org/foo/entry", entry_doc.getRoot().getId().toString());
+
+    }
+
+}

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

Added: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/security/filter/CustomProvider.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/test/src/main/java/org/apache/abdera2/test/security/filter/CustomProvider.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/test/src/main/java/org/apache/abdera2/test/security/filter/CustomProvider.java (added)
+++ abdera/abdera2/test/src/main/java/org/apache/abdera2/test/security/filter/CustomProvider.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,74 @@
+/*
+ * 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.security.filter;
+
+import org.apache.abdera2.common.protocol.RequestContext;
+import org.apache.abdera2.common.protocol.RouteManager;
+import org.apache.abdera2.common.protocol.TargetType;
+import org.apache.abdera2.protocol.server.AtompubCollectionAdapter;
+import org.apache.abdera2.protocol.server.impl.AbstractAtompubWorkspaceProvider;
+import org.apache.abdera2.protocol.server.impl.SimpleWorkspaceInfo;
+import org.apache.abdera2.security.util.filters.SignedRequestFilter;
+import org.apache.abdera2.security.util.filters.SignedResponseFilter;
+
+public class CustomProvider 
+  extends AbstractAtompubWorkspaceProvider {
+
+    private final SimpleAdapter adapter;
+
+    private static final String keystoreFile = "/key.jks";
+    private static final String keystorePass = "testing";
+    private static final String privateKeyAlias = "James";
+    private static final String privateKeyPass = "testing";
+    private static final String certificateAlias = "James";
+
+    @SuppressWarnings({ "rawtypes", "unchecked" })
+    public CustomProvider() {
+
+        this.adapter = new SimpleAdapter();
+
+        RouteManager rm =
+            new RouteManager()
+              .addRoute("service", "/", TargetType.TYPE_SERVICE)
+              .addRoute("collection","/:collection",TargetType.TYPE_COLLECTION)
+              .addRoute("entry", "/:collection/:entry", TargetType.TYPE_ENTRY);
+
+        setTargetBuilder(rm);
+        setTargetResolver(rm);
+
+        SimpleWorkspaceInfo workspace = new SimpleWorkspaceInfo();
+        workspace.setTitle("A Simple Workspace");
+        workspace.addCollection(adapter);
+        addWorkspace(workspace);
+
+        addFilter(
+          new SignedRequestFilter());
+        addFilter(new SignedResponseFilter(
+              keystoreFile, 
+              keystorePass, 
+              privateKeyAlias,
+              privateKeyPass, 
+              certificateAlias, 
+              null));
+    }
+
+    public AtompubCollectionAdapter getCollectionAdapter(RequestContext request) {
+        return adapter;
+    }
+
+}

Propchange: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/security/filter/CustomProvider.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/security/filter/JettyServer.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/test/src/main/java/org/apache/abdera2/test/security/filter/JettyServer.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/test/src/main/java/org/apache/abdera2/test/security/filter/JettyServer.java (added)
+++ abdera/abdera2/test/src/main/java/org/apache/abdera2/test/security/filter/JettyServer.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,62 @@
+/*
+ * 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.security.filter;
+
+import org.apache.abdera2.common.protocol.Provider;
+import org.apache.abdera2.common.protocol.servlet.AbderaServlet;
+import org.apache.abdera2.protocol.server.AtompubServiceManager;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.servlet.ServletHolder;
+
+
+public class JettyServer {
+
+    public static final int DEFAULT_PORT = 9002;
+
+    private final int port;
+    private Server server;
+
+    public JettyServer() {
+        this(DEFAULT_PORT);
+    }
+
+    public JettyServer(int port) {
+        this.port = port;
+    }
+
+    public void start(Class<? extends Provider> _class) throws Exception {
+        server = new Server(port);
+        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
+        context.setContextPath("/");
+        server.setHandler(context);
+        ServletHolder servletHolder = new ServletHolder(new AbderaServlet());
+        servletHolder.setInitParameter(AtompubServiceManager.PROVIDER, _class.getName());
+        context.addServlet(servletHolder, "/*");
+        server.start();
+    }
+
+    public void stop() throws Exception {
+        server.stop();
+    }
+
+    public void join() throws Exception {
+        server.join();
+    }
+
+}

Propchange: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/security/filter/JettyServer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/security/filter/SecurityFilterTest.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/test/src/main/java/org/apache/abdera2/test/security/filter/SecurityFilterTest.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/test/src/main/java/org/apache/abdera2/test/security/filter/SecurityFilterTest.java (added)
+++ abdera/abdera2/test/src/main/java/org/apache/abdera2/test/security/filter/SecurityFilterTest.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,125 @@
+/*
+ * 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.security.filter;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.InputStream;
+import java.security.KeyStore;
+import java.security.PrivateKey;
+import java.security.cert.X509Certificate;
+import java.util.Date;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.common.http.ResponseType;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Element;
+import org.apache.abdera2.model.Entry;
+import org.apache.abdera2.protocol.client.AbderaClient;
+import org.apache.abdera2.protocol.client.AbderaClientResponse;
+import org.apache.abdera2.protocol.client.AbderaSession;
+import org.apache.abdera2.security.Security;
+import org.apache.abdera2.security.Signature;
+import org.apache.abdera2.security.SignatureOptions;
+import org.apache.abdera2.test.security.DigitalSignatureTest;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class SecurityFilterTest {
+
+    private static JettyServer server;
+    private static Abdera abdera = Abdera.getInstance();
+    private static AbderaClient client = new AbderaClient(abdera);
+    
+    @BeforeClass
+    public static void setUp() throws Exception {
+        try {
+
+            server = new JettyServer();
+            server.start(CustomProvider.class);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    @AfterClass
+    public static void tearDown() throws Exception {
+        server.stop();
+    }
+
+    @Test
+    public void testSignedResponseFilter() throws Exception {
+        Document<Element> doc = client.get("http://localhost:9002/");
+        Element root = doc.getRoot();
+        Security security = new Security(abdera);
+        Signature sig = security.getSignature();
+        assertTrue(sig.isSigned(root));
+        assertTrue(sig.verify(root, sig.getDefaultSignatureOptions()));
+    }
+
+    private static final String keystoreFile = "/key.jks";
+    private static final String keystoreType = "JKS";
+    private static final String keystorePass = "testing";
+    private static final String privateKeyAlias = "James";
+    private static final String privateKeyPass = "testing";
+    private static final String certificateAlias = "James";
+
+    @Test
+    public void testSignedRequestFilter() throws Exception {
+        Entry entry = abdera.newEntry();
+        entry.setId("http://localhost:9002/feed/entries/1");
+        entry.setTitle("test entry");
+        entry.setContent("Test Content");
+        entry.addLink("http://example.org");
+        entry.setUpdated(new Date());
+        entry.addAuthor("James");
+        AbderaSession session = (AbderaSession) client.newSession();
+        AbderaClientResponse resp = (AbderaClientResponse) session.post("http://localhost:9002/feed", entry);
+        assertNotNull(resp);
+        assertEquals(ResponseType.CLIENT_ERROR, resp.getType());
+
+        // Initialize the keystore
+        Security security = new Security(abdera);
+        KeyStore ks = KeyStore.getInstance(keystoreType);
+        assertNotNull(ks);
+
+        InputStream in = DigitalSignatureTest.class.getResourceAsStream(keystoreFile);
+        assertNotNull(in);
+
+        ks.load(in, keystorePass.toCharArray());
+        PrivateKey signingKey = (PrivateKey)ks.getKey(privateKeyAlias, privateKeyPass.toCharArray());
+        X509Certificate cert = (X509Certificate)ks.getCertificate(certificateAlias);
+        assertNotNull(signingKey);
+        assertNotNull(cert);
+
+        Signature sig = security.getSignature();
+        SignatureOptions options = sig.getDefaultSignatureOptions();
+        options.setCertificate(cert);
+        options.setSigningKey(signingKey);
+
+        // Sign the entry
+        entry = sig.sign(entry, options);
+        resp = (AbderaClientResponse) session.post("http://localhost:9002/feed", entry);
+        assertNotNull(resp);
+        assertEquals(ResponseType.SUCCESSFUL, resp.getType());
+        client.shutdown();
+    }
+}

Propchange: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/security/filter/SecurityFilterTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/security/filter/SimpleAdapter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/test/src/main/java/org/apache/abdera2/test/security/filter/SimpleAdapter.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/test/src/main/java/org/apache/abdera2/test/security/filter/SimpleAdapter.java (added)
+++ abdera/abdera2/test/src/main/java/org/apache/abdera2/test/security/filter/SimpleAdapter.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,220 @@
+/*
+ * 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.security.filter;
+
+import java.io.IOException;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.common.Constants;
+import org.apache.abdera2.common.protocol.RequestContext;
+import org.apache.abdera2.common.protocol.RequestContext.Scope;
+import org.apache.abdera2.common.protocol.ResponseContext;
+import org.apache.abdera2.common.protocol.ProviderHelper;
+import org.apache.abdera2.common.protocol.ResponseContextException;
+import org.apache.abdera2.common.protocol.TargetType;
+import org.apache.abdera2.common.text.UrlEncoding;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Entry;
+import org.apache.abdera2.model.Feed;
+import org.apache.abdera2.parser.ParseException;
+import org.apache.abdera2.protocol.server.context.AtompubRequestContext;
+import org.apache.abdera2.protocol.server.context.FOMResponseContext;
+import org.apache.abdera2.protocol.server.context.StreamWriterResponseContext;
+import org.apache.abdera2.protocol.server.impl.AbstractAtompubCollectionAdapter;
+import org.apache.abdera2.protocol.server.impl.AbstractAtompubProvider;
+import org.apache.abdera2.writer.StreamWriter;
+
+@SuppressWarnings("unchecked")
+public class SimpleAdapter extends AbstractAtompubCollectionAdapter {
+
+    @Override
+    public String getAuthor(RequestContext request) throws ResponseContextException {
+        return "Simple McGee";
+    }
+
+    @Override
+    public String getId(RequestContext request) {
+        return "tag:example.org,2008:feed";
+    }
+
+    public String getHref(RequestContext request) {
+        Map<String, Object> params = new HashMap<String, Object>();
+        params.put("collection", "feed");
+        return request.urlFor("feed", params);
+    }
+
+    public String getTitle(RequestContext request) {
+        return "A simple feed";
+    }
+
+    public ResponseContext extensionRequest(RequestContext request) {
+        return ProviderHelper.notallowed(request, "Method Not Allowed", ProviderHelper.getDefaultMethods(request));
+    }
+
+    private Document<Feed> getFeedDocument(RequestContext context) throws ResponseContextException {
+        Feed feed = (Feed)context.getAttribute(Scope.SESSION, "feed");
+        if (feed == null) {
+            feed = createFeedBase(context);
+            feed.setBaseUri(getHref(context));
+            context.setAttribute(Scope.SESSION, "feed", feed);
+        }
+        return feed.getDocument();
+    }
+
+    public ResponseContext getItemList(RequestContext request) {
+        Document<Feed> feed;
+        try {
+            feed = getFeedDocument(request);
+        } catch (ResponseContextException e) {
+            return e.getResponseContext();
+        }
+
+        return AbstractAtompubProvider.returnBase(feed, 200, feed.getRoot().getUpdated()).setEntityTag(AbstractAtompubProvider
+            .calculateEntityTag(feed.getRoot()));
+    }
+
+    public ResponseContext deleteItem(RequestContext request) {
+        Entry entry = getAbderaEntry(request);
+        if (entry != null)
+            entry.discard();
+        return ProviderHelper.nocontent();
+    }
+
+    public ResponseContext getItem(RequestContext request) {
+        Entry entry = (Entry)getAbderaEntry(request);
+        if (entry != null) {
+            Feed feed = entry.getParentElement();
+            entry = (Entry)entry.clone();
+            entry.setSource(feed.getAsSource());
+            Document<Entry> entry_doc = entry.getDocument();
+            return AbstractAtompubProvider.returnBase(entry_doc, 200, entry.getEdited()).setEntityTag(AbstractAtompubProvider
+                .calculateEntityTag(entry));
+        } else {
+            return ProviderHelper.notfound(request);
+        }
+    }
+
+    private static Abdera getAbdera(RequestContext request) {
+      return AbstractAtompubProvider.getAbdera(request);
+    }
+    
+    public ResponseContext postItem(RequestContext context) {
+        Abdera abdera = getAbdera(context);
+        AtompubRequestContext request = (AtompubRequestContext) context;
+        try {
+            Document<Entry> entry_doc = (Document<Entry>)request.getDocument(abdera.getParser()).clone();
+            if (entry_doc != null) {
+                Entry entry = entry_doc.getRoot();
+                if (!AbstractAtompubProvider.isValidEntry(entry))
+                    return ProviderHelper.badrequest(request);
+                setEntryDetails(request, entry, abdera.getFactory().newUuidUri());
+                Feed feed = getFeedDocument(request).getRoot();
+                feed.insertEntry(entry);
+                feed.setUpdated(new Date());
+                FOMResponseContext<?> rc =
+                    (FOMResponseContext<?>)AbstractAtompubProvider.returnBase(entry_doc, 201, entry.getEdited());
+                return rc.setLocation(ProviderHelper.resolveBase(request).resolve(entry.getEditLinkResolvedHref())
+                    .toString()).setContentLocation(rc.getLocation().toString()).setEntityTag(AbstractAtompubProvider
+                    .calculateEntityTag(entry));
+            } else {
+                return ProviderHelper.badrequest(request);
+            }
+        } catch (ParseException pe) {
+            return ProviderHelper.notsupported(request);
+        } catch (ClassCastException cce) {
+            return ProviderHelper.notsupported(request);
+        } catch (Exception e) {
+            return ProviderHelper.badrequest(request);
+        }
+    }
+
+    private void setEntryDetails(RequestContext request, Entry entry, String id) {
+        entry.setUpdated(new Date());
+        entry.setEdited(entry.getUpdated());
+        entry.getIdElement().setValue(id);
+        entry.addLink(getEntryLink(request, entry.getId().toASCIIString()), "edit");
+    }
+
+    private String getEntryLink(RequestContext request, String entryid) {
+        Map<String, String> params = new HashMap<String, String>();
+        params.put("collection", request.getTarget().getParameter("collection"));
+        params.put("entry", entryid);
+        return request.urlFor("entry", params);
+    }
+
+    public ResponseContext putItem(RequestContext context) {
+        Abdera abdera = getAbdera(context);
+        AtompubRequestContext request = (AtompubRequestContext) context;
+        Entry orig_entry = getAbderaEntry(request);
+        if (orig_entry != null) {
+            try {
+                Document<Entry> entry_doc = (Document<Entry>)request.getDocument(abdera.getParser()).clone();
+                if (entry_doc != null) {
+                    Entry entry = entry_doc.getRoot();
+                    if (!entry.getId().equals(orig_entry.getId()))
+                        return ProviderHelper.conflict(request);
+                    if (!AbstractAtompubProvider.isValidEntry(entry))
+                        return ProviderHelper.badrequest(request);
+                    setEntryDetails(request, entry, orig_entry.getId().toString());
+                    orig_entry.discard();
+                    Feed feed = getFeedDocument(request).getRoot();
+                    feed.insertEntry(entry);
+                    feed.setUpdated(new Date());
+                    return ProviderHelper.nocontent();
+                } else {
+                    return ProviderHelper.badrequest(request);
+                }
+            } catch (ParseException pe) {
+                return ProviderHelper.notsupported(request);
+            } catch (ClassCastException cce) {
+                return ProviderHelper.notsupported(request);
+            } catch (Exception e) {
+                return ProviderHelper.badrequest(request);
+            }
+        } else {
+            return ProviderHelper.notfound(request);
+        }
+    }
+
+    private Entry getAbderaEntry(RequestContext request) {
+        try {
+            return getFeedDocument(request).getRoot().getEntry(getResourceName(request));
+        } catch (Exception e) {
+        }
+        return null;
+    }
+
+    public String getResourceName(RequestContext request) {
+        if (request.getTarget().getType() != TargetType.TYPE_ENTRY)
+            return null;
+        String[] segments = request.getUri().toString().split("/");
+        return UrlEncoding.decode(segments[segments.length - 1]);
+    }
+
+    public ResponseContext getCategories(RequestContext request) {
+        return new StreamWriterResponseContext(getAbdera(request)) {
+            protected void writeTo(StreamWriter sw) throws IOException {
+                sw.startDocument().startCategories(false).writeCategory("foo").writeCategory("bar")
+                    .writeCategory("baz").endCategories().endDocument();
+            }
+        }.setStatus(200).setContentType(Constants.CAT_MEDIA_TYPE);
+    }
+}

Propchange: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/security/filter/SimpleAdapter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/selector/SelectorTest.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/test/src/main/java/org/apache/abdera2/test/selector/SelectorTest.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/test/src/main/java/org/apache/abdera2/test/selector/SelectorTest.java (added)
+++ abdera/abdera2/test/src/main/java/org/apache/abdera2/test/selector/SelectorTest.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,40 @@
+package org.apache.abdera2.test.selector;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.model.Entry;
+import org.apache.abdera2.model.Link;
+import org.apache.abdera2.model.selector.LinkHrefLangSelector;
+import org.apache.abdera2.model.selector.LinkRelSelector;
+import org.junit.Test;
+
+public class SelectorTest {
+
+  @Test
+  public void selectorTest() {
+    
+    Abdera abdera = Abdera.getInstance();
+    Entry entry = abdera.newEntry();
+    entry.addLink("foo1", "bar").setHrefLang("en");
+    entry.addLink("foo2", "bar").setHrefLang("fr");
+    entry.addLink("foo3", "baz").setHrefLang("fr");
+    
+    LinkRelSelector lrs = new LinkRelSelector("bar");
+    
+    List<Link> links = entry.getLinks(lrs);
+    assertEquals(2,links.size());
+    assertEquals("foo1",links.get(0).getHref().toString());
+    assertEquals("foo2",links.get(1).getHref().toString());
+    
+    LinkHrefLangSelector lhls = new LinkHrefLangSelector("fr");
+    links = entry.getLinks(lhls);
+    assertEquals(2,links.size());
+    assertEquals("foo2",links.get(0).getHref().toString());
+    assertEquals("foo3",links.get(1).getHref().toString());
+    
+  }
+  
+}

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

Added: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/server/JettyServer.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/test/src/main/java/org/apache/abdera2/test/server/JettyServer.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/test/src/main/java/org/apache/abdera2/test/server/JettyServer.java (added)
+++ abdera/abdera2/test/src/main/java/org/apache/abdera2/test/server/JettyServer.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,85 @@
+/*
+ * 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.server;
+
+import java.util.EventListener;
+
+import org.apache.abdera2.common.protocol.Provider;
+import org.apache.abdera2.common.protocol.ServiceManager;
+import org.apache.abdera2.common.protocol.servlet.AbderaServlet;
+import org.apache.abdera2.common.protocol.servlet.async.AbderaAsyncService;
+import org.apache.abdera2.common.protocol.servlet.async.AbderaChannelServlet;
+import org.apache.abdera2.common.protocol.servlet.async.AsyncAbderaServlet;
+import org.apache.abdera2.protocol.server.AtompubServiceManager;
+import org.apache.abdera2.test.JettyUtil;
+import org.eclipse.jetty.servlet.ServletHolder;
+
+public class JettyServer {
+
+    public void start(Class<? extends Provider> _class) throws Exception {
+        ServletHolder servletHolder = new ServletHolder(new AbderaServlet());
+        servletHolder.setInitParameter(AtompubServiceManager.PROVIDER, _class.getName());
+
+      JettyUtil.addServlet(servletHolder, "/*");
+      JettyUtil.start();
+    }
+
+    
+    public void start(
+        Class<? extends ServiceManager<?>> _smclass, 
+        Class<? extends Provider> _class) throws Exception {
+      
+      ServletHolder servletHolder = new ServletHolder(new AbderaServlet());
+      servletHolder.setInitParameter(ServiceManager.PROVIDER, _class.getName());
+      servletHolder.setInitParameter(ServiceManager.class.getName(), _smclass.getName());
+      JettyUtil.addServlet(servletHolder, "/*");
+      JettyUtil.start();
+    }
+    
+    
+    public void startAsync(
+        Class<? extends ServiceManager<?>> _smclass, 
+        Class<? extends Provider> _class,
+        AbderaChannelServlet acs) throws Exception {
+      
+      ServletHolder servletHolder = new ServletHolder(new AsyncAbderaServlet());
+      JettyUtil.addServlet(servletHolder, "/*");
+      
+      if (acs != null) {
+        servletHolder = new ServletHolder(acs);
+        JettyUtil.addServlet(servletHolder, "/stream/*");
+      }
+      
+      EventListener[] listeners = 
+        new EventListener[] {
+          new AbderaAsyncService()
+      };
+      JettyUtil.getSch().setInitParameter("AbderaAtompubService", "true");
+      JettyUtil.getSch().setInitParameter("AbderaChannelService", "true");
+      JettyUtil.getSch().setInitParameter(ServiceManager.class.getName(), _smclass.getName());
+      JettyUtil.getSch().setInitParameter(ServiceManager.PROVIDER, _class.getName());
+      JettyUtil.getSch().setEventListeners(listeners);
+      JettyUtil.start();
+    }
+
+    public void stop() throws Exception {
+       // server.stop();
+      JettyUtil.stop();
+    }
+
+}

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

Added: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/server/basic/BasicTest.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/test/src/main/java/org/apache/abdera2/test/server/basic/BasicTest.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/test/src/main/java/org/apache/abdera2/test/server/basic/BasicTest.java (added)
+++ abdera/abdera2/test/src/main/java/org/apache/abdera2/test/server/basic/BasicTest.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,175 @@
+/*
+ * 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.server.basic;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.Date;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.model.Base;
+import org.apache.abdera2.model.Collection;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Entry;
+import org.apache.abdera2.model.Feed;
+import org.apache.abdera2.model.Service;
+import org.apache.abdera2.model.Workspace;
+import org.apache.abdera2.protocol.client.AbderaClient;
+import org.apache.abdera2.protocol.client.AbderaClientResponse;
+import org.apache.abdera2.protocol.client.AbderaSession;
+import org.apache.abdera2.protocol.client.ClientResponse;
+import org.apache.abdera2.protocol.client.RequestOptions;
+import org.apache.abdera2.protocol.client.Session;
+import org.apache.abdera2.protocol.server.provider.basic.BasicProvider;
+import org.apache.abdera2.test.server.JettyServer;
+import org.apache.abdera2.common.Constants;
+import org.apache.abdera2.common.http.ResponseType;
+import org.apache.abdera2.common.mediatype.MimeTypeHelper;
+import org.apache.abdera2.writer.Writer;
+import org.apache.abdera2.writer.WriterFactory;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class BasicTest {
+
+    private static JettyServer server;
+    private static Abdera abdera = Abdera.getInstance();
+    private static AbderaClient client = new AbderaClient(abdera);
+
+    @BeforeClass
+    public static void setUp() throws Exception {
+        if (server == null) {
+            server = new JettyServer();
+            server.start(BasicProvider.class);
+        }
+    }
+
+    @AfterClass
+    public static void tearDown() throws Exception {
+        client.shutdown();
+        server.stop();
+    }
+
+    protected void prettyPrint(Base doc) throws IOException {
+        WriterFactory factory = abdera.getWriterFactory();
+        Writer writer = factory.getWriter("prettyxml");
+        writer.writeTo(doc, System.out);
+        System.out.println();
+    }
+
+    @Test
+    public void testGetService() throws IOException {
+        Document<Service> doc = client.get("http://localhost:9002/");
+        Service service = doc.getRoot();
+        assertEquals(1, service.getWorkspaces().size());
+        Workspace workspace = service.getWorkspace("Abdera");
+        assertEquals(1, workspace.getCollections().size());
+        Collection collection = workspace.getCollection("title for any sample feed");
+        assertNotNull(collection);
+        assertTrue(collection.acceptsEntry());
+        assertEquals("http://localhost:9002/sample", collection.getResolvedHref().toString());
+    }
+
+    @Test
+    public void testGetFeed() throws IOException {
+        Document<Feed> doc = client.get("http://localhost:9002/sample");
+        Feed feed = doc.getRoot();
+        assertEquals("http://localhost:9002/sample", feed.getId().toString());
+        assertEquals("title for any sample feed", feed.getTitle());
+        assertEquals("rayc", feed.getAuthor().getName());
+        assertEquals(0, feed.getEntries().size());
+    }
+
+    @Test
+    public void testPostEntry() {
+        Entry entry = abdera.newEntry();
+        entry.setId("http://localhost:9002/sample/foo");
+        entry.setTitle("test entry");
+        entry.setContent("Test Content");
+        entry.addLink("http://example.org");
+        entry.setUpdated(new Date());
+        entry.addAuthor("James");
+        AbderaSession session = (AbderaSession) client.newSession();
+        AbderaClientResponse resp = (AbderaClientResponse) session.post("http://localhost:9002/sample", entry);
+        assertNotNull(resp);
+        assertEquals(ResponseType.SUCCESSFUL, resp.getType());
+        assertEquals(201, resp.getStatus());
+        assertEquals("http://localhost:9002/sample/foo", resp.getLocation().toString());
+        resp.release();
+        resp = (AbderaClientResponse) session.get("http://localhost:9002/sample");
+        Document<Feed> feed_doc = resp.getDocument();
+        Feed feed = feed_doc.getRoot();
+        assertEquals(1, feed.getEntries().size());
+        resp.release();
+    }
+
+    @Test
+    public void testPostMedia() {
+        Session session = client.newSession();
+        ByteArrayInputStream in = new ByteArrayInputStream(new byte[] {0x01, 0x02, 0x03, 0x04});
+        RequestOptions options = session.getDefaultRequestOptions();
+        options.setContentType("application/octet-stream");
+        ClientResponse resp = session.post("http://localhost:9002/sample", in, options);
+        assertEquals(ResponseType.CLIENT_ERROR, resp.getType());
+        assertEquals(405, resp.getStatus());
+        resp.release();
+    }
+
+    @Test
+    public void testPutEntry() {
+      AbderaSession session = (AbderaSession) client.newSession();
+        AbderaClientResponse resp = (AbderaClientResponse) session.get("http://localhost:9002/sample/foo");
+        assertTrue(MimeTypeHelper.isMatch(resp.getContentType().toString(), Constants.ENTRY_MEDIA_TYPE));
+        Document<Entry> doc = resp.getDocument();
+        Entry entry = doc.getRoot();
+        entry.setTitle("This is the modified title");
+        resp.release();
+        resp = (AbderaClientResponse) session.put("http://localhost:9002/sample/foo", entry);
+        assertEquals(ResponseType.SUCCESSFUL, resp.getType());
+        assertEquals(200, resp.getStatus());
+        resp.release();
+        resp = (AbderaClientResponse) session.get("http://localhost:9002/sample/foo");
+        doc = resp.getDocument();
+        entry = doc.getRoot();
+        assertEquals("This is the modified title", entry.getTitle());
+        resp.release();
+        resp = (AbderaClientResponse) session.get("http://localhost:9002/sample");
+        Document<Feed> feed_doc = resp.getDocument();
+        Feed feed = feed_doc.getRoot();
+        assertEquals(1, feed.getEntries().size());
+        resp.release();
+    }
+
+    @Test
+    public void testDeleteEntry() {
+      AbderaSession session = (AbderaSession) client.newSession();
+        AbderaClientResponse resp = (AbderaClientResponse) session.delete("http://localhost:9002/sample/foo");
+        assertEquals(ResponseType.SUCCESSFUL, resp.getType());
+        resp.release();
+        resp = (AbderaClientResponse) session.get("http://localhost:9002/sample");
+        Document<Feed> feed_doc = resp.getDocument();
+        Feed feed = feed_doc.getRoot();
+        assertEquals(0, feed.getEntries().size());
+        resp.release();
+    }
+}

Propchange: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/server/basic/BasicTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/server/basic/SampleBasicAdapter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/test/src/main/java/org/apache/abdera2/test/server/basic/SampleBasicAdapter.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/test/src/main/java/org/apache/abdera2/test/server/basic/SampleBasicAdapter.java (added)
+++ abdera/abdera2/test/src/main/java/org/apache/abdera2/test/server/basic/SampleBasicAdapter.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,152 @@
+/*
+ * 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.server.basic;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Set;
+import java.util.logging.Logger;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.common.protocol.RequestContext;
+import org.apache.abdera2.common.protocol.ResponseContextException;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Element;
+import org.apache.abdera2.model.Entry;
+import org.apache.abdera2.model.Feed;
+import org.apache.abdera2.protocol.server.provider.basic.BasicAdapter;
+import org.apache.abdera2.protocol.server.provider.managed.FeedConfiguration;
+
+public class SampleBasicAdapter extends BasicAdapter {
+
+    private static final String ERROR_DUP_ENTRY = "Entry Already Exists";
+    private static final String ERROR_INVALID_ENTRY = "No Such Entry in the Feed";
+
+    public static Logger logger = Logger.getLogger(SampleBasicAdapter.class.getName());
+    protected HashMap<String, byte[]> entries = new HashMap<String, byte[]>();
+
+    public SampleBasicAdapter(Abdera abdera, FeedConfiguration config) {
+        super(abdera, config);
+    }
+
+    public Feed getFeed() throws Exception {
+        Feed feed = createFeed();
+
+        // get all keys in the feed - with keys in descending order of
+        // lastUpdatedDate
+        Set<String> keys = entries.keySet();
+        for (String s : keys) {
+            Entry entry = getEntry(s);
+            // TODO: why clone this? Abdera seems to mess up the object
+            // if we pass the reference to this object
+            feed.addEntry((Entry)entry.clone());
+        }
+        return feed;
+    }
+
+    public Entry getEntry(Object entryId) throws Exception {
+        return retrieveEntry((String)entryId);
+    }
+
+    public Entry createEntry(Entry entry) throws Exception {
+        // entryId may be null. if it is, assign one
+        setEntryIdIfNull(entry);
+        logger.info("assigning id to Entry: " + entry.getId().toString());
+        String entryId = getEntryIdFromUri(entry.getId().toString());
+
+        if (entries.containsKey(entryId)) {
+            throw new Exception(ERROR_DUP_ENTRY);
+        }
+        // add an "updated" element if one was not provided
+        if (entry.getUpdated() == null) {
+            entry.setUpdated(new Date());
+        }
+        addEditLinkToEntry(entry);
+        storeEntry(entryId, entry);
+        logger.finest("returning this entry from sampleadapter.createEntry: " + entry.toString());
+        return entry;
+    }
+
+    public Entry updateEntry(Object entryId, Entry entry) throws Exception {
+        if (!entries.containsKey(entryId)) {
+            throw new Exception(ERROR_INVALID_ENTRY);
+        }
+        entries.remove(entryId);
+        // add an "updated" element if one was not provided
+        if (entry.getUpdated() == null) {
+            entry.setUpdated(new Date());
+        }
+        addEditLinkToEntry(entry);
+        storeEntry((String)entryId, entry);
+        logger.finest("returning this entry from sampleadapter.updateEntry: " + entry.toString());
+        return entry;
+    }
+
+    public boolean deleteEntry(Object entryId) throws Exception {
+        if (!entries.containsKey(entryId)) {
+            return false;
+        }
+        entries.remove(entryId);
+        return true;
+    }
+
+    protected String getEntryIdFromUri(String uri) {
+        String[] segments = uri.split("/");
+        return segments[segments.length - 1];
+    }
+
+    protected void storeEntry(String entryId, Entry entry) throws Exception {
+        Document<Element> entryDoc = entry.getDocument();
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        entryDoc.writeTo(bos);
+
+        // Get the bytes of the serialized object and store in hashmap
+        byte[] buf = bos.toByteArray();
+        bos.close();
+        entries.put(entryId, buf);
+    }
+
+    protected Entry retrieveEntry(String entryId) throws Exception {
+        // Deserialize from a byte array
+        byte[] bytes = entries.get(entryId);
+        if (bytes == null) {
+            // entry not found
+            return null;
+        }
+        ByteArrayInputStream in = new ByteArrayInputStream(bytes);
+        Document<Entry> entryDoc = abdera.getParser().parse(in);
+        Entry entry = entryDoc.getRoot();
+        return entry;
+    }
+
+    @Override
+    public String getAuthor(RequestContext request) throws ResponseContextException {
+        return config.getFeedAuthor();
+    }
+
+    @Override
+    public String getId(RequestContext request) {
+        return config.getFeedId();
+    }
+
+    public String getTitle(RequestContext request) {
+        return config.getFeedTitle();
+    }
+}

Propchange: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/server/basic/SampleBasicAdapter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/server/custom/CustomProvider.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/test/src/main/java/org/apache/abdera2/test/server/custom/CustomProvider.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/test/src/main/java/org/apache/abdera2/test/server/custom/CustomProvider.java (added)
+++ abdera/abdera2/test/src/main/java/org/apache/abdera2/test/server/custom/CustomProvider.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,80 @@
+/*
+ * 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.server.custom;
+
+import org.apache.abdera2.common.protocol.RequestContext;
+import org.apache.abdera2.common.protocol.BaseRequestContextWrapper;
+import org.apache.abdera2.common.protocol.ResponseContext;
+import org.apache.abdera2.common.protocol.Filter;
+import org.apache.abdera2.common.protocol.FilterChain;
+import org.apache.abdera2.common.protocol.RegexTargetResolver;
+import org.apache.abdera2.common.protocol.TargetType;
+import org.apache.abdera2.common.protocol.TemplateManagerTargetBuilder;
+import org.apache.abdera2.protocol.server.AtompubCollectionAdapter;
+import org.apache.abdera2.protocol.server.impl.AbstractAtompubWorkspaceProvider;
+import org.apache.abdera2.protocol.server.impl.SimpleWorkspaceInfo;
+
+public class CustomProvider extends AbstractAtompubWorkspaceProvider {
+
+    private final SimpleAdapter adapter;
+
+    public CustomProvider() {
+
+        this.adapter = new SimpleAdapter();
+
+        RegexTargetResolver<RequestContext> resolver = 
+          new RegexTargetResolver<RequestContext>()
+            .setPattern("/atom(\\?[^#]*)?", TargetType.TYPE_SERVICE)
+            .setPattern("/atom/([^/#?]+);categories", TargetType.TYPE_CATEGORIES, "collection")
+            .setPattern("/atom/([^/#?;]+)(\\?[^#]*)?", TargetType.TYPE_COLLECTION, "collection")
+            .setPattern("/atom/([^/#?]+)/([^/#?]+)(\\?[^#]*)?", TargetType.TYPE_ENTRY, "collection", "entry");
+        setTargetResolver(resolver);
+
+        TemplateManagerTargetBuilder<TargetType> tmb = 
+          new TemplateManagerTargetBuilder<TargetType>();
+        
+        tmb.add(TargetType.TYPE_SERVICE, "{target_base}/atom");
+        tmb.add(TargetType.TYPE_COLLECTION,
+                         "{target_base}/atom/{collection}{?q,c,s,p,l,i,o}");
+        tmb.add(TargetType.TYPE_CATEGORIES, "{target_base}/atom/{collection};categories");
+        tmb.add(TargetType.TYPE_ENTRY, "{target_base}/atom/{collection}/{entry}");
+
+        setTargetBuilder(tmb);
+        
+        SimpleWorkspaceInfo workspace = new SimpleWorkspaceInfo();
+        workspace.setTitle("A Simple Workspace");
+        workspace.addCollection(adapter);
+        addWorkspace(workspace);
+
+        addFilter(new SimpleFilter());
+    }
+
+    public AtompubCollectionAdapter getCollectionAdapter(RequestContext request) {
+        return adapter;
+    }
+
+    public class SimpleFilter implements Filter {
+        public <S extends ResponseContext>S filter(RequestContext request, FilterChain chain) {
+            BaseRequestContextWrapper rcw = new BaseRequestContextWrapper(request);
+            rcw.setAttribute("offset", 10);
+            rcw.setAttribute("count", 10);
+            return chain.next(rcw);
+        }
+    }
+
+}

Propchange: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/server/custom/CustomProvider.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/server/custom/CustomProviderTest.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/test/src/main/java/org/apache/abdera2/test/server/custom/CustomProviderTest.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/test/src/main/java/org/apache/abdera2/test/server/custom/CustomProviderTest.java (added)
+++ abdera/abdera2/test/src/main/java/org/apache/abdera2/test/server/custom/CustomProviderTest.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,222 @@
+/*
+ * 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.server.custom;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.Date;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.model.Base;
+import org.apache.abdera2.model.Categories;
+import org.apache.abdera2.model.Collection;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Entry;
+import org.apache.abdera2.model.Feed;
+import org.apache.abdera2.model.Service;
+import org.apache.abdera2.model.Workspace;
+import org.apache.abdera2.protocol.client.AbderaClient;
+import org.apache.abdera2.protocol.client.AbderaClientResponse;
+import org.apache.abdera2.protocol.client.AbderaSession;
+import org.apache.abdera2.protocol.client.ClientResponse;
+import org.apache.abdera2.protocol.client.RequestOptions;
+import org.apache.abdera2.protocol.client.Session;
+import org.apache.abdera2.test.server.JettyServer;
+import org.apache.abdera2.common.Constants;
+import org.apache.abdera2.common.http.ResponseType;
+import org.apache.abdera2.common.mediatype.MimeTypeHelper;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class CustomProviderTest {
+
+    private static JettyServer server;
+    private static Abdera abdera = Abdera.getInstance();
+    private static AbderaClient client = new AbderaClient();
+
+    private static String BASE = "http://localhost:9002/atom";
+
+    @BeforeClass
+    public static void setUp() throws Exception {
+        try {
+            server = new JettyServer();
+            server.start(CustomProvider.class);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    @AfterClass
+    public static void tearDown() throws Exception {
+        client.shutdown();
+        server.stop();
+    }
+
+    @Test
+    public void testGetService() throws IOException {
+      AbderaSession session = (AbderaSession) client.newSession();
+        AbderaClientResponse resp = (AbderaClientResponse) session.get(BASE);
+        assertNotNull(resp);
+        assertEquals(ResponseType.SUCCESSFUL, resp.getType());
+        assertTrue(MimeTypeHelper.isMatch(resp.getContentType().toString(), Constants.APP_MEDIA_TYPE));
+        Document<Service> doc = resp.getDocument();        
+        try {
+            prettyPrint(doc);
+        } catch (Exception e) {
+        }
+        Service service = doc.getRoot();
+        prettyPrint(service);
+        assertEquals(1, service.getWorkspaces().size());
+        Workspace workspace = service.getWorkspaces().get(0);
+        assertEquals(1, workspace.getCollections().size());
+        Collection collection = workspace.getCollections().get(0);
+        assertEquals(BASE + "/feed?", collection.getResolvedHref().toString());
+        assertEquals("A simple feed", collection.getTitle().toString());
+        resp.release();
+    }
+
+    @Test
+    public void testGetCategories() {
+      AbderaSession session = (AbderaSession) client.newSession();
+        AbderaClientResponse resp = (AbderaClientResponse) session.get(BASE + "/feed;categories");
+        assertNotNull(resp);
+        assertEquals(ResponseType.SUCCESSFUL, resp.getType());
+        assertTrue(MimeTypeHelper.isMatch(resp.getContentType().toString(), Constants.CAT_MEDIA_TYPE));
+        Document<Categories> doc = resp.getDocument();
+        Categories cats = doc.getRoot();
+        assertEquals(3, cats.getCategories().size());
+        assertEquals("foo", cats.getCategories().get(0).getTerm());
+        assertEquals("bar", cats.getCategories().get(1).getTerm());
+        assertEquals("baz", cats.getCategories().get(2).getTerm());
+        assertFalse(cats.isFixed());
+    }
+
+    @Test
+    public void testGetFeed() throws Exception {
+      AbderaSession session = (AbderaSession) client.newSession();
+        AbderaClientResponse resp = (AbderaClientResponse) session.get(BASE + "/feed");
+        assertNotNull(resp);
+        assertEquals(ResponseType.SUCCESSFUL, resp.getType());
+        assertTrue(MimeTypeHelper.isMatch(resp.getContentType().toString(), Constants.ATOM_MEDIA_TYPE));
+        Document<Feed> doc = resp.getDocument();
+        Feed feed = doc.getRoot();
+        assertEquals("tag:example.org,2008:feed", feed.getId().toString());
+        assertEquals("A simple feed", feed.getTitle());
+        assertEquals("Simple McGee", feed.getAuthor().getName());
+        assertEquals(0, feed.getEntries().size());
+        resp.release();
+    }
+
+    protected void prettyPrint(Base doc) throws IOException {
+        // WriterFactory writerFactory = abdera.getWriterFactory();
+        // Writer writer = writerFactory.getWriter("prettyxml");
+        // writer.writeTo(doc, System.out);
+        // System.out.println();
+    }
+
+    @Test
+    public void testPostEntry() {
+      AbderaSession session = (AbderaSession) client.newSession();
+        Entry entry = abdera.newEntry();
+        entry.setId(BASE + "/feed/entries/1");
+        entry.setTitle("test entry");
+        entry.setContent("Test Content");
+        entry.addLink("http://example.org");
+        entry.setUpdated(new Date());
+        entry.addAuthor("James");
+        AbderaClientResponse resp = (AbderaClientResponse) session.post(BASE + "/feed", entry);
+        assertNotNull(resp);
+        assertEquals(ResponseType.SUCCESSFUL, resp.getType());
+        assertEquals(201, resp.getStatus());
+        assertNotNull(resp.getLocation());
+        resp.release();
+        resp = (AbderaClientResponse) session.get(BASE + "/feed");
+        Document<Feed> feed_doc = resp.getDocument();
+        Feed feed = feed_doc.getRoot();
+        assertEquals(1, feed.getEntries().size());
+    }
+
+    @Test
+    public void testPostMedia() {
+      Session session = client.newSession();
+        ByteArrayInputStream in = new ByteArrayInputStream(new byte[] {0x01, 0x02, 0x03, 0x04});
+        RequestOptions options = session.getDefaultRequestOptions();
+        options.setContentType("application/octet-stream");
+        ClientResponse resp = session.post(BASE + "/feed", in, options);
+        assertEquals(ResponseType.CLIENT_ERROR, resp.getType());
+        assertEquals(405, resp.getStatus());
+        resp.release();
+    }
+
+    @Test
+    public void testPutEntry() throws IOException {
+      AbderaSession session = (AbderaSession) client.newSession();
+      AbderaClientResponse resp = (AbderaClientResponse) session.get(BASE + "/feed");
+        Document<Feed> feed_doc = resp.getDocument();
+        Feed feed = feed_doc.getRoot();
+        prettyPrint(feed);
+        Entry entry = feed.getEntries().get(0);
+        String edit = entry.getEditLinkResolvedHref().toString();
+        resp.release();
+        resp = (AbderaClientResponse) session.get(edit);
+        Document<Entry> doc = resp.getDocument();
+        prettyPrint(doc.getRoot());
+        entry = doc.getRoot();
+        entry.setTitle("This is the modified title");
+        resp.release();
+        resp = (AbderaClientResponse) session.put(edit, entry);
+        assertEquals(ResponseType.SUCCESSFUL, resp.getType());
+        assertEquals(204, resp.getStatus());
+        resp.release();
+        resp = (AbderaClientResponse) session.get(edit);
+        doc = resp.getDocument();
+        entry = doc.getRoot();
+        assertEquals("This is the modified title", entry.getTitle());
+        resp.release();
+        resp = (AbderaClientResponse) session.get(BASE + "/feed");
+        feed_doc = resp.getDocument();
+        feed = feed_doc.getRoot();
+        assertEquals(1, feed.getEntries().size());
+        resp.release();
+    }
+
+    @Test
+    public void testDeleteEntry() {
+      AbderaSession session = (AbderaSession) client.newSession();
+      AbderaClientResponse resp = (AbderaClientResponse) session.get(BASE + "/feed");
+        Document<Feed> feed_doc = resp.getDocument();
+        Feed feed = feed_doc.getRoot();
+        Entry entry = feed.getEntries().get(0);
+        String edit = entry.getEditLinkResolvedHref().toString();
+        resp.release();
+        resp = (AbderaClientResponse) session.delete(edit);
+        assertEquals(ResponseType.SUCCESSFUL, resp.getType());
+        resp.release();
+        resp = (AbderaClientResponse) session.get(BASE + "/feed");
+        feed_doc = resp.getDocument();
+        feed = feed_doc.getRoot();
+        assertEquals(0, feed.getEntries().size());
+        resp.release();
+    }
+}

Propchange: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/server/custom/CustomProviderTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message