@Test
  public void addGetAndDeleteDatasetTest() throws Exception {
    Account testAccount = new ArrayList<>(accountService.getAllAccounts()).get(1);
    Container testContainer = new ArrayList<>(testAccount.getAllContainers()).get(1);
    Dataset.VersionSchema versionSchema = Dataset.VersionSchema.TIMESTAMP;
    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);
    assertEquals("Dataset not created correctly", dataset,
        accountService.getDataset(testAccount.getName(), testContainer.getName(), DATASET_NAME));

    headers = new JSONObject().put(RestUtils.Headers.TARGET_ACCOUNT_NAME, testAccount.getName())
        .put(RestUtils.Headers.TARGET_CONTAINER_NAME, testContainer.getName())
        .put(RestUtils.Headers.TARGET_DATASET_NAME, DATASET_NAME);
    restRequest = createRestRequest(RestMethod.GET, Operations.ACCOUNTS_CONTAINERS_DATASETS, headers, null);
    restResponseChannel = new MockRestResponseChannel();
    doOperation(restRequest, restResponseChannel);
    Dataset datasetFromResponse = AccountCollectionSerde.datasetsFromInputStreamInJson(
        new ByteArrayInputStream(restResponseChannel.getResponseBody()));
    assertEquals("Unexpected GET /accounts/containers/datasets response ", dataset, datasetFromResponse);
    assertEquals("Unexpected response status", ResponseStatus.Ok, restResponseChannel.getStatus());
    assertEquals("Unexpected header", testAccount.getName(),
        restResponseChannel.getHeader(RestUtils.Headers.TARGET_ACCOUNT_NAME));
    assertEquals("Unexpected header", testContainer.getName(),
        restResponseChannel.getHeader(RestUtils.Headers.TARGET_CONTAINER_NAME));

    //update dataset
    Dataset datasetToUpdate = new DatasetBuilder(dataset).setRetentionCount(10).build();
    datasetsUpdateJson = AccountCollectionSerde.serializeDatasetsInJson(datasetToUpdate);
    body = new LinkedList<>();
    body.add(ByteBuffer.wrap(datasetsUpdateJson));
    body.add(null);
    headers = new JSONObject().put(RestUtils.Headers.TARGET_ACCOUNT_NAME, testAccount.getName())
        .put(RestUtils.Headers.TARGET_CONTAINER_NAME, testContainer.getName())
        .put(RestUtils.Headers.TARGET_DATASET_NAME, DATASET_NAME)
        .put(RestUtils.Headers.DATASET_UPDATE, true);
    restRequest = createRestRequest(RestMethod.POST, Operations.ACCOUNTS_CONTAINERS_DATASETS, headers, body);
    restResponseChannel = new MockRestResponseChannel();
    doOperation(restRequest, restResponseChannel);
    assertEquals("Dataset not created correctly", datasetToUpdate,
        accountService.getDataset(testAccount.getName(), testContainer.getName(), DATASET_NAME));

    //delete dataset
    headers = new JSONObject().put(RestUtils.Headers.TARGET_ACCOUNT_NAME, testAccount.getName())
        .put(RestUtils.Headers.TARGET_CONTAINER_NAME, testContainer.getName())
        .put(RestUtils.Headers.TARGET_DATASET_NAME, DATASET_NAME);
    restRequest = createRestRequest(RestMethod.DELETE, Operations.ACCOUNTS_CONTAINERS_DATASETS, headers, null);
    verifyDeleteAccepted(restRequest);

    headers = new JSONObject().put(RestUtils.Headers.TARGET_ACCOUNT_NAME, testAccount.getName())
        .put(RestUtils.Headers.TARGET_CONTAINER_NAME, testContainer.getName())
        .put(RestUtils.Headers.TARGET_DATASET_NAME, DATASET_NAME);
    restRequest = createRestRequest(RestMethod.GET, Operations.ACCOUNTS_CONTAINERS_DATASETS, headers, null);
    verifyOperationFailure(restRequest, RestServiceErrorCode.Deleted);
  }
Test add, get and delete {@link Dataset}.
@throws Exception
ambry-frontend/src/test/java/com/github/ambry/frontend/FrontendRestRequestServiceTest.java