Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions chapter22/chapter22-consumer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -32,7 +33,7 @@ public ApplicationConfig() {
HashSet<Class<?>> c = new HashSet<>();
c.add(BookRestService.class);

c.add(MOXyJsonProvider.class);
c.add(JacksonJsonProvider.class);

classes = Collections.unmodifiableSet(c);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,6 +18,7 @@
import java.net.URI;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
* @author Antonio Goncalves
Expand All @@ -34,6 +38,11 @@ public class BookRestServiceIT {

private static final String XML = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><book><description>Science fiction comedy book</description><illustrations>false</illustrations><isbn>1-84023-742-2</isbn><nbOfPage>354</nbOfPage><price>12.5</price><title>The Hitchhiker's Guide to the Galaxy</title></book>";

@BeforeClass
public static void setupClass() {
client.configuration().register(MOXyJsonProvider.class);
}

// ======================================
// = Unit tests =
// ======================================
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<version.glassfish>4.0-b72</version.glassfish>
<version.weld>2.0.0.Beta3</version.weld>
<version.jersey>2.0-m10</version.jersey>
<version.eclipselink>2.5.0-M6</version.eclipselink>
<version.eclipselink>2.5.0-M7</version.eclipselink>
<version.hibernate.validator>5.0.0.Alpha2</version.hibernate.validator>
<version.json>1.0-b04</version.json>
<!-- Databases -->
Expand Down