Unit testing Spring controllers
Since we declared RESTful endpoints as Java methods with annotations, normal unit testing techniques can be employed. The de facto unit testing library for Java is JUnit. (http://www.junit.org). JUnit is a simple framework used for writing repeatable tests. The following code snippet illustrates how one can test a RESTful endpoint:
public class AvailabilityResourceTest { @Test public void testGetAvailability() throws Exception { AvailabilityService service = ... AvailabilityResource resource = new AvailabilityResource(service); WebRequest request = ... // invalid from date ApiResponse response = resource.getAvailability(null, "2017-01-02", "1", request); assertEquals(Status.ERROR, response.getStatus()); assertEquals(17, response.getError().getErrorCode()); // from is after until response = resource.getAvailability("2017-01-03", "2017-01-02", "1", request); assertEquals(Status.ERROR, response.getStatus()); assertEquals...