public void testGetAccount() throws Exception { User u1 = testHelper.makeDummyUser(); u1 = userService.createUser(u1); logInUser(u1); MockHttpServletRequest request = createMockRequest("GET", "/account"); MockHttpServletResponse response = new MockHttpServletResponse(); servlet.service(request, response); assertEquals(response.getStatus(), MockHttpServletResponse.SC_OK); assertNotNull(response.getHeader("ETag")); CmpUser user = createUserFromXml(readXmlResponse(response)); assertNotNull("user null", user); assertNotNull("user has no username", user.getUsername()); assertEquals("usernames don't match", user.getUsername(), u1.getUsername()); assertNotNull("user has no first name", user.getFirstName()); assertEquals("first names don't match", user.getFirstName(), u1.getFirstName()); assertNotNull("user has no last name", user.getLastName()); assertEquals("last names don't match", user.getLastName(), u1.getLastName()); assertNotNull("user has no email", user.getEmail()); assertEquals("emails don't match", user.getEmail(), u1.getEmail()); assertNotNull("user has no url", user.getUrl()); assertNotNull("user has no homedir url", user.getHomedirUrl()); }
public void testGetUser() throws Exception { User u1 = testHelper.makeDummyUser(); u1 = userService.createUser(u1); MockHttpServletRequest request = createMockRequest("GET", "/user/" + u1.getUsername()); MockHttpServletResponse response = new MockHttpServletResponse(); servlet.service(request, response); assertEquals(response.getStatus(), MockHttpServletResponse.SC_OK); assertNotNull(response.getHeader("ETag")); CmpUser user = createUserFromXml(readXmlResponse(response)); assertNotNull("user null", user); assertNotNull("user has no username", user.getUsername()); assertEquals("usernames don't match", user.getUsername(), u1.getUsername()); assertNotNull("user has no first name", user.getFirstName()); assertEquals("first names don't match", user.getFirstName(), u1.getFirstName()); assertNotNull("user has no last name", user.getLastName()); assertEquals("last names don't match", user.getLastName(), u1.getLastName()); assertNotNull("user has no email", user.getEmail()); assertEquals("emails don't match", user.getEmail(), u1.getEmail()); assertNotNull("user has no creation date", user.getCreationDate()); assertEquals( "creation dates don't match", DateUtil.formatRfc3339Date(user.getCreationDate()), DateUtil.formatRfc3339Date(u1.getCreationDate())); assertNotNull("user has no modification date", user.getModifiedDate()); assertEquals( "modification dates don't match", DateUtil.formatRfc3339Date(user.getModifiedDate()), DateUtil.formatRfc3339Date(u1.getModifiedDate())); assertNotNull("user has no administrator boolean", user.getAdmin()); assertEquals("administrator booleans don't match", user.getAdmin(), u1.getAdmin()); assertNotNull("user has no url", user.getUrl()); assertNotNull("user has no homedir url", user.getHomedirUrl()); }
public void testGetUsers() throws Exception { User u1 = testHelper.makeDummyUser(); userService.createUser(u1); User u2 = testHelper.makeDummyUser(); userService.createUser(u2); User u3 = testHelper.makeDummyUser(); userService.createUser(u3); MockHttpServletRequest request = createMockRequest("GET", "/users"); MockHttpServletResponse response = new MockHttpServletResponse(); servlet.service(request, response); assertEquals(response.getStatus(), MockHttpServletResponse.SC_OK); Set users = createUsersFromXml(readXmlResponse(response)); assertTrue(users.size() == 4); // account for overlord // can't just blindly check users.contains(u1) cos users read // from the response don't have passwords assertTrue("User 1 not found in users", containsUser(users, u1)); assertTrue("User 2 not found in users", containsUser(users, u2)); assertTrue("User 3 not found in users", containsUser(users, u3)); CmpUser regular = findUser(users, u1.getUsername()); assertNotNull("regular user has no first name", regular.getFirstName()); assertNotNull("regular user has no last name", regular.getLastName()); assertNotNull("regular user has no email", regular.getEmail()); assertNotNull("regular user has no url", regular.getUrl()); assertNotNull("regular user has no homedir url", regular.getHomedirUrl()); CmpUser overlord = findUser(users, User.USERNAME_OVERLORD); assertNotNull("overlord has no first name", overlord.getFirstName()); assertNotNull("overlord has no last name", overlord.getLastName()); assertNotNull("overlord has no email", overlord.getEmail()); assertNotNull("overlord has no url", overlord.getUrl()); assertNull("overlord has a homedir url", overlord.getHomedirUrl()); }
private boolean containsUser(Set users, User test) { return findUser(users, test.getUsername()) != null; }