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:org.commonjava.maven.ext.io.JSONIOTest.java

@Test
public void updateVersions() throws ManipulationException, IOException {
    String modifyPath = "$..version";
    DocumentContext doc = jsonIO.parseJSON(pluginFile);
    doc.set(modifyPath, "1.3.0.rebuild-1");

    logger.debug("Modified {} ", doc.jsonString());

    File target = tf.newFile();/*ww  w  .j a v  a 2 s. c  om*/

    jsonIO.writeJSON(target, doc.jsonString());

    assertTrue(!doc.jsonString().contains("1.2.2-SNAPSHOT"));
    assertTrue(doc.jsonString().contains("1.3.0.rebuild-1"));
    assertFalse(FileUtils.contentEquals(pluginFile, target));
}

From source file:org.commonjava.maven.ext.io.JSONIOTest.java

@Test
public void updateURL() throws ManipulationException, IOException {
    String modifyPath = "$.repository.url";
    DocumentContext doc = jsonIO.parseJSON(pluginFile);
    doc.set(modifyPath, "https://maven.repository.redhat.com/ga/");

    logger.debug("Modified {} ", doc.jsonString());

    File target = tf.newFile();//from w w w. ja v a2 s  .c  o  m

    jsonIO.writeJSON(target, doc.jsonString());

    assertTrue(doc.jsonString().contains("https://maven.repository.redhat.com/ga/"));
    assertTrue(doc.jsonString().contains("1.2.2-SNAPSHOT"));
    assertFalse(FileUtils.contentEquals(pluginFile, target));
}

From source file:org.commonjava.maven.ext.io.PomIOTest.java

@Test
public void testRewritePOMs() throws Exception {
    URL resource = PomIOTest.class.getResource(filename);
    assertNotNull(resource);//from  w  w  w . j a  va 2s .  c  o  m
    File pom = new File(resource.getFile());
    assertTrue(pom.exists());

    File targetFile = folder.newFile("target.xml");
    FileUtils.copyFile(pom, targetFile);

    Model model = new Model();
    model.setGroupId("org.commonjava.maven.ext.versioning.test");
    model.setArtifactId("dospom");
    model.setVersion("1.0");
    model.setPackaging("pom");
    model.setModelVersion("4.0.0");

    Project p = new Project(targetFile, model);
    HashSet<Project> changed = new HashSet<>();
    changed.add(p);

    pomIO.rewritePOMs(changed);

    assertTrue(FileUtils.contentEqualsIgnoreEOL(pom, targetFile, "UTF-8"));
    assertTrue(FileUtils.contentEquals(targetFile, pom));
}

From source file:org.commonjava.maven.ext.manip.impl.JSONManipulatorTest.java

@Test
public void updateURL() throws ManipulationException, IOException {
    String modifyPath = "$.repository.url";

    File target = tf.newFile();//from  ww  w . j a  va  2s.  co  m
    FileUtils.copyFile(pluginFile, target);
    Project project = new Project(null, target, null);

    jsonManipulator.internalApplyChanges(project, new JSONState.JSONOperation(target.getName(), modifyPath,
            "https://maven.repository.redhat.com/ga/"));
    assertTrue(FileUtils.readFileToString(target).contains("https://maven.repository.redhat.com/ga/"));
    assertFalse(FileUtils.contentEquals(pluginFile, target));
}

From source file:org.commonjava.maven.ext.manip.io.PomIOTest.java

@Test
public void testRewritePOMs() throws Exception {
    URL resource = PomIOTest.class.getResource(filename);
    assertNotNull(resource);/*from w w  w.j  a  v  a  2 s . co  m*/
    File pom = new File(resource.getFile());
    assertTrue(pom.exists());

    File targetFile = folder.newFile("target.xml");
    FileUtils.copyFile(pom, targetFile);

    Model model = new Model();
    model.setGroupId("org.commonjava.maven.ext.versioning.test");
    model.setArtifactId("dospom");
    model.setVersion("1.0");
    model.setPackaging("pom");
    model.setModelVersion("4.0.0");

    Project p = new Project(targetFile, model);
    HashSet<Project> changed = new HashSet<>();
    changed.add(p);

    pomIO.rewritePOMs(new GAV(), changed);

    assertTrue(FileUtils.contentEqualsIgnoreEOL(pom, targetFile, "UTF-8"));
    assertTrue(FileUtils.contentEquals(targetFile, pom));
}

From source file:org.corehunter.tests.data.simple.SimpleBiAllelicGenotypeDataTest.java

@Test
public void toCsvFileWithAllIds() throws IOException {
    expectedHeaders = HEADERS_UNIQUE_NAMES;
    expectedMarkerNames = MARKER_NAMES;//www .  j a va 2 s. co m

    SimpleBiAllelicGenotypeData genotypicData = new SimpleBiAllelicGenotypeData(expectedHeaders,
            expectedMarkerNames, ALLELE_SCORES_BIALLELIC);

    Set<Integer> ids = genotypicData.getIDs();

    Path dirPath = Paths.get(TEST_OUTPUT);

    Files.createDirectories(dirPath);

    dirPath = Files.createTempDirectory(dirPath, "GenoBiallelic-AllIds");

    // create solution
    SubsetSolution solution = new SubsetSolution(ids);
    for (int sel : SELECTION) {
        solution.select(sel);
    }

    Path path;

    // write allele score format with integer ids
    dataName = "bi-with-ids.csv";

    path = Paths.get(dirPath.toString(), dataName);

    System.out.println(" |- Write biallelic genotypes file (with solution) " + dataName);

    genotypicData.writeData(path, FileType.CSV, solution, true, true, true);

    assertTrue("Output file is not correct!",
            FileUtils.contentEquals(
                    new File(SimpleDistanceMatrixDataTest.class
                            .getResource("/biallelic_genotypes/out/all-bi-with-ids.csv").getPath()),
                    path.toFile()));

    // write allele score format without integer ids
    dataName = "bi-no-ids.csv";

    path = Paths.get(dirPath.toString(), dataName);

    System.out.println(" |- Write biallelic genotypes file (with solution) " + dataName);

    genotypicData.writeData(path, FileType.CSV, solution, true, true, false);

    assertTrue("Output file is not correct!",
            FileUtils.contentEquals(
                    new File(SimpleDistanceMatrixDataTest.class
                            .getResource("/biallelic_genotypes/out/all-bi-no-ids.csv").getPath()),
                    path.toFile()));

}

From source file:org.corehunter.tests.data.simple.SimpleBiAllelicGenotypeDataTest.java

@Test
public void toCsvFileWithSelectedIds() throws IOException {
    expectedHeaders = HEADERS_UNIQUE_NAMES;
    expectedMarkerNames = MARKER_NAMES;//  w w  w  . j  av  a2 s  .c  o  m

    SimpleBiAllelicGenotypeData genotypicData = new SimpleBiAllelicGenotypeData(expectedHeaders,
            expectedMarkerNames, ALLELE_SCORES_BIALLELIC);

    Set<Integer> ids = genotypicData.getIDs();

    Path dirPath = Paths.get(TEST_OUTPUT);

    Files.createDirectories(dirPath);

    dirPath = Files.createTempDirectory(dirPath, "GenoBiallelic-SelectedIds");

    // create solution
    SubsetSolution solution = new SubsetSolution(ids);
    for (int sel : SELECTION) {
        solution.select(sel);
    }

    Path path;

    // write allele score format with integer ids
    dataName = "bi-with-ids.csv";

    path = Paths.get(dirPath.toString(), dataName);

    System.out.println(" |- Write biallelic genotypes file (with solution) " + dataName);

    genotypicData.writeData(path, FileType.CSV, solution, true, false, true);

    assertTrue("Output file is not correct!",
            FileUtils.contentEquals(
                    new File(SimpleDistanceMatrixDataTest.class
                            .getResource("/biallelic_genotypes/out/sel-bi-with-ids.csv").getPath()),
                    path.toFile()));

    // write allele score format without integer ids
    dataName = "bi-no-ids.csv";

    path = Paths.get(dirPath.toString(), dataName);

    System.out.println(" |- Write biallelic genotypes file (with solution) " + dataName);

    genotypicData.writeData(path, FileType.CSV, solution, true, false, false);

    assertTrue("Output file is not correct!",
            FileUtils.contentEquals(
                    new File(SimpleDistanceMatrixDataTest.class
                            .getResource("/biallelic_genotypes/out/sel-bi-no-ids.csv").getPath()),
                    path.toFile()));

}

From source file:org.corehunter.tests.data.simple.SimpleBiAllelicGenotypeDataTest.java

@Test
public void toCsvFileWithUnselectedIds() throws IOException {
    expectedHeaders = HEADERS_UNIQUE_NAMES;
    expectedMarkerNames = MARKER_NAMES;//from  w  ww  . j a  v  a 2s .  co m

    SimpleBiAllelicGenotypeData genotypicData = new SimpleBiAllelicGenotypeData(expectedHeaders,
            expectedMarkerNames, ALLELE_SCORES_BIALLELIC);

    Set<Integer> ids = genotypicData.getIDs();

    Path dirPath = Paths.get(TEST_OUTPUT);

    Files.createDirectories(dirPath);

    dirPath = Files.createTempDirectory(dirPath, "GenoBiallelic-UnselectedIds");

    // create solution
    SubsetSolution solution = new SubsetSolution(ids);
    for (int sel : SELECTION) {
        solution.select(sel);
    }

    Path path;

    // write allele score format with integer ids
    dataName = "bi-with-ids.csv";

    path = Paths.get(dirPath.toString(), dataName);

    System.out.println(" |- Write biallelic genotypes file (with solution) " + dataName);

    genotypicData.writeData(path, FileType.CSV, solution, false, true, true);

    assertTrue("Output file is not correct!",
            FileUtils.contentEquals(
                    new File(SimpleDistanceMatrixDataTest.class
                            .getResource("/biallelic_genotypes/out/unsel-bi-with-ids.csv").getPath()),
                    path.toFile()));

    // write allele score format without integer ids
    dataName = "bi-no-ids.csv";

    path = Paths.get(dirPath.toString(), dataName);

    System.out.println(" |- Write biallelic genotypes file (with solution) " + dataName);

    genotypicData.writeData(path, FileType.CSV, solution, false, true, false);

    assertTrue("Output file is not correct!",
            FileUtils.contentEquals(
                    new File(SimpleDistanceMatrixDataTest.class
                            .getResource("/biallelic_genotypes/out/unsel-bi-no-ids.csv").getPath()),
                    path.toFile()));

}

From source file:org.corehunter.tests.data.simple.SimpleDefaultGenotypeDataTest.java

@Test
public void homozygousToCsvFileWithAllIds() throws IOException {
    expectedHeaders = HEADERS_UNIQUE_NAMES;
    expectedMarkerNames = MARKER_NAMES_DEFAULT;
    expectedAlleleNames = ALLELE_NAMES_HOMOZYGOUS;

    SimpleDefaultGenotypeData genotypicData = new SimpleDefaultGenotypeData(NAME, HEADERS_UNIQUE_NAMES,
            MARKER_NAMES_DEFAULT, ALLELE_OBS_HOMOZYGOUS);

    Set<Integer> ids = genotypicData.getIDs();

    Path dirPath = Paths.get(TEST_OUTPUT);

    Files.createDirectories(dirPath);

    dirPath = Files.createTempDirectory(dirPath, "GenoHomozygous-AllIds");

    // create solution
    SubsetSolution solution = new SubsetSolution(ids);
    for (int sel : SELECTION) {
        solution.select(sel);/*from w w  w.  j a  v  a  2  s .c  o  m*/
    }

    Path path;

    // write with integer ids
    dataName = "with-ids.csv";

    path = Paths.get(dirPath.toString(), dataName);

    System.out.println(" |- Write default genotypes file (homozygous, with solution) " + dataName);

    genotypicData.writeData(path, FileType.CSV, solution, true, true, true);

    assertTrue("Output is not correct!",
            FileUtils.contentEquals(
                    new File(SimpleDistanceMatrixDataTest.class
                            .getResource("/homozygous_genotypes/out/all-with-ids.csv").getPath()),
                    path.toFile()));

    // write without integer ids
    dataName = "no-ids.csv";

    path = Paths.get(dirPath.toString(), dataName);

    System.out.println(" |- Write default genotypes file (homozygous, with solution) " + dataName);

    genotypicData.writeData(path, FileType.CSV, solution, true, true, false);

    assertTrue("Output is not correct!",
            FileUtils.contentEquals(
                    new File(SimpleDistanceMatrixDataTest.class
                            .getResource("/homozygous_genotypes/out/all-no-ids.csv").getPath()),
                    path.toFile()));

}

From source file:org.corehunter.tests.data.simple.SimpleDefaultGenotypeDataTest.java

@Test
public void homozygousToCsvFileWithSelectedIds() throws IOException {
    expectedHeaders = HEADERS_UNIQUE_NAMES;
    expectedMarkerNames = MARKER_NAMES_DEFAULT;
    expectedAlleleNames = ALLELE_NAMES_HOMOZYGOUS;

    SimpleDefaultGenotypeData genotypicData = new SimpleDefaultGenotypeData(NAME, HEADERS_UNIQUE_NAMES,
            MARKER_NAMES_DEFAULT, ALLELE_OBS_HOMOZYGOUS);

    Set<Integer> ids = genotypicData.getIDs();

    Path dirPath = Paths.get(TEST_OUTPUT);

    Files.createDirectories(dirPath);

    dirPath = Files.createTempDirectory(dirPath, "GenoHomozygous-SelectedIds");

    // create solution
    SubsetSolution solution = new SubsetSolution(ids);
    for (int sel : SELECTION) {
        solution.select(sel);/*w  w  w  . ja  va 2s.com*/
    }

    Path path;

    // write with integer ids
    dataName = "with-ids.csv";

    path = Paths.get(dirPath.toString(), dataName);

    System.out.println(" |- Write default genotypes file (homozygous, with solution) " + dataName);

    genotypicData.writeData(path, FileType.CSV, solution, true, false, true);

    assertTrue("Output is not correct!",
            FileUtils.contentEquals(
                    new File(SimpleDistanceMatrixDataTest.class
                            .getResource("/homozygous_genotypes/out/sel-with-ids.csv").getPath()),
                    path.toFile()));

    // write without integer ids
    dataName = "no-ids.csv";

    path = Paths.get(dirPath.toString(), dataName);

    System.out.println(" |- Write default genotypes file (homozygous, with solution) " + dataName);

    genotypicData.writeData(path, FileType.CSV, solution, true, false, false);

    assertTrue("Output is not correct!",
            FileUtils.contentEquals(
                    new File(SimpleDistanceMatrixDataTest.class
                            .getResource("/homozygous_genotypes/out/sel-no-ids.csv").getPath()),
                    path.toFile()));

}