Added:
incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/VariantListBuilderImplTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/VariantListBuilderImplTest.java?rev=636586&view=auto
==============================================================================
---
incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/VariantListBuilderImplTest.java
(added)
+++
incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/VariantListBuilderImplTest.java
Wed Mar 12 17:20:41 2008
@@ -0,0 +1,141 @@
+/**
+ * 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.cxf.jaxrs.provider;
+
+import java.util.List;
+
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Variant;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class VariantListBuilderImplTest extends Assert {
+
+ @Test
+ public void testBuildAll() {
+ VariantListBuilderImpl vb = new VariantListBuilderImpl();
+ MediaType mt1 = new MediaType("*", "*");
+ MediaType mt2 = new MediaType("text", "xml");
+ List<Variant> variants =
+ vb.mediaTypes(mt1, mt2).languages("en", "fr").encodings("zip",
"identity").add().build();
+ assertEquals("8 variants need to be created", 8, variants.size());
+ assertTrue(verifyVariant(variants, new Variant(mt1, "en", "zip")));
+ assertTrue(verifyVariant(variants, new Variant(mt1, "en",
"identity")));
+ assertTrue(verifyVariant(variants, new Variant(mt1, "fr", "zip")));
+ assertTrue(verifyVariant(variants, new Variant(mt1, "fr",
"identity")));
+ assertTrue(verifyVariant(variants, new Variant(mt2, "en", "zip")));
+ assertTrue(verifyVariant(variants, new Variant(mt2, "en",
"identity")));
+ assertTrue(verifyVariant(variants, new Variant(mt2, "fr", "zip")));
+ assertTrue(verifyVariant(variants, new Variant(mt2, "fr",
"identity")));
+ }
+
+ @Test
+ public void testBuildTypeAndEnc() {
+ VariantListBuilderImpl vb = new VariantListBuilderImpl();
+ MediaType mt1 = new MediaType("*", "*");
+ MediaType mt2 = new MediaType("text", "xml");
+ List<Variant> variants =
+ vb.mediaTypes(mt1, mt2).encodings("zip", "identity").add().build();
+ assertEquals("4 variants need to be created", 4, variants.size());
+ assertTrue(verifyVariant(variants, new Variant(mt1, null, "zip")));
+ assertTrue(verifyVariant(variants, new Variant(mt1, null,
"identity")));
+ assertTrue(verifyVariant(variants, new Variant(mt2, null, "zip")));
+ assertTrue(verifyVariant(variants, new Variant(mt2, null,
"identity")));
+ }
+
+ @Test
+ public void testBuildTypeAndLang() {
+ VariantListBuilderImpl vb = new VariantListBuilderImpl();
+ MediaType mt1 = new MediaType("*", "*");
+ MediaType mt2 = new MediaType("text", "xml");
+ List<Variant> variants =
+ vb.mediaTypes(mt1, mt2).languages("en", "fr").add().build();
+ assertEquals("8 variants need to be created", 4, variants.size());
+ assertTrue(verifyVariant(variants, new Variant(mt1, "en", null)));
+ assertTrue(verifyVariant(variants, new Variant(mt1, "fr", null)));
+ assertTrue(verifyVariant(variants, new Variant(mt2, "en", null)));
+ assertTrue(verifyVariant(variants, new Variant(mt2, "fr", null)));
+ }
+
+ @Test
+ public void testBuildLangAndEnc() {
+ VariantListBuilderImpl vb = new VariantListBuilderImpl();
+ List<Variant> variants =
+ vb.languages("en", "fr").encodings("zip",
"identity").add().build();
+ assertEquals("4 variants need to be created", 4, variants.size());
+ assertTrue(verifyVariant(variants, new Variant(null, "en", "zip")));
+ assertTrue(verifyVariant(variants, new Variant(null, "en",
"identity")));
+ assertTrue(verifyVariant(variants, new Variant(null, "fr", "zip")));
+ assertTrue(verifyVariant(variants, new Variant(null, "fr",
"identity")));
+ }
+
+ @Test
+ public void testBuildLang() {
+ VariantListBuilderImpl vb = new VariantListBuilderImpl();
+ List<Variant> variants =
+ vb.languages("en", "fr").add().build();
+ assertEquals("2 variants need to be created", 2, variants.size());
+ assertTrue(verifyVariant(variants, new Variant(null, "en", null)));
+ assertTrue(verifyVariant(variants, new Variant(null, "en", null)));
+ }
+
+ @Test
+ public void testBuildEnc() {
+ VariantListBuilderImpl vb = new VariantListBuilderImpl();
+ List<Variant> variants =
+ vb.encodings("zip", "identity").add().build();
+ assertEquals("2 variants need to be created", 2, variants.size());
+ assertTrue(verifyVariant(variants, new Variant(null, null, "zip")));
+ assertTrue(verifyVariant(variants, new Variant(null, null,
"identity")));
+ }
+
+ @Test
+ public void testBuildType() {
+ VariantListBuilderImpl vb = new VariantListBuilderImpl();
+ List<Variant> variants =
+ vb.mediaTypes(new MediaType("*", "*"), new MediaType("text",
"xml")).add().build();
+ assertEquals("2 variants need to be created", 2, variants.size());
+ assertTrue(verifyVariant(variants, new Variant(new MediaType("*",
"*"), null, null)));
+ assertTrue(verifyVariant(variants, new Variant(new MediaType("text",
"xml"), null, null)));
+ }
+
+ private boolean verifyVariant(List<Variant> vs, Variant var) {
+ for (Variant v : vs) {
+
+ if (v.getLanguage() == null
+ && v.getEncoding() == null
+ && v.getMediaType() == null) {
+ return false;
+ }
+ boolean encodCheck = v.getEncoding() == null && var.getEncoding()
== null
+ || v.getEncoding().equals(var.getEncoding());
+ boolean langCheck = v.getLanguage() == null && var.getLanguage()
== null
+ || v.getLanguage().equals(var.getLanguage());
+ boolean typeCheck = v.getMediaType() == null && var.getMediaType()
== null
+ || v.getMediaType().equals(var.getMediaType());
+ if (encodCheck && langCheck && typeCheck) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+}
Propchange:
incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/VariantListBuilderImplTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/VariantListBuilderImplTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/Book.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/Book.java?rev=636586&r1=636585&r2=636586&view=diff
==============================================================================
---
incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/Book.java
(original)
+++
incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/Book.java
Wed Mar 12 17:20:41 2008
@@ -24,7 +24,7 @@
import javax.ws.rs.GET;
import javax.ws.rs.Path;
-import javax.ws.rs.UriParam;
+import javax.ws.rs.PathParam;
import javax.xml.bind.annotation.XmlRootElement;
@@ -54,7 +54,7 @@
@Path("chapters/{chapterid}/")
@GET
- public Chapter getChapter(@UriParam("id")int chapterid) {
+ public Chapter getChapter(@PathParam("id")int chapterid) {
return chapters.get(new Long(chapterid));
}
Modified:
incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookNoSubResource.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookNoSubResource.java?rev=636586&r1=636585&r2=636586&view=diff
==============================================================================
---
incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookNoSubResource.java
(original)
+++
incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookNoSubResource.java
Wed Mar 12 17:20:41 2008
@@ -24,7 +24,7 @@
import javax.ws.rs.GET;
import javax.ws.rs.Path;
-import javax.ws.rs.UriParam;
+import javax.ws.rs.PathParam;
import javax.xml.bind.annotation.XmlRootElement;
@@ -54,7 +54,7 @@
@Path("chapters/{chapterid}/")
@GET
- public Chapter getChapter(@UriParam("id")int chapterid) {
+ public Chapter getChapter(@PathParam("id")int chapterid) {
return chapters.get(new Long(chapterid));
}
Modified:
incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookStore.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookStore.java?rev=636586&r1=636585&r2=636586&view=diff
==============================================================================
---
incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookStore.java
(original)
+++
incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookStore.java
Wed Mar 12 17:20:41 2008
@@ -24,7 +24,7 @@
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
-import javax.ws.rs.UriParam;
+import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
@Path("/bookstore/")
@@ -34,7 +34,7 @@
}
@Path("/books/{bookId}/")
- public Book getBook(@UriParam("bookId") String id) {
+ public Book getBook(@PathParam("bookId") String id) {
return null;
}
@@ -52,7 +52,7 @@
@DELETE
@Path("/books/{bookId}/")
- public Response deleteBook(@UriParam("bookId") String id) {
+ public Response deleteBook(@PathParam("bookId") String id) {
return null;
}
}
Modified:
incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookStoreNoSubResource.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookStoreNoSubResource.java?rev=636586&r1=636585&r2=636586&view=diff
==============================================================================
---
incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookStoreNoSubResource.java
(original)
+++
incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookStoreNoSubResource.java
Wed Mar 12 17:20:41 2008
@@ -25,45 +25,61 @@
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
import javax.ws.rs.ProduceMime;
-import javax.ws.rs.UriParam;
import javax.ws.rs.core.Response;
[EMAIL PROTECTED]("text/plain")
@Path("/bookstore/")
public class BookStoreNoSubResource {
public BookStoreNoSubResource() {
}
+
+ @GET
+ public String getBookStoreInfo() {
+ return "This is a great store";
+ }
@GET
+ @Path("/books")
+ @ProduceMime("application/xml")
+ public Book getBooks() {
+ return null;
+ }
+
+ @GET
@Path("/books/{bookId}/")
@ProduceMime("application/xml")
- public Book getBook(@UriParam("bookId") String id) {
+ public Book getBook(@PathParam("bookId") String id) {
return null;
}
@GET
@Path("/books/{bookId}/")
@ProduceMime("application/json")
- public Book getBookJSON(@UriParam("bookId") String id) {
+ public Book getBookJSON(@PathParam("bookId") String id) {
return null;
}
@POST
@Path("/books")
+ @ProduceMime("application/xml")
public Response addBook(Book book) {
return null;
}
@PUT
@Path("/books/")
+ @ProduceMime("application/*")
public Response updateBook(Book book) {
return null;
}
@Path("/books/{bookId}/")
@DELETE
- public Response deleteBook(@UriParam("bookId") String id) {
+ @ProduceMime("application/xml")
+ public Response deleteBook(@PathParam("bookId") String id) {
return null;
}
}
Added:
incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookStoreTemplates.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookStoreTemplates.java?rev=636586&view=auto
==============================================================================
---
incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookStoreTemplates.java
(added)
+++
incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookStoreTemplates.java
Wed Mar 12 17:20:41 2008
@@ -0,0 +1,56 @@
+/**
+ * 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.cxf.jaxrs.resources;
+
+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.ProduceMime;
+import javax.ws.rs.core.Response;
+
[EMAIL PROTECTED]("{id}")
+public class BookStoreTemplates {
+
+ public BookStoreTemplates() {
+ }
+
+ @POST
+ public Response updateBookStoreInfo(@PathParam("id") String id) {
+ return null;
+ }
+
+ @GET
+ @Path("{id}")
+ public Book getBooks(@PathParam("id") String id) {
+ return null;
+ }
+
+ @PUT
+ @Path("{bookId}")
+ @ProduceMime("application/xml")
+ public Response updateBook(@PathParam("id") String id,
@PathParam("bookId") String bookId) {
+ return null;
+ }
+}
+
+
Propchange:
incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookStoreTemplates.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookStoreTemplates.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomBookStore.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomBookStore.java?rev=636586&r1=636585&r2=636586&view=diff
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomBookStore.java
(original)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomBookStore.java
Wed Mar 12 17:20:41 2008
@@ -30,9 +30,9 @@
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
import javax.ws.rs.ProduceMime;
-import javax.ws.rs.UriParam;
-import javax.ws.rs.core.HttpContext;
+import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import javax.xml.bind.JAXBContext;
@@ -47,7 +47,7 @@
@Path("/bookstore/")
public class AtomBookStore {
- @HttpContext private UriInfo uField;
+ @Context private UriInfo uField;
private Map<Long, Book> books = new HashMap<Long, Book>();
private Map<Long, CD> cds = new HashMap<Long, CD>();
private long bookId = 123;
@@ -60,8 +60,8 @@
@GET
@Path("/books/feed")
- @ProduceMime("application/atom+xml")
- public Feed getBooksAsFeed(@HttpContext UriInfo uParam) {
+ @ProduceMime({"application/atom+xml", "application/json" })
+ public Feed getBooksAsFeed(@Context UriInfo uParam) {
Factory factory = Abdera.getNewFactory();
Feed f = factory.newFeed();
f.setBaseUri(uParam.getAbsolutePath().toString());
@@ -97,7 +97,7 @@
URI uri =
uField.getBaseUriBuilder().path("bookstore", "books",
"entries",
Long.toString(b.getId())).build();
- return Response.created(uri).build();
+ return Response.created(uri).entity(e).build();
} catch (Exception ex) {
return Response.serverError().build();
}
@@ -105,8 +105,8 @@
@GET
@Path("/books/entries/{bookId}/")
- @ProduceMime("application/atom+xml")
- public Entry getBookAsEntry(@UriParam("bookId") String id) throws
BookNotFoundFault {
+ @ProduceMime({"application/atom+xml", "application/json" })
+ public Entry getBookAsEntry(@PathParam("bookId") String id) throws
BookNotFoundFault {
System.out.println("----invoking getBook with id: " + id);
Book book = books.get(Long.parseLong(id));
if (book != null) {
@@ -124,7 +124,7 @@
}
@Path("/books/subresources/{bookId}/")
- public AtomBook getBook(@UriParam("bookId") String id) throws
BookNotFoundFault {
+ public AtomBook getBook(@PathParam("bookId") String id) throws
BookNotFoundFault {
System.out.println("----invoking getBook with id: " + id);
Book book = books.get(Long.parseLong(id));
if (book != null) {
Modified:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomClientBookTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomClientBookTest.java?rev=636586&r1=636585&r2=636586&view=diff
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomClientBookTest.java
(original)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomClientBookTest.java
Wed Mar 12 17:20:41 2008
@@ -21,7 +21,6 @@
import java.io.InputStream;
import java.io.StringWriter;
-import java.net.URL;
import javax.xml.bind.JAXBContext;
@@ -32,8 +31,11 @@
import org.apache.abdera.model.Entry;
import org.apache.abdera.model.Feed;
import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.io.CachedOutputStream;
import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -51,21 +53,16 @@
public void testGetBooks() throws Exception {
String endpointAddress =
"http://localhost:9080/bookstore/books/feed";
- URL url = new URL(endpointAddress);
- InputStream in = url.openStream();
- assertNotNull(in);
-
- Document<Feed> doc = abdera.getParser().parse(in);
- Feed feed = doc.getRoot();
+ Feed feed = getFeed(endpointAddress, null);
assertEquals(endpointAddress, feed.getBaseUri().toString());
assertEquals("Collection of Books", feed.getTitle());
+ getAndCompareAsStrings("http://localhost:9080/bookstore/books/feed",
+ "resources/expected_atom_books_json.txt",
+ "application/json");
// add new book
- Book b = new Book();
- b.setId(256);
- b.setName("AtomBook");
- Entry e = createBookEntry(b);
+ Entry e = createBookEntry(256, "AtomBook");
StringWriter w = new StringWriter();
e.writeTo(w);
@@ -79,39 +76,67 @@
int result = httpclient.executeMethod(post);
assertEquals(201, result);
location = post.getResponseHeader("Location").getValue();
+ Document<Entry> entryDoc =
abdera.getParser().parse(post.getResponseBodyAsStream());
+ assertEquals(entryDoc.getRoot().toString(), e.toString());
} finally {
// Release current connection to the connection pool once you are
done
post.releaseConnection();
}
- url = new URL(location);
- in = url.openStream();
- assertNotNull(in);
-
- Document<Entry> entryDoc = abdera.getParser().parse(in);
- Entry entry = entryDoc.getRoot();
+ Entry entry = getEntry(location, null);
assertEquals(location, entry.getBaseUri().toString());
assertEquals("AtomBook", entry.getTitle());
-
- in.close();
-
+
// get existing book
endpointAddress =
"http://localhost:9080/bookstore/books/subresources/123";
- url = new URL(endpointAddress);
- in = url.openStream();
- assertNotNull(in);
-
- entryDoc = abdera.getParser().parse(in);
- entry = entryDoc.getRoot();
+ entry = getEntry(endpointAddress, null);
assertEquals("CXF in Action", entry.getTitle());
- in.close();
+ // now json
+
getAndCompareAsStrings("http://localhost:9080/bookstore/books/entries/123",
+ "resources/expected_atom_book_json.txt",
+ "application/json");
+
+ // do the same using a system query
+
getAndCompareAsStrings("http://localhost:9080/bookstore/books/entries/123?_contentType="
+ + "application/json",
+ "resources/expected_atom_book_json.txt",
+ "*/*");
+// do the same using a system query shortcut
+
getAndCompareAsStrings("http://localhost:9080/bookstore/books/entries/123?_contentType="
+ + "json",
+ "resources/expected_atom_book_json.txt",
+ "*/*");
+
}
- private Entry createBookEntry(Book b) throws Exception {
+ private void getAndCompareAsStrings(String address,
+ String resourcePath,
+ String type) throws Exception {
+ GetMethod get = new GetMethod(address);
+ get.setRequestHeader("Accept", type);
+ HttpClient httpClient = new HttpClient();
+ try {
+ httpClient.executeMethod(get);
+ String jsonContent =
getStringFromInputStream(get.getResponseBodyAsStream());
+ String expected = getStringFromInputStream(
+ getClass().getResourceAsStream(resourcePath));
+ assertEquals("Atom entry should've been formatted as json",
expected, jsonContent);
+ } finally {
+ get.releaseConnection();
+ }
+ }
+
+ private Entry createBookEntry(int id, String name) throws Exception {
+
+ Book b = new Book();
+ b.setId(id);
+ b.setName(name);
+
+
Factory factory = Abdera.getNewFactory();
JAXBContext jc = JAXBContext.newInstance(Book.class);
@@ -130,5 +155,41 @@
return e;
}
-
+ private Feed getFeed(String endpointAddress, String acceptType) throws
Exception {
+ GetMethod get = new GetMethod(endpointAddress);
+ if (acceptType != null) {
+ get.setRequestHeader("Accept", acceptType);
+ }
+ HttpClient httpClient = new HttpClient();
+ try {
+ httpClient.executeMethod(get);
+ Document<Feed> doc =
abdera.getParser().parse(get.getResponseBodyAsStream());
+ return doc.getRoot();
+ } finally {
+ get.releaseConnection();
+ }
+ }
+
+ private Entry getEntry(String endpointAddress, String acceptType) throws
Exception {
+ GetMethod get = new GetMethod(endpointAddress);
+ if (acceptType != null) {
+ get.setRequestHeader("Accept", acceptType);
+ }
+ HttpClient httpClient = new HttpClient();
+ try {
+ httpClient.executeMethod(get);
+ Document<Entry> doc =
abdera.getParser().parse(get.getResponseBodyAsStream());
+ return doc.getRoot();
+ } finally {
+ get.releaseConnection();
+ }
+ }
+
+ private String getStringFromInputStream(InputStream in) throws Exception {
+ CachedOutputStream bos = new CachedOutputStream();
+ IOUtils.copy(in, bos);
+ in.close();
+ bos.close();
+ return bos.getOut().toString();
+ }
}
Modified:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BadgerFishProvider.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BadgerFishProvider.java?rev=636586&r1=636585&r2=636586&view=diff
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BadgerFishProvider.java
(original)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BadgerFishProvider.java
Wed Mar 12 17:20:41 2008
@@ -31,6 +31,7 @@
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 javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
@@ -46,6 +47,7 @@
@ProduceMime("application/json")
@ConsumeMime("application/json")
[EMAIL PROTECTED]
public final class BadgerFishProvider
implements MessageBodyReader<Object>, MessageBodyWriter<Object> {
Modified:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Book.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Book.java?rev=636586&r1=636585&r2=636586&view=diff
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Book.java
(original)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Book.java
Wed Mar 12 17:20:41 2008
@@ -24,7 +24,7 @@
import javax.ws.rs.GET;
import javax.ws.rs.Path;
-import javax.ws.rs.UriParam;
+import javax.ws.rs.PathParam;
import javax.xml.bind.annotation.XmlRootElement;
@@ -56,7 +56,7 @@
@GET
@Path("chapters/{chapterid}/")
- public Chapter getChapter(@UriParam("chapterid")int chapterid) {
+ public Chapter getChapter(@PathParam("chapterid")int chapterid) {
System.out.println("----invoking getChapter with chapterid: " +
chapterid);
return chapters.get(new Long(chapterid));
Modified:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=636586&r1=636585&r2=636586&view=diff
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
(original)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
Wed Mar 12 17:20:41 2008
@@ -17,7 +17,6 @@
* under the License.
*/
-
package org.apache.cxf.systest.jaxrs;
@@ -29,8 +28,8 @@
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
import javax.ws.rs.ProduceMime;
-import javax.ws.rs.UriParam;
import javax.ws.rs.core.Response;
import javax.xml.transform.dom.DOMSource;
@@ -53,14 +52,21 @@
@GET
@Path("/books/{bookId}/")
- public Book getBook(@UriParam("bookId") String id) throws
BookNotFoundFault {
+ public Book getBook(@PathParam("bookId") String id) throws
BookNotFoundFault {
return doGetBook(id);
}
@GET
+ @Path("/books")
+ public Books getBooks() {
+ return new Books(books.values());
+ }
+
+
+ @GET
@Path("/books/{bookId}/")
@ProduceMime("application/json")
- public Book getBookAsJSON(@UriParam("bookId") String id) throws
BookNotFoundFault {
+ public Book getBookAsJSON(@PathParam("bookId") String id) throws
BookNotFoundFault {
return doGetBook(id);
}
@@ -77,7 +83,7 @@
}
@Path("/booksubresource/{bookId}/")
- public Book getBookSubResource(@UriParam("bookId") String id) throws
BookNotFoundFault {
+ public Book getBookSubResource(@PathParam("bookId") String id) throws
BookNotFoundFault {
System.out.println("----invoking getBookSubResource with id: " + id);
Book book = books.get(Long.parseLong(id));
if (book != null) {
@@ -92,7 +98,7 @@
@GET
@Path("/booknames/{bookId}/")
@ProduceMime("text/*")
- public String getBookName(@UriParam("bookId") int id) throws
BookNotFoundFault {
+ public String getBookName(@PathParam("bookId") int id) throws
BookNotFoundFault {
System.out.println("----invoking getBookName with id: " + id);
Book book = books.get(new Long(id));
if (book != null) {
@@ -159,7 +165,7 @@
@DELETE
@Path("/books/{bookId}/")
- public Response deleteBook(@UriParam("bookId") String id) {
+ public Response deleteBook(@PathParam("bookId") String id) {
System.out.println("----invoking deleteBook with bookId: " + id);
Book b = books.get(Long.parseLong(id));
@@ -175,7 +181,7 @@
@GET
@Path("/cd/{CDId}/")
- public CD getCD(@UriParam("CDId") String id) {
+ public CD getCD(@PathParam("CDId") String id) {
System.out.println("----invoking getCD with cdId: " + id);
CD cd = cds.get(Long.parseLong(id));
@@ -185,7 +191,7 @@
@GET
@Path("/cdwithmultitypes/{CDId}/")
@ProduceMime({"application/xml", "application/json" })
- public CD getCDWithMultiContentTypes(@UriParam("CDId") String id) {
+ public CD getCDWithMultiContentTypes(@PathParam("CDId") String id) {
System.out.println("----invoking getCDWithMultiContentTypes with cdId:
" + id);
CD cd = cds.get(Long.parseLong(id));
Added:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Books.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Books.java?rev=636586&view=auto
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Books.java
(added)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Books.java
Wed Mar 12 17:20:41 2008
@@ -0,0 +1,44 @@
+/**
+ * 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.cxf.systest.jaxrs;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
[EMAIL PROTECTED](name = "Books")
+public class Books {
+
+ private Collection<Book> books;
+
+ public Books() {
+ this.books = new ArrayList<Book>();
+ }
+
+ public Books(Collection<Book> books) {
+ this.books = books;
+ }
+
+ public Collection<Book> getBooks() {
+ return books;
+ }
+
+}
Propchange:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Books.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Books.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/PetStore.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/PetStore.java?rev=636586&r1=636585&r2=636586&view=diff
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/PetStore.java
(original)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/PetStore.java
Wed Mar 12 17:20:41 2008
@@ -23,8 +23,8 @@
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
import javax.ws.rs.ProduceMime;
-import javax.ws.rs.UriParam;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
@@ -40,7 +40,7 @@
@GET
@Path("/pets/{petId}/")
@ProduceMime("text/xml")
- public Response getStatus(@UriParam("petId")
+ public Response getStatus(@PathParam("petId")
String petId) throws Exception {
System.out.println("----invoking getStatus on the petStore for id: " +
petId);
Added:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_atom_book_json.txt
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_atom_book_json.txt?rev=636586&view=auto
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_atom_book_json.txt
(added)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_atom_book_json.txt
Wed Mar 12 17:20:41 2008
@@ -0,0 +1 @@
+{"contributors":[],"title":"CXF in
Action","content":{"value":"<Book><id>123<\/id><name>CXF in
Action<\/name><\/Book>","type":"application/xml"},"categories":[],"authors":[],"id":"123","links":[]}
\ No newline at end of file
Propchange:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_atom_book_json.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_atom_book_json.txt
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_atom_books_json.txt
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_atom_books_json.txt?rev=636586&view=auto
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_atom_books_json.txt
(added)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_atom_books_json.txt
Wed Mar 12 17:20:41 2008
@@ -0,0 +1 @@
+{"contributors":[],"title":"Collection of
Books","categories":[],"entries":[{"contributors":[],"title":"CXF in
Action","content":{"value":"<Book><id>123<\/id><name>CXF in
Action<\/name><\/Book>","type":"application/xml"},"categories":[],"authors":[],"id":"123","links":[]}],"authors":[{"name":"BookStore
Management Company"}],"id":"http://www.books.com","links":[]}
\ No newline at end of file
Propchange:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_atom_books_json.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_atom_books_json.txt
------------------------------------------------------------------------------
svn:mime-type = text/plain