コード例 #1
0
ファイル: BoxFileTest.java プロジェクト: Zeimyth/box-java-sdk
  @Test
  @Category(IntegrationTest.class)
  public void promoteVersionsSucceeds() throws UnsupportedEncodingException {
    BoxAPIConnection api = new BoxAPIConnection(TestConfig.getAccessToken());
    BoxFolder rootFolder = BoxFolder.getRootFolder(api);
    String fileName = "[promoteVersionsSucceeds] Multi-version File.txt";
    String version1Content = "Version 1";
    byte[] version1Bytes = version1Content.getBytes(StandardCharsets.UTF_8);
    byte[] version2Bytes = "Version 2".getBytes(StandardCharsets.UTF_8);

    InputStream uploadStream = new ByteArrayInputStream(version1Bytes);
    BoxFile uploadedFile = rootFolder.uploadFile(uploadStream, fileName).getResource();
    uploadStream = new ByteArrayInputStream(version2Bytes);
    uploadedFile.uploadVersion(uploadStream);

    Collection<BoxFileVersion> versions = uploadedFile.getVersions();
    BoxFileVersion previousVersion = versions.iterator().next();
    previousVersion.promote();

    ByteArrayOutputStream downloadStream = new ByteArrayOutputStream();
    uploadedFile.download(downloadStream);
    String downloadedContent = downloadStream.toString(StandardCharsets.UTF_8.name());
    assertThat(downloadedContent, equalTo(version1Content));

    uploadedFile.delete();
  }
コード例 #2
0
ファイル: BoxFileTest.java プロジェクト: Zeimyth/box-java-sdk
  @Test
  @Category(IntegrationTest.class)
  public void fileLockAndUnlockSucceeds() {
    BoxAPIConnection api = new BoxAPIConnection(TestConfig.getAccessToken());
    BoxFolder rootFolder = BoxFolder.getRootFolder(api);
    String fileName = "[getInfoWithOnlyTheLockField] Test File.txt";
    String fileContent = "Test file";
    byte[] fileBytes = fileContent.getBytes(StandardCharsets.UTF_8);

    InputStream uploadStream = new ByteArrayInputStream(fileBytes);
    BoxFile uploadedFile = rootFolder.uploadFile(uploadStream, fileName).getResource();

    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DAY_OF_YEAR, 1);
    Date expiresAt = calendar.getTime();
    uploadedFile.lock(expiresAt, false);

    BoxFile.Info uploadedFileInfo = uploadedFile.getInfo("lock", "created_by");
    BoxLock fileLock = uploadedFileInfo.getLock();

    assertThat(fileLock, is(instanceOf(BoxLock.class)));
    assertThat(fileLock.getExpiresAt().toString(), is(equalTo(expiresAt.toString())));
    assertThat(fileLock.getIsDownloadPrevented(), is(equalTo(false)));
    assertThat(
        fileLock.getCreatedBy().getID(), is(equalTo(uploadedFileInfo.getCreatedBy().getID())));

    uploadedFile.unlock();

    BoxFile.Info updatedFileInfo = uploadedFile.getInfo("lock");
    assertThat(updatedFileInfo.getLock(), is(nullValue()));

    updatedFileInfo.getResource().delete();
  }
コード例 #3
0
ファイル: BoxFileTest.java プロジェクト: Zeimyth/box-java-sdk
  @Test
  @Category(IntegrationTest.class)
  public void shouldReturnTrashedAtForADeleteVersion() {
    BoxAPIConnection api = new BoxAPIConnection(TestConfig.getAccessToken());
    BoxFolder rootFolder = BoxFolder.getRootFolder(api);
    String fileName = "[deleteVersionSucceeds] Multi-version File.txt";
    byte[] version1Bytes = "Version 1".getBytes(StandardCharsets.UTF_8);
    byte[] version2Bytes = "Version 2".getBytes(StandardCharsets.UTF_8);

    InputStream uploadStream = new ByteArrayInputStream(version1Bytes);
    BoxFile uploadedFile = rootFolder.uploadFile(uploadStream, fileName).getResource();
    uploadStream = new ByteArrayInputStream(version2Bytes);
    uploadedFile.uploadVersion(uploadStream);

    Collection<BoxFileVersion> versions = uploadedFile.getVersions();
    BoxFileVersion previousVersion = versions.iterator().next();

    assertThat(previousVersion.getTrashedAt(), is(nullValue()));

    previousVersion.delete();
    versions = uploadedFile.getVersions();
    previousVersion = versions.iterator().next();

    assertThat(previousVersion.getTrashedAt(), is(notNullValue()));

    uploadedFile.delete();
  }
コード例 #4
0
ファイル: BoxFileTest.java プロジェクト: Zeimyth/box-java-sdk
  @Test
  @Category(IntegrationTest.class)
  public void downloadFileRangeSucceeds() throws IOException {
    BoxAPIConnection api = new BoxAPIConnection(TestConfig.getAccessToken());
    BoxFolder rootFolder = BoxFolder.getRootFolder(api);
    String fileName = "Tamme-Lauri_tamm_suvepäeval.jpg";
    URL fileURL = this.getClass().getResource("/sample-files/" + fileName);
    String filePath = URLDecoder.decode(fileURL.getFile(), "utf-8");
    long fileSize = new File(filePath).length();
    byte[] fileContent = readAllBytes(filePath);

    InputStream uploadStream = new FileInputStream(filePath);
    ProgressListener mockUploadListener = mock(ProgressListener.class);
    BoxFile.Info uploadedFileInfo =
        rootFolder.uploadFile(uploadStream, fileName, fileSize, mockUploadListener);
    BoxFile uploadedFile = uploadedFileInfo.getResource();
    long firstHalf = uploadedFileInfo.getSize() / 2;

    ByteArrayOutputStream downloadStream = new ByteArrayOutputStream();
    uploadedFile.downloadRange(downloadStream, 0, firstHalf);
    uploadedFile.downloadRange(downloadStream, firstHalf + 1);
    byte[] downloadedFileContent = downloadStream.toByteArray();

    assertThat(downloadedFileContent, is(equalTo(fileContent)));
    assertThat(
        rootFolder,
        hasItem(Matchers.<BoxItem.Info>hasProperty("ID", equalTo(uploadedFile.getID()))));
    verify(mockUploadListener, atLeastOnce())
        .onProgressChanged(anyLong(), longThat(is(equalTo(fileSize))));

    uploadedFile.delete();
  }
コード例 #5
0
ファイル: BoxFileTest.java プロジェクト: Zeimyth/box-java-sdk
  @Test
  @Category(IntegrationTest.class)
  public void createAndUpdateSharedLinkSucceeds() {
    BoxAPIConnection api = new BoxAPIConnection(TestConfig.getAccessToken());
    BoxFolder rootFolder = BoxFolder.getRootFolder(api);
    String fileName = "[createAndUpdateSharedLinkSucceeds] Test File.txt";
    byte[] fileBytes = "Non-empty string".getBytes(StandardCharsets.UTF_8);

    InputStream uploadStream = new ByteArrayInputStream(fileBytes);
    BoxFile uploadedFile = rootFolder.uploadFile(uploadStream, fileName).getResource();
    BoxSharedLink.Permissions permissions = new BoxSharedLink.Permissions();
    permissions.setCanDownload(true);
    permissions.setCanPreview(true);
    BoxSharedLink sharedLink =
        uploadedFile.createSharedLink(BoxSharedLink.Access.OPEN, null, permissions);

    assertThat(sharedLink.getURL(), not(isEmptyOrNullString()));

    sharedLink.getPermissions().setCanDownload(false);
    BoxFile.Info info = uploadedFile.new Info();
    info.setSharedLink(sharedLink);
    uploadedFile.updateInfo(info);

    assertThat(info.getSharedLink().getPermissions().getCanDownload(), is(false));

    uploadedFile.delete();
  }
コード例 #6
0
ファイル: BoxFileTest.java プロジェクト: Zeimyth/box-java-sdk
  @Test
  @Category(IntegrationTest.class)
  public void addCommentSucceeds() {
    BoxAPIConnection api = new BoxAPIConnection(TestConfig.getAccessToken());
    BoxFolder rootFolder = BoxFolder.getRootFolder(api);
    String fileName = "[addCommentSucceeds] Test File.txt";
    byte[] fileBytes = "Non-empty string".getBytes(StandardCharsets.UTF_8);
    String commentMessage = "Non-empty message";

    InputStream uploadStream = new ByteArrayInputStream(fileBytes);
    BoxFile uploadedFile = rootFolder.uploadFile(uploadStream, fileName).getResource();
    BoxComment.Info addedCommentInfo = uploadedFile.addComment(commentMessage);

    assertThat(addedCommentInfo.getMessage(), is(equalTo(commentMessage)));

    uploadedFile.delete();
  }
コード例 #7
0
ファイル: BoxFileTest.java プロジェクト: Zeimyth/box-java-sdk
  @Test
  @Category(IntegrationTest.class)
  public void updateFileWithSpecialCharsInNameSucceeds() {
    BoxAPIConnection api = new BoxAPIConnection(TestConfig.getAccessToken());
    BoxFolder rootFolder = BoxFolder.getRootFolder(api);
    String originalFileName = "[updateFileWithSpecialCharsInNameSucceeds] abc\";def.txt";
    String fileContent = "Test file";
    byte[] fileBytes = fileContent.getBytes(StandardCharsets.UTF_8);

    InputStream uploadStream = new ByteArrayInputStream(fileBytes);
    BoxFile.Info uploadedFileInfo = rootFolder.uploadFile(uploadStream, originalFileName);
    BoxFile uploadedFile = uploadedFileInfo.getResource();

    assertThat(uploadedFileInfo.getName(), is(equalTo(originalFileName)));

    uploadedFile.delete();
  }
コード例 #8
0
ファイル: BoxFileTest.java プロジェクト: Zeimyth/box-java-sdk
  @Test
  @Category(IntegrationTest.class)
  public void getDownloadURL() {
    BoxAPIConnection api = new BoxAPIConnection(TestConfig.getAccessToken());
    BoxFolder rootFolder = BoxFolder.getRootFolder(api);
    String fileName = "[getPreviewLink] Test File.txt";
    String fileContent = "Test file";
    byte[] fileBytes = fileContent.getBytes(StandardCharsets.UTF_8);
    InputStream uploadStream = new ByteArrayInputStream(fileBytes);
    BoxFile uploadedFile = rootFolder.uploadFile(uploadStream, fileName).getResource();

    URL uploadedFileDownloadURL = uploadedFile.getDownloadURL();

    assertThat(uploadedFileDownloadURL, is(notNullValue()));
    assertThat(uploadedFileDownloadURL.toString(), not(isEmptyOrNullString()));

    uploadedFile.delete();
  }
コード例 #9
0
ファイル: BoxFileTest.java プロジェクト: Zeimyth/box-java-sdk
  @Test
  @Category(IntegrationTest.class)
  public void getThumbnail() {
    BoxAPIConnection api = new BoxAPIConnection(TestConfig.getAccessToken());
    BoxFolder rootFolder = BoxFolder.getRootFolder(api);
    String fileName = "[getPreviewLink] Test File.txt";
    String fileContent = "Test file";
    byte[] fileBytes = fileContent.getBytes(StandardCharsets.UTF_8);
    InputStream uploadStream = new ByteArrayInputStream(fileBytes);
    BoxFile uploadedFile = rootFolder.uploadFile(uploadStream, fileName).getResource();

    byte[] thumbnail = uploadedFile.getThumbnail(BoxFile.ThumbnailFileType.PNG, 256, 256, 256, 256);

    assertThat(thumbnail, is(notNullValue()));
    assertNotEquals(thumbnail.length, 0);

    uploadedFile.delete();
  }
コード例 #10
0
ファイル: BoxFileTest.java プロジェクト: Zeimyth/box-java-sdk
  @Test
  @Category(IntegrationTest.class)
  public void createMetadataSucceeds() {
    BoxAPIConnection api = new BoxAPIConnection(TestConfig.getAccessToken());
    BoxFolder rootFolder = BoxFolder.getRootFolder(api);
    String fileName = "[createMetadataSucceeds] Test File.txt";
    byte[] fileBytes = "Non-empty string".getBytes(StandardCharsets.UTF_8);

    InputStream uploadStream = new ByteArrayInputStream(fileBytes);
    BoxFile uploadedFile = rootFolder.uploadFile(uploadStream, fileName).getResource();
    uploadedFile.createMetadata(new Metadata().add("/foo", "bar"));

    Metadata check1 = uploadedFile.getMetadata();
    Assert.assertNotNull(check1);
    Assert.assertEquals("bar", check1.get("/foo"));

    uploadedFile.delete();
  }
コード例 #11
0
ファイル: BoxFileTest.java プロジェクト: Zeimyth/box-java-sdk
  @Test
  @Category(IntegrationTest.class)
  public void getInfoWithOnlyTheNameField() {
    BoxAPIConnection api = new BoxAPIConnection(TestConfig.getAccessToken());
    BoxFolder rootFolder = BoxFolder.getRootFolder(api);
    String fileName = "[getInfoWithOnlyTheNameField] Test File.txt";
    String fileContent = "Test file";
    byte[] fileBytes = fileContent.getBytes(StandardCharsets.UTF_8);

    InputStream uploadStream = new ByteArrayInputStream(fileBytes);
    BoxFile uploadedFile = rootFolder.uploadFile(uploadStream, fileName).getResource();
    BoxFile.Info uploadedFileInfo = uploadedFile.getInfo("name");

    assertThat(uploadedFileInfo.getName(), is(equalTo(fileName)));
    assertThat(uploadedFileInfo.getDescription(), is(nullValue()));
    assertThat(uploadedFileInfo.getSize(), is(equalTo(0L)));

    uploadedFileInfo.getResource().delete();
  }
コード例 #12
0
ファイル: BoxFileTest.java プロジェクト: Zeimyth/box-java-sdk
  @Test
  @Category(IntegrationTest.class)
  public void uploadAndDownloadMultipleVersionsSucceeds() throws UnsupportedEncodingException {
    BoxAPIConnection api = new BoxAPIConnection(TestConfig.getAccessToken());
    BoxFolder rootFolder = BoxFolder.getRootFolder(api);
    String fileName = "[uploadAndDownloadMultipleVersionsSucceeds] Multi-version File.txt";
    String version1Content = "Version 1";
    String version1Sha = "db3cbc01da600701b9fe4a497fe328e71fa7022f";
    byte[] version1Bytes = version1Content.getBytes(StandardCharsets.UTF_8);
    long version1Size = version1Bytes.length;
    String version2Content = "Version 2";
    byte[] version2Bytes = version2Content.getBytes(StandardCharsets.UTF_8);
    long version2Size = version1Bytes.length;

    InputStream uploadStream = new ByteArrayInputStream(version1Bytes);
    BoxFile uploadedFile = rootFolder.uploadFile(uploadStream, fileName).getResource();

    uploadStream = new ByteArrayInputStream(version2Bytes);
    ProgressListener mockUploadListener = mock(ProgressListener.class);
    uploadedFile.uploadVersion(uploadStream, null, version2Size, mockUploadListener);

    Collection<BoxFileVersion> versions = uploadedFile.getVersions();
    BoxFileVersion previousVersion = versions.iterator().next();

    ByteArrayOutputStream downloadStream = new ByteArrayOutputStream();
    ProgressListener mockDownloadListener = mock(ProgressListener.class);
    previousVersion.download(downloadStream, mockDownloadListener);
    String downloadedContent = downloadStream.toString(StandardCharsets.UTF_8.name());

    assertThat(versions, hasSize(1));
    assertThat(previousVersion.getSha1(), is(equalTo(version1Sha)));
    assertThat(downloadedContent, equalTo(version1Content));
    verify(mockDownloadListener, atLeastOnce()).onProgressChanged(anyLong(), anyLong());
    verify(mockUploadListener, atLeastOnce())
        .onProgressChanged(anyLong(), longThat(is(equalTo(version1Size))));

    uploadedFile.delete();
  }
コード例 #13
0
ファイル: BoxFileTest.java プロジェクト: Zeimyth/box-java-sdk
  @Test
  @Category(IntegrationTest.class)
  public void moveFileSucceeds() throws UnsupportedEncodingException {
    BoxAPIConnection api = new BoxAPIConnection(TestConfig.getAccessToken());
    BoxFolder rootFolder = BoxFolder.getRootFolder(api);
    String fileName = "[moveFileSucceeds] Test File.txt";
    String fileContent = "Test file";
    byte[] fileBytes = fileContent.getBytes(StandardCharsets.UTF_8);
    String folderName = "[moveFileSucceeds] Destination Folder";

    InputStream uploadStream = new ByteArrayInputStream(fileBytes);
    BoxFile uploadedFile = rootFolder.uploadFile(uploadStream, fileName).getResource();

    BoxFolder destinationFolder = rootFolder.createFolder(folderName).getResource();
    uploadedFile.move(destinationFolder);

    assertThat(
        destinationFolder,
        hasItem(Matchers.<BoxItem.Info>hasProperty("ID", equalTo(uploadedFile.getID()))));

    uploadedFile.delete();
    destinationFolder.delete(false);
  }
コード例 #14
0
ファイル: BoxFileTest.java プロジェクト: Zeimyth/box-java-sdk
  @Test
  @Category(IntegrationTest.class)
  public void addTaskSucceeds() {
    BoxAPIConnection api = new BoxAPIConnection(TestConfig.getAccessToken());
    BoxFolder rootFolder = BoxFolder.getRootFolder(api);
    String fileName = "[addTaskSucceeds] Test File.txt";
    byte[] fileBytes = "Non-empty string".getBytes(StandardCharsets.UTF_8);
    String taskMessage = "Non-empty message";
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
    Date dueAt = new Date();

    InputStream uploadStream = new ByteArrayInputStream(fileBytes);
    BoxFile uploadedFile = rootFolder.uploadFile(uploadStream, fileName).getResource();
    BoxTask.Info addedTaskInfo = uploadedFile.addTask(BoxTask.Action.REVIEW, taskMessage, dueAt);

    assertThat(addedTaskInfo.getMessage(), is(equalTo(taskMessage)));
    assertThat(dateFormat.format(addedTaskInfo.getDueAt()), is(equalTo(dateFormat.format(dueAt))));
    assertThat(
        uploadedFile.getTasks(),
        hasItem(Matchers.<BoxTask.Info>hasProperty("ID", equalTo(addedTaskInfo.getID()))));

    uploadedFile.delete();
  }
コード例 #15
0
ファイル: BoxFileTest.java プロジェクト: Zeimyth/box-java-sdk
  @Test
  @Category(IntegrationTest.class)
  public void getInfoWithAllFields() {
    BoxAPIConnection api = new BoxAPIConnection(TestConfig.getAccessToken());
    BoxFolder rootFolder = BoxFolder.getRootFolder(api);
    String fileName = "[getInfoWithAllFields] Test File.txt";
    String fileContent = "Test file";
    byte[] fileBytes = fileContent.getBytes(StandardCharsets.UTF_8);

    InputStream uploadStream = new ByteArrayInputStream(fileBytes);
    BoxFile uploadedFile = rootFolder.uploadFile(uploadStream, fileName).getResource();
    BoxFile.Info uploadedFileInfo = uploadedFile.getInfo(BoxFile.ALL_FIELDS);

    assertThat(uploadedFileInfo.getName(), is(equalTo(fileName)));
    assertThat(uploadedFileInfo.getVersionNumber(), is(equalTo("1")));
    assertThat(uploadedFileInfo.getCommentCount(), is(equalTo(0L)));
    assertThat(uploadedFileInfo.getExtension(), is(equalTo("txt")));
    assertThat(uploadedFileInfo.getIsPackage(), is(false));
    assertThat(uploadedFileInfo.getItemStatus(), is(equalTo("active")));
    assertThat(uploadedFileInfo.getVersion(), not(nullValue()));
    assertThat(uploadedFileInfo.getVersion().getVersionID(), not(nullValue()));

    uploadedFileInfo.getResource().delete();
  }
コード例 #16
0
ファイル: BoxFileTest.java プロジェクト: Zeimyth/box-java-sdk
  @Test
  @Category(IntegrationTest.class)
  public void addCommentWithMentionSucceeds() {
    BoxAPIConnection api = new BoxAPIConnection(TestConfig.getAccessToken());
    BoxFolder rootFolder = BoxFolder.getRootFolder(api);
    String fileName = "[addCommentSucceeds] Test File.txt";
    byte[] fileBytes = "Non-empty string".getBytes(StandardCharsets.UTF_8);
    String commentMessage =
        String.format(
            "Message mentioning @[%s:%s]",
            TestConfig.getCollaboratorID(), TestConfig.getCollaborator());
    String expectedCommentMessage = "Message mentioning " + TestConfig.getCollaborator();

    InputStream uploadStream = new ByteArrayInputStream(fileBytes);
    BoxFile uploadedFile = rootFolder.uploadFile(uploadStream, fileName).getResource();
    BoxComment.Info addedCommentInfo = uploadedFile.addComment(commentMessage);

    assertThat(addedCommentInfo.getMessage(), is(equalTo(expectedCommentMessage)));
    assertThat(
        uploadedFile.getComments(),
        hasItem(Matchers.<BoxComment.Info>hasProperty("ID", equalTo(addedCommentInfo.getID()))));

    uploadedFile.delete();
  }
コード例 #17
0
ファイル: BoxFileTest.java プロジェクト: Zeimyth/box-java-sdk
  @Test
  @Category(IntegrationTest.class)
  public void copyFileSucceeds() throws UnsupportedEncodingException {
    BoxAPIConnection api = new BoxAPIConnection(TestConfig.getAccessToken());
    BoxFolder rootFolder = BoxFolder.getRootFolder(api);
    String originalFileName = "[copyFileSucceeds] Original File.txt";
    String newFileName = "[copyFileSucceeds] New File.txt";
    String fileContent = "Test file";
    byte[] fileBytes = fileContent.getBytes(StandardCharsets.UTF_8);

    InputStream uploadStream = new ByteArrayInputStream(fileBytes);
    BoxFile uploadedFile = rootFolder.uploadFile(uploadStream, originalFileName).getResource();

    BoxFile.Info copiedFileInfo = uploadedFile.copy(rootFolder, newFileName);
    BoxFile copiedFile = copiedFileInfo.getResource();

    ByteArrayOutputStream downloadStream = new ByteArrayOutputStream();
    copiedFile.download(downloadStream);
    String downloadedContent = downloadStream.toString(StandardCharsets.UTF_8.name());
    assertThat(downloadedContent, equalTo(fileContent));

    uploadedFile.delete();
    copiedFile.delete();
  }