SecretsResource { @Path("{name}/partialupdate") @Timed @ExceptionMetered @POST @Consumes(APPLICATION_JSON) public Response partialUpdateSecret(@Auth User user, @PathParam("name") String secretName, @Valid PartialUpdateSecretRequestV2 request) { logger.info("User '{}' partialUpdate secret '{}'.", user, secretName); long id = secretDAOReadWrite.partialUpdateSecret(secretName, user.getName(), request); URI uri = UriBuilder.fromResource(SecretsResource.class) .path(secretName) .path("partialupdate") .build(); Response response = Response.created(uri).entity(secretDetailResponseFromId(id)).build(); if (response.getStatus() == HttpStatus.SC_CREATED) { Map<String, String> extraInfo = new HashMap<>(); if (request.descriptionPresent()) { extraInfo.put("description", request.description()); } if (request.metadataPresent()) { extraInfo.put("metadata", request.metadata().toString()); } if (request.expiryPresent()) { extraInfo.put("expiry", Long.toString(request.expiry())); } auditLog.recordEvent( new Event(Instant.now(), EventTag.SECRET_UPDATE, user.getName(), secretName, extraInfo)); } return response; } @SuppressWarnings("unused") @Inject  SecretsResource(SecretController secretController, AclDAOFactory aclDAOFactory,
      SecretDAOFactory secretDAOFactory, AuditLog auditLog); @VisibleForTesting  SecretsResource(SecretController secretController, AclDAO aclDAOReadOnly,
      SecretDAO secretDAOReadWrite, AuditLog auditLog); @Timed @ExceptionMetered @GET Response findSecrets(@Auth User user, @DefaultValue("") @QueryParam("name") String name,
      @DefaultValue("") @QueryParam("nameOnly") String nameOnly, @QueryParam("idx") Integer idx,
      @QueryParam("num") Integer num,
      @DefaultValue("true") @QueryParam("newestFirst") Boolean newestFirst); @Timed @ExceptionMetered @POST @Consumes(APPLICATION_JSON) Response createSecret(@Auth User user, @Valid CreateSecretRequestV2 request); @Path("{name}") @Timed @ExceptionMetered @POST @Consumes(APPLICATION_JSON) Response createOrUpdateSecret(@Auth User user, @PathParam("name") String secretName,
      @Valid CreateOrUpdateSecretRequestV2 request); @Path("{name}/partialupdate") @Timed @ExceptionMetered @POST @Consumes(APPLICATION_JSON) Response partialUpdateSecret(@Auth User user, @PathParam("name") String secretName, @Valid
      PartialUpdateSecretRequestV2 request); @Path("{secretId}") @Timed @ExceptionMetered @GET SecretDetailResponse retrieveSecret(@Auth User user,
      @PathParam("secretId") LongParam secretId); @Timed @ExceptionMetered @GET @Path("versions/{name}") @Produces(APPLICATION_JSON) List<SanitizedSecret> secretVersions(@Auth User user,
      @PathParam("name") String name, @QueryParam("versionIdx") int versionIdx,
      @QueryParam("numVersions") int numVersions); @Path("rollback/{secretName}/{versionId}") @Timed @ExceptionMetered @POST Response resetSecretVersion(@Auth User user, @PathParam("secretName") String secretName,
      @PathParam("versionId") LongParam versionId); @Path("{secretId}") @Timed @ExceptionMetered @DELETE Response deleteSecret(@Auth User user, @PathParam("secretId") LongParam secretId);  }
@Test public void partialUpdateSecret() throws Exception { when(secretController.getSecretById(secret.getId())).thenReturn(Optional.of(secret)); PartialUpdateSecretRequestV2 req = PartialUpdateSecretRequestV2.builder() .description(secret.getDescription()) .descriptionPresent(true) .metadata(ImmutableMap.of("owner", "keywhizAdmin")) .metadataPresent(true) .expiry(1487268151L) .expiryPresent(true) .type("test") .typePresent(true) .content(secret.getSecret()) .contentPresent(true) .build(); when(secretDAO.partialUpdateSecret(eq(secret.getName()), any(), eq(req))).thenReturn( secret.getId()); Response response = resource.partialUpdateSecret(user, secret.getName(), req); assertThat(response.getStatus()).isEqualTo(201); assertThat(response.getMetadata().get(HttpHeaders.LOCATION)) .containsExactly(new URI("/admin/secrets/" + secret.getName() + "/partialupdate")); }