private String postBlobAndVerifyWithAccountAndContainer(String accountName, String containerName, String serviceId,
      boolean isPrivate, Account expectedAccount, Container expectedContainer,
      RestServiceErrorCode expectedRestErrorCode) throws Exception {
    ByteBuffer content = ByteBuffer.wrap(TestUtils.getRandomBytes(CONTENT_LENGTH));
    List<ByteBuffer> contents = new LinkedList<>();
    contents.add(content);
    contents.add(null);
    String contentType = "application/octet-stream";
    String ownerId = "postGetHeadDeleteOwnerID";
    JSONObject headers = new JSONObject();
    setAmbryHeadersForPut(headers, 7200, isPrivate, serviceId, contentType, ownerId, accountName, containerName, null);
    RestRequest restRequest = createRestRequest(RestMethod.POST, "/", headers, contents);
    MockRestResponseChannel restResponseChannel = new MockRestResponseChannel();
    try {
      doOperation(restRequest, restResponseChannel);
      if (expectedRestErrorCode != null) {
        fail("Should have thrown");
      }
    } catch (RestServiceException e) {
      assertEquals("Wrong RestServiceErrorCode", expectedRestErrorCode, e.getErrorCode());
    }
    assertEquals("Wrong account object in RestRequest's args", expectedAccount,
        restRequest.getArgs().get(RestUtils.InternalKeys.TARGET_ACCOUNT_KEY));
    assertEquals("Wrong container object in RestRequest's args", expectedContainer,
        restRequest.getArgs().get(RestUtils.InternalKeys.TARGET_CONTAINER_KEY));
    if (expectedRestErrorCode == null) {
      // Verify that container metrics were injected iff the account is not in the exclusion list
      ContainerMetrics containerMetrics = restRequest.getMetricsTracker().getContainerMetrics();
      if (frontendConfig.containerMetricsExcludedAccounts.contains(accountName)) {
        assertNull("Expected no container metrics", containerMetrics);
      } else {
        assertNotNull("Expected container metrics", containerMetrics);
      }
    }
    return expectedRestErrorCode == null ? restResponseChannel.getHeader(RestUtils.Headers.LOCATION) : null;
  }
Posts a blob and verifies the injected {@link Account} and {@link Container} into the {@link RestRequest}.
@param accountName The accountName to send as the header of the request.
@param containerName The containerName to send as the header of the request.
@param serviceId The serviceId to send as the header of the request.
@param isPrivate The isPrivate flag for the blob.
@param expectedAccount The expected {@link Account} that would be injected into the {@link RestRequest}.
@param expectedContainer The expected {@link Container} that would be injected into the {@link RestRequest}.
@param expectedRestErrorCode The expected {@link RestServiceErrorCode} after the put operation.
@return The blobId string if the put operation is successful, {@link null} otherwise.
@throws Exception
ambry-frontend/src/test/java/com/github/ambry/frontend/FrontendRestRequestServiceTest.java