public void testSearchUsers() throws Exception {
    // now we should have two jcoders, one from the mock and one from the XML realm

    PlexusResource userSearchResource =
        this.lookup(PlexusResource.class, "UserSearchPlexusResource");

    Request request = this.buildRequest();
    request.getAttributes().put(UserSearchPlexusResource.USER_SOURCE_KEY, "all");
    request.getAttributes().put(UserSearchPlexusResource.USER_ID_KEY, "jcoder");

    List<PlexusUserResource> result =
        ((PlexusUserListResourceResponse) userSearchResource.get(null, request, null, null))
            .getData();

    // now make sure we have 2 jcoders
    PlexusUserResource jcoderXML = null;
    PlexusUserResource jcoderMock = null;

    for (PlexusUserResource plexusUserResource : result) {
      if (plexusUserResource.getUserId().equals("jcoder")) {
        if (plexusUserResource.getSource().endsWith(SecurityXmlUserManager.SOURCE)) {
          jcoderXML = plexusUserResource;
        } else if (plexusUserResource.getSource().endsWith(MockUserManager.SOURCE)) {
          jcoderMock = plexusUserResource;
        } else {
          Assert.fail(
              "found a jcoder with an unknown source of: " + plexusUserResource.getSource());
        }
      }
    }

    Assert.assertNotNull("jcoderXML is null", jcoderXML);
    Assert.assertNotNull("jcoderMock is null", jcoderMock);
  }
Exemplo n.º 2
0
 private boolean containsUser(List<PlexusUserResource> users, String userId) {
   for (PlexusUserResource user : users) {
     if (userId.equals(user.getUserId())) {
       return true;
     }
   }
   return false;
 }