AutomationSecretResource { @Path("{secretName}") @Timed @ExceptionMetered @DELETE public Response deleteSecretSeries( @Auth AutomationClient automationClient, @PathParam("secretName") String secretName) { Secret secret = secretController.getSecretByName(secretName).orElseThrow(() -> new NotFoundException("Secret series not found.")); Set<String> groups = aclDAO.getGroupsFor(secret).stream().map(Group::getName).collect(toSet()); secretDAO.deleteSecretsByName(secretName); Map<String, String> extraInfo = new HashMap<>(); extraInfo.put("deprecated", "true"); extraInfo.put("groups", groups.toString()); extraInfo.put("current version", secret.getVersion().toString()); auditLog.recordEvent(new Event(Instant.now(), EventTag.SECRET_DELETE, automationClient.getName(), secretName, extraInfo)); return Response.ok().build(); } @Inject  AutomationSecretResource(SecretController secretController,
                                          SecretDAOFactory secretDAOFactory, AclDAOFactory aclDAOFactory, AuditLog auditLog); @VisibleForTesting  AutomationSecretResource(SecretController secretController,
                                              SecretDAO secretDAO, AclDAO aclDAO, AuditLog auditLog); @Timed @ExceptionMetered @POST @Consumes(APPLICATION_JSON) AutomationSecretResponse createSecret(
      @Auth AutomationClient automationClient,
      @Valid CreateSecretRequest request); @Timed @ExceptionMetered @GET ImmutableList<AutomationSecretResponse> readSecrets(
      @Auth AutomationClient automationClient, @QueryParam("name") String name); @Path("{secretId}") @Timed @ExceptionMetered @GET AutomationSecretResponse readSecretById(
      @Auth AutomationClient automationClient,
      @PathParam("secretId") LongParam secretId); @Path("{secretName}") @Timed @ExceptionMetered @DELETE Response deleteSecretSeries(
      @Auth AutomationClient automationClient,
      @PathParam("secretName") String secretName);  }
@Test public void deleteSecret() throws Exception { Secret secret = new Secret(0, "mySecret", null, (Secret.LazyString) () -> "meh", "checksum", NOW, null, NOW, null, ImmutableMap.of(), null, null, 0, 1L, NOW, null); HashSet<Group> groups = new HashSet<>(); groups.add(new Group(0, "group1", "", NOW, null, NOW, null, null)); groups.add(new Group(0, "group2", "", NOW, null, NOW, null, null)); when(secretController.getSecretByName(secret.getName())) .thenReturn(Optional.of(secret)); when(aclDAO.getGroupsFor(secret)).thenReturn(groups); resource.deleteSecretSeries(automation, secret.getName()); verify(secretDAO).deleteSecretsByName(secret.getName()); }