예제 #1
0
  @Test
  public void testFileHistoryInitEmpty() {
    PartialFileHistory fileHistory = new PartialFileHistory(FileHistoryId.parseFileId("1234"));

    assertEquals(FileHistoryId.parseFileId("1234"), fileHistory.getFileHistoryId());
    assertNotSame(FileHistoryId.parseFileId("9999"), fileHistory.getFileHistoryId());
    assertNull(fileHistory.getLastVersion());
    assertNotNull(fileHistory.toString());
    assertTrue(fileHistory.toString().contains("1234"));
    assertNotNull(fileHistory.getFileVersions());
    assertEquals(0, fileHistory.getFileVersions().size());
  }
예제 #2
0
  @Test
  public void testFileHistoryClone() {
    FileVersion fileVersion1 = new FileVersion();
    fileVersion1.setVersion(1L);
    fileVersion1.setPath("/somepath");

    FileVersion fileVersion2 = new FileVersion();
    fileVersion2.setVersion(2L);
    fileVersion2.setPath("/somepath");

    PartialFileHistory fileHistory = new PartialFileHistory(FileHistoryId.parseFileId("1234"));
    fileHistory.addFileVersion(fileVersion1);
    fileHistory.addFileVersion(fileVersion2);

    PartialFileHistory fileHistoryClone = fileHistory.clone();

    assertEquals(fileHistory, fileHistoryClone);
    assertEquals(fileHistory.getFileVersions().size(), fileHistoryClone.getFileVersions().size());
    assertEquals(fileHistory.getFileVersions(), fileHistoryClone.getFileVersions());

    FileVersion fileVersion3 = new FileVersion();
    fileVersion3.setVersion(3L);
    fileVersion3.setPath("/somepath");

    fileHistoryClone.addFileVersion(fileVersion3);
    assertEquals(
        fileHistory.getFileVersions().size() + 1, fileHistoryClone.getFileVersions().size());
  }
예제 #3
0
  private void handleGetFileRequest(GetFileRequest fileRequest) {
    try {
      FileHistoryId fileHistoryId = FileHistoryId.parseFileId(fileRequest.getFileHistoryId());
      long version = fileRequest.getVersion();

      FileVersion fileVersion = localDatabase.getFileVersion(fileHistoryId, version);
      FileContent fileContent = localDatabase.getFileContent(fileVersion.getChecksum(), true);
      Map<ChunkChecksum, MultiChunkId> multiChunks =
          localDatabase.getMultiChunkIdsByChecksums(fileContent.getChunks());

      TransferManager transferManager =
          config.getTransferPlugin().createTransferManager(config.getConnection());
      Downloader downloader = new Downloader(config, transferManager);
      Assembler assembler = new Assembler(config, localDatabase);

      downloader.downloadAndDecryptMultiChunks(new HashSet<MultiChunkId>(multiChunks.values()));

      File tempFile = assembler.assembleToCache(fileVersion);
      String tempFileToken = StringUtil.toHex(ObjectId.secureRandomBytes(40));

      GetFileResponse fileResponse =
          new GetFileResponse(fileRequest.getId(), fileRequest.getRoot(), tempFileToken);
      GetFileResponseInternal fileResponseInternal =
          new GetFileResponseInternal(fileResponse, tempFile);

      eventBus.post(fileResponseInternal);
    } catch (Exception e) {
      logger.log(Level.WARNING, "Cannot reassemble file.", e);
      eventBus.post(new BadRequestResponse(fileRequest.getId(), "Cannot reassemble file."));
    }
  }
예제 #4
0
  private void handleGetFileHistoryRequest(GetFileHistoryRequest fileHistoryRequest) {
    FileHistoryId fileHistoryId = FileHistoryId.parseFileId(fileHistoryRequest.getFileHistoryId());
    List<FileVersion> fileHistory = localDatabase.getFileHistory(fileHistoryId);
    GetFileHistoryResponse fileHistoryRespose =
        new GetFileHistoryResponse(
            fileHistoryRequest.getId(), fileHistoryRequest.getRoot(), fileHistory);

    eventBus.post(fileHistoryRespose);
  }
예제 #5
0
  private void handleRestoreRequest(RestoreRequest restoreRequest) {
    RestoreOperationOptions restoreOptions = new RestoreOperationOptions();

    restoreOptions.setFileHistoryId(FileHistoryId.parseFileId(restoreRequest.getFileHistoryId()));
    restoreOptions.setFileVersion(restoreRequest.getVersion());

    try {
      RestoreOperationResult restoreResult = new RestoreOperation(config, restoreOptions).execute();

      RestoreResponse restoreResponse =
          new RestoreResponse(restoreRequest.getId(), restoreResult.getTargetFile());
      eventBus.post(restoreResponse);
    } catch (Exception e) {
      logger.log(Level.WARNING, "BadRequestResponse: Cannot restore file.");
      eventBus.post(new BadRequestResponse(restoreRequest.getId(), "Cannot restore file."));
    }
  }
예제 #6
0
  @Test
  public void testFileHistoryGetVersionsNonEmpty() {
    FileVersion fileVersion = new FileVersion();
    fileVersion.setVersion(5L);
    fileVersion.setPath("/somepath");

    PartialFileHistory fileHistory = new PartialFileHistory(FileHistoryId.parseFileId("1234"));
    fileHistory.addFileVersion(fileVersion);

    assertNotNull(fileHistory.getLastVersion());
    assertNotNull(fileHistory.getFileVersions());
    assertEquals(1, fileHistory.getFileVersions().size());
    assertEquals(fileVersion, fileHistory.getLastVersion());
    assertNull(fileHistory.getFileVersions().get(1L));
    assertNull(fileHistory.getFileVersion(1L));
    assertEquals(fileVersion, fileHistory.getFileVersions().get(5L));
    assertEquals(fileVersion, fileHistory.getFileVersion(5L));
  }
예제 #7
0
 @Test(expected = IllegalArgumentException.class)
 public void testFileHistoryAddFileVersionInvalidVersionNull() {
   PartialFileHistory fileHistory = new PartialFileHistory(FileHistoryId.parseFileId("1234"));
   fileHistory.addFileVersion(new FileVersion());
 }
예제 #8
0
 @Test(expected = IllegalArgumentException.class)
 public void testFileHistoryIdInvalidNull() {
   FileHistoryId.parseFileId(null);
 }
예제 #9
0
 @Test
 public void testFileHistoryIdParsedOk() {
   assertEquals("12", FileHistoryId.parseFileId("12").toString());
 }