You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wink.apache.org by jr...@apache.org on 2009/07/27 21:13:15 UTC
svn commit: r798259 - in
/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers:
./ src/ src/main/ src/main/java/ src/main/java/org/
src/main/java/org/apache/ src/main/java/org/apache/wink/ src/main/java/...
Author: jramos
Date: Mon Jul 27 19:13:14 2009
New Revision: 798259
URL: http://svn.apache.org/viewvc?rev=798259&view=rev
Log:
[WINK-92]: Add tests for atom model code
Added:
incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/
incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/pom.xml
incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/
incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/
incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/
incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/
incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/apache/
incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/apache/wink/
incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/apache/wink/jaxrs/
incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/apache/wink/jaxrs/test/
incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/apache/wink/jaxrs/test/Application.java
incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/apache/wink/jaxrs/test/atom/
incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/apache/wink/jaxrs/test/atom/Author.java
incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/apache/wink/jaxrs/test/atom/Blog.java
incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/apache/wink/jaxrs/test/atom/BlogEntry.java
incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/apache/wink/jaxrs/test/atom/BlogService.java
incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/apache/wink/jaxrs/test/atom/Comment.java
incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/resources/
incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/webapp/
incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/webapp/WEB-INF/
incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/webapp/WEB-INF/geronimo-web.xml
incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/webapp/WEB-INF/web.xml
incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/test/
incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/test/java/
incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/test/java/org/
incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/test/java/org/apache/
incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/test/java/org/apache/wink/
incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/test/java/org/apache/wink/jaxrs/
incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/test/java/org/apache/wink/jaxrs/test/
incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/test/java/org/apache/wink/jaxrs/test/AtomTest.java
Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/pom.xml
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/pom.xml?rev=798259&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/pom.xml (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/pom.xml Mon Jul 27 19:13:14 2009
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?><project>
+ <parent>
+ <artifactId>wink-server-integration-test</artifactId>
+ <groupId>org.apache.wink</groupId>
+ <version>0.1-incubating-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.wink</groupId>
+ <artifactId>wink-jaxrs-optional-providers</artifactId>
+ <packaging>war</packaging>
+ <name>wink-jaxrs-optional-providers Maven Webapp</name>
+ <version>0.1-incubating-SNAPSHOT</version>
+</project>
Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/apache/wink/jaxrs/test/Application.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/apache/wink/jaxrs/test/Application.java?rev=798259&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/apache/wink/jaxrs/test/Application.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/apache/wink/jaxrs/test/Application.java Mon Jul 27 19:13:14 2009
@@ -0,0 +1,36 @@
+/*
+ * 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.jaxrs.test;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.wink.jaxrs.test.atom.BlogService;
+
+public class Application extends javax.ws.rs.core.Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ Set<Class<?>> classes = new HashSet<Class<?>>();
+ classes.add(BlogService.class);
+ return classes;
+ }
+
+}
Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/apache/wink/jaxrs/test/atom/Author.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/apache/wink/jaxrs/test/atom/Author.java?rev=798259&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/apache/wink/jaxrs/test/atom/Author.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/apache/wink/jaxrs/test/atom/Author.java Mon Jul 27 19:13:14 2009
@@ -0,0 +1,52 @@
+/*
+ * 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.jaxrs.test.atom;
+
+import org.apache.wink.common.model.atom.AtomPerson;
+
+public class Author {
+
+ public String name;
+ public String email;
+
+ public AtomPerson toAtomPerson() {
+ AtomPerson person = new AtomPerson();
+ person.setName(name);
+ person.setEmail(email);
+ return person;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+}
Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/apache/wink/jaxrs/test/atom/Blog.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/apache/wink/jaxrs/test/atom/Blog.java?rev=798259&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/apache/wink/jaxrs/test/atom/Blog.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/apache/wink/jaxrs/test/atom/Blog.java Mon Jul 27 19:13:14 2009
@@ -0,0 +1,144 @@
+/*
+ * 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.jaxrs.test.atom;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.core.Response.ResponseBuilder;
+
+import org.apache.wink.common.model.atom.AtomEntry;
+import org.apache.wink.common.model.atom.AtomFeed;
+import org.apache.wink.common.model.atom.AtomLink;
+import org.apache.wink.common.model.atom.AtomText;
+
+public class Blog {
+
+ private int id;
+ private String title;
+ private Date updated;
+ private Map<Integer, BlogEntry> entries = new HashMap<Integer, BlogEntry>();
+
+ @GET
+ @Produces("application/atom+xml")
+ public AtomFeed getBlog(@Context UriInfo uriInfo) {
+ return toAtomFeed(uriInfo);
+ }
+
+ @Path("entries/{entryid}")
+ public BlogEntry getEntry(@PathParam("entryid") Integer entryId) {
+ BlogEntry entry = entries.get(entryId);
+ if (entry == null)
+ throw new WebApplicationException(404);
+ return entry;
+ }
+
+ @POST
+ @Path("entries")
+ public Response postBlogEntry(@Context UriInfo uriInfo, AtomEntry blogEntry) {
+ BlogEntry newEntry = new BlogEntry(this);
+ Author author = new Author();
+ author.setName(blogEntry.getAuthors().get(0).getName());
+ author.setEmail(blogEntry.getAuthors().get(0).getEmail());
+ newEntry.setAuthor(author);
+ newEntry.setId(BlogEntry.getNextId());
+ newEntry.setPosting(blogEntry.getContent().getValue());
+ newEntry.setTitle(blogEntry.getTitle().getValue());
+ newEntry.setUpdated(new Date());
+ entries.put(new Integer(newEntry.getId()), newEntry);
+ try {
+ URI uri = new URI(uriInfo.getBaseUri() + "blogservice/blogs/"+this.id+"/entries/"+newEntry.getId());
+ return Response.created(uri).build();
+ } catch (URISyntaxException e) {
+ throw new WebApplicationException(e);
+ }
+ }
+
+ public AtomFeed toAtomFeed(UriInfo uriInfo) {
+ AtomFeed feed = new AtomFeed();
+ feed.setId(id+"");
+ feed.setTitle(new AtomText(title));
+ feed.setUpdated(updated);
+ Set<Integer> ids = entries.keySet();
+ List<Integer> idList = new ArrayList<Integer>(ids);
+ Collections.sort(idList);
+ AtomLink link = null;
+ for (Integer entryId : idList) {
+ link = new AtomLink();
+ link.setHref(uriInfo.getBaseUri() + "blogservice/blogs/"
+ + this.id
+ + "/entries/"
+ + entries.get(entryId).getId());
+ link.setTitle(entries.get(entryId).getTitle());
+ feed.getLinks().add(link);
+ }
+ return feed;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public Date getUpdated() {
+ return updated;
+ }
+
+ public void setUpdated(Date updated) {
+ this.updated = updated;
+ }
+
+ public Map<Integer, BlogEntry> getEntries() {
+ return entries;
+ }
+
+ public void addEntry(BlogEntry newEntry) {
+ this.entries.put(newEntry.getId(), newEntry);
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+}
Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/apache/wink/jaxrs/test/atom/BlogEntry.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/apache/wink/jaxrs/test/atom/BlogEntry.java?rev=798259&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/apache/wink/jaxrs/test/atom/BlogEntry.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/apache/wink/jaxrs/test/atom/BlogEntry.java Mon Jul 27 19:13:14 2009
@@ -0,0 +1,183 @@
+/*
+ * 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.jaxrs.test.atom;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.wink.common.model.atom.AtomContent;
+import org.apache.wink.common.model.atom.AtomEntry;
+import org.apache.wink.common.model.atom.AtomLink;
+import org.apache.wink.common.model.atom.AtomText;
+
+public class BlogEntry {
+
+ private static int nextId = 0;
+
+ private Blog parent;
+ private String posting;
+ private int id;
+ private String title;
+ private Date updated;
+ private Author author;
+ private List<Comment> comments = new ArrayList<Comment>();
+
+ public BlogEntry(Blog parent) {
+ this.parent = parent;
+ }
+
+ @GET
+ @Produces("application/atom+xml")
+ public AtomEntry getEntry(@Context UriInfo uriInfo) {
+ return toAtomEntry(uriInfo);
+ }
+
+ @PUT
+ @Produces("application/atom+xml")
+ public AtomEntry updateBlogEntry(@Context UriInfo uriInfo, AtomEntry updatedEntry) {
+ Author author = getAuthor();
+ author.setName(updatedEntry.getAuthors().get(0).getName());
+ author.setEmail(updatedEntry.getAuthors().get(0).getEmail());
+ setPosting(updatedEntry.getContent().getValue());
+ setTitle(updatedEntry.getTitle().getValue());
+ setUpdated(new Date());
+ return toAtomEntry(uriInfo);
+ }
+
+ @Path("comments/{commentid}")
+ public Comment getComments(@PathParam("commentid") Integer commentId) {
+ Comment comment = this.comments.get(commentId);
+ if (comment == null)
+ throw new WebApplicationException(404);
+ return comment;
+ }
+
+ @POST
+ @Path("comments")
+ public Response postComment(@Context UriInfo uriInfo, AtomEntry comment) {
+ Comment newComment = new Comment();
+ Author author = new Author();
+ author.setName(comment.getAuthors().get(0).getName());
+ author.setEmail(comment.getAuthors().get(0).getEmail());
+ newComment.setAuthor(author);
+ newComment.setTitle(comment.getTitle().getValue());
+ newComment.setContent(comment.getContent().getValue());
+ comments.add(newComment);
+ try {
+ URI uri = new URI(uriInfo.getBaseUri() + "blogservice/blogs/"+this.parent.getId()+"/entries/"+this.id+"/comments/"+(comments.size()-1));
+ return Response.created(uri).build();
+ } catch (URISyntaxException e) {
+ throw new WebApplicationException(e);
+ }
+ }
+
+ public AtomEntry toAtomEntry(UriInfo uriInfo) {
+ AtomEntry entry = new AtomEntry();
+ entry.setId("" + this.id);
+ entry.setTitle(new AtomText(this.title));
+ entry.setUpdated(this.updated);
+ entry.getAuthors().add(author.toAtomPerson());
+ AtomContent content = new AtomContent();
+ content.setType("text");
+ content.setValue(this.posting);
+ entry.setContent(content);
+ AtomLink link = null;
+ int i = 0;
+ for (Comment comment : comments) {
+ link = new AtomLink();
+ link.setHref(uriInfo.getBaseUri() + "blogservice/blogs/"
+ + parent.getId()
+ + "/entries/"
+ + this.id
+ + "/comments/"
+ + i);
+ entry.getLinks().add(link);
+ ++i;
+ }
+ return entry;
+ }
+
+ public static int getNextId() {
+ return BlogEntry.nextId++;
+ }
+
+ public String getTitle() {
+ return this.title;
+ }
+
+ public String getPosting() {
+ return posting;
+ }
+
+ public void setPosting(String posting) {
+ this.posting = posting;
+ }
+
+ public List<Comment> getComments() {
+ return comments;
+ }
+
+ public void addComment(Comment comment) {
+ this.comments.add(comment);
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public Date getUpdated() {
+ return updated;
+ }
+
+ public void setUpdated(Date updated) {
+ this.updated = updated;
+ }
+
+ public Author getAuthor() {
+ return author;
+ }
+
+ public void setAuthor(Author author) {
+ this.author = author;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+}
Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/apache/wink/jaxrs/test/atom/BlogService.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/apache/wink/jaxrs/test/atom/BlogService.java?rev=798259&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/apache/wink/jaxrs/test/atom/BlogService.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/apache/wink/jaxrs/test/atom/BlogService.java Mon Jul 27 19:13:14 2009
@@ -0,0 +1,131 @@
+/*
+ * 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.jaxrs.test.atom;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.wink.common.model.atom.AtomFeed;
+import org.apache.wink.common.model.atom.AtomLink;
+import org.apache.wink.common.model.atom.AtomText;
+import org.slf4j.LoggerFactory;
+
+@Path("blogservice")
+public class BlogService {
+ public static final String ID = "wink-blog-service";
+
+ private static List<Blog> blogs = new ArrayList<Blog>();
+
+ @Context
+ private UriInfo baseUri;
+
+ static {
+ Date date = new Date();
+ Blog winkDevBlog = new Blog();
+ winkDevBlog.setId(0);
+ winkDevBlog.setTitle("wink-developer-blog");
+ winkDevBlog.setUpdated(date);
+ BlogEntry entry1 = new BlogEntry(winkDevBlog);
+ Author author = new Author();
+ author.setName("Blog Admin");
+ author.setEmail("winkblogadmin@wink.blog.com");
+ entry1.setAuthor(author);
+ entry1.setId(BlogEntry.getNextId());
+ entry1.setPosting("Welcome to the wink developer blog!!");
+ entry1.setTitle("welcomePosting");
+ entry1.setUpdated(date);
+ winkDevBlog.addEntry(entry1);
+ BlogEntry entry2 = new BlogEntry(winkDevBlog);
+ entry2.setAuthor(author);
+ entry2.setId(BlogEntry.getNextId());
+ entry2
+ .setPosting("Wink developers,\n\nInstructions on how to set up the wink development have been posted to the wink wiki. Happy wink development!\n\nw--inkblogadmin");
+ entry2.setTitle("Wink Development Env");
+ entry2.setUpdated(date);
+ winkDevBlog.addEntry(entry2);
+ Comment comment = new Comment();
+ Author author2 = new Author();
+ author2.setName("Wink Coder");
+ author2.setEmail("winkcoder@mybusiness.com");
+ comment.setAuthor(author2);
+ comment.setContent("Instructions look great! Now I can begin Wink development!");
+ comment.setTitle("Great!");
+ entry2.addComment(comment);
+ BlogService.blogs.add(winkDevBlog);
+
+ Blog winkUserBlog = new Blog();
+ winkUserBlog.setId(1);
+ winkUserBlog.setTitle("wink-user-blog");
+ winkUserBlog.setUpdated(date);
+ BlogEntry entry3 = new BlogEntry(winkUserBlog);
+ Author author3 = new Author();
+ author3.setName("Eager User");
+ author3.setEmail("winkuser@wink.blog.com");
+ entry3.setAuthor(author3);
+ entry3.setId(BlogEntry.getNextId());
+ entry3.setPosting("I hear that the 0.1 SNAPSHOT will be available soon! I can't wait!!!");
+ entry3.setTitle("0.1 SNAPSHOT");
+ entry3.setUpdated(date);
+ winkUserBlog.addEntry(entry3);
+ Comment comment2 = new Comment();
+ Author author4 = new Author();
+ author4.setName("Blog Reader");
+ author4.setEmail("blogreader@blogreaders.org");
+ comment2.setAuthor(author4);
+ comment2.setContent("This is good news. I'll be sure to try it out.");
+ comment2.setTitle("Good news");
+ entry3.addComment(comment2);
+ BlogService.blogs.add(winkUserBlog);
+ }
+
+ @GET
+ @Produces("application/atom+xml")
+ public AtomFeed getBlogs() {
+ AtomFeed ret = new AtomFeed();
+ ret.setId(BlogService.ID);
+ ret.setTitle(new AtomText(BlogService.ID));
+ AtomLink link = null;
+ for(int i = 0; i < BlogService.blogs.size(); ++i) {
+ link = new AtomLink();
+ link.setHref(baseUri.getAbsolutePath() + "/blogs/" + i);
+ link.setTitle(BlogService.blogs.get(i).getTitle());
+ ret.getLinks().add(link);
+ }
+ return ret;
+ }
+
+ @Path("blogs/{blogid}")
+ public Blog getBlog(@PathParam("blogid") int blogId) {
+ Blog blog = BlogService.blogs.get(blogId);
+ LoggerFactory.getLogger(BlogService.class).info(blog.getTitle());
+ if (blog == null)
+ throw new WebApplicationException(404);
+ return blog;
+ }
+}
Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/apache/wink/jaxrs/test/atom/Comment.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/apache/wink/jaxrs/test/atom/Comment.java?rev=798259&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/apache/wink/jaxrs/test/atom/Comment.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/java/org/apache/wink/jaxrs/test/atom/Comment.java Mon Jul 27 19:13:14 2009
@@ -0,0 +1,106 @@
+/*
+ * 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.jaxrs.test.atom;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Produces;
+
+import org.apache.wink.common.model.atom.AtomContent;
+import org.apache.wink.common.model.atom.AtomEntry; /*
+ * 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.
+ */
+
+import org.apache.wink.common.model.atom.AtomText;
+
+public class Comment {
+
+ private String content;
+ private Author author;
+ private String title;
+
+ @GET
+ @Produces("application/atom+xml")
+ public AtomEntry getComment() {
+ return toAtomEntry();
+ }
+
+ @PUT
+ @Produces("application/atom+xml")
+ public AtomEntry updateComment(AtomEntry comment) {
+ Author author = getAuthor();
+ author.setName(comment.getAuthors().get(0).getName());
+ author.setEmail(comment.getAuthors().get(0).getEmail());
+ setTitle(comment.getTitle().getValue());
+ setContent(comment.getContent().getValue());
+ return toAtomEntry();
+ }
+
+ public AtomEntry toAtomEntry() {
+ AtomEntry entry = new AtomEntry();
+ AtomContent content = new AtomContent();
+ content.setValue(this.content);
+ content.setType("String");
+ entry.setContent(content);
+ entry.getAuthors().add(this.author.toAtomPerson());
+ entry.setTitle(new AtomText(this.title));
+ return entry;
+ }
+
+ public String getContent() {
+ return content;
+ }
+
+ public void setContent(String content) {
+ this.content = content;
+ }
+
+ public Author getAuthor() {
+ return author;
+ }
+
+ public void setAuthor(Author author) {
+ this.author = author;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+}
Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/webapp/WEB-INF/geronimo-web.xml
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/webapp/WEB-INF/geronimo-web.xml?rev=798259&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/webapp/WEB-INF/geronimo-web.xml (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/webapp/WEB-INF/geronimo-web.xml Mon Jul 27 19:13:14 2009
@@ -0,0 +1,35 @@
+<?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.
+-->
+
+<web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1"
+ xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.2"
+ xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2">
+
+ <sys:environment>
+ <sys:moduleId>
+ <sys:groupId>${groupId}</sys:groupId>
+ <sys:artifactId>${artifactId}</sys:artifactId>
+ <sys:version>${version}</sys:version>
+ <sys:type>war</sys:type>
+ </sys:moduleId>
+ </sys:environment>
+
+ <context-root>${artifactId}</context-root>
+</web-app>
Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/webapp/WEB-INF/web.xml?rev=798259&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/webapp/WEB-INF/web.xml (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/main/webapp/WEB-INF/web.xml Mon Jul 27 19:13:14 2009
@@ -0,0 +1,40 @@
+<?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.
+-->
+
+<!DOCTYPE web-app PUBLIC
+ "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd" >
+
+<web-app>
+ <display-name>Archetype Created Web Application</display-name>
+ <servlet>
+ <servlet-name>OptionalProviders</servlet-name>
+ <servlet-class>${wink.rest.servlet}</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.apache.wink.jaxrs.test.Application</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>OptionalProviders</servlet-name>
+ <url-pattern>/optionalproviders/*</url-pattern>
+ </servlet-mapping>
+</web-app>
Added: incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/test/java/org/apache/wink/jaxrs/test/AtomTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/test/java/org/apache/wink/jaxrs/test/AtomTest.java?rev=798259&view=auto
==============================================================================
--- incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/test/java/org/apache/wink/jaxrs/test/AtomTest.java (added)
+++ incubator/wink/trunk/wink-integration-test/wink-server-integration-test/wink-jaxrs-optional-providers/src/test/java/org/apache/wink/jaxrs/test/AtomTest.java Mon Jul 27 19:13:14 2009
@@ -0,0 +1,308 @@
+/*******************************************************************************
+ * 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.jaxrs.test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.wink.client.ClientResponse;
+import org.apache.wink.client.Resource;
+import org.apache.wink.client.RestClient;
+import org.apache.wink.common.model.atom.AtomContent;
+import org.apache.wink.common.model.atom.AtomEntry;
+import org.apache.wink.common.model.atom.AtomFeed;
+import org.apache.wink.common.model.atom.AtomLink;
+import org.apache.wink.common.model.atom.AtomPerson;
+import org.apache.wink.common.model.atom.AtomText;
+import org.apache.wink.jaxrs.test.atom.BlogService;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+
+public class AtomTest extends TestCase {
+
+ final private static String BASE_URI = ServerEnvironmentInfo.getBaseURI() + "/optionalproviders/blogservice";
+
+ public void testAtomGETBlogs() throws Exception {
+ RestClient client = new RestClient();
+ Resource resource = client.resource(BASE_URI);
+ AtomFeed feed = resource.accept("application/atom+xml").get(AtomFeed.class);
+ assertEquals(BlogService.ID, feed.getId());
+ assertEquals(BlogService.ID, feed.getTitle().getValue());
+
+ List<AtomLink> expectedLinks = new ArrayList<AtomLink>();
+ AtomLink link = new AtomLink();
+ link.setHref(BASE_URI+"/blogs/0");
+ expectedLinks.add(link);
+ link = new AtomLink();
+ link.setHref(BASE_URI+"/blogs/1");
+ expectedLinks.add(link);
+ List<AtomLink> actual = feed.getLinks();
+ assertEquals(expectedLinks.size(), actual.size());
+ for(int i = 0; i < actual.size(); ++i)
+ assertEquals(expectedLinks.get(i).getHref(), actual.get(i).getHref());
+ }
+
+ public void testAtomGETBlog() throws Exception {
+ RestClient client = new RestClient();
+ Resource resource = client.resource(BASE_URI+"/blogs/0");
+ AtomFeed feed = resource.accept("application/atom+xml").get(AtomFeed.class);
+ assertEquals("0", feed.getId());
+ assertEquals("wink-developer-blog", feed.getTitle().getValue());
+
+ List<AtomLink> expectedLinks = new ArrayList<AtomLink>();
+ AtomLink link = new AtomLink();
+ link.setHref(BASE_URI+"/blogs/0/entries/0");
+ expectedLinks.add(link);
+ link = new AtomLink();
+ link.setHref(BASE_URI+"/blogs/0/entries/1");
+ expectedLinks.add(link);
+ List<AtomLink> actual = feed.getLinks();
+ assertEquals(expectedLinks.size(), actual.size());
+ for(int i = 0; i < actual.size(); ++i)
+ assertEquals(expectedLinks.get(i).getHref(), actual.get(i).getHref());
+
+ client = new RestClient();
+ resource = client.resource(BASE_URI+"/blogs/1");
+ feed = resource.accept("application/atom+xml").get(AtomFeed.class);
+ assertEquals("1", feed.getId());
+ assertEquals("wink-user-blog", feed.getTitle().getValue());
+
+ expectedLinks = new ArrayList<AtomLink>();
+ link = new AtomLink();
+ link.setHref(BASE_URI+"/blogs/1/entries/2");
+ expectedLinks.add(link);
+ actual = feed.getLinks();
+ assertEquals(expectedLinks.size(), actual.size());
+ for(int i = 0; i < actual.size(); ++i)
+ assertEquals(expectedLinks.get(i).getHref(), actual.get(i).getHref());
+ }
+
+ public void testAtomGETBlogEntry() throws Exception {
+ RestClient client = new RestClient();
+ Resource resource = client.resource(BASE_URI+"/blogs/0/entries/0");
+ AtomEntry entry = resource.accept("application/atom+xml").get(AtomEntry.class);
+ assertNotNull(entry.getAuthors());
+ assertEquals(1, entry.getAuthors().size());
+ AtomPerson author = entry.getAuthors().get(0);
+ assertNotNull(author);
+ assertEquals("Blog Admin", author.getName());
+ assertEquals("winkblogadmin@wink.blog.com", author.getEmail());
+ assertEquals("0", entry.getId());
+ assertEquals("Welcome to the wink developer blog!!", entry.getContent().getValue());
+ assertEquals("welcomePosting", entry.getTitle().getValue());
+ assertEquals(0, entry.getLinks().size());
+
+ resource = client.resource(BASE_URI+"/blogs/0/entries/1");
+ entry = resource.accept("application/atom+xml").get(AtomEntry.class);
+ assertNotNull(entry.getAuthors());
+ assertEquals(1, entry.getAuthors().size());
+ author = entry.getAuthors().get(0);
+ assertNotNull(author);
+ assertEquals("Blog Admin", author.getName());
+ assertEquals("winkblogadmin@wink.blog.com", author.getEmail());
+ assertEquals("1", entry.getId());
+ assertEquals("Wink developers,\n\nInstructions on how to set up the wink development have been posted to the wink wiki. Happy wink development!\n\nw--inkblogadmin", entry.getContent().getValue());
+ assertEquals("Wink Development Env", entry.getTitle().getValue());
+ assertEquals(1, entry.getLinks().size());
+ List<AtomLink> comments = entry.getLinks();
+ assertEquals(BASE_URI+"/blogs/0/entries/1/comments/0", comments.get(0).getHref());
+
+ resource = client.resource(BASE_URI+"/blogs/1/entries/2");
+ entry = resource.accept("application/atom+xml").get(AtomEntry.class);
+ assertNotNull(entry.getAuthors());
+ assertEquals(1, entry.getAuthors().size());
+ author = entry.getAuthors().get(0);
+ assertNotNull(author);
+ assertEquals("Eager User", author.getName());
+ assertEquals("winkuser@wink.blog.com", author.getEmail());
+ assertEquals("2", entry.getId());
+ assertEquals("I hear that the 0.1 SNAPSHOT will be available soon! I can't wait!!!", entry.getContent().getValue());
+ assertEquals("0.1 SNAPSHOT", entry.getTitle().getValue());
+ comments = entry.getLinks();
+ assertEquals(1, entry.getLinks().size());
+ assertEquals(BASE_URI+"/blogs/1/entries/2/comments/0", comments.get(0).getHref());
+ }
+
+ public void testAtomGETBlogComments() throws Exception {
+ RestClient client = new RestClient();
+ Resource resource = client.resource(BASE_URI+"/blogs/0/entries/1/comments/0");
+ AtomEntry entry = resource.accept("application/atom+xml").get(AtomEntry.class);
+ assertNotNull(entry.getAuthors());
+ assertEquals(1, entry.getAuthors().size());
+ AtomPerson author = entry.getAuthors().get(0);
+ assertNotNull(author);
+ assertEquals("Wink Coder", author.getName());
+ assertEquals("winkcoder@mybusiness.com", author.getEmail());
+ assertEquals("Great!", entry.getTitle().getValue());
+ assertEquals("Instructions look great! Now I can begin Wink development!", entry.getContent().getValue());
+
+ resource = client.resource(BASE_URI+"/blogs/1/entries/2/comments/0");
+ entry = resource.accept("application/atom+xml").get(AtomEntry.class);
+ assertNotNull(entry.getAuthors());
+ assertEquals(1, entry.getAuthors().size());
+ author = entry.getAuthors().get(0);
+ assertNotNull(author);
+ assertEquals("Blog Reader", author.getName());
+ assertEquals("blogreader@blogreaders.org", author.getEmail());
+ assertEquals("Good news", entry.getTitle().getValue());
+ assertEquals("This is good news. I'll be sure to try it out.", entry.getContent().getValue());
+ }
+
+ public void testAtomPOSTBlogEntry() throws Exception {
+ RestClient client = new RestClient();
+ Resource resource = client.resource(BASE_URI+"/blogs/0/entries");
+ AtomEntry entry = new AtomEntry();
+ AtomPerson author = new AtomPerson();
+ author.setName("Blog Admin");
+ author.setEmail("winkblogadmin@wink.blog.com");
+ entry.getAuthors().add(author);
+ AtomContent content = new AtomContent();
+ content.setType("String");
+ content.setValue("This is a new entry in the blog");
+ entry.setContent(content);
+ entry.setTitle(new AtomText(("New blog entry")));
+
+ ClientResponse uri = resource.accept("application/atom+xml").contentType("application/atom+xml").post(entry);
+ String location = uri.getHeaders().getFirst("Location");
+ assertEquals(BASE_URI+"/blogs/0/entries/3", location);
+
+ resource = client.resource(location);
+ AtomEntry postedEntry = resource.accept("application/atom+xml").get(AtomEntry.class);
+ author = postedEntry.getAuthors().get(0);
+ assertNotNull(author);
+ assertEquals("Blog Admin", author.getName());
+ assertEquals("winkblogadmin@wink.blog.com", author.getEmail());
+ assertEquals("3", postedEntry.getId());
+ assertEquals("This is a new entry in the blog", entry.getContent().getValue());
+ assertEquals("New blog entry", entry.getTitle().getValue());
+ assertEquals(0, entry.getLinks().size());
+
+ resource = client.resource(BASE_URI+"/blogs/0");
+ AtomFeed feed = resource.accept("application/atom+xml").get(AtomFeed.class);
+ List<AtomLink> expectedLinks = new ArrayList<AtomLink>();
+ AtomLink link = new AtomLink();
+ link.setHref(BASE_URI+"/blogs/0/entries/0");
+ expectedLinks.add(link);
+ link = new AtomLink();
+ link.setHref(BASE_URI+"/blogs/0/entries/1");
+ expectedLinks.add(link);
+ link = new AtomLink();
+ link.setHref(BASE_URI+"/blogs/0/entries/3");
+ expectedLinks.add(link);
+ List<AtomLink> actual = feed.getLinks();
+ assertEquals(expectedLinks.size(), actual.size());
+ for(int i = 0; i < actual.size(); ++i)
+ assertEquals(expectedLinks.get(i).getHref(), actual.get(i).getHref());
+ }
+
+ public void testAtomPostBlogComment() throws Exception {
+ RestClient client = new RestClient();
+ Resource resource = client.resource(BASE_URI+"/blogs/0/entries/1/comments");
+ AtomEntry entry = new AtomEntry();
+ AtomPerson author = new AtomPerson();
+ author.setName("Wink Coder");
+ author.setEmail("winkcoder@mybusiness.com");
+ entry.getAuthors().add(author);
+ AtomContent content = new AtomContent();
+ content.setType("String");
+ content.setValue("I was able to set up the Wink development environment!");
+ entry.setContent(content);
+ entry.setTitle(new AtomText(("Success")));
+
+ ClientResponse uri = resource.accept("application/atom+xml").contentType("application/atom+xml").post(entry);
+ String location = uri.getHeaders().getFirst("Location");
+ assertEquals(BASE_URI+"/blogs/0/entries/1/comments/1", location);
+
+ resource = client.resource(location);
+ AtomEntry postedEntry = resource.accept("application/atom+xml").get(AtomEntry.class);
+ author = postedEntry.getAuthors().get(0);
+ assertNotNull(author);
+ assertEquals("Wink Coder", author.getName());
+ assertEquals("winkcoder@mybusiness.com", author.getEmail());
+ assertEquals("I was able to set up the Wink development environment!", entry.getContent().getValue());
+ assertEquals("Success", entry.getTitle().getValue());
+
+ resource = client.resource(BASE_URI+"/blogs/0/entries/1");
+ entry = resource.accept("application/atom+xml").get(AtomEntry.class);
+ List<AtomLink> expectedLinks = new ArrayList<AtomLink>();
+ AtomLink link = new AtomLink();
+ link.setHref(BASE_URI+"/blogs/0/entries/1/comments/0");
+ expectedLinks.add(link);
+ link = new AtomLink();
+ link.setHref(BASE_URI+"/blogs/0/entries/1/comments/1");
+ expectedLinks.add(link);
+ List<AtomLink> actual = entry.getLinks();
+ assertEquals(expectedLinks.size(), actual.size());
+ for(int i = 0; i < actual.size(); ++i)
+ assertEquals(expectedLinks.get(i).getHref(), actual.get(i).getHref());
+ }
+
+ public void testAtomPUTBlogEntry() throws Exception {
+ RestClient client = new RestClient();
+ Resource resource = client.resource(BASE_URI+"/blogs/0/entries/0");
+ AtomEntry entry = resource.accept("application/atom+xml").get(AtomEntry.class);
+ AtomPerson author = entry.getAuthors().get(0);
+ author.setName(author.getName()+"Updated");
+ author.setEmail(author.getEmail()+"Updated");
+ AtomText title = entry.getTitle();
+ title.setValue(title.getValue()+"Updated");
+ AtomContent content = entry.getContent();
+ content.setValue(content.getValue()+"Updated");
+
+ resource = client.resource(BASE_URI+"/blogs/0/entries/0");
+ AtomEntry updated = resource.accept("application/atom+xml").contentType("application/atom+xml").put(AtomEntry.class, entry);
+ assertNotNull(updated.getAuthors());
+ assertEquals(1, updated.getAuthors().size());
+ author = updated.getAuthors().get(0);
+ assertNotNull(author);
+ assertEquals("Blog AdminUpdated", author.getName());
+ assertEquals("winkblogadmin@wink.blog.comUpdated", author.getEmail());
+ assertEquals("0", updated.getId());
+ assertEquals("Welcome to the wink developer blog!!Updated", updated.getContent().getValue());
+ assertEquals("welcomePostingUpdated", updated.getTitle().getValue());
+ }
+
+ public void testAtomPUTBlogComment() throws Exception {
+ RestClient client = new RestClient();
+ Resource resource = client.resource(BASE_URI+"/blogs/0/entries/1/comments/0");
+ AtomEntry entry = resource.accept("application/atom+xml").get(AtomEntry.class);
+ AtomPerson author = entry.getAuthors().get(0);
+ author.setName(author.getName()+"Updated");
+ author.setEmail(author.getEmail()+"Updated");
+ AtomText title = entry.getTitle();
+ title.setValue(title.getValue()+"Updated");
+ AtomContent content = entry.getContent();
+ content.setValue(content.getValue()+"Updated");
+
+ resource = client.resource(BASE_URI+"/blogs/0/entries/1/comments/0");
+ AtomEntry updated = resource.accept("application/atom+xml").contentType("application/atom+xml").put(AtomEntry.class, entry);
+ assertNotNull(updated.getAuthors());
+ assertEquals(1, updated.getAuthors().size());
+ author = updated.getAuthors().get(0);
+ assertNotNull(author);
+ assertNotNull(author);
+ assertEquals("Wink CoderUpdated", author.getName());
+ assertEquals("winkcoder@mybusiness.comUpdated", author.getEmail());
+ assertEquals("Great!Updated", entry.getTitle().getValue());
+ assertEquals("Instructions look great! Now I can begin Wink development!Updated", entry.getContent().getValue());
+ }
+}