예제 #1
0
  @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();
  }
예제 #2
0
  @Test
  @Category(IntegrationTest.class)
  public void updateFileInfoSucceeds() {
    BoxAPIConnection api = new BoxAPIConnection(TestConfig.getAccessToken());
    BoxFolder rootFolder = BoxFolder.getRootFolder(api);
    String originalFileName = "[updateFileInfoSucceeds] Original Name.txt";
    String newFileName = "[updateFileInfoSucceeds] New Name.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();

    BoxFile.Info newInfo = uploadedFile.new Info();
    newInfo.setName(newFileName);
    uploadedFile.updateInfo(newInfo);

    assertThat(newInfo.getName(), is(equalTo(newFileName)));

    uploadedFile.delete();
  }