Package org.sonatype.plexus.rest.resource

Examples of org.sonatype.plexus.rest.resource.PlexusResource


    ldapServer2.setName("testDelete2");
    ldapServer2.setConnectionInfo(this.buildConnectionInfo());
    ldapServer2.setUserAndGroupConfig(this.buildUserAndGroupAuthConfiguration());
    ldapConfigurationManager.addLdapServerConfiguration(ldapServer2);

    PlexusResource pr = this.lookup(PlexusResource.class, "LdapServerPlexusResource");
    pr.delete(null, this.buildRequest(ldapServer1.getId()), null);
    try {
      ldapConfigurationManager.getLdapServerConfiguration(ldapServer1.getId());
      Assert.fail("epected LdapServerNotFoundException");
    }
    catch (LdapServerNotFoundException e) {
      // expected
    }

    pr.delete(null, this.buildRequest(ldapServer2.getId()), null);
    try {
      ldapConfigurationManager.getLdapServerConfiguration(ldapServer1.getId());
      Assert.fail("epected LdapServerNotFoundException");
    }
    catch (LdapServerNotFoundException e) {
      // expected
    }

    try {
      pr.delete(null, this.buildRequest(ldapServer2.getId()), null);
    }
    catch (ResourceException e) {
      Assert.assertEquals(404, e.getStatus().getCode());
    }
View Full Code Here


      // attach all PlexusResources
      if (isStarted) {
        for (Map.Entry<String, PlexusResource> entry : plexusResources.entrySet()) {
          try {
            PlexusResource resource = entry.getValue();
            attach(applicationRouter, resource);
          }
          catch (Exception e) {
            logger.warn("Failed to attach resource: {}", entry.getKey(), e);
          }
View Full Code Here

    xstream = doConfigureXstream(xstream);

    // then apply all the needed stuff from Resources
    for (Map.Entry<String, PlexusResource> entry : plexusResources.entrySet()) {
      try {
        PlexusResource resource = entry.getValue();
        resource.configureXStream(xstream);
      }
      catch (Exception e) {
        logger.warn("Failed to configure xstream for resource: {}", entry.getKey(), e);
      }
    }
View Full Code Here

  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;
View Full Code Here

    Request request = this.buildRequest();
    Response response = new Response(request);
    request.getAttributes().put(UserToRolePlexusResource.USER_ID_KEY, "jcoder");
    request.getAttributes().put(UserToRolePlexusResource.SOURCE_ID_KEY, MockUserManager.SOURCE);

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

    UserToRoleResourceRequest payload = new UserToRoleResourceRequest();
    payload.setData(new UserToRoleResource());
    payload.getData().setUserId("jcoder");
    payload.getData().setSource(MockUserManager.SOURCE);
    payload.getData().getRoles().add("admin");

    userToRoleResource.put(null, request, response, null);

    // the xml user should have the original roles the mock users should only have admin.

    jcoderXML = securitySystem.getUser("jcoder", SecurityXmlUserManager.SOURCE);
    jcoderMock = securitySystem.getUser("jcoder", MockUserManager.SOURCE);
View Full Code Here

{

  public void testGet()
      throws Exception
  {
    PlexusResource resource = this.lookup(PlexusResource.class, "UserLocatorComponentListPlexusResource");
    Object result = resource.get(null, null, null, null);
    assertThat(result, instanceOf(PlexusComponentListResourceResponse.class));

    PlexusComponentListResourceResponse response = (PlexusComponentListResourceResponse) result;

    assertThat("Result: " + new XStream().toXML(response), response.getData().size(), equalTo(3));
View Full Code Here

  public void testAddUser()
      throws Exception
  {

    PlexusResource resource = this.lookup(PlexusResource.class, "UserListPlexusResource");

    UserResourceRequest resourceRequest = new UserResourceRequest();
    UserResource userResource = new UserResource();
    resourceRequest.setData(userResource);
    userResource.setEmail("test@test.com");
    userResource.setFirstName("firstAddUser");
    userResource.setStatus("active");
    userResource.setUserId("testAddUser");
    userResource.addRole("admin");

    // try
    // {

    resource.post(null, this.buildRequest(), null, resourceRequest);
    // }
    // catch ( PlexusResourceException e )
    // {
    // ErrorResponse errorResponse = (ErrorResponse) e.getResultObject();
    // ErrorMessage errorMessage = (ErrorMessage) errorResponse.getErrors().get( 0 );
    // Assert.fail( e.getMessage() + ": " + errorMessage.getMsg() );
    // }

    // now list
    resource.get(null, this.buildRequest(), null, null);

  }
View Full Code Here

  public void testInvalidEmailAddUser()
      throws Exception
  {

    PlexusResource resource = this.lookup(PlexusResource.class, "UserListPlexusResource");

    UserResourceRequest resourceRequest = new UserResourceRequest();
    UserResource userResource = new UserResource();
    resourceRequest.setData(userResource);
    userResource.setEmail("testInvalidEmailAddUser");
    userResource.setFirstName("firstTestInvalidEmailAddUser");
    userResource.setLastName("firstTestInvalidEmailAddUser");
    userResource.setStatus("active");
    userResource.setUserId("testInvalidEmailAddUser");
    userResource.addRole("admin");

    try {

      resource.post(null, this.buildRequest(), null, resourceRequest);
      Assert.fail("expected PlexusResourceException");
    }
    catch (PlexusResourceException e) {
      ErrorResponse errorResponse = (ErrorResponse) e.getResultObject();
      ErrorMessage errorMessage = (ErrorMessage) errorResponse.getErrors().get(0);
      Assert.assertTrue(errorMessage.getId().contains("email"));
    }

    // now list
    resource.get(null, this.buildRequest(), null, null);
  }
View Full Code Here

  public void testUserIdWithSpace()
      throws Exception
  {

    PlexusResource resource = this.lookup(PlexusResource.class, "UserListPlexusResource");

    UserResourceRequest resourceRequest = new UserResourceRequest();
    UserResource userResource = new UserResource();
    resourceRequest.setData(userResource);
    userResource.setEmail("testUserIdWithSpace@testUserIdWithSpace.com");
    userResource.setFirstName("testUserIdWithSpace");
    userResource.setLastName("Last Name testUserIdWithSpace");
    userResource.setStatus("active");
    userResource.setUserId("test User Id With Space");
    userResource.addRole("admin");

    try {

      resource.post(null, this.buildRequest(), null, resourceRequest);
      Assert.fail("expected PlexusResourceException");
    }
    catch (PlexusResourceException e) {
      ErrorResponse errorResponse = (ErrorResponse) e.getResultObject();
      ErrorMessage errorMessage = (ErrorMessage) errorResponse.getErrors().get(0);
      Assert.assertTrue(errorMessage.getId().contains("userId"));
    }

    // fix it
    userResource.setUserId("testUserIdWithSpace");
    resource.post(null, this.buildRequest(), null, resourceRequest);

    // NOTE: update not supported

  }
View Full Code Here

      throws Exception
  {
    // test user creation with NO status

    // add a user
    PlexusResource resource = this.lookup(PlexusResource.class, "UserListPlexusResource");

    UserResourceRequest resourceRequest = new UserResourceRequest();
    UserResource userResource = new UserResource();
    resourceRequest.setData(userResource);
    userResource.setEmail("testUpdateUserValidation@test.com");
    userResource.setLastName("testUpdateUserValidation");
    userResource.setStatus("active");
    userResource.setUserId("testUpdateUserValidation");
    userResource.addRole("admin");

    resource.post(null, this.buildRequest(), null, resourceRequest);

    // remove the status
    userResource.setStatus("");

    resource = this.lookup(PlexusResource.class, "UserPlexusResource");
    try {
      resource.put(null, this.buildRequest(), null, resourceRequest);
      Assert.fail("expected PlexusResourceException");
    }
    catch (PlexusResourceException e) {
      // expected
    }
View Full Code Here

TOP

Related Classes of org.sonatype.plexus.rest.resource.PlexusResource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.