Ejemplo n.º 1
0
  @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();
  }
Ejemplo n.º 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();
  }
Ejemplo n.º 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();
  }