Example usage for org.apache.commons.io FileUtils contentEquals

List of usage examples for org.apache.commons.io FileUtils contentEquals

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils contentEquals.

Prototype

public static boolean contentEquals(File file1, File file2) throws IOException 

Source Link

Document

Compares the contents of two files to determine if they are equal or not.

Usage

From source file:com.microsoft.alm.plugin.idea.setup.ApplicationStartupTest.java

@Test
public void testCacheIdeLocationOtherEntries() throws Exception {
    File expectedFile = File.createTempFile("expectedLocation", ".csv");
    writeToFile(expectedFile, IDEA_NAME + ",/current/location/of/ide\npycharm,/current/dir/for/pycharm\n");
    writeToFile(new File(LOCATIONS_CSV_PATH), "pycharm,/current/dir/for/pycharm\n");

    ApplicationStartup appStartup = new ApplicationStartup();
    appStartup.cacheIdeLocation(VSTS_DIR, "/current/location/of/ide");
    Assert.assertTrue(FileUtils.contentEquals(expectedFile, new File(LOCATIONS_CSV_PATH)));
}

From source file:com.microsoft.alm.plugin.idea.common.setup.ApplicationStartupTest.java

@Test
public void testCacheIdeLocationOtherEntries() throws Exception {
    File expectedFile = File.createTempFile("expectedLocation", ".csv");
    writeToFile(expectedFile, "pycharm,/current/dir/for/pycharm\n" + IDEA_NAME + ",/current/location/of/ide\n");
    writeToFile(new File(LOCATIONS_CSV_PATH), "pycharm,/current/dir/for/pycharm\n");

    ApplicationStartup appStartup = new ApplicationStartup();
    appStartup.cacheIdeLocation(VSTS_DIR, "/current/location/of/ide");
    Assert.assertTrue(FileUtils.contentEquals(expectedFile, new File(LOCATIONS_CSV_PATH)));
}

From source file:com.geewhiz.pacify.commandline.TestShowUsedProperties.java

@Test
public void writeToFile() throws Exception {
    File targetResourceFolder = new File("target/test-classes/testShowUsedProperties");

    File packagePath = new File(targetResourceFolder, "package");
    File expectedResult = new File(targetResourceFolder, "expectedResult/result.txt");
    File destinationFile = new File(targetResourceFolder, "result/result.txt");

    destinationFile.delete();//  w ww  .  ja  v a 2s. c o  m

    PacifyViaCommandline pacifyViaCommandline = new PacifyViaCommandline();

    int result = pacifyViaCommandline.mainInternal(new String[] { "showUsedProperties",
            "--packagePath=" + packagePath, "--destinationFile=" + destinationFile });

    Assert.assertEquals("ShowUsedProperties should not return an error.", 0, result);
    Assert.assertTrue("Content is same", FileUtils.contentEquals(expectedResult, destinationFile));
}

From source file:ExamTest.java

public void testOutputExamCSV() {
    FileWriter testWriter;//ww w. jav  a2  s  .c  o  m
    Exam testExam;
    ArrayList<StudentExam> stExams = new ArrayList<>();
    int[] incorrect = { 1 };
    File testOutputDir;
    String[] studentName = { "First", "Last" };

    // Output Directory of the tests
    testOutputDir = Paths.get("TestFiles_External").toFile();

    Student student1 = new Student("id", studentName);

    // Set up the studentExam
    StudentExam stExam = new StudentExam("stExam1", null, null, student1);
    stExam.setCorrectCount(0);
    stExam.setIncorrectCount(1);
    stExam.setPercent(0.0);
    // Add to the array
    stExams.add(stExam);

    // Set up the key
    ExamKey key = new ExamKey("testKey", null, null, 1);

    // Create the Exam
    testExam = new Exam(stExams, key);

    // Test with an incorrect answers array
    testExam.setFileName("testExam1_output.csv");
    String testOneOutput = testExam.outputExamCSV(testOutputDir, incorrect);

    // Test without an incorrect array
    testExam.setFileName("testExam2_output.csv");
    String testTwoOutput = testExam.outputExamCSV(testOutputDir, null);

    try {
        // Assert that testOneOutput is the same as an expected file
        assertTrue(FileUtils.contentEquals(
                new File(testOutputDir.getAbsolutePath() + File.separator + "examOutTest1.csv"),
                new File(testOneOutput)));
    } catch (IOException ex) {
        Logger.getLogger(ExamTest.class.getName()).log(Level.SEVERE, null, ex);
    }

    try {
        // Assert that testTwoOutput is the same as an expected file
        assertTrue(FileUtils.contentEquals(
                new File(testOutputDir.getAbsolutePath() + File.separator + "examOutTest2.csv"),
                new File(testTwoOutput)));
    } catch (IOException ex) {
        Logger.getLogger(ExamTest.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:dremel.common.AvroTest.java

@Test
public void shallowCopyTest() throws IOException {

    Schema inSchema = getSchema("OrecSchema.avpr.json");
    File inFile = getFile("OrecDremelPaperData.avro.json");
    Array<GenericRecord> inData = getData(inSchema, inFile, FileEncoding.JSON);
    File outFile = getTempFile("AvroTestCopyShallow.avro.json");
    FileUtils.deleteQuietly(outFile);/*from  w w w. j  a va  2 s  .  c  o  m*/

    Encoder encoder = new JsonEncoder(inSchema, new FileOutputStream(outFile));

    DatumWriter<Array<GenericRecord>> writer = new GenericDatumWriter<Array<GenericRecord>>(inSchema);

    writer.write(inData, encoder);

    encoder.flush();

    assertTrue("Copied files differs", FileUtils.contentEquals(inFile, outFile));

    // FileUtils.forceDelete(outFile);
    FileUtils.forceDeleteOnExit(outFile); // TODO fucking file hasn't being
    // deleted for some reason
}

From source file:de.nbi.ontology.test.OntologyUtilTest.java

/**
 * Test, if concept labels are created properly. The input file contains a
 * URI in each line.//  ww w .  j  a v  a 2 s . co  m
 * 
 * @param inFile
 *            input file
 * @throws IOException
 */
@SuppressWarnings("unchecked")
@Test(dataProviderClass = TestFileProvider.class, dataProvider = "labelTestFiles", groups = { "functest" })
public void getLabel(File inFile) throws IOException {

    // TODO. With the recent change to the OntologyUtil class, labels are
    // not extracted from a concept's uri any more. Instead, the RDF Label
    // annotations are used. Thus, a concept can have more than one label now.
    // The problem is that no assumption about the order in which the labels
    // are returned can be made. We have to rewrite the test case such that
    // it does not make this assumption.

    log.info("Processing " + inFile.getName());
    String basename = FilenameUtils.removeExtension(inFile.getAbsolutePath());
    File outFile = new File(basename + ".out");
    File resFile = new File(basename + ".res");

    List<String> uris = FileUtils.readLines(inFile);
    PrintWriter w = new PrintWriter(new FileWriter(outFile));

    for (String u : uris) {
        OntClass clazz = index.getModel().getOntClass(u);
        List<String> labels = OntologyUtils.getLabels(clazz);
        for (String l : labels) {
            log.debug("** " + u + " => " + l);
            w.println(l);
        }
    }
    w.flush();
    w.close();

    Assert.assertTrue(FileUtils.contentEquals(outFile, resFile));
}

From source file:com.ftb2om2.view.ConverterNGTest.java

@Test(enabled = true)
public void FtbOldTreeToOsuMania() throws Exception {
    System.out.println("Testing conversion between FtbClassic and o!m");
    String x = getClass().getResource("/").getPath();
    String inputFilePath = getClass().getResource("/ftbOldTest1.txt").getPath();
    String outputFilePath = getClass().getResource("/").getPath();
    String name = "osuTestOutput2";
    Integer volume = 100;//from  w  ww .  j  a  v  a 2 s .co m
    Metadata metadata = new Metadata("", "", "", "", "", "");
    Converter instance = new Converter(new FtbOldReader(), new OsuManiaV14Writer());
    instance.convert(inputFilePath, outputFilePath, name, volume, metadata);
    // TODO review the generated test code and remove the default call to fail.
    File correctOutput = new File(getClass().getResource("/osuCorrectOutput2.osu").getPath());
    File generatedOutput = new File(getClass().getResource("/osuTestOutput2.osu").getPath());
    assertTrue(FileUtils.contentEquals(correctOutput, generatedOutput));
}

From source file:avantssar.aslanpp.testing.TranslationInstance.java

public void report(PrintStream out, int index, List<String> backendNames, boolean odd) {
    out.print("<tr style='background-color: ");
    out.print(TranslationReport.BG(odd));
    out.println(";'>");
    out.println("<td style='text-align: right;'>" + index + "</td>");

    out.print("<td");
    boolean different = false;
    boolean differentDet = false;
    if (aslanPPcheck1 != null || aslanPPcheck2 != null) {
        try {//from  ww  w  . java  2  s.co m
            if (aslanPPcheck1 != null && aslanPPcheck2 != null) {
                different = !FileUtils.contentEquals(aslanPPcheck1, aslanPPcheck2);
            } else {
                different = true;
            }
            if (aslanPPcheck1det != null && aslanPPcheck2det != null) {
                differentDet = !FileUtils.contentEquals(aslanPPcheck1det, aslanPPcheck2det);
            } else {
                differentDet = aslanPPcheck1det != null || aslanPPcheck2det != null;
            }
            out.print(" style='background-color: ");
            if (different || differentDet) {
                out.print(TranslationReport.RED(odd));
            } else {
                out.print(TranslationReport.GREEN(odd));
            }
            out.print(";'");
        } catch (IOException e) {
            Debug.logger.error("Failed to compare files '" + aslanPPcheck1.getAbsolutePath() + "' and '"
                    + aslanPPcheck2.getAbsolutePath() + "'.", e);
        }
    }
    out.print(">");
    HTMLHelper.fileOrDash(out, outputDir, aslanPPfile, null);
    // if (different) {
    // out.print(" ");
    // HTMLHelper.fileOrDash(out, aslanPPcheck1, "pp1");
    // out.print(" ");
    // HTMLHelper.fileOrDash(out, aslanPPcheck2, "pp2");
    // }
    // if (differentDet) {
    // out.print(" ");
    // HTMLHelper.fileOrDash(out, aslanPPcheck1det, "pp1d");
    // out.print(" ");
    // HTMLHelper.fileOrDash(out, aslanPPcheck2det, "pp2d");
    // }
    out.println("</td>");

    out.print("<td style='background-color: ");
    if (errors > 0) {
        out.print(TranslationReport.RED(odd));
    } else {
        out.print(TranslationReport.GREEN(odd));
    }
    out.print(";'>");
    HTMLHelper.fileOrDash(out, outputDir, errorsFile, errors > 0 ? Integer.toString(errors) : "-");
    out.println("</td>");
    out.print("<td style='background-color: ");
    if (warnings > 0) {
        out.print(TranslationReport.RED(odd));
    } else {
        out.print(TranslationReport.GREEN(odd));
    }
    out.print(";'>");
    HTMLHelper.fileOrDash(out, outputDir, warningsFile, warnings > 0 ? Integer.toString(warnings) : "-");
    out.println("</td>");
    filesCompared(out, aslanFile, expectedASLanFile, "expected", odd);
    out.println("<td>" + expectedVerdict.toString() + "</td>");
    for (String s : backendNames) {
        BackendRun br = verdicts.get(s);
        if (br != null) {
            br.report(out, odd, expectedVerdict);
        } else {
            out.print("<td>-</td>");
        }
    }
    out.println("</tr>");
}

From source file:com.amazonaws.ant.s3.UploadFileSetToS3TaskTests.java

@Test
public void testExecuteMultipleFiles() throws IOException {
    UploadFileSetToS3Task task = new UploadFileSetToS3Task();
    task.setProject(new Project());
    FileSet fileset = new FileSet();
    fileset.setDir(testFile1.getParentFile());
    fileset.setIncludes("*.txt");
    task.addFileset(fileset);/*from ww  w.  j a  v  a  2  s. c  o  m*/
    task.setBucketName(BUCKET_NAME);
    task.setKeyPrefix(KEY_PREFIX);
    task.execute();
    resFile1 = File.createTempFile(RES_FILE_1, TESTFILE_SUFFIX);
    resFile2 = File.createTempFile(RES_FILE_2, TESTFILE_SUFFIX);
    resFile3 = File.createTempFile(RES_FILE_3, TESTFILE_SUFFIX);
    client.getObject(new GetObjectRequest(BUCKET_NAME, KEY_PREFIX + fileName1), resFile1);
    client.getObject(new GetObjectRequest(BUCKET_NAME, KEY_PREFIX + fileName2), resFile2);
    client.getObject(new GetObjectRequest(BUCKET_NAME, KEY_PREFIX + fileName3), resFile3);
    assertTrue(FileUtils.contentEquals(testFile1, resFile1));
    assertTrue(FileUtils.contentEquals(testFile1, resFile1));
    assertTrue(FileUtils.contentEquals(testFile1, resFile1));
}

From source file:azkaban.utils.FileIOUtilsTest.java

private boolean areDirsEqualUtil(File file1, File file2, boolean isRoot, boolean ignoreRoot)
        throws IOException {
    if (!file1.getName().equals(file2.getName())) {
        if (!isRoot && ignoreRoot)
            return false;
    }/*from  ww  w  .j  a va 2 s.  c  o m*/
    if (file1.isDirectory() && file2.isDirectory()) {
        if (file1.listFiles().length != file2.listFiles().length) {
            return false;
        }
        File[] fileList1 = file1.listFiles(), fileList2 = file2.listFiles();
        Arrays.sort(fileList1, NameFileComparator.NAME_COMPARATOR);
        Arrays.sort(fileList2, NameFileComparator.NAME_COMPARATOR);

        for (int i = 0; i < fileList1.length; i++) {
            if (!areDirsEqualUtil(fileList1[i], fileList2[i], false, ignoreRoot)) {
                return false;
            }
        }
        return true;
    } else if (file1.isFile() && file2.isFile()) {
        return file1.getName().equals(file2.getName()) && FileUtils.contentEquals(file1, file2);
    } else
        return false;
}