@Test public void deleteByIdShouldRemoveUser() throws Exception { helper.putAndGetJsonResponse("/user/id/999"); helper.doDelete("/user/id/999"); final HttpResponse rsp = helper.doGet("/user/id/999", APPLICATION_XML); assertEquals(404, rsp.getStatusLine().getStatusCode()); }
@Test public void putShouldCreateAndReturnAnEmptyJsonUser() throws Exception { final JSONObject u = helper.putAndGetJsonResponse("/user/id/99"); assertEquals(99, u.getInt("id")); assertTrue(u.isNull("name")); assertTrue(u.isNull("nick")); }
@Test public void putShouldCreateAndReturnAnEmptyXmlUser() throws Exception { final User u = helper.putAndGetXmlResponse("/user/id/98", User.class); assertEquals(new Integer(98), u.getId()); assertNull(u.getName()); assertNull(u.getNick()); }
@Test public void getByInvalidNickShouldFailWith404() throws Exception { final HttpResponse rsp = helper.doGet("/user/nick/invalid", APPLICATION_XML); assertEquals(404, rsp.getStatusLine().getStatusCode()); }
@Test public void putShouldFailWith409WhenIdAlreadyExists() throws Exception { final HttpResponse rsp = helper.doPut("/user/id/1", APPLICATION_XML); assertEquals(409, rsp.getStatusLine().getStatusCode()); }
@Test public void putShouldStoreEmptyUser() throws Exception { helper.putAndGetJsonResponse("/user/id/97"); final User u = helper.getXmlResponse("/user/id/97", User.class); assertNotNull(u); }
@Test public void jsonUserInstanceShouldContainUrlAttribute() throws Exception { final JSONObject u = helper.getJsonResponse("/user/id/1"); assertTrue(u.has("url")); assertEquals(helper.getBaseUrl() + "/user/id/1", u.get("url")); }
@Test public void xmlUserInstanceShouldContainUrlAttribute() throws Exception { final User u = helper.getXmlResponse("/user/id/1", User.class); assertEquals(helper.getBaseUrl() + "/user/id/1", u.getUrl()); }
@Test public void userResourceShouldReturnXmlUserForUserUrlWithNick() throws Exception { final User u = helper.getXmlResponse("/user/nick/wimplash", User.class); assertEquals(new Integer(1), u.getId()); }
@Test public void userResourceShouldReturnXmlListForBaseUserUrl() throws Exception { final Users u = helper.getXmlResponse("/user", Users.class); assertEquals(2, u.getUser().size()); }
@Test public void userResourceShouldReturnJsonUserForUserUrlWithNick() throws Exception { final JSONObject user = helper.getJsonResponse("/user/nick/wimplash"); assertEquals(1, user.getInt("id")); }
@Test public void userResourceShouldReturnJsonListForBaseUserUrl() throws Exception { final JSONArray array = helper.getJsonArrayResponse("/user"); assertEquals(2, array.length()); }
@Test public void deleteByInvalidIdShouldFailWith404() throws Exception { final HttpResponse rsp = helper.doDelete("/user/id/999"); assertEquals(404, rsp.getStatusLine().getStatusCode()); }