MembershipResource { @Path("/secrets/{secretId}/groups/{groupId}") @Timed @ExceptionMetered @PUT public Response allowAccess( @Auth User user, @PathParam("secretId") LongParam secretId, @PathParam("groupId") LongParam groupId) { logger.info("User '{}' allowing groupId {} access to secretId {}", user, groupId, secretId); try { aclDAO.findAndAllowAccess(secretId.get(), groupId.get(), auditLog, user.getName(), new HashMap<>()); } catch (IllegalStateException e) { throw new NotFoundException(); } return Response.ok().build(); } @Inject  MembershipResource(AclDAOFactory aclDAOFactory, AuditLog auditLog); @VisibleForTesting  MembershipResource(AclDAO aclDAO, AuditLog auditLog); @Path("/secrets/{secretId}/groups/{groupId}") @Timed @ExceptionMetered @PUT Response allowAccess(
      @Auth User user,
      @PathParam("secretId") LongParam secretId,
      @PathParam("groupId") LongParam groupId); @Path("/secrets/{secretId}/groups/{groupId}") @Timed @ExceptionMetered @DELETE Response disallowAccess(
      @Auth User user,
      @PathParam("secretId") LongParam secretId,
      @PathParam("groupId") LongParam groupId); @Path("/clients/{clientId}/groups/{groupId}") @Timed @ExceptionMetered @PUT Response enrollClient(
    @Auth User user,
    @PathParam("clientId") LongParam clientId,
    @PathParam("groupId") LongParam groupId); @Path("/clients/{clientId}/groups/{groupId}") @Timed @ExceptionMetered @DELETE Response evictClient(
      @Auth User user,
      @PathParam("clientId") LongParam clientId,
      @PathParam("groupId") LongParam groupId);  }
@Test public void canAllowAccess() { Response response = resource.allowAccess(user, new LongParam("66"), new LongParam("55")); assertThat(response.getStatus()).isEqualTo(200); verify(aclDAO).findAndAllowAccess(66, 55, auditLog, "user",new HashMap<>()); }
@Test(expected = NotFoundException.class) public void missingSecretAllow() { doThrow(IllegalStateException.class).when(aclDAO).findAndAllowAccess(3, group.getId(), auditLog, "user",new HashMap<>()); resource.allowAccess(user, new LongParam("3"), new LongParam(Long.toString(group.getId()))); }
@Test(expected = NotFoundException.class) public void missingGroupAllow() { doThrow(IllegalStateException.class).when(aclDAO).findAndAllowAccess(secret.getId(), 98, auditLog, "user",new HashMap<>()); resource.allowAccess(user, new LongParam(Long.toString(secret.getId())), new LongParam("98")); }