コード例 #1
0
ファイル: CmpGetTest.java プロジェクト: ellen/cosmo
  private CmpUser createUserFromXml(Element root) throws Exception {
    if (root == null) {
      return null;
    }

    CmpUser u = new CmpUser();

    u.setUsername(DomUtil.getChildTextTrim(root, UserResource.EL_USERNAME, OutputsXml.NS_CMP));
    u.setFirstName(DomUtil.getChildTextTrim(root, UserResource.EL_FIRSTNAME, OutputsXml.NS_CMP));
    u.setLastName(DomUtil.getChildTextTrim(root, UserResource.EL_LASTNAME, OutputsXml.NS_CMP));
    u.setEmail(DomUtil.getChildTextTrim(root, UserResource.EL_EMAIL, OutputsXml.NS_CMP));
    u.setUrl(DomUtil.getChildTextTrim(root, UserResource.EL_URL, OutputsXml.NS_CMP));
    u.setHomedirUrl(DomUtil.getChildTextTrim(root, UserResource.EL_HOMEDIRURL, OutputsXml.NS_CMP));

    u.setCreationDate(
        DateUtil.parseRfc3339Date(
            DomUtil.getChildTextTrim(root, UserResource.EL_CREATED, OutputsXml.NS_CMP)));

    u.setModifiedDate(
        DateUtil.parseRfc3339Date(
            DomUtil.getChildTextTrim(root, UserResource.EL_MODIFIED, OutputsXml.NS_CMP)));

    u.setAdmin(
        Boolean.parseBoolean(
            DomUtil.getChildTextTrim(root, UserResource.EL_ADMINISTRATOR, OutputsXml.NS_CMP)));

    return u;
  }
コード例 #2
0
ファイル: CmpGetTest.java プロジェクト: ellen/cosmo
 private CmpUser findUser(Set users, String username) {
   for (Iterator i = users.iterator(); i.hasNext(); ) {
     CmpUser u = (CmpUser) i.next();
     if (u.getUsername().equals(username)) {
       return u;
     }
   }
   return null;
 }
コード例 #3
0
ファイル: CmpGetTest.java プロジェクト: ellen/cosmo
  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());
  }
コード例 #4
0
ファイル: CmpGetTest.java プロジェクト: ellen/cosmo
  public void testGetOverlord() throws Exception {
    MockHttpServletRequest request = createMockRequest("GET", "/user/" + User.USERNAME_OVERLORD);
    MockHttpServletResponse response = new MockHttpServletResponse();
    servlet.service(request, response);

    assertEquals(response.getStatus(), MockHttpServletResponse.SC_OK);
    assertNotNull(response.getHeader("ETag"));

    CmpUser overlord = createUserFromXml(readXmlResponse(response));
    assertNotNull("overlord null", overlord);
    assertNotNull("overlord has no username", overlord.getUsername());
    assertEquals("usernames don't match", overlord.getUsername(), 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());
  }
コード例 #5
0
ファイル: CmpGetTest.java プロジェクト: ellen/cosmo
  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());
  }
コード例 #6
0
ファイル: CmpGetTest.java プロジェクト: ellen/cosmo
  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());
  }