@Test public void findGroupByName() { Group group = new Group(50, "testGroup", "testing group", now, "automation client", now, "automation client", ImmutableMap.of("app", "keywhiz")); when(groupDAO.getGroup("testGroup")).thenReturn(Optional.of(group)); when(aclDAO.getClientsFor(group)).thenReturn(ImmutableSet.of()); when(aclDAO.getSanitizedSecretsFor(group)).thenReturn(ImmutableSet.of()); GroupDetailResponse expectedResponse = GroupDetailResponse.fromGroup(group, ImmutableList.of(), ImmutableList.of()); Response response = resource.getGroupByName(automation, Optional.of("testGroup")); assertThat(response.getEntity()).isEqualTo(expectedResponse); }
@Timed @ExceptionMetered @GET public Response getGroupByName( @Auth AutomationClient automationClient, @QueryParam("name") Optional<String> name) { if (name.isPresent()) { Group group = groupDAO.getGroup(name.get()).orElseThrow(NotFoundException::new); ImmutableList<Client> clients = ImmutableList.copyOf(aclDAO.getClientsFor(group)); ImmutableList<SanitizedSecret> sanitizedSecrets = ImmutableList.copyOf(aclDAO.getSanitizedSecretsFor(group)); return Response.ok() .entity(GroupDetailResponse.fromGroup(group, sanitizedSecrets, clients)) .build(); } ImmutableList<SanitizedSecret> emptySecrets = ImmutableList.of(); ImmutableList<Client> emptyClients = ImmutableList.of(); List<GroupDetailResponse> groups = groupDAO.getGroups().stream() .map((g) -> GroupDetailResponse.fromGroup(g, emptySecrets, emptyClients)) .collect(toList()); return Response.ok() .entity(groups) .build(); }
AutomationGroupResource { @Timed @ExceptionMetered @GET public Response getGroupByName( @Auth AutomationClient automationClient, @QueryParam("name") Optional<String> name) { if (name.isPresent()) { Group group = groupDAO.getGroup(name.get()).orElseThrow(NotFoundException::new); ImmutableList<Client> clients = ImmutableList.copyOf(aclDAO.getClientsFor(group)); ImmutableList<SanitizedSecret> sanitizedSecrets = ImmutableList.copyOf(aclDAO.getSanitizedSecretsFor(group)); return Response.ok() .entity(GroupDetailResponse.fromGroup(group, sanitizedSecrets, clients)) .build(); } ImmutableList<SanitizedSecret> emptySecrets = ImmutableList.of(); ImmutableList<Client> emptyClients = ImmutableList.of(); List<GroupDetailResponse> groups = groupDAO.getGroups().stream() .map((g) -> GroupDetailResponse.fromGroup(g, emptySecrets, emptyClients)) .collect(toList()); return Response.ok() .entity(groups) .build(); } }
AutomationGroupResource { @Timed @ExceptionMetered @GET public Response getGroupByName( @Auth AutomationClient automationClient, @QueryParam("name") Optional<String> name) { if (name.isPresent()) { Group group = groupDAO.getGroup(name.get()).orElseThrow(NotFoundException::new); ImmutableList<Client> clients = ImmutableList.copyOf(aclDAO.getClientsFor(group)); ImmutableList<SanitizedSecret> sanitizedSecrets = ImmutableList.copyOf(aclDAO.getSanitizedSecretsFor(group)); return Response.ok() .entity(GroupDetailResponse.fromGroup(group, sanitizedSecrets, clients)) .build(); } ImmutableList<SanitizedSecret> emptySecrets = ImmutableList.of(); ImmutableList<Client> emptyClients = ImmutableList.of(); List<GroupDetailResponse> groups = groupDAO.getGroups().stream() .map((g) -> GroupDetailResponse.fromGroup(g, emptySecrets, emptyClients)) .collect(toList()); return Response.ok() .entity(groups) .build(); } @Inject  AutomationGroupResource(GroupDAOFactory groupDAOFactory, AclDAOFactory aclDAOFactory,
      AuditLog auditLog); @VisibleForTesting  AutomationGroupResource(GroupDAO groupDAO, AclDAO aclDAO, AuditLog auditLog); }
AutomationGroupResource { @Timed @ExceptionMetered @GET public Response getGroupByName( @Auth AutomationClient automationClient, @QueryParam("name") Optional<String> name) { if (name.isPresent()) { Group group = groupDAO.getGroup(name.get()).orElseThrow(NotFoundException::new); ImmutableList<Client> clients = ImmutableList.copyOf(aclDAO.getClientsFor(group)); ImmutableList<SanitizedSecret> sanitizedSecrets = ImmutableList.copyOf(aclDAO.getSanitizedSecretsFor(group)); return Response.ok() .entity(GroupDetailResponse.fromGroup(group, sanitizedSecrets, clients)) .build(); } ImmutableList<SanitizedSecret> emptySecrets = ImmutableList.of(); ImmutableList<Client> emptyClients = ImmutableList.of(); List<GroupDetailResponse> groups = groupDAO.getGroups().stream() .map((g) -> GroupDetailResponse.fromGroup(g, emptySecrets, emptyClients)) .collect(toList()); return Response.ok() .entity(groups) .build(); } @Inject  AutomationGroupResource(GroupDAOFactory groupDAOFactory, AclDAOFactory aclDAOFactory,
      AuditLog auditLog); @VisibleForTesting  AutomationGroupResource(GroupDAO groupDAO, AclDAO aclDAO, AuditLog auditLog); @Timed @ExceptionMetered @GET @Path("{groupId}") GroupDetailResponse getGroupById(
      @Auth AutomationClient automationClient,
      @PathParam("groupId") LongParam groupId); @Timed @ExceptionMetered @GET Response getGroupByName(
      @Auth AutomationClient automationClient,
      @QueryParam("name") Optional<String> name); @Timed @ExceptionMetered @POST @Consumes(APPLICATION_JSON) Group createGroup(
      @Auth AutomationClient automationClient,
      @Valid CreateGroupRequest groupRequest); @Timed @ExceptionMetered @DELETE @Path("{groupId}") Response deleteGroup(
      @Auth AutomationClient automationClient,
      @PathParam("groupId") LongParam groupId); }
AutomationGroupResource { @Timed @ExceptionMetered @GET public Response getGroupByName( @Auth AutomationClient automationClient, @QueryParam("name") Optional<String> name) { if (name.isPresent()) { Group group = groupDAO.getGroup(name.get()).orElseThrow(NotFoundException::new); ImmutableList<Client> clients = ImmutableList.copyOf(aclDAO.getClientsFor(group)); ImmutableList<SanitizedSecret> sanitizedSecrets = ImmutableList.copyOf(aclDAO.getSanitizedSecretsFor(group)); return Response.ok() .entity(GroupDetailResponse.fromGroup(group, sanitizedSecrets, clients)) .build(); } ImmutableList<SanitizedSecret> emptySecrets = ImmutableList.of(); ImmutableList<Client> emptyClients = ImmutableList.of(); List<GroupDetailResponse> groups = groupDAO.getGroups().stream() .map((g) -> GroupDetailResponse.fromGroup(g, emptySecrets, emptyClients)) .collect(toList()); return Response.ok() .entity(groups) .build(); } @Inject  AutomationGroupResource(GroupDAOFactory groupDAOFactory, AclDAOFactory aclDAOFactory,
      AuditLog auditLog); @VisibleForTesting  AutomationGroupResource(GroupDAO groupDAO, AclDAO aclDAO, AuditLog auditLog); @Timed @ExceptionMetered @GET @Path("{groupId}") GroupDetailResponse getGroupById(
      @Auth AutomationClient automationClient,
      @PathParam("groupId") LongParam groupId); @Timed @ExceptionMetered @GET Response getGroupByName(
      @Auth AutomationClient automationClient,
      @QueryParam("name") Optional<String> name); @Timed @ExceptionMetered @POST @Consumes(APPLICATION_JSON) Group createGroup(
      @Auth AutomationClient automationClient,
      @Valid CreateGroupRequest groupRequest); @Timed @ExceptionMetered @DELETE @Path("{groupId}") Response deleteGroup(
      @Auth AutomationClient automationClient,
      @PathParam("groupId") LongParam groupId);  }