コード例 #1
0
  @Test
  public void createRoleWithIdTest() throws IOException {

    RoleResource resource = new RoleResource();

    resource.setDescription("Create Test Role With ID");
    resource.setName("CreateRoleWithID");
    resource.setId("CreateRoleWithID");
    resource.setSessionTimeout(30);
    resource.addPrivilege("1");
    resource.addPrivilege("2");

    this.messageUtil.createRole(resource);
  }
コード例 #2
0
  @Test
  public void updateTest() throws IOException {

    RoleResource resource = new RoleResource();

    resource.setDescription("Update Test Role");
    resource.setName("UpdateRole");
    resource.setSessionTimeout(99999);
    resource.addPrivilege("5");
    resource.addPrivilege("4");

    RoleResource responseResource = this.messageUtil.createRole(resource);

    // update the Role
    // TODO: add tests that changes the Id
    resource.setId(responseResource.getId());
    resource.setName("UpdateRole Again");
    resource.setDescription("Update Test Role Again");
    resource.getPrivileges().clear(); // clear the privs
    resource.addPrivilege("6");
    resource.setSessionTimeout(10);

    Response response = this.messageUtil.sendMessage(Method.PUT, resource);

    if (!response.getStatus().isSuccess()) {
      Assert.fail("Could not update Role: " + response.getStatus());
    }

    // get the Resource object
    responseResource = this.messageUtil.getResourceFromResponse(response);

    Assert.assertEquals(resource.getId(), responseResource.getId());
    Assert.assertEquals(resource.getDescription(), responseResource.getDescription());
    Assert.assertEquals(resource.getName(), responseResource.getName());
    Assert.assertEquals(resource.getSessionTimeout(), responseResource.getSessionTimeout());
    Assert.assertEquals(resource.getPrivileges(), responseResource.getPrivileges());
    Assert.assertEquals(resource.getRoles(), responseResource.getRoles());

    getSecurityConfigUtil().verifyRole(resource);
  }