@Test
  public void testRenameDatasetVersion() throws Exception {
    //Add dataset
    Account testAccount = new ArrayList<>(accountService.getAllAccounts()).get(1);
    Container testContainer = new ArrayList<>(testAccount.getAllContainers()).get(1);
    Dataset.VersionSchema versionSchema = Dataset.VersionSchema.SEMANTIC_LONG;
    Dataset dataset =
        new DatasetBuilder(testAccount.getName(), testContainer.getName(), DATASET_NAME).setVersionSchema(versionSchema)
            .build();
    byte[] datasetsUpdateJson = AccountCollectionSerde.serializeDatasetsInJson(dataset);
    List<ByteBuffer> body = new LinkedList<>();
    body.add(ByteBuffer.wrap(datasetsUpdateJson));
    body.add(null);
    JSONObject headers = new JSONObject().put(RestUtils.Headers.TARGET_ACCOUNT_NAME, testAccount.getName())
        .put(RestUtils.Headers.TARGET_CONTAINER_NAME, testContainer.getName());
    RestRequest restRequest =
        createRestRequest(RestMethod.POST, Operations.ACCOUNTS_CONTAINERS_DATASETS, headers, body);
    MockRestResponseChannel restResponseChannel = new MockRestResponseChannel();
    doOperation(restRequest, restResponseChannel);

    // add dataset version
    String version = "1.1.1.1";
    String blobName = DATASET_NAME + SLASH + version;
    String namedBlobPathUri =
        NAMED_BLOB_PREFIX + SLASH + testAccount.getName() + SLASH + testContainer.getName() + SLASH + blobName;
    ByteBuffer content = ByteBuffer.wrap(TestUtils.getRandomBytes(10));
    body = new LinkedList<>();
    body.add(content);
    body.add(null);
    headers = new JSONObject();
    setAmbryHeadersForPut(headers, -1, testContainer.isCacheable(), "test", "application/octet-stream", "owner", null,
        null, null);
    headers.put(RestUtils.Headers.DATASET_VERSION_QUERY_ENABLED, true);
    restRequest = createRestRequest(RestMethod.PUT, namedBlobPathUri, headers, body);
    restResponseChannel = new MockRestResponseChannel();

    BlobProperties blobProperties =
        new BlobProperties(0, testAccount.getName(), "owner", "image/gif", false, 7200, testAccount.getId(),
            testContainer.getId(), false, null, null, null);
    ReadableStreamChannel byteBufferContent = new ByteBufferReadableStreamChannel(ByteBuffer.allocate(10));
    String blobIdFromRouter =
        router.putBlobWithIdVersion(blobProperties, new byte[0], byteBufferContent, BlobId.BLOB_ID_V6).get();

    reset(namedBlobDb);
    NamedBlobRecord namedBlobRecord =
        new NamedBlobRecord(testAccount.getName(), testContainer.getName(), blobName, blobIdFromRouter, 3600);
    when(namedBlobDb.put(any(), any(), any())).thenReturn(
        CompletableFuture.completedFuture(new PutResult(namedBlobRecord)));
    when(namedBlobDb.delete(namedBlobRecord.getAccountName(), namedBlobRecord.getContainerName(), blobName)).thenReturn(
        CompletableFuture.completedFuture(new DeleteResult(blobIdFromRouter, false)));
    when(namedBlobDb.get(namedBlobRecord.getAccountName(), namedBlobRecord.getContainerName(), blobName, GetOption.None,
        false)).thenReturn(CompletableFuture.completedFuture(namedBlobRecord));
    when(namedBlobDb.updateBlobTtlAndStateToReady(any())).thenReturn(
        CompletableFuture.completedFuture(new PutResult(namedBlobRecord)));
    doOperation(restRequest, restResponseChannel);

    // rename dataset version
    String newVersion = "10.10.10.10";
    String blobNewName = DATASET_NAME + SLASH + newVersion;
    namedBlobPathUri =
        NAMED_BLOB_PREFIX + SLASH + testAccount.getName() + SLASH + testContainer.getName() + SLASH + blobName
            + "?op=RENAME&targetVersion=" + newVersion;
    headers.put(RestUtils.Headers.DATASET_VERSION_QUERY_ENABLED, true);
    restRequest = createRestRequest(RestMethod.PUT, namedBlobPathUri, headers, body);
    restResponseChannel = new MockRestResponseChannel();

    reset(namedBlobDb);
    NamedBlobRecord newNamedBlobRecord =
        new NamedBlobRecord(testAccount.getName(), testContainer.getName(), blobNewName, blobIdFromRouter, 3600);
    when(namedBlobDb.get(namedBlobRecord.getAccountName(), namedBlobRecord.getContainerName(), blobNewName,
        GetOption.None, false)).thenReturn(CompletableFuture.completedFuture(newNamedBlobRecord));
    when(namedBlobDb.get(namedBlobRecord.getAccountName(), namedBlobRecord.getContainerName(), blobName, GetOption.None,
        false)).thenThrow(new RuntimeException());
    when(namedBlobDb.delete(namedBlobRecord.getAccountName(), namedBlobRecord.getContainerName(), blobName)).thenReturn(
        CompletableFuture.completedFuture(new DeleteResult(blobIdFromRouter, false)));
    when(namedBlobDb.updateBlobTtlAndStateToReady(any())).thenReturn(
        CompletableFuture.completedFuture(new PutResult(namedBlobRecord)));
    doOperation(restRequest, restResponseChannel);
    assertEquals("Mismatch on status", ResponseStatus.Ok, restResponseChannel.getStatus());

    try {
      accountService.getDatasetVersion(testAccount.getName(), testContainer.getName(), DATASET_NAME, version);
      fail("Should fail due to dataset version has been deleted");
    } catch (AccountServiceException e) {
      assertEquals("Mismatch on error code", AccountServiceErrorCode.Deleted, e.getErrorCode());
    }

    DatasetVersionRecord newDatasetVersionRecord =
        accountService.getDatasetVersion(testAccount.getName(), testContainer.getName(), DATASET_NAME, newVersion);
    assertEquals("Version mismatch", newVersion, newDatasetVersionRecord.getVersion());
  }
Tests blob POST, GET, HEAD, TTL update and DELETE operations.
@throws Exception
ambry-frontend/src/test/java/com/github/ambry/frontend/FrontendRestRequestServiceTest.java