From 9b7add4570c21556a9a672c5bb16ce04a675dc0f Mon Sep 17 00:00:00 2001 From: Alexis Hassler Date: Sat, 8 Dec 2012 16:52:29 +0100 Subject: [PATCH 1/3] Added test for GET of several books in json --- chapter22/chapter22-consumer/pom.xml | 4 +++ .../javaee7/chapter22/ApplicationConfig.java | 1 + .../javaee7/chapter22/BookRestServiceIT.java | 34 +++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/chapter22/chapter22-consumer/pom.xml b/chapter22/chapter22-consumer/pom.xml index 9c48a408..77b646f2 100644 --- a/chapter22/chapter22-consumer/pom.xml +++ b/chapter22/chapter22-consumer/pom.xml @@ -28,6 +28,10 @@ org.glassfish.jersey.containers jersey-container-servlet + + junit + junit + \ No newline at end of file diff --git a/chapter22/chapter22-service/src/main/java/org/agoncal/book/javaee7/chapter22/ApplicationConfig.java b/chapter22/chapter22-service/src/main/java/org/agoncal/book/javaee7/chapter22/ApplicationConfig.java index 1c2e5c37..986fa8e1 100644 --- a/chapter22/chapter22-service/src/main/java/org/agoncal/book/javaee7/chapter22/ApplicationConfig.java +++ b/chapter22/chapter22-service/src/main/java/org/agoncal/book/javaee7/chapter22/ApplicationConfig.java @@ -1,5 +1,6 @@ package org.agoncal.book.javaee7.chapter22; +import org.codehaus.jackson.jaxrs.JacksonJsonProvider; import org.eclipse.persistence.jaxb.rs.MOXyJsonProvider; import javax.ws.rs.ApplicationPath; diff --git a/chapter22/chapter22-service/src/test/java/org/agoncal/book/javaee7/chapter22/BookRestServiceIT.java b/chapter22/chapter22-service/src/test/java/org/agoncal/book/javaee7/chapter22/BookRestServiceIT.java index c35345ab..0888061e 100644 --- a/chapter22/chapter22-service/src/test/java/org/agoncal/book/javaee7/chapter22/BookRestServiceIT.java +++ b/chapter22/chapter22-service/src/test/java/org/agoncal/book/javaee7/chapter22/BookRestServiceIT.java @@ -1,5 +1,8 @@ package org.agoncal.book.javaee7.chapter22; +import org.codehaus.jackson.jaxrs.JacksonJsonProvider; +import org.eclipse.persistence.jaxb.rs.MOXyJsonProvider; +import org.junit.BeforeClass; import org.junit.Test; import javax.ws.rs.client.Client; @@ -15,6 +18,7 @@ import java.net.URI; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** * @author Antonio Goncalves @@ -34,6 +38,11 @@ public class BookRestServiceIT { private static final String XML = "Science fiction comedy bookfalse1-84023-742-235412.5The Hitchhiker's Guide to the Galaxy"; + @BeforeClass + public static void setupClass() { + client.configuration().register(MOXyJsonProvider.class); + } + // ====================================== // = Unit tests = // ====================================== @@ -63,6 +72,31 @@ public void shouldMarshallAListOfBooks() throws JAXBException { m.marshal(books, writer); } + @Test + public void shouldCreateReadAndDeleteTwoBooks() throws JAXBException { + Book firstBook = new Book("The Hitchhiker's Guide to the Galaxy", 12.5F, "Science fiction comedy book", "1-84023-742-2", 354, false); + Response firstResponse = client.target(uri).request().post(Entity.entity(firstBook, MediaType.APPLICATION_XML)); + assertEquals(Response.Status.CREATED, firstResponse.getStatusInfo()); + + Book secondBook = new Book("The Hitchhiker's Guide to the Galaxy, part 2", 42.5F, "Science fiction comedy book", "1-84023-742-x", 23, false); + Response secondResponse = client.target(uri).request().post(Entity.entity(secondBook, MediaType.APPLICATION_XML)); + assertEquals(Response.Status.CREATED, secondResponse.getStatusInfo()); + + Response response = client.target(uri).request(MediaType.APPLICATION_JSON).get(); + assertEquals(Response.Status.OK, response.getStatusInfo()); + Books books = response.readEntity(Books.class); + assertTrue(books.size() == 2); + + response = client.target(firstResponse.getLocation()).request().delete(); + assertEquals(Response.Status.NO_CONTENT, response.getStatusInfo()); + response = client.target(secondResponse.getLocation()).request().delete(); + assertEquals(Response.Status.NO_CONTENT, response.getStatusInfo()); + + response = client.target(uri).request(MediaType.APPLICATION_JSON).get(); + assertEquals(Response.Status.OK, response.getStatusInfo()); + assertTrue(response.readEntity(Books.class).isEmpty()); + } + @Test public void shouldCreateAndDeleteABook() throws JAXBException { From ebef68320e23edee89f1c2d393947d02bf7c7d90 Mon Sep 17 00:00:00 2001 From: Alexis Hassler Date: Sat, 8 Dec 2012 16:57:50 +0100 Subject: [PATCH 2/3] Use JacksonJsonProvider in place of MOXyJsonProvider (issue #5) --- .../org/agoncal/book/javaee7/chapter22/ApplicationConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapter22/chapter22-service/src/main/java/org/agoncal/book/javaee7/chapter22/ApplicationConfig.java b/chapter22/chapter22-service/src/main/java/org/agoncal/book/javaee7/chapter22/ApplicationConfig.java index 986fa8e1..7118dcc0 100644 --- a/chapter22/chapter22-service/src/main/java/org/agoncal/book/javaee7/chapter22/ApplicationConfig.java +++ b/chapter22/chapter22-service/src/main/java/org/agoncal/book/javaee7/chapter22/ApplicationConfig.java @@ -33,7 +33,7 @@ public ApplicationConfig() { HashSet> c = new HashSet<>(); c.add(BookRestService.class); - c.add(MOXyJsonProvider.class); + c.add(JacksonJsonProvider.class); classes = Collections.unmodifiableSet(c); } From 437241fd09b2df9c97bbafbec0ec66f5cd3890fe Mon Sep 17 00:00:00 2001 From: Alexis Hassler Date: Thu, 28 Feb 2013 11:06:50 +0100 Subject: [PATCH 3/3] chapter05 : NoClassDefFoundError --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2c1c7b77..3ba2c2ea 100644 --- a/pom.xml +++ b/pom.xml @@ -32,7 +32,7 @@ 4.0-b72 2.0.0.Beta3 2.0-m10 - 2.5.0-M6 + 2.5.0-M7 5.0.0.Alpha2 1.0-b04