/**
   * @throws StorageException
   * @throws URISyntaxException
   * @throws IOException
   * @throws InterruptedException
   */
  @Test
  public void testPageBlobNamePlusEncodingTest()
      throws StorageException, URISyntaxException, IOException, InterruptedException {
    final int length = 1 * 1024;

    final CloudPageBlob originalBlob =
        (CloudPageBlob)
            BlobTestHelper.uploadNewBlob(
                this.container, BlobType.PAGE_BLOB, "a+b.txt", length, null);
    final CloudPageBlob copyBlob =
        this.container.getPageBlobReference(originalBlob.getName() + "copyed");

    copyBlob.startCopy(originalBlob);
    BlobTestHelper.waitForCopy(copyBlob);
    copyBlob.downloadAttributes();
  }
  /**
   * Start copying a blob and then abort
   *
   * @throws StorageException
   * @throws URISyntaxException
   * @throws IOException
   * @throws InterruptedException
   */
  @Test
  public void testCopyFromPageBlobAbortTest()
      throws StorageException, URISyntaxException, IOException {
    final int length = 512;
    CloudPageBlob originalBlob =
        (CloudPageBlob)
            BlobTestHelper.uploadNewBlob(
                this.container, BlobType.PAGE_BLOB, "originalBlob", length, null);
    CloudPageBlob copyBlob = this.container.getPageBlobReference(originalBlob.getName() + "copyed");
    copyBlob.startCopy(originalBlob);

    try {
      copyBlob.abortCopy(copyBlob.getProperties().getCopyState().getCopyId());
    } catch (StorageException e) {
      if (!e.getErrorCode().contains("NoPendingCopyOperation")) {
        throw e;
      }
    }
  }
  /**
   * Create a snapshot
   *
   * @throws StorageException
   * @throws URISyntaxException
   * @throws IOException
   * @throws InterruptedException
   */
  @Test
  public void testPageBlobSnapshotValidationTest()
      throws StorageException, URISyntaxException, IOException {
    final int length = 1024;
    CloudPageBlob blockBlobRef =
        (CloudPageBlob)
            BlobTestHelper.uploadNewBlob(
                this.container, BlobType.PAGE_BLOB, "originalBlob", length, null);
    final CloudBlob blobSnapshot = blockBlobRef.createSnapshot();

    for (ListBlobItem blob :
        this.container.listBlobs(null, true, EnumSet.allOf(BlobListingDetails.class), null, null)) {
      final ByteArrayOutputStream outStream = new ByteArrayOutputStream(length);
      ((CloudBlob) blob).download(outStream);
    }

    ByteArrayOutputStream outStream = new ByteArrayOutputStream(length);

    blobSnapshot.download(outStream);
    byte[] retrievedBuff = outStream.toByteArray();
    assertEquals(length, retrievedBuff.length);

    // Read operation should work fine.
    blobSnapshot.downloadAttributes();

    final CloudPageBlob blobSnapshotUsingRootUri =
        this.container.getPageBlobReference(blockBlobRef.getName(), blobSnapshot.getSnapshotID());
    outStream = new ByteArrayOutputStream(length);

    blobSnapshotUsingRootUri.download(outStream);
    retrievedBuff = outStream.toByteArray();
    assertEquals(length, retrievedBuff.length);
    assertEquals(blobSnapshot.getSnapshotID(), blobSnapshotUsingRootUri.getSnapshotID());

    // Expect an IllegalArgumentException from upload.
    try {
      final Random randGenerator = new Random();
      final byte[] buff = new byte[length];
      randGenerator.nextBytes(buff);
      blobSnapshot.upload(new ByteArrayInputStream(buff), -1);
      fail("Expect an IllegalArgumentException from upload");
    } catch (IllegalArgumentException e) {
      assertEquals(
          "Cannot perform this operation on a blob representing a snapshot.", e.getMessage());
    }

    // Expect an IllegalArgumentException from uploadMetadata.
    try {
      blobSnapshot.uploadMetadata();
      fail("Expect an IllegalArgumentException from uploadMetadata");
    } catch (IllegalArgumentException e) {
      assertEquals(
          "Cannot perform this operation on a blob representing a snapshot.", e.getMessage());
    }

    // Expect an IllegalArgumentException from uploadProperties.
    try {
      blobSnapshot.uploadProperties();
      fail("Expect an IllegalArgumentException from uploadProperties");
    } catch (IllegalArgumentException e) {
      assertEquals(
          "Cannot perform this operation on a blob representing a snapshot.", e.getMessage());
    }

    // Expect an IllegalArgumentException from createSnapshot.
    try {
      blobSnapshot.createSnapshot();
      fail("Expect an IllegalArgumentException from createSnapshot");
    } catch (IllegalArgumentException e) {
      assertEquals(
          "Cannot perform this operation on a blob representing a snapshot.", e.getMessage());
    }
  }