wink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r810124 - in /incubator/wink/trunk/wink-providers: ./ wink-abdera-provider/ wink-abdera-provider/src/ wink-abdera-provider/src/main/ wink-abdera-provider/src/main/java/ wink-abdera-provider/src/main/java/org/ wink-abdera-provider/src/main/j...
Date Tue, 01 Sep 2009 17:03:14 GMT
Author: bluk
Date: Tue Sep  1 17:03:13 2009
New Revision: 810124

URL: http://svn.apache.org/viewvc?rev=810124&view=rev
Log:
Add Apache Abdera Provider

See [WINK-69]

Added:
    incubator/wink/trunk/wink-providers/wink-abdera-provider/
    incubator/wink/trunk/wink-providers/wink-abdera-provider/pom.xml   (with props)
    incubator/wink/trunk/wink-providers/wink-abdera-provider/src/
    incubator/wink/trunk/wink-providers/wink-abdera-provider/src/main/
    incubator/wink/trunk/wink-providers/wink-abdera-provider/src/main/java/
    incubator/wink/trunk/wink-providers/wink-abdera-provider/src/main/java/org/
    incubator/wink/trunk/wink-providers/wink-abdera-provider/src/main/java/org/apache/
    incubator/wink/trunk/wink-providers/wink-abdera-provider/src/main/java/org/apache/wink/
    incubator/wink/trunk/wink-providers/wink-abdera-provider/src/main/java/org/apache/wink/common/
    incubator/wink/trunk/wink-providers/wink-abdera-provider/src/main/java/org/apache/wink/common/internal/
    incubator/wink/trunk/wink-providers/wink-abdera-provider/src/main/java/org/apache/wink/common/internal/providers/
    incubator/wink/trunk/wink-providers/wink-abdera-provider/src/main/java/org/apache/wink/common/internal/providers/entity/
    incubator/wink/trunk/wink-providers/wink-abdera-provider/src/main/java/org/apache/wink/common/internal/providers/entity/abdera/
    incubator/wink/trunk/wink-providers/wink-abdera-provider/src/main/java/org/apache/wink/common/internal/providers/entity/abdera/AbderaAtomEntryProvider.java
  (with props)
    incubator/wink/trunk/wink-providers/wink-abdera-provider/src/main/java/org/apache/wink/common/internal/providers/entity/abdera/AbderaAtomFeedProvider.java
  (with props)
    incubator/wink/trunk/wink-providers/wink-abdera-provider/src/test/
    incubator/wink/trunk/wink-providers/wink-abdera-provider/src/test/java/
    incubator/wink/trunk/wink-providers/wink-abdera-provider/src/test/java/org/
    incubator/wink/trunk/wink-providers/wink-abdera-provider/src/test/java/org/apache/
    incubator/wink/trunk/wink-providers/wink-abdera-provider/src/test/java/org/apache/wink/
    incubator/wink/trunk/wink-providers/wink-abdera-provider/src/test/java/org/apache/wink/common/
    incubator/wink/trunk/wink-providers/wink-abdera-provider/src/test/java/org/apache/wink/common/internal/
    incubator/wink/trunk/wink-providers/wink-abdera-provider/src/test/java/org/apache/wink/common/internal/providers/
    incubator/wink/trunk/wink-providers/wink-abdera-provider/src/test/java/org/apache/wink/common/internal/providers/entity/
    incubator/wink/trunk/wink-providers/wink-abdera-provider/src/test/java/org/apache/wink/common/internal/providers/entity/abdera/
    incubator/wink/trunk/wink-providers/wink-abdera-provider/src/test/java/org/apache/wink/common/internal/providers/entity/abdera/AbderaAtomEntryProviderTest.java
  (with props)
    incubator/wink/trunk/wink-providers/wink-abdera-provider/src/test/java/org/apache/wink/common/internal/providers/entity/abdera/AbderaAtomFeedProviderTest.java
  (with props)
Modified:
    incubator/wink/trunk/wink-providers/pom.xml

Modified: incubator/wink/trunk/wink-providers/pom.xml
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-providers/pom.xml?rev=810124&r1=810123&r2=810124&view=diff
==============================================================================
--- incubator/wink/trunk/wink-providers/pom.xml (original)
+++ incubator/wink/trunk/wink-providers/pom.xml Tue Sep  1 17:03:13 2009
@@ -31,6 +31,7 @@
 	</parent>
 	<modules>
 		<module>wink-jettison-provider</module>
+		<module>wink-abdera-provider</module>
 	</modules>
 	<dependencies>
         <dependency>

Added: incubator/wink/trunk/wink-providers/wink-abdera-provider/pom.xml
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-providers/wink-abdera-provider/pom.xml?rev=810124&view=auto
==============================================================================
--- incubator/wink/trunk/wink-providers/wink-abdera-provider/pom.xml (added)
+++ incubator/wink/trunk/wink-providers/wink-abdera-provider/pom.xml Tue Sep  1 17:03:13 2009
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+    <!--
+        Licensed to the Apache Software Foundation (ASF) under one or
+        more contributor license agreements. See the NOTICE file
+        distributed with this work for additional information regarding
+        copyright ownership. The ASF licenses this file to you under the
+        Apache License, Version 2.0 (the "License"); you may not use
+        this file except in compliance with the License. You may obtain
+        a copy of the License at
+
+        http://www.apache.org/licenses/LICENSE-2.0 Unless required by
+        applicable law or agreed to in writing, software distributed
+        under the License is distributed on an "AS IS" BASIS, WITHOUT
+        WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+        See the License for the specific language governing permissions
+        and limitations under the License.
+    -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <parent>
+        <artifactId>wink-providers</artifactId>
+        <groupId>org.apache.wink</groupId>
+        <version>0.2-incubating-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>org.apache.wink</groupId>
+    <artifactId>wink-abdera-provider</artifactId>
+    <name>Apache Wink Providers :: Abdera Provider</name>
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.abdera</groupId>
+            <artifactId>abdera-core</artifactId>
+            <version>0.4.0-incubating</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.abdera</groupId>
+            <artifactId>abdera-extensions-json</artifactId>
+            <version>0.4.0-incubating</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.wink</groupId>
+            <artifactId>wink-component-test-support</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-test</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-j2ee_1.4_spec</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.wink</groupId>
+            <artifactId>wink-server</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <repositories>
+        <repository>
+            <id>apache-incubating</id>
+            <name>Apache Incubating Repository</name>
+            <url>http://people.apache.org/repo/m2-incubating-repository/</url>
+        </repository>
+    </repositories>
+</project>
\ No newline at end of file

Propchange: incubator/wink/trunk/wink-providers/wink-abdera-provider/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/wink/trunk/wink-providers/wink-abdera-provider/src/main/java/org/apache/wink/common/internal/providers/entity/abdera/AbderaAtomEntryProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-providers/wink-abdera-provider/src/main/java/org/apache/wink/common/internal/providers/entity/abdera/AbderaAtomEntryProvider.java?rev=810124&view=auto
==============================================================================
--- incubator/wink/trunk/wink-providers/wink-abdera-provider/src/main/java/org/apache/wink/common/internal/providers/entity/abdera/AbderaAtomEntryProvider.java
(added)
+++ incubator/wink/trunk/wink-providers/wink-abdera-provider/src/main/java/org/apache/wink/common/internal/providers/entity/abdera/AbderaAtomEntryProvider.java
Tue Sep  1 17:03:13 2009
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *  
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *  
+ *******************************************************************************/
+package org.apache.wink.common.internal.providers.entity.abdera;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.writer.Writer;
+
+@Produces( {MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
+@Consumes(MediaType.APPLICATION_ATOM_XML)
+@Provider
+public class AbderaAtomEntryProvider implements MessageBodyReader<Entry>, MessageBodyWriter<Entry>
{
+
+    private static final Abdera ATOM_ENGINE = new Abdera();
+
+    public long getSize(Entry entry,
+                        Class<?> type,
+                        Type genericType,
+                        Annotation[] annotations,
+                        MediaType mediaType) {
+        return -1;
+    }
+
+    public boolean isWriteable(Class<?> type,
+                               Type genericType,
+                               Annotation[] annotations,
+                               MediaType mediaType) {
+        return Entry.class.isAssignableFrom(type);
+    }
+
+    public void writeTo(Entry entry,
+                        Class<?> type,
+                        Type genericType,
+                        Annotation[] annotations,
+                        MediaType mediaType,
+                        MultivaluedMap<String, Object> httpHeaders,
+                        OutputStream entityStream) throws IOException {
+        if (MediaType.APPLICATION_JSON_TYPE.isCompatible(mediaType)) {
+            Writer w = ATOM_ENGINE.getWriterFactory().getWriter("json");
+            entry.writeTo(w, entityStream);
+        } else {
+            entry.writeTo(entityStream);
+        }
+    }
+
+    public boolean isReadable(Class<?> type,
+                              Type genericType,
+                              Annotation[] annotations,
+                              MediaType mediaType) {
+        return Entry.class == type;
+    }
+
+    public Entry readFrom(Class<Entry> type,
+                          Type genericType,
+                          Annotation[] annotations,
+                          MediaType mediaType,
+                          MultivaluedMap<String, String> httpHeaders,
+                          InputStream entityStream) throws IOException {
+        Document<Entry> doc = ATOM_ENGINE.getParser().parse(entityStream);
+        return doc.getRoot();
+    }
+}

Propchange: incubator/wink/trunk/wink-providers/wink-abdera-provider/src/main/java/org/apache/wink/common/internal/providers/entity/abdera/AbderaAtomEntryProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/wink/trunk/wink-providers/wink-abdera-provider/src/main/java/org/apache/wink/common/internal/providers/entity/abdera/AbderaAtomFeedProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-providers/wink-abdera-provider/src/main/java/org/apache/wink/common/internal/providers/entity/abdera/AbderaAtomFeedProvider.java?rev=810124&view=auto
==============================================================================
--- incubator/wink/trunk/wink-providers/wink-abdera-provider/src/main/java/org/apache/wink/common/internal/providers/entity/abdera/AbderaAtomFeedProvider.java
(added)
+++ incubator/wink/trunk/wink-providers/wink-abdera-provider/src/main/java/org/apache/wink/common/internal/providers/entity/abdera/AbderaAtomFeedProvider.java
Tue Sep  1 17:03:13 2009
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *  
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *  
+ *******************************************************************************/
+package org.apache.wink.common.internal.providers.entity.abdera;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Feed;
+import org.apache.abdera.writer.Writer;
+
+@Produces( {MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
+@Consumes(MediaType.APPLICATION_ATOM_XML)
+@Provider
+public class AbderaAtomFeedProvider implements MessageBodyWriter<Feed>, MessageBodyReader<Feed>
{
+
+    private static final Abdera ATOM_ENGINE = new Abdera();
+
+    public long getSize(Feed feed,
+                        Class<?> type,
+                        Type genericType,
+                        Annotation[] annotations,
+                        MediaType mediaType) {
+        return -1;
+    }
+
+    public boolean isWriteable(Class<?> type,
+                               Type genericType,
+                               Annotation[] annotations,
+                               MediaType mediaType) {
+        return Feed.class.isAssignableFrom(type);
+    }
+
+    public void writeTo(Feed feed,
+                        Class<?> type,
+                        Type genericType,
+                        Annotation[] annotations,
+                        MediaType mediaType,
+                        MultivaluedMap<String, Object> httpHeaders,
+                        OutputStream entityStream) throws IOException {
+        if (MediaType.APPLICATION_JSON_TYPE.isCompatible(mediaType)) {
+            Writer w = ATOM_ENGINE.getWriterFactory().getWriter("json");
+            feed.writeTo(w, entityStream);
+        } else {
+            feed.writeTo(entityStream);
+        }
+    }
+
+    public boolean isReadable(Class<?> type,
+                              Type genericType,
+                              Annotation[] annotations,
+                              MediaType mediaType) {
+        return Feed.class == type;
+    }
+
+    public Feed readFrom(Class<Feed> type,
+                         Type genericType,
+                         Annotation[] annotations,
+                         MediaType mediaType,
+                         MultivaluedMap<String, String> httpHeaders,
+                         InputStream entityStream) throws IOException {
+        Document<Feed> doc = ATOM_ENGINE.getParser().parse(entityStream);
+        return doc.getRoot();
+    }
+}

Propchange: incubator/wink/trunk/wink-providers/wink-abdera-provider/src/main/java/org/apache/wink/common/internal/providers/entity/abdera/AbderaAtomFeedProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/wink/trunk/wink-providers/wink-abdera-provider/src/test/java/org/apache/wink/common/internal/providers/entity/abdera/AbderaAtomEntryProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-providers/wink-abdera-provider/src/test/java/org/apache/wink/common/internal/providers/entity/abdera/AbderaAtomEntryProviderTest.java?rev=810124&view=auto
==============================================================================
--- incubator/wink/trunk/wink-providers/wink-abdera-provider/src/test/java/org/apache/wink/common/internal/providers/entity/abdera/AbderaAtomEntryProviderTest.java
(added)
+++ incubator/wink/trunk/wink-providers/wink-abdera-provider/src/test/java/org/apache/wink/common/internal/providers/entity/abdera/AbderaAtomEntryProviderTest.java
Tue Sep  1 17:03:13 2009
@@ -0,0 +1,167 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *  
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *  
+ *******************************************************************************/
+package org.apache.wink.common.internal.providers.entity.abdera;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.Unmarshaller;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Entry;
+import org.apache.wink.common.model.atom.AtomEntry;
+import org.apache.wink.common.model.json.JSONUtils;
+import org.apache.wink.server.internal.servlet.MockServletInvocationTest;
+import org.apache.wink.test.mock.MockRequestConstructor;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
+
+/**
+ * Tests the Abdera Atom Entry provider.
+ */
+public class AbderaAtomEntryProviderTest extends MockServletInvocationTest {
+
+    @Override
+    protected Class<?>[] getClasses() {
+        return new Class<?>[] {TestResource.class};
+    }
+
+    @Override
+    protected Object[] getSingletons() {
+        return new Object[] {new AbderaAtomEntryProvider()};
+    }
+
+    @Path("test")
+    public static class TestResource {
+
+        @GET
+        @Path("atomentry")
+        @Produces( {MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML})
+        public Entry getAtomEntry() throws IOException {
+            Abdera abdera = new Abdera();
+            Entry e = abdera.newEntry();
+            e.setId("toptenvalidators");
+            e.setTitle("top ten validators");
+            e.addLink("http://b216:8080/reporting/reports/toptenvalidators?alt=application/json",
+                      "alternate");
+            e.addAuthor("admin");
+            e.addCategory("urn:com:systinet:reporting:kind",
+                          "urn:com:systinet:reporting:kind:definition",
+                          "report definition");
+            return e;
+        }
+
+        @POST
+        @Path("atomentry")
+        @Produces( {MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML})
+        @Consumes( {MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML})
+        public Entry postAtomEntry(Entry e) throws IOException {
+            return e;
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    public void testGetAtomEntryInXML() throws Exception {
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("GET",
+                                                        "/test/atomentry",
+                                                        MediaType.APPLICATION_ATOM_XML);
+        MockHttpServletResponse response = invoke(request);
+        assertEquals(200, response.getStatus());
+        Unmarshaller u =
+            JAXBContext.newInstance(AtomEntry.class.getPackage().getName()).createUnmarshaller();
+        AtomEntry entry =
+            ((JAXBElement<AtomEntry>)u.unmarshal(new ByteArrayInputStream(response
+                .getContentAsByteArray()))).getValue();
+        assertEquals("toptenvalidators", entry.getId());
+        assertEquals("top ten validators", entry.getTitle().getValue());
+        assertEquals("http://b216:8080/reporting/reports/toptenvalidators?alt=application/json",
+                     entry.getLinks().get(0).getHref());
+        assertEquals("alternate", entry.getLinks().get(0).getRel());
+        assertEquals("admin", entry.getAuthors().get(0).getName());
+        assertEquals("urn:com:systinet:reporting:kind", entry.getCategories().get(0).getScheme());
+        assertEquals("urn:com:systinet:reporting:kind:definition", entry.getCategories().get(0)
+            .getTerm());
+        assertEquals("report definition", entry.getCategories().get(0).getLabel());
+    }
+
+    public void testGetAtomEntryInJSON() throws Exception {
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("GET",
+                                                        "/test/atomentry",
+                                                        MediaType.APPLICATION_JSON);
+        MockHttpServletResponse response = invoke(request);
+        assertEquals(200, response.getStatus());
+        assertTrue(response.getContentAsString(), JSONUtils.equals(JSONUtils
+            .objectForString(ENTRY_STR_JSON), JSONUtils.objectForString(response
+            .getContentAsString())));
+    }
+
+    @SuppressWarnings("unchecked")
+    public void testPostAtomEntry() throws Exception {
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("POST",
+                                                        "/test/atomentry",
+                                                        MediaType.APPLICATION_ATOM_XML);
+        request.setContentType(MediaType.APPLICATION_ATOM_XML);
+        request.setContent(ENTRY_STR.getBytes());
+        MockHttpServletResponse response = invoke(request);
+        assertEquals(200, response.getStatus());
+
+        Unmarshaller u =
+            JAXBContext.newInstance(AtomEntry.class.getPackage().getName()).createUnmarshaller();
+        AtomEntry entry =
+            ((JAXBElement<AtomEntry>)u.unmarshal(new ByteArrayInputStream(response
+                .getContentAsByteArray()))).getValue();
+        assertEquals("toptenvalidators", entry.getId());
+        assertEquals("top ten validators", entry.getTitle().getValue());
+        assertEquals("http://b216:8080/reporting/reports/toptenvalidators?alt=application/json",
+                     entry.getLinks().get(0).getHref());
+        assertEquals("alternate", entry.getLinks().get(0).getRel());
+        assertEquals("admin", entry.getAuthors().get(0).getName());
+        assertEquals("urn:com:systinet:reporting:kind", entry.getCategories().get(0).getScheme());
+        assertEquals("urn:com:systinet:reporting:kind:definition", entry.getCategories().get(0)
+            .getTerm());
+        assertEquals("report definition", entry.getCategories().get(0).getLabel());
+    }
+
+    private static final String ENTRY_STR      =
+                                                   "<entry xml:base=\"http://b216:8080/reporting/reports\"
xmlns=\"http://www.w3.org/2005/Atom\">\n" + "    <id>toptenvalidators</id>\n"
+                                                       + "    <updated>@TIME@</updated>\n"
+                                                       + "    <title>top ten validators</title>\n"
+                                                       + "    <link href=\"http://b216:8080/reporting/reports/toptenvalidators?alt=application/json\"
rel=\"alternate\"/>\n"
+                                                       + "    <author>\n"
+                                                       + "        <name>admin</name>\n"
+                                                       + "    </author>\n"
+                                                       + "    <category label=\"report
definition\" scheme=\"urn:com:systinet:reporting:kind\" term=\"urn:com:systinet:reporting:kind:definition\"/>\n"
+                                                       + "</entry>\n";
+
+    private static String       ENTRY_STR_JSON =
+                                                   "{\"id\":\"toptenvalidators\", \"title\":\"top
ten validators\", \"authors\":[{\"name\":\"admin\"}], \"links\":[{\"href\":\"http://b216:8080/reporting/reports/toptenvalidators?alt=application/json\",\"rel\":\"alternate\"}],\"categories\":[{\"term\":\"urn:com:systinet:reporting:kind:definition\",\"scheme\":\"urn:com:systinet:reporting:kind\",\"label\":\"report
definition\"}]}";
+
+}

Propchange: incubator/wink/trunk/wink-providers/wink-abdera-provider/src/test/java/org/apache/wink/common/internal/providers/entity/abdera/AbderaAtomEntryProviderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/wink/trunk/wink-providers/wink-abdera-provider/src/test/java/org/apache/wink/common/internal/providers/entity/abdera/AbderaAtomFeedProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-providers/wink-abdera-provider/src/test/java/org/apache/wink/common/internal/providers/entity/abdera/AbderaAtomFeedProviderTest.java?rev=810124&view=auto
==============================================================================
--- incubator/wink/trunk/wink-providers/wink-abdera-provider/src/test/java/org/apache/wink/common/internal/providers/entity/abdera/AbderaAtomFeedProviderTest.java
(added)
+++ incubator/wink/trunk/wink-providers/wink-abdera-provider/src/test/java/org/apache/wink/common/internal/providers/entity/abdera/AbderaAtomFeedProviderTest.java
Tue Sep  1 17:03:13 2009
@@ -0,0 +1,232 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *  
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *  
+ *******************************************************************************/
+package org.apache.wink.common.internal.providers.entity.abdera;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.Unmarshaller;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+import org.apache.wink.common.model.atom.AtomEntry;
+import org.apache.wink.common.model.atom.AtomFeed;
+import org.apache.wink.common.model.json.JSONUtils;
+import org.apache.wink.server.internal.servlet.MockServletInvocationTest;
+import org.apache.wink.test.mock.MockRequestConstructor;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
+
+/**
+ * Tests the Abdera Atom Feed provider.
+ */
+public class AbderaAtomFeedProviderTest extends MockServletInvocationTest {
+
+    @Override
+    protected Class<?>[] getClasses() {
+        return new Class<?>[] {TestResource.class};
+    }
+
+    @Override
+    protected Object[] getSingletons() {
+        return new Object[] {new AbderaAtomFeedProvider()};
+    }
+
+    @Path("test")
+    public static class TestResource {
+
+        @GET
+        @Path("atomfeed")
+        @Produces( {MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML})
+        public Feed getAtomFeed() throws IOException {
+            Feed feed = new Abdera().newFeed();
+            feed.setTitle("Report Definitions Collection");
+            feed
+                .setSubtitle("Collection of report definitions. Report definition is a XML
document describing how to build the report. It describes data sources, data sets, business
logic and rendering and report parameters. Report definitions may also use libraries.");
+            feed
+                .addLink("http://b216:8080/reporting/reports/?start-index=0&max-results=30&amp;alt=text/plain",
+                         "first");
+            feed.addLink("http://b216:8080/reporting/reports?alt=application/json", "alternate");
+            feed.addLink("http://b216:8080/reporting/reports", "self");
+            feed.addAuthor("admin");
+            feed.addCategory("urn:com:systinet:reporting:kind",
+                             "urn:com:systinet:reporting:kind:definitions:collection",
+                             "report definitions");
+            Entry e = feed.addEntry();
+            e.setId("toptenvalidators");
+            e.setTitle("top ten validators");
+            e.addLink("http://b216:8080/reporting/reports/toptenvalidators?alt=application/json",
+                      "alternate");
+            e.addAuthor("admin");
+            e.addCategory("urn:com:systinet:reporting:kind",
+                          "urn:com:systinet:reporting:kind:definition",
+                          "report definition");
+            return feed;
+        }
+
+        @POST
+        @Path("atomfeed")
+        @Produces( {MediaType.APPLICATION_ATOM_XML})
+        @Consumes( {MediaType.APPLICATION_ATOM_XML})
+        public Feed postAtomFeed(Feed feed) {
+            return feed;
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    public void testGetAtomFeedInXML() throws Exception {
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("GET",
+                                                        "/test/atomfeed",
+                                                        MediaType.APPLICATION_ATOM_XML);
+        MockHttpServletResponse response = invoke(request);
+        assertEquals(200, response.getStatus());
+        Unmarshaller u =
+            JAXBContext.newInstance(AtomEntry.class.getPackage().getName()).createUnmarshaller();
+        AtomFeed feed =
+            ((JAXBElement<AtomFeed>)u.unmarshal(new ByteArrayInputStream(response
+                .getContentAsByteArray()))).getValue();
+        assertEquals("Report Definitions Collection", feed.getTitle().getValue());
+        assertEquals("Collection of report definitions. Report definition is a XML document
describing how to build the report. It describes data sources, data sets, business logic and
rendering and report parameters. Report definitions may also use libraries.",
+                     feed.getSubtitle().getValue());
+        assertEquals("http://b216:8080/reporting/reports/?start-index=0&max-results=30&amp;alt=text/plain",
+                     feed.getLinks().get(0).getHref());
+        assertEquals("first", feed.getLinks().get(0).getRel());
+        assertEquals("http://b216:8080/reporting/reports?alt=application/json", feed.getLinks()
+            .get(1).getHref());
+        assertEquals("alternate", feed.getLinks().get(1).getRel());
+        assertEquals("http://b216:8080/reporting/reports", feed.getLinks().get(2).getHref());
+        assertEquals("self", feed.getLinks().get(2).getRel());
+        assertEquals("admin", feed.getAuthors().get(0).getName());
+        assertEquals("urn:com:systinet:reporting:kind", feed.getCategories().get(0).getScheme());
+        assertEquals("urn:com:systinet:reporting:kind:definitions:collection", feed.getCategories()
+            .get(0).getTerm());
+        assertEquals("report definitions", feed.getCategories().get(0).getLabel());
+
+        AtomEntry entry = feed.getEntries().get(0);
+        assertEquals("toptenvalidators", entry.getId());
+        assertEquals("top ten validators", entry.getTitle().getValue());
+        assertEquals("http://b216:8080/reporting/reports/toptenvalidators?alt=application/json",
+                     entry.getLinks().get(0).getHref());
+        assertEquals("alternate", entry.getLinks().get(0).getRel());
+        assertEquals("admin", entry.getAuthors().get(0).getName());
+        assertEquals("urn:com:systinet:reporting:kind", entry.getCategories().get(0).getScheme());
+        assertEquals("urn:com:systinet:reporting:kind:definition", entry.getCategories().get(0)
+            .getTerm());
+        assertEquals("report definition", entry.getCategories().get(0).getLabel());
+    }
+
+    public void testGetAtomEntryInJSON() throws Exception {
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("GET",
+                                                        "/test/atomfeed",
+                                                        MediaType.APPLICATION_JSON);
+        MockHttpServletResponse response = invoke(request);
+        assertEquals(200, response.getStatus());
+        System.out.println(response.getContentAsString());
+        assertTrue(response.getContentAsString(), JSONUtils.equals(JSONUtils
+            .objectForString(FEED_STR_JSON), JSONUtils.objectForString(response
+            .getContentAsString())));
+    }
+
+    @SuppressWarnings("unchecked")
+    public void testPostAtomEntry() throws Exception {
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("POST",
+                                                        "/test/atomfeed",
+                                                        MediaType.APPLICATION_ATOM_XML);
+        request.setContentType(MediaType.APPLICATION_ATOM_XML);
+        request.setContent(FEED_STR.getBytes());
+        MockHttpServletResponse response = invoke(request);
+        assertEquals(200, response.getStatus());
+
+        Unmarshaller u =
+            JAXBContext.newInstance(AtomEntry.class.getPackage().getName()).createUnmarshaller();
+        AtomFeed feed =
+            ((JAXBElement<AtomFeed>)u.unmarshal(new ByteArrayInputStream(response
+                .getContentAsByteArray()))).getValue();
+        assertEquals("Report Definitions Collection", feed.getTitle().getValue());
+        assertEquals("Collection of report definitions. Report definition is a XML document
describing how to build the report. It describes data sources, data sets, business logic and
rendering and report parameters. Report definitions may also use libraries.",
+                     feed.getSubtitle().getValue());
+        assertEquals("http://b216:8080/reporting/reports/?start-index=0&max-results=30&alt=text/plain",
+                     feed.getLinks().get(0).getHref());
+        assertEquals("first", feed.getLinks().get(0).getRel());
+        assertEquals("http://b216:8080/reporting/reports?alt=application/json", feed.getLinks()
+            .get(1).getHref());
+        assertEquals("alternate", feed.getLinks().get(1).getRel());
+        assertEquals("http://b216:8080/reporting/reports", feed.getLinks().get(2).getHref());
+        assertEquals("self", feed.getLinks().get(2).getRel());
+        assertEquals("admin", feed.getAuthors().get(0).getName());
+        assertEquals("urn:com:systinet:reporting:kind", feed.getCategories().get(0).getScheme());
+        assertEquals("urn:com:systinet:reporting:kind:definitions:collection", feed.getCategories()
+            .get(0).getTerm());
+        assertEquals("report definitions", feed.getCategories().get(0).getLabel());
+
+        AtomEntry entry = feed.getEntries().get(0);
+        assertEquals("toptenvalidators", entry.getId());
+        assertEquals("top ten validators", entry.getTitle().getValue());
+        assertEquals("http://b216:8080/reporting/reports/toptenvalidators?alt=application/json",
+                     entry.getLinks().get(0).getHref());
+        assertEquals("alternate", entry.getLinks().get(0).getRel());
+        assertEquals("admin", entry.getAuthors().get(0).getName());
+        assertEquals("urn:com:systinet:reporting:kind", entry.getCategories().get(0).getScheme());
+        assertEquals("urn:com:systinet:reporting:kind:definition", entry.getCategories().get(0)
+            .getTerm());
+        assertEquals("report definition", entry.getCategories().get(0).getLabel());
+    }
+
+    private static final String FEED_STR      =
+                                                  "<feed xml:base=\"http://b216:8080/reporting/reports\"
xmlns:opensearch=\"http://a9.com/-/spec/opensearch/1.1/\" xmlns=\"http://www.w3.org/2005/Atom\">\n"
+ "    <id>urn:systinet2:reporting:collection:reportdefinition</id>\n"
+                                                      + "    <title type=\"text\" xml:lang=\"en\">Report
Definitions Collection</title>\n"
+                                                      + "    <subtitle type=\"text\" xml:lang=\"en\">Collection
of report definitions. Report definition is a XML document describing how to build the report.
It describes data sources, data sets, business logic and rendering and report parameters.
Report definitions may also use libraries.</subtitle>\n"
+                                                      + "    <opensearch:itemsPerPage>1</opensearch:itemsPerPage>\n"
+                                                      + "    <opensearch:startIndex>0</opensearch:startIndex>\n"
+                                                      + "    <opensearch:totalResults>32</opensearch:totalResults>\n"
+                                                      + "    <link href=\"http://b216:8080/reporting/reports/?start-index=0&amp;max-results=30&amp;alt=text/plain\"
type=\"text/plain\" rel=\"first\"/>\n"
+                                                      + "    <link href=\"http://b216:8080/reporting/reports?alt=application/json\"
type=\"application/json\" rel=\"alternate\"/>\n"
+                                                      + "    <link href=\"http://b216:8080/reporting/reports\"
rel=\"self\"/>\n"
+                                                      + "    <author>\n"
+                                                      + "        <name>admin</name>\n"
+                                                      + "    </author>\n"
+                                                      + "    <category label=\"report
definitions\" scheme=\"urn:com:systinet:reporting:kind\" term=\"urn:com:systinet:reporting:kind:definitions:collection\"/>\n"
+                                                      + "    <entry>\n"
+                                                      + "        <id>toptenvalidators</id>\n"
+                                                      + "        <title type=\"text\"
xml:lang=\"en\">top ten validators</title>\n"
+                                                      + "        <published>@TIME@</published>\n"
+                                                      + "        <link href=\"http://b216:8080/reporting/reports/toptenvalidators?alt=application/json\"
type=\"application/json\" rel=\"alternate\"/>\n"
+                                                      + "        <author>\n"
+                                                      + "            <name>admin</name>\n"
+                                                      + "        </author>\n"
+                                                      + "        <category label=\"report
definition\" scheme=\"urn:com:systinet:reporting:kind\" term=\"urn:com:systinet:reporting:kind:definition\"/>\n"
+                                                      + "    </entry>\n"
+                                                      + "</feed>\n";
+    private static String       FEED_STR_JSON =
+                                                  "{ \"title\":\"Report Definitions Collection\",\"subtitle\":\"Collection
of report definitions. Report definition is a XML document describing how to build the report.
It describes data sources, data sets, business logic and rendering and report parameters.
Report definitions may also use libraries.\",\"authors\":[{\"name\":\"admin\"}],\"links\":[{\"href\":\"http://b216:8080/reporting/reports/?start-index=0&max-results=30&amp;alt=text/plain\",\"rel\":\"first\"},{\"href\":\"http://b216:8080/reporting/reports?alt=application/json\",\"rel\":\"alternate\"},{\"href\":\"http://b216:8080/reporting/reports\",\"rel\":\"self\"}],\"categories\":[{\"term\":\"urn:com:systinet:reporting:kind:definitions:collection\",\"scheme\":\"urn:com:systinet:reporting:kind\",\"label\":\"report
definitions\"}],\"entries\":[{\"id\":\"toptenvalidators\",\"title\":\"top ten validators\",\"authors\":[{\"name\":\"admin\"}],\"links\":[{\"href\":\"http://b216:
 8080/reporting/reports/toptenvalidators?alt=application/json\",\"rel\":\"alternate\"}],\"categories\":[{\"term\":\"urn:com:systinet:reporting:kind:definition\",\"scheme\":\"urn:com:systinet:reporting:kind\",\"label\":\"report
definition\"}]}]}";
+
+}

Propchange: incubator/wink/trunk/wink-providers/wink-abdera-provider/src/test/java/org/apache/wink/common/internal/providers/entity/abdera/AbderaAtomFeedProviderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message