private void doConditionalUpdateAndDeleteTest(Account expectedAccount, Container expectedContainer, String serviceId)
      throws Exception {
    PostResults postResults =
        prepareAndPostBlob(1024, serviceId, TTL_SECS, "application/octet-stream", "doConditionalUpdateAndDeleteTest",
            expectedAccount, expectedContainer, null);
    getBlobAndVerify(postResults.blobId, null, null, postResults.headers, postResults.content, expectedAccount,
        expectedContainer);
    getHeadAndVerify(postResults.blobId, null, null, postResults.headers, expectedAccount, expectedContainer);
    // failures
    Map<RestMethod, String> methodsToUris = new HashMap<>();
    methodsToUris.put(RestMethod.PUT, Operations.UPDATE_TTL);
    methodsToUris.put(RestMethod.DELETE, postResults.blobId);
    for (Map.Entry<RestMethod, String> methodToUri : methodsToUris.entrySet()) {
      RestMethod method = methodToUri.getKey();
      String uri = methodToUri.getValue();
      JSONObject badHeaders = new JSONObject();
      if (uri.equals(Operations.UPDATE_TTL)) {
        setUpdateTtlHeaders(badHeaders, postResults.blobId, serviceId);
      }
      // test Conditional op failure because only container name is set
      setAccountAndContainerHeaders(badHeaders, null, expectedContainer.getName());
      RestRequest restRequest = createRestRequest(method, uri, badHeaders, null);
      verifyOperationFailure(restRequest, RestServiceErrorCode.BadRequest);
      // test Conditional op failure because of incorrect account name
      setAccountAndContainerHeaders(badHeaders, "INCORRECT_ACCOUNT_NAME", expectedContainer.getName());
      restRequest = createRestRequest(method, uri, badHeaders, null);
      verifyOperationFailure(restRequest, RestServiceErrorCode.PreconditionFailed);
      // test Conditional op failure because of incorrect container name
      setAccountAndContainerHeaders(badHeaders, expectedAccount.getName(), "INCORRECT_CONTAINER_NAME");
      restRequest = createRestRequest(method, uri, badHeaders, null);
      verifyOperationFailure(restRequest, RestServiceErrorCode.PreconditionFailed);
    }
    // test success of conditional update
    updateBlobTtlAndVerify(postResults.blobId, postResults.headers, expectedAccount, expectedContainer, true);
    // test Conditional Delete succeeds
    deleteBlobAndVerify(postResults.blobId, postResults.headers, postResults.content, expectedAccount,
        expectedContainer, true);
  }
Tests blob conditional TTL update and DELETE operations on the given {@code container}.
@param expectedAccount the {@link Account} to use in post headers.
@param expectedContainer the {@link Container} to use in post headers.
@param serviceId the serviceId to use for the POST
@throws Exception
ambry-frontend/src/test/java/com/github/ambry/frontend/FrontendRestRequestServiceTest.java