Book Image

Building a RESTful Web Service with Spring

By : Ludovic Dewailly
Book Image

Building a RESTful Web Service with Spring

By: Ludovic Dewailly

Overview of this book

Table of Contents (17 chapters)
Building a RESTful Web Service with Spring
About the Author
About the Reviewers


We have built our sample property management system by decoupling the RESTful layer from the service implementation with the use of Java interfaces. Besides helping structure the code base and preventing tight coupling, this process also benefits unit testing. Indeed, instead of using concrete service implementations when testing the web tier of our application, we can rig mocked implementations in. For instance, consider the following unit test:

public class RoomsResourceTest {
  public void testGetRoom() throws Exception {
    RoomsResource resource = new RoomsResource();
    InventoryService inventoryService = ...
    ApiResponse response = resource.getRoom(1);
    assertEquals(Status.OK, response.getStatus());
    RoomDTO room = (RoomDTO) response.getData();
    assertEquals("Room1", room.getName());

When invoking RoomResource.getRoom() for an existing room, we expect non-null, successful responses containing a...