Java Reference
In-Depth Information
Listing 9.3. The Spock test method to insert and delete a new Person
def 'insert and delete a new person'() {
Person taggart = new Person(first:'Peter Quincy', last:'Taggart')
when:
dao.create(taggart)
then:
dao.findAll().size() == old(dao.findAll().size()) + 1
taggart.id
when:
dao.delete(taggart.id)
then:
dao.findAll().size() == old(dao.findAll().size()) - 1
}
Now that the preliminaries are out of the way it's time to look at the features provided by
the JAX-RS API.
9.2.1. JAX-RS resource and tests
Moving now to the RESTful part of the application, there are several features of the JAX-
RS API involved in the implementation. Here I'll use a PersonResource class to im-
plement the CRUD methods.
Collection and item Resources
Normally two resources are provided: one for a collection of person instances and one for
an individual person. In this case both are combined to keep the sample short.
First, each method that's tied to a particular type of HTTP request uses one of these an-
notations: @GET , @POST , @PUT , or @DELETE . For example, the findAll method can be
implemented as follows:
@GET
public List<Person> findAll() {
return dao.findAll();
}
 
Search WWH ::




Custom Search