diff --git a/resteasy-links/src/main/java/org/jboss/resteasy/links/impl/JsonLinkDecorator.java b/resteasy-links/src/main/java/org/jboss/resteasy/links/impl/JsonLinkDecorator.java index 7bdee2dfb39..c62ead72b62 100644 --- a/resteasy-links/src/main/java/org/jboss/resteasy/links/impl/JsonLinkDecorator.java +++ b/resteasy-links/src/main/java/org/jboss/resteasy/links/impl/JsonLinkDecorator.java @@ -10,6 +10,7 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriInfo; import java.lang.annotation.Annotation; +import java.util.Collection; public class JsonLinkDecorator implements DecoratorProcessor { @@ -19,7 +20,15 @@ public DecoratedEntityContainer decorate(DecoratedEntityContainer target, AddLin ResourceMethodRegistry registry = (ResourceMethodRegistry) ResteasyContext.getContextData(Registry.class); // find all rest service classes and scan them - RESTUtils.addDiscovery(target.getEntity(), uriInfo, registry); + if (Collection.class.isAssignableFrom(target.getEntity().getClass())) { + Collection coll = (Collection) target.getEntity(); + for (Object entity : coll) { + RESTUtils.addDiscovery(entity, uriInfo, registry); + } + } else { + RESTUtils.addDiscovery(target.getEntity(), uriInfo, registry); + } + return target; } } diff --git a/resteasy-links/src/test/java/org/jboss/resteasy/links/test/Book.java b/resteasy-links/src/test/java/org/jboss/resteasy/links/test/Book.java index c40094da923..541b3309659 100644 --- a/resteasy-links/src/test/java/org/jboss/resteasy/links/test/Book.java +++ b/resteasy-links/src/test/java/org/jboss/resteasy/links/test/Book.java @@ -72,13 +72,13 @@ public void setComments(List comments) { this.comments = comments; } - public void addComment(int id, String text){ + public void addComment(String id, String text){ comments.add(new Comment(id, text, this)); } public Comment getComment(int commentId) { for(Comment c : comments) - if(c.getId() == commentId) + if(c.getId().equals(commentId)) return c; return null; } diff --git a/resteasy-links/src/test/java/org/jboss/resteasy/links/test/BookStore.java b/resteasy-links/src/test/java/org/jboss/resteasy/links/test/BookStore.java index a1d5339f32f..e354bf365ac 100644 --- a/resteasy-links/src/test/java/org/jboss/resteasy/links/test/BookStore.java +++ b/resteasy-links/src/test/java/org/jboss/resteasy/links/test/BookStore.java @@ -33,8 +33,8 @@ public class BookStore { { Book book = new Book("foo", "bar"); - book.addComment(0, "great book"); - book.addComment(1, "terrible book"); + book.addComment(Integer.toString(0), "great book"); + book.addComment(Integer.toString(1), "terrible book"); books.put(book.getTitle(), book); } @@ -160,5 +160,4 @@ public void deleteComment(@PathParam("id") String bookId, @PathParam("cid") int Comment c = book.getComment(commentId); book.getComments().remove(c); } - } diff --git a/resteasy-links/src/test/java/org/jboss/resteasy/links/test/BookStoreMinimal.java b/resteasy-links/src/test/java/org/jboss/resteasy/links/test/BookStoreMinimal.java index 9c3cac6011a..b901f5614ca 100644 --- a/resteasy-links/src/test/java/org/jboss/resteasy/links/test/BookStoreMinimal.java +++ b/resteasy-links/src/test/java/org/jboss/resteasy/links/test/BookStoreMinimal.java @@ -33,8 +33,9 @@ public class BookStoreMinimal { { Book book = new Book("foo", "bar"); - book.addComment(0, "great book"); - book.addComment(1, "terrible book"); + book.addComment(Integer.toString(0), "great book"); + book.addComment(Integer.toString(1), "terrible book"); + books.put(book.getTitle(), book); } diff --git a/resteasy-links/src/test/java/org/jboss/resteasy/links/test/Comment.java b/resteasy-links/src/test/java/org/jboss/resteasy/links/test/Comment.java index 5e421dad971..a616c2dfa75 100644 --- a/resteasy-links/src/test/java/org/jboss/resteasy/links/test/Comment.java +++ b/resteasy-links/src/test/java/org/jboss/resteasy/links/test/Comment.java @@ -13,42 +13,48 @@ @XmlRootElement @XmlAccessorType(XmlAccessType.NONE) public class Comment { - public int id; + + @XmlAttribute + @XmlID + public String id; + @XmlElement public String text; @ParentResource public Book book; @XmlElement - // These both fail deserialisation for some reason -// @XmlElement(name = "link", namespace = "http://www.w3.org/2005/Atom") -// @XmlElementRef private RESTServiceDiscovery rest; public Comment() { } - public Comment(final int id, final String text, final Book book) { + public Comment(final String id, final String text, final Book book) { this.id = id; this.text = text; this.book = book; } - public int getId() { + public String getId() { return id; } - public void setId(int id) { + + public void setId(String id) { this.id = id; } + public String getText() { return text; } + public void setText(String text) { this.text = text; } + public Book getBook() { return book; } + public void setBook(Book book) { this.book = book; } @@ -60,11 +66,4 @@ public RESTServiceDiscovery getRest() { public void setRest(RESTServiceDiscovery rest) { this.rest = rest; } - - // JAXB wants an ID to be a String... - @XmlAttribute - @XmlID - public String getXMLID(){ - return Integer.toString(id); - } } diff --git a/resteasy-links/src/test/java/org/jboss/resteasy/links/test/SecureBookStore.java b/resteasy-links/src/test/java/org/jboss/resteasy/links/test/SecureBookStore.java index 700d0dc48b5..0252c155f4f 100644 --- a/resteasy-links/src/test/java/org/jboss/resteasy/links/test/SecureBookStore.java +++ b/resteasy-links/src/test/java/org/jboss/resteasy/links/test/SecureBookStore.java @@ -23,8 +23,8 @@ public class SecureBookStore { { Book book = new Book("foo", "bar"); - book.addComment(0, "great book"); - book.addComment(1, "terrible book"); + book.addComment(Integer.toString(0), "great book"); + book.addComment(Integer.toString(1), "terrible book"); books.put(book.getTitle(), book); } diff --git a/resteasy-links/src/test/java/org/jboss/resteasy/links/test/SecureBookStoreMinimal.java b/resteasy-links/src/test/java/org/jboss/resteasy/links/test/SecureBookStoreMinimal.java index 0e165c8a414..65736b16a2e 100644 --- a/resteasy-links/src/test/java/org/jboss/resteasy/links/test/SecureBookStoreMinimal.java +++ b/resteasy-links/src/test/java/org/jboss/resteasy/links/test/SecureBookStoreMinimal.java @@ -23,8 +23,8 @@ public class SecureBookStoreMinimal { { Book book = new Book("foo", "bar"); - book.addComment(0, "great book"); - book.addComment(1, "terrible book"); + book.addComment(Integer.toString(0), "great book"); + book.addComment(Integer.toString(1), "terrible book"); books.put(book.getTitle(), book); } diff --git a/resteasy-links/src/test/java/org/jboss/resteasy/links/test/TestFacadeLinks.java b/resteasy-links/src/test/java/org/jboss/resteasy/links/test/TestFacadeLinks.java index 8b887cd7e0d..c8d19358cad 100644 --- a/resteasy-links/src/test/java/org/jboss/resteasy/links/test/TestFacadeLinks.java +++ b/resteasy-links/src/test/java/org/jboss/resteasy/links/test/TestFacadeLinks.java @@ -24,7 +24,6 @@ import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -89,12 +88,14 @@ public void after(){ } @Test - @Ignore - public void testLinks() throws Exception - { + public void testLinksXML() throws Exception { ScrollableCollection comments = client.getScrollableCommentsXML("foo", "book"); checkCommentsLinks(url, comments); - comments = client.getScrollableCommentsJSON("foo", "book"); + } + + @Test + public void testLinksJSON() throws Exception { + ScrollableCollection comments = client.getScrollableCommentsJSON("foo", "book"); checkCommentsLinks(url, comments); } @@ -124,36 +125,4 @@ private void checkCommentsLinks(String url, ScrollableCollection comments) { Assert.assertNotNull(atomLink); Assert.assertEquals(url+"/", atomLink.getHref()); } - - private void checkCommentLinks(String url, Comment comment) { - Assert.assertNotNull(comment); - Assert.assertEquals(0, comment.getId()); - RESTServiceDiscovery links = comment.getRest(); - Assert.assertNotNull(links); - Assert.assertEquals(6, links.size()); - // self - AtomLink atomLink = links.getLinkForRel("self"); - Assert.assertNotNull(atomLink); - Assert.assertEquals(url+"/book/foo/comment/0", atomLink.getHref()); - // update - atomLink = links.getLinkForRel("update"); - Assert.assertNotNull(atomLink); - Assert.assertEquals(url+"/book/foo/comment/0", atomLink.getHref()); - // remove - atomLink = links.getLinkForRel("remove"); - Assert.assertNotNull(atomLink); - Assert.assertEquals(url+"/book/foo/comment/0", atomLink.getHref()); - // list - atomLink = links.getLinkForRel("list"); - Assert.assertNotNull(atomLink); - Assert.assertEquals(url+"/book/foo/comments", atomLink.getHref()); - // add - atomLink = links.getLinkForRel("add"); - Assert.assertNotNull(atomLink); - Assert.assertEquals(url+"/book/foo/comments", atomLink.getHref()); - // collection - atomLink = links.getLinkForRel("collection"); - Assert.assertNotNull(atomLink); - Assert.assertEquals(url+"/book/foo/comment-collection", atomLink.getHref()); - } } diff --git a/resteasy-links/src/test/java/org/jboss/resteasy/links/test/TestLinks.java b/resteasy-links/src/test/java/org/jboss/resteasy/links/test/TestLinks.java index c023d055727..b4c4a595016 100644 --- a/resteasy-links/src/test/java/org/jboss/resteasy/links/test/TestLinks.java +++ b/resteasy-links/src/test/java/org/jboss/resteasy/links/test/TestLinks.java @@ -24,11 +24,9 @@ import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; @RunWith(Parameterized.class) public class TestLinks @@ -54,7 +52,7 @@ public static void afterClass() throws Exception dispatcher = null; } - @Parameters + @Parameterized.Parameters public static List[]> getParameters(){ return Arrays.asList(new Class[]{BookStore.class}, new Class[]{BookStoreMinimal.class}); } @@ -90,7 +88,6 @@ public void after(){ @Test public void testLinksXML() throws Exception { - Book book = client.getBookXML("foo"); checkBookLinks1(url, book); @@ -98,21 +95,22 @@ public void testLinksXML() throws Exception { @Test public void testLinksJson() throws Exception { - Book book = client.getBookJSON("foo"); checkBookLinks1(url, book); - } @Test - @Ignore - public void testComments() throws Exception + public void testCommentsXML() throws Exception { List comments = client.getBookCommentsXML("foo"); Assert.assertNotNull(comments); Assert.assertFalse(comments.isEmpty()); checkCommentLinks(url, comments.get(0)); - comments = client.getBookCommentsJSON("foo"); + } + + @Test + public void testCommentsJson() throws Exception { + List comments = client.getBookCommentsJSON("foo"); Assert.assertNotNull(comments); Assert.assertFalse(comments.isEmpty()); checkCommentLinks(url, comments.get(0)); @@ -157,7 +155,7 @@ private void checkBookLinks1(String url, Book book) { private void checkCommentLinks(String url, Comment comment) { Assert.assertNotNull(comment); - Assert.assertEquals(0, comment.getId()); + Assert.assertEquals(Integer.toString(0), comment.getId()); RESTServiceDiscovery links = comment.getRest(); Assert.assertNotNull(links); Assert.assertEquals(6, links.size()); diff --git a/resteasy-links/src/test/java/org/jboss/resteasy/links/test/el/BookStoreInvalidEL.java b/resteasy-links/src/test/java/org/jboss/resteasy/links/test/el/BookStoreInvalidEL.java index 571dbf93e35..9d2b959d764 100644 --- a/resteasy-links/src/test/java/org/jboss/resteasy/links/test/el/BookStoreInvalidEL.java +++ b/resteasy-links/src/test/java/org/jboss/resteasy/links/test/el/BookStoreInvalidEL.java @@ -18,8 +18,8 @@ public class BookStoreInvalidEL { { Book book = new Book("foo", "bar"); - book.addComment(0, "great book"); - book.addComment(1, "terrible book"); + book.addComment(Integer.toString(0), "great book"); + book.addComment(Integer.toString(1), "terrible book"); books.put(book.getTitle(), book); } diff --git a/resteasy-links/src/test/java/org/jboss/resteasy/links/test/el/BookStoreNoPackage.java b/resteasy-links/src/test/java/org/jboss/resteasy/links/test/el/BookStoreNoPackage.java index 6e94f23d707..d10c97ccd7a 100644 --- a/resteasy-links/src/test/java/org/jboss/resteasy/links/test/el/BookStoreNoPackage.java +++ b/resteasy-links/src/test/java/org/jboss/resteasy/links/test/el/BookStoreNoPackage.java @@ -18,8 +18,8 @@ public class BookStoreNoPackage { { Book book = new Book("foo", "bar"); - book.addComment(0, "great book"); - book.addComment(1, "terrible book"); + book.addComment(Integer.toString(0), "great book"); + book.addComment(Integer.toString(1), "terrible book"); books.put(book.getTitle(), book); }