Example #1
0
  @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();
  }
Example #2
0
  @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();
  }
Example #3
0
  @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();
  }