ClientsResource { @Path("{clientId}") @Timed @ExceptionMetered @GET public ClientDetailResponse getClient(@Auth User user, @PathParam("clientId") LongParam clientId) { logger.info("User '{}' retrieving client id={}.", user, clientId); return clientDetailResponseFromId(clientId.get()); } @Inject  ClientsResource(AclDAOFactory aclDAOFactory, ClientDAOFactory clientDAOFactory,
      AuditLog auditLog); @VisibleForTesting  ClientsResource(AclDAO aclDAO, ClientDAO clientDAO, AuditLog auditLog); @Timed @ExceptionMetered @GET Response findClients(@Auth User user, @DefaultValue("") @QueryParam("name") String name); @Timed @ExceptionMetered @POST @Consumes(APPLICATION_JSON) Response createClient(@Auth User user,
      @Valid CreateClientRequestV2 createClientRequest); @Path("{clientId}") @Timed @ExceptionMetered @GET ClientDetailResponse getClient(@Auth User user,
      @PathParam("clientId") LongParam clientId); @Path("{clientId}") @Timed @ExceptionMetered @DELETE Response deleteClient(@Auth User user, @PathParam("clientId") LongParam clientId);  }
@Test public void includesTheClient() { when(clientDAO.getClientById(1)).thenReturn(Optional.of(client)); when(aclDAO.getGroupsFor(client)).thenReturn(Collections.emptySet()); when(aclDAO.getSanitizedSecretsFor(client)).thenReturn(ImmutableSet.of()); ClientDetailResponse response = resource.getClient(user, new LongParam("1")); assertThat(response.id).isEqualTo(client.getId()); assertThat(response.name).isEqualTo(client.getName()); assertThat(response.description).isEqualTo(client.getDescription()); assertThat(response.creationDate).isEqualTo(client.getCreatedAt()); assertThat(response.createdBy).isEqualTo(client.getCreatedBy()); assertThat(response.updateDate).isEqualTo(client.getUpdatedAt()); assertThat(response.updatedBy).isEqualTo(client.getUpdatedBy()); }
@Test public void handlesNoAssociations() { when(clientDAO.getClientById(1)).thenReturn(Optional.of(client)); when(aclDAO.getGroupsFor(client)).thenReturn(Collections.emptySet()); when(aclDAO.getSanitizedSecretsFor(client)).thenReturn(ImmutableSet.of()); ClientDetailResponse response = resource.getClient(user, new LongParam("1")); assertThat(response.groups).isEmpty(); assertThat(response.secrets).isEmpty(); }
@Test public void includesAssociations() { Group group1 = new Group(0, "group1", null, null, null, null, null, null); Group group2 = new Group(0, "group2", null, null, null, null, null, null); Secret secret = new Secret(15, "secret", null, () -> "supersecretdata", "checksum", now, "creator", now, "updater", null, null, null, 0, 1L, now, "updater"); when(clientDAO.getClientById(1)).thenReturn(Optional.of(client)); when(aclDAO.getGroupsFor(client)).thenReturn(Sets.newHashSet(group1, group2)); when(aclDAO.getSanitizedSecretsFor(client)) .thenReturn(ImmutableSet.of(SanitizedSecret.fromSecret(secret))); ClientDetailResponse response = resource.getClient(user, new LongParam("1")); assertThat(response.groups).containsOnly(group1, group2); assertThat(response.secrets).containsOnly(SanitizedSecret.fromSecret(secret)); }
@Test(expected = NotFoundException.class) public void badIdNotFound() { when(clientDAO.getClientById(41)).thenReturn(Optional.empty()); resource.getClient(user, new LongParam("41")); }