示例#1
0
  @Test
  public void merge_a_branch_without_a_dep() throws Exception {
    setup();

    // do a merges.
    WithCwd wd = new WithCwd(project.getRepo().getWorkTree());
    {
      // switch to the branch with the lib
      git.args("checkout", "blue").start().get();

      // merge the master branch, which doesn't have the lib yet
      git.args("merge", "--no-ff", "master").start().get();

      // that should have just committed cleanly, that's it
    }
    wd.close();

    // now verify.
    File depWorkTreePath =
        new File(project.getRepo().getWorkTree() + "/lib/beta").getCanonicalFile();
    File depGitDataPath =
        new File(project.getRepo().getDirectory() + "/modules/lib/beta").getCanonicalFile();

    // i do hope there's a filesystem there now
    assertTrue("dependency module path exists on fs", depWorkTreePath.exists());
    assertTrue("dependency module path is dir", depWorkTreePath.isDirectory());

    // check that anyone else can read this state with a straight face; status should be clean
    new Josh("git")
        .args("status")
        .cwd(project.getRepo().getWorkTree()) /*.opts(Opts.NullIO)*/
        .start()
        .get();
    new Josh("git").args("status").cwd(depWorkTreePath) /*.opts(Opts.NullIO)*/.start().get();
  }
示例#2
0
  private void compareBinaryFolder(String path, boolean res) throws BrutException, IOException {
    Boolean exists = true;

    String tmp = "";
    if (res) {
      tmp = File.separatorChar + "res" + File.separatorChar;
    }

    String location = tmp + path;

    FileDirectory fileDirectory = new FileDirectory(sTestOrigDir + location);

    Set<String> files = fileDirectory.getFiles(true);
    for (String filename : files) {

      File control = new File((sTestOrigDir + location), filename);
      File test = new File((sTestNewDir + location), filename);

      if (!test.isFile() || !control.isFile()) {
        exists = false;
      }
    }

    assertTrue(exists);
  }
  @Test
  public void testSaveLoad() throws FileNotFoundException, IOException {
    System.out.println("---  testSaveLoad...");
    XMLEncoder xmlEncoder = null;
    FileOutputStream fos = null;
    BufferedOutputStream bos = null;

    File f = new File("testProjects/TEMP_PROJECTS/Test.ser");

    System.out.println("Saving to: " + f.getCanonicalPath());

    fos = new FileOutputStream(f);
    bos = new BufferedOutputStream(fos);
    xmlEncoder = new XMLEncoder(bos);

    // Metric m = Metric.PATH_LENGTH_FROM_ROOT;
    Object o1 = pg1;

    System.out.println("Pre: " + o1);

    // ProximalPref p = ProximalPref.MOST_PROX_AT_0;

    xmlEncoder.writeObject(o1);
    xmlEncoder.close();

    FileInputStream fis = new FileInputStream(f);
    BufferedInputStream bis = new BufferedInputStream(fis);
    XMLDecoder xd = new XMLDecoder(bis);

    Object o2 = xd.readObject();

    System.out.println("Post: " + o2);

    assertEquals(o2, o1);
  }
示例#4
0
  /**
   * Shuts down the test harness, and makes the best attempt possible to delete dataDir, unless the
   * system property "solr.test.leavedatadir" is set.
   */
  @Override
  public void tearDown() throws Exception {
    log.info("####TEARDOWN_START " + getTestName());
    if (factoryProp == null) {
      System.clearProperty("solr.directoryFactory");
    }

    if (h != null) {
      h.close();
    }
    String skip = System.getProperty("solr.test.leavedatadir");
    if (null != skip && 0 != skip.trim().length()) {
      System.err.println(
          "NOTE: per solr.test.leavedatadir, dataDir will not be removed: "
              + dataDir.getAbsolutePath());
    } else {
      if (!recurseDelete(dataDir)) {
        System.err.println(
            "!!!! WARNING: best effort to remove " + dataDir.getAbsolutePath() + " FAILED !!!!!");
      }
    }

    resetExceptionIgnores();
    super.tearDown();
  }
  private void testMultiFileFailedWriteHelper(
      EvenOddHDFSExactlyOnceWriter writer, ProcessingMode mode) {
    File meta = new File(testMeta.getDir());
    writer.setFilePath(meta.getAbsolutePath());

    writer.setup(new DummyContext(0, mode));

    writer.beginWindow(0);
    writer.input.put(0);
    writer.input.put(1);
    writer.input.put(2);
    writer.input.put(3);
    writer.endWindow();

    CheckPointWriter checkPointWriter = checkpoint(writer);

    writer.beginWindow(1);
    writer.input.put(4);
    writer.input.put(5);
    writer.endWindow();
    writer.teardown();

    restoreCheckPoint(checkPointWriter, writer);
    writer.setup(new DummyContext(0, mode));

    writer.beginWindow(2);
    writer.input.put(6);
    writer.input.put(7);
    writer.input.put(8);
    writer.input.put(9);
    writer.endWindow();
  }
示例#6
0
 protected void eraseFiles() {
   File tmpdirF = new File(tmpdir);
   String[] files = tmpdirF.list();
   for (int i = 0; files != null && i < files.length; i++) {
     new File(tmpdir + "/" + files[i]).delete();
   }
 }
示例#7
0
 protected void eraseTempDir() {
   File tmpdirF = new File(tmpdir);
   if (tmpdirF.exists()) {
     eraseFiles();
     tmpdirF.delete();
   }
 }
示例#8
0
  @Test
  public void canFollowLogfile() throws IOException {
    File tempFile =
        File.createTempFile("commons-io", "", new File(System.getProperty("java.io.tmpdir")));
    tempFile.deleteOnExit();
    System.out.println("Temp file = " + tempFile.getAbsolutePath());
    PrintStream log = new PrintStream(tempFile);
    LogfileFollower follower = new LogfileFollower(tempFile);
    List<String> lines;

    // Empty file:
    lines = follower.newLines();
    assertEquals(0, lines.size());

    // Write two lines:
    log.println("Line 1");
    log.println("Line 2");
    lines = follower.newLines();
    assertEquals(2, lines.size());
    assertEquals("Line 2", lines.get(1));

    // Write one more line:
    log.println("Line 3");
    lines = follower.newLines();
    assertEquals(1, lines.size());
    assertEquals("Line 3", lines.get(0));

    // Write one and a half line and finish later:
    log.println("Line 4");
    log.print("Line 5 begin");
    lines = follower.newLines();
    assertEquals(1, lines.size());

    // End last line and start a new one:
    log.println(" end");
    log.print("Line 6 begin");
    lines = follower.newLines();
    assertEquals(1, lines.size());
    assertEquals("Line 5 begin end", lines.get(0));

    // End last line:
    log.println(" end");
    lines = follower.newLines();
    assertEquals(1, lines.size());
    assertEquals("Line 6 begin end", lines.get(0));

    // A line only missing a newline:
    log.print("Line 7");
    lines = follower.newLines();
    assertEquals(0, lines.size());
    log.println();
    lines = follower.newLines();
    assertEquals(1, lines.size());
    assertEquals("Line 7", lines.get(0));

    // Delete:
    log.close();
    lines = follower.newLines();
    assertEquals(0, lines.size());
  }
示例#9
0
 @After
 public void tearDown() {
   for (File file : new File[] {_fileExisting, _fileText}) {
     if (file.exists()) {
       file.delete();
     }
   }
 }
示例#10
0
 protected void eraseFiles(final String filesEndingWith) {
   File tmpdirF = new File(tmpdir);
   String[] files = tmpdirF.list();
   for (int i = 0; files != null && i < files.length; i++) {
     if (files[i].endsWith(filesEndingWith)) {
       new File(tmpdir + "/" + files[i]).delete();
     }
   }
 }
 private static void delete(File directory) {
   for (File file : directory.listFiles()) {
     if (file.isDirectory()) {
       delete(file);
     } else {
       assertTrue(file.delete());
     }
   }
   assertTrue(directory.delete());
 }
  public IncrementalJUnit4Runner() {
    File testRunFile = new File("testRun.properties");

    if (testRunFile.exists() && !testRunFile.canWrite()) {
      throw new IllegalStateException();
    }

    coverageMap = new Properties();
    testMethods = new HashMap<Method, Boolean>();
  }
 /**
  * Set up.
  *
  * @throws Exception
  */
 @BeforeClass
 public static void setUpClass() throws Exception {
   URL sigFileV67Url = new URL(SIGNATURE_FILE_V67_URL);
   InputStream sigFileStream = sigFileV67Url.openStream();
   File tmpSigFile = File.createTempFile("tmpsigfile", ".xml");
   FileOutputStream fos = new FileOutputStream(tmpSigFile);
   IOUtils.copy(sigFileStream, fos);
   fos.close();
   dihj = DroidIdentification.getInstance(tmpSigFile.getAbsolutePath());
 }
  private void assertExpectedFileIO() {
    File realFile = new File(FILE_NAME);
    boolean realFileCreated = realFile.exists();

    if (realFileCreated) {
      realFile.delete();
    }

    assertFalse("Real file created", realFileCreated);
    assertTrue("File not written", testOutput.toString().startsWith("File written"));
  }
  @BeforeClass
  public static void createTestFiles() throws IOException {
    final boolean result =
        TEST_FILE_DIRECTORY.mkdir()
            && TEST_FILE.createNewFile()
            && TEST_FILE_BAD_EXT.createNewFile();

    if (!result) {
      throw new RuntimeException("unable to initialize test suite");
    }
  }
示例#16
0
 public static boolean recurseDelete(File f) {
   if (f.isDirectory()) {
     for (File sub : f.listFiles()) {
       if (!recurseDelete(sub)) {
         System.err.println(
             "!!!! WARNING: best effort to remove " + sub.getAbsolutePath() + " FAILED !!!!!");
         return false;
       }
     }
   }
   return f.delete();
 }
  @Test
  public void getStorableEntityLocationReturnsAbsolutePathToStorableEntity() {
    // Arrange:
    final File file =
        new File(Paths.get(TEST_FILE_DIRECTORY.toString(), "blah").toString(), "foo.bar");
    final TEntityFileDescriptor descriptor = this.createDescriptor(file);

    // Act:
    final String path = descriptor.getStorableEntityLocation();

    // Assert:
    Assert.assertThat(path, IsEqual.equalTo(file.getAbsolutePath()));
  }
  @Test
  public void deleteDeletesUnderlyingStorableEntityFile() throws IOException {
    // Arrange:
    final File file = new File(TEST_FILE_DIRECTORY, "to-be-deleted.bar");
    final TEntityFileDescriptor descriptor = this.createDescriptor(file);
    Assert.assertThat(file.createNewFile(), IsEqual.equalTo(true));

    // Act:
    descriptor.delete();

    // Assert:
    Assert.assertThat(file.exists(), IsEqual.equalTo(false));
  }
  private void testMultiRollingFileCompletedWriteHelper(
      EvenOddHDFSExactlyOnceWriter writer, ProcessingMode mode) {
    writer.setMaxLength(4);
    File meta = new File(testMeta.getDir());
    writer.setFilePath(meta.getAbsolutePath());

    writer.setup(new DummyContext(0, mode));

    writer.beginWindow(0);
    writer.input.put(0);
    writer.input.put(1);
    writer.input.put(2);
    writer.input.put(3);
    writer.input.put(4);
    writer.input.put(5);
    writer.endWindow();

    writer.beginWindow(1);
    writer.input.put(6);
    writer.input.put(7);
    writer.input.put(8);
    writer.input.put(9);
    writer.input.put(6);
    writer.input.put(7);
    writer.endWindow();

    // Even file

    String evenFileName = testMeta.getDir() + File.separator + EVEN_FILE;

    String correctContents = "0\n" + "2\n" + "4\n";

    checkOutput(0, evenFileName, correctContents);

    correctContents = "6\n" + "8\n" + "6\n";

    checkOutput(1, evenFileName, correctContents);

    // Odd file

    String oddFileName = testMeta.getDir() + File.separator + ODD_FILE;

    correctContents = "1\n" + "3\n" + "5\n";

    checkOutput(0, oddFileName, correctContents);

    correctContents = "7\n" + "9\n" + "7\n";

    checkOutput(1, oddFileName, correctContents);
  }
 /**
  * Test ODT file format identification
  *
  * @throws IOException
  */
 @Test
 public void testIdentifyOdt() throws IOException {
   InputStream odtTestFileStream =
       DroidIdentificationTest.class.getResourceAsStream("testfile.odt");
   File tmpOdtTestFile = File.createTempFile("odttestfile", ".odt");
   FileOutputStream fos = new FileOutputStream(tmpOdtTestFile);
   IOUtils.copy(odtTestFileStream, fos);
   fos.close();
   String result = dihj.identify(tmpOdtTestFile.getAbsolutePath());
   if (result.isEmpty()) {
     fail("No identification result");
   }
   assertEquals("fmt/291", result);
 }
  @Test
  public void openWriteCannotOpenFileThatIsInvalid() {
    // Arrange:
    final File file = Mockito.mock(File.class);
    Mockito.when(file.getName()).thenReturn("fo\0o.bar");
    Mockito.when(file.getAbsolutePath()).thenReturn("fo\0o.bar");
    final TEntityFileDescriptor descriptor = this.createDescriptor(file);

    // Act:
    ExceptionAssert.assertThrowsStorageException(
        v -> descriptor.openWrite(),
        this.getExceptionClass(),
        this.getExceptionValue(
            StorableEntityStorageException.Code.STORABLE_ENTITY_COULD_NOT_BE_SAVED.value()));
  }
示例#22
0
  public void testExecutePs2pdfConvertStreamed() throws Exception {

    LOG.info("TEST ps2pdf-convert-streamed");
    Tool tool = repo.getTool("ps2pdf");

    String tmpInputFile = this.getClass().getClassLoader().getResource("ps2pdf-input.ps").getFile();
    String tmpOutputFile = File.createTempFile("ps2pdf", ".pdf").getAbsolutePath();

    ToolProcessor processor = new ToolProcessor(tool);
    Operation operation = processor.findOperation("convert-streamed");
    processor.setOperation(operation);

    LOG.debug("tmpInputFile = " + tmpInputFile);

    LOG.debug("tmpOutputFile = " + tmpOutputFile);

    FileInputStream fin = new FileInputStream(new File(tmpInputFile));
    StreamProcessor in = new StreamProcessor(fin);
    in = new StreamProcessor(fin);
    in.next(processor);

    FileOutputStream fout = new FileOutputStream(new File(tmpOutputFile));
    processor.next(new StreamProcessor(fout));

    try {
      in.execute();
    } catch (IOException ex) {
      LOG.error("Exception during execution (maybe unresolved system dependency?): " + ex);
    }
  }
示例#23
0
  public void testExecutePs2pdfConvert() throws Exception {

    LOG.info("TEST ps2pdf-convert");
    Tool tool = repo.getTool("ps2pdf");

    String tmpInputFile = this.getClass().getClassLoader().getResource("ps2pdf-input.ps").getFile();

    ToolProcessor processor = new ToolProcessor(tool);
    Operation operation = processor.findOperation("convert");
    processor.setOperation(operation);

    Map<String, String> mapInput = new HashMap<String, String>();

    LOG.debug("tool = " + tool.getName());

    LOG.debug("tmpInputFile = " + tmpInputFile);

    mapInput = new HashMap<String, String>();
    mapInput.put("inFile", tmpInputFile);

    String tmpOutputFile = File.createTempFile("ps2pdf", ".pdf").getAbsolutePath();
    LOG.debug("tmpOutputFile = " + tmpOutputFile);

    Map<String, String> mapOutput = new HashMap<String, String>();
    mapOutput.put("outFile", tmpOutputFile);

    processor.setInputFileParameters(mapInput);
    processor.setOutputFileParameters(mapOutput);
    try {
      processor.execute();
    } catch (IOException ex) {
      LOG.error("Exception during execution (maybe unresolved system dependency?): " + ex);
    }
  }
示例#24
0
  @Test
  public void update_while_merging_a_branch_without_a_dep() throws Exception {
    setup();

    // do a merges.
    WithCwd wd = new WithCwd(project.getRepo().getWorkTree());
    {
      // switch to the branch with the lib
      git.args("checkout", "blue").start().get();

      // add a conflicting file so we get halted mid merge (inb4: no, '--no-commit' isn't quite the
      // same)
      IOForge.saveFile("qwer", new File("somefile").getCanonicalFile());
      git.args("add", "--", "somefile").start().get();
      git.args("commit", "-m", "bluecommit").start().get();

      // merge the master branch, which doesn't have the lib yet.  should conflict (exit code is
      // nonzero)
      git.args("merge", "--no-ff", "master").okExit(1).start().get();

      // we're stuck in a merge conflict.  try to mdm-update during it
      assertJoy(Mdm.run("update", "--strict"));

      // finish the merge.
      git.args("add", "somefile").start().get();
      git.args("commit", "--no-edit").start().get();
    }
    wd.close();

    // now verify.
    File depWorkTreePath =
        new File(project.getRepo().getWorkTree() + "/lib/beta").getCanonicalFile();
    File depGitDataPath =
        new File(project.getRepo().getDirectory() + "/modules/lib/beta").getCanonicalFile();

    // i do hope there's a filesystem there now
    assertTrue("dependency module path exists on fs", depWorkTreePath.exists());
    assertTrue("dependency module path is dir", depWorkTreePath.isDirectory());

    // check that anyone else can read this state with a straight face; status should be clean
    new Josh("git")
        .args("status")
        .cwd(project.getRepo().getWorkTree()) /*.opts(Opts.NullIO)*/
        .start()
        .get();
    new Josh("git").args("status").cwd(depWorkTreePath) /*.opts(Opts.NullIO)*/.start().get();
  }
  @Test
  public void descriptorCanBeCreatedAroundStorableEntityWithMixedCaseExtension() {
    // Arrange:
    final File file =
        new File(Paths.get(TEST_FILE_DIRECTORY.toString(), "BlAh").toString(), "FoO.BaR");

    // Act:
    final TEntityFileDescriptor descriptor = this.createDescriptor(file);

    // Assert:
    Assert.assertThat(descriptor.getName(), IsEqual.equalTo(this.createEntityName("FoO")));
    Assert.assertThat(
        descriptor.getFileExtension(), IsEqual.equalTo(this.createEntityFileExtension(".BaR")));
    Assert.assertThat(
        descriptor.getStorableEntityLocation(),
        IsEqual.equalTo(Paths.get(TEST_FILE_DIRECTORY.toString(), "BlAh", "FoO.BaR").toString()));
  }
  @Test
  public void descriptorCanBeSerialized() {
    // Arrange:
    final File file =
        new File(Paths.get(TEST_FILE_DIRECTORY.toString(), "blah").toString(), "foo.bar");
    final TEntityFileDescriptor descriptor = this.createDescriptor(file);

    // Act:
    final JSONObject jsonObject = JsonSerializer.serializeToJson(descriptor);

    // Assert:
    Assert.assertThat(jsonObject.size(), IsEqual.equalTo(2));
    Assert.assertThat(jsonObject.get(descriptor.getName().getLabel()), IsEqual.equalTo("foo"));
    Assert.assertThat(
        jsonObject.get("location"),
        IsEqual.equalTo(Paths.get(TEST_FILE_DIRECTORY.toString(), "blah", "foo.bar").toString()));
  }
  @Test
  public void deleteRaisesExceptionIfFileCannotBeDeleted() {
    // Arrange:
    final File file = Mockito.mock(File.class);
    Mockito.when(file.getName()).thenReturn("foo.bar");
    Mockito.when(file.getAbsolutePath()).thenReturn("foo.bar");
    final TEntityFileDescriptor descriptor = this.createDescriptor(file);

    Mockito.when(file.delete()).thenReturn(false);

    // Act:
    ExceptionAssert.assertThrowsStorageException(
        v -> descriptor.delete(),
        this.getExceptionClass(),
        this.getExceptionValue(
            StorableEntityStorageException.Code.STORABLE_ENTITY_COULD_NOT_BE_DELETED.value()));
  }
示例#28
0
  @Before
  public void setUp() throws Exception {
    _rgchPwTest = new char[] {'p', 'a', 's', 's', 'w', 'o', 'r', 'd'};

    _fileExisting = File.createTempFile("obzvaultexisting", ".vault");
    _strDecryptedExisting = "existing";
    OBZVaultDocument doc = new OBZVaultDocument();
    doc.setAppVersion("X.Y.DEV");
    doc.setText(_strDecryptedExisting);
    doc.saveAsVaultDoc(_fileExisting, _rgchPwTest);

    _fileText = File.createTempFile("obzvaulttext", ".txt");
    _strText = "Hello world!";
    OutputStream os = new FileOutputStream(_fileText);
    os.write(_strText.getBytes());
    os.close();
  }
  private void populateFile(String fileName, String contents) {
    File testFile = new File(testMeta.getDir() + "/" + fileName);

    try {
      testFile.createNewFile();
    } catch (IOException ex) {
      DTThrowable.rethrow(ex);
    }

    FileWriter fileWriter;

    try {
      fileWriter = new FileWriter(testFile);
      fileWriter.write(contents);
      fileWriter.close();
    } catch (IOException ex) {
      DTThrowable.rethrow(ex);
    }
  }
  @Test
  public void descriptorCanBeCreatedAroundUrlEncodedStorableEntityWithValidExtension() {
    // Arrange:
    final File file =
        new File(
            Paths.get(TEST_FILE_DIRECTORY.toString(), "blah").toString(),
            "%C3%B6%C3%A4%C3%BC%40.bar");

    // Act:
    final TEntityFileDescriptor descriptor = this.createDescriptor(file);

    // Assert:
    Assert.assertThat(descriptor.getName(), IsEqual.equalTo(this.createEntityName("öäü@")));
    Assert.assertThat(
        descriptor.getFileExtension(), IsEqual.equalTo(this.createEntityFileExtension(".bar")));
    Assert.assertThat(
        descriptor.getStorableEntityLocation(),
        IsEqual.equalTo(
            Paths.get(TEST_FILE_DIRECTORY.toString(), "blah", "%C3%B6%C3%A4%C3%BC%40.bar")
                .toString()));
  }