Exemple #1
0
  @Test
  public void usage() throws Exception {
    dir = testDir("usage");
    File headFile = new File(dir, "HEAD");
    File pagesDir = new File(dir, "pages");

    IndexCodec indexCodec = mock(IndexCodec.class);
    Codec<Entry<Key, Integer>> entryCodec = mock(Codec.class);

    Snapshot<Integer> snapshot = new Snapshot<Integer>(dir, indexCodec, entryCodec);

    snapshot.updateAndCleanUp();

    String snapshotFileName = Files.readFirstLine(headFile, Charset.defaultCharset());
    assertThat(snapshotFileName, is(not("null.s")));
    assertThat(new File(pagesDir, snapshotFileName).exists(), is(true));

    assertThat(new File(pagesDir, "null.s").exists(), is(false));
  }
 private Set<Checksum> readChecksumFromHsm(File file) throws IOException {
   File checksumFile = new File(file.getCanonicalPath() + ".crcval");
   try {
     if (checksumFile.exists()) {
       try {
         String firstLine = Files.readFirstLine(checksumFile, Charsets.US_ASCII);
         if (firstLine != null) {
           Checksum checksum = Checksum.parseChecksum("1:" + firstLine);
           return Collections.singleton(checksum);
         }
       } finally {
         checksumFile.delete();
       }
     }
   } catch (FileNotFoundException e) {
     /* Should not happen unless somebody else is removing
      * the file before we got a chance to read it.
      */
     throw Throwables.propagate(e);
   }
   return Collections.emptySet();
 }
  @Test
  public void testCopy() {
    try {
      // given
      String testContent = "some content";

      String sourcePath = Paths.Library.testDir + File.separator + "testCopyInstall.txt";
      File source = new File(sourcePath);
      Files.createParentDirs(source);
      source.deleteOnExit();
      Files.write(testContent, source, Charset.defaultCharset());

      String destinationPath =
          Paths.Library.testDir
              + File.separator
              + "testProcess"
              + File.separator
              + "testCopyInstall.txt";
      File destination = new File(destinationPath);
      destination.deleteOnExit();

      String[] args = {"1", "copy", sourcePath, destinationPath};

      // when
      new InstallationPerformer().install(args);
      File destinationTest = new File(destinationPath);
      destinationTest.deleteOnExit();

      // then
      assertThat(destinationTest)
          .as("process(File,File) should copy file to a selected location")
          .exists();
      assertThat(Files.readFirstLine(destinationTest, Charset.defaultCharset()))
          .as("process(File,File) should copy file's content")
          .isEqualTo(testContent);
    } catch (IOException e) {
      fail("process(File,File) should not throw exception while working on accessible files");
    }
  }