/** @throws Exception */
  @Test
  public void testCreateS3TokenRelativePath() throws Exception {
    Code code = new Code();
    code.setParentId(project.getId());
    code = testHelper.createEntity(code, null);

    // a relative path to a file
    String initialPath = "foo.java";
    S3Token token = new S3Token();
    token.setPath(initialPath);
    token.setMd5(TEST_MD5);

    token = testHelper.createObject(code.getS3Token(), token);

    assertEquals(StackConfiguration.getS3Bucket(), token.getBucket());
    assertTrue(
        token
            .getPath()
            .matches("^/" + KeyFactory.stringToKey(code.getId()) + "/\\d+/" + initialPath + "$"));
    assertEquals(TEST_MD5, token.getMd5());
    assertEquals("text/plain", token.getContentType());
    assertNotNull(token.getSecretAccessKey());
    assertNotNull(token.getAccessKeyId());
    assertNotNull(token.getSessionToken());
    assertTrue(token.getPresignedUrl().matches("^http.*" + initialPath + ".*"));
  }
  /** @throws Exception */
  @Test
  public void testCreateS3TokenAbsolutePath() throws Exception {
    Data layer = new Data();
    layer.setParentId(dataset.getId());
    layer.setType(LayerTypeNames.E);
    layer = testHelper.createEntity(layer, null);

    // an absolute path to a file
    String initialPath = "/data/123.zip";

    S3Token token = new S3Token();
    token.setPath(initialPath);
    token.setMd5(TEST_MD5);

    token = testHelper.createObject(layer.getS3Token(), token);

    assertEquals(StackConfiguration.getS3Bucket(), token.getBucket());
    assertTrue(
        token
            .getPath()
            .matches("^/" + KeyFactory.stringToKey(layer.getId()) + "/\\d+" + initialPath + "$"));
    assertEquals(TEST_MD5, token.getMd5());
    assertEquals("application/zip", token.getContentType());
    assertNotNull(token.getSecretAccessKey());
    assertNotNull(token.getAccessKeyId());
    assertNotNull(token.getSessionToken());
    assertTrue(token.getPresignedUrl().matches("^http.*" + initialPath + ".*"));
  }