Date inDate = new Date();
LocalDateTime in1Date = new LocalDateTime();
DateTime in2Date = new DateTime();
// A customer object test entry
Customer customerIn = new Customer();
customerIn.name = "Felix";
customerIn.address = "Test";
customerIn.date = inDate;
customerIn.date1 = in1Date;
customerIn.date2 = in2Date;
// TEST: Check the persistence operations "POST"
Customer customerOut = persistTestRecord(customerIn);
assertEquals("Checking name", customerOut.name, customerIn.name);
assertEquals("Checking id", customerOut._id > 0,true);
// TEST: Check the retrieval of the collections "GET"
JsonArray array = getTestCollection(null);
// Expect an array with the last entry must be a meta data record (with a attribute _cursor)
assertEquals("Checking received numbers of JSON Elements", 2,array.size());
JsonObject elem = array.get(array.size()-1).getAsJsonObject();
assertEquals("Checking that there is a 'cursor' elemen",elem.get("_cursor").getAsString().equals(""),true);
// TEST: Check the retrieval of a single entry "GET"
// Expect a single entry which can be converted in our domain object and correct attributes
customerOut = getTestRecord(customerOut._id,null);
assertEquals("Checking Name", customerOut.name, customerIn.name);
assertEquals("Checking Surname", customerOut.surname, customerIn.surname);
// 2014-06-14T15:17:20.262Z
assertEquals("Checking Date", customerOut.date,inDate);
// 2014-06-14T17:17:20.320
assertEquals("Checking Joda DateTime", customerOut.date1,in1Date);
//
assertEquals("Checking Joda DateTime", customerOut.date2,in2Date);
// TEST: Going to delete the entry "DELETE"
StringWriter outputStringWriter = new StringWriter();
when(request.getPathInfo()).thenReturn("/"+customerOut._id);
when(response.getWriter()).thenReturn(new PrintWriter(outputStringWriter));
customerServlet.doDelete(request, response);
// TEST: We shouldn't get any data back (i.e. deleted)
outputStringWriter = getTestRecordStringWriter(customerOut._id);
assertEquals("Checking empty JSON","{}", outputStringWriter.toString());
// TEST: Paging functionality
// Add 4 records
customerIn = new Customer();
customerIn.name = "Name1";
customerIn.surname = "Surname1";
customerIn.address = "Address1";
persistTestRecord(customerIn);
customerIn.name = "Name2";