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.activiti.crystalball.simulator.OptimizeBottleneckTest.java

@Test
public void testUser2OverLoadedWithHelp45() throws Exception {
    System.setProperty("liveDB", LIVE_DB);
    System.setProperty("_SIM_DB_PATH",
            tempDir + "/simulationRunDB-SimulateBottleNeck-Overload45-" + Thread.currentThread().getId());

    FileUtils.copyFile(new File(LIVE_DB + ".h2.db"), new File(tempDir
            + "/simulationRunDB-SimulateBottleNeck-Overload45-" + Thread.currentThread().getId() + ".h2.db"));

    ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(
            "/org/activiti/crystalball/simulator/SimEngine-simulateBottleneck-h2-context.xml");
    ProcessEngine processEngine = (ProcessEngine) appContext.getBean("simProcessEngine");

    // increase frequency of process starts to 45 mins (default is 1 hour)
    StartProcessEventHandler startProcessEventHandler = appContext.getBean(StartProcessEventHandler.class);
    startProcessEventHandler.setPeriod(2700000);
    // add new user5 to the Group2 to help user2 and to Group4 to help user4
    IdentityService identityService = (IdentityService) appContext.getBean("simIdentityService");
    identityService.saveUser(identityService.newUser("user5"));
    identityService.createMembership("user5", "Group2");
    identityService.createMembership("user5", "Group4");

    runSimulation(appContext, tempDir + "/OptimizeBottleneckTest45.png",
            tempDir + "/OptimizeBottleneckTest45-dueDate.png");

    processEngine.close();/*from w w  w.  j ava2  s  .com*/
    appContext.close();

    File expected = new File(System.getProperty("baseDir", ".")
            + "/src/test/resources/org/activiti/crystalball/simulator/OptimizeBottleneckTest45.png");
    File generated = new File(tempDir + "/OptimizeBottleneckTest45.png");
    assertTrue(FileUtils.contentEquals(expected, generated));

    expected = new File(System.getProperty("baseDir", ".")
            + "/src/test/resources/org/activiti/crystalball/simulator/OptimizeBottleneckTest45-dueDate.png");
    generated = new File(tempDir + "/OptimizeBottleneckTest45-dueDate.png");
    assertTrue(FileUtils.contentEquals(expected, generated));

    // delete database file
    File f = new File(System.getProperty("_SIM_DB_PATH") + ".h2.db");
    if (!f.delete())
        System.err.println("unable to delete file");
}

From source file:org.activiti.crystalball.simulator.SimulateBottleneckTest.java

@Test
public void testOK() throws Exception {
    System.setProperty("liveDB", LIVE_DB);
    System.setProperty("_SIM_DB_PATH",
            tempDir + "/simulationRunDB-SimulateBottleNeck-OK-" + Thread.currentThread().getId());

    FileUtils.copyFile(new File(LIVE_DB + ".h2.db"), new File(
            tempDir + "/simulationRunDB-SimulateBottleNeck-OK-" + Thread.currentThread().getId() + ".h2.db"));

    ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(
            "/org/activiti/crystalball/simulator/SimEngine-simulateBottleneck-h2-context.xml");
    ProcessEngine processEngine = (ProcessEngine) appContext.getBean("simProcessEngine");

    runSimulation(appContext, tempDir + "/SimulateBottleneckTest-1.png");

    processEngine.close();//from   ww w  .jav a2s .  co m
    appContext.close();

    File expected = new File(System.getProperty("baseDir", ".")
            + "/src/test/resources/org/activiti/crystalball/simulator/simulateBottleneckTest-1.png");
    File generated = new File(tempDir + "/SimulateBottleneckTest-1.png");
    assertTrue(FileUtils.contentEquals(expected, generated));
    // delete database file
    File f = new File(System.getProperty("_SIM_DB_PATH") + ".h2.db");
    if (!f.delete())
        System.err.println("unable to delete file");
}

From source file:org.activiti.crystalball.simulator.SimulateBottleneckTest.java

/**
 * results differs - that's why this test is ignored - possible bug. 
 * @throws Exception /* w  w w . j  a  va  2 s . c o  m*/
 */
@Test
public void testUser2OverLoaded() throws Exception {
    System.setProperty("liveDB", LIVE_DB);
    System.setProperty("_SIM_DB_PATH",
            tempDir + "/simulationRunDB-SimulateBottleNeck-Overload-" + Thread.currentThread().getId());

    FileUtils.copyFile(new File(LIVE_DB + ".h2.db"), new File(tempDir
            + "/simulationRunDB-SimulateBottleNeck-Overload-" + Thread.currentThread().getId() + ".h2.db"));

    ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(
            "/org/activiti/crystalball/simulator/SimEngine-simulateBottleneck-h2-context.xml");
    ProcessEngine processEngine = (ProcessEngine) appContext.getBean("simProcessEngine");

    // increase frequency of process starts to 45 mins (default is 1 hour)
    StartProcessEventHandler startProcessEventHandler = appContext.getBean(StartProcessEventHandler.class);
    startProcessEventHandler.setPeriod(2700000);

    runSimulation(appContext, tempDir + "/SimulateBottleneckTest-2.png");

    processEngine.close();
    appContext.close();

    File expected = new File(System.getProperty("baseDir", ".")
            + "/src/test/resources/org/activiti/crystalball/simulator/simulateBottleneckTest-2.png");
    File generated = new File(tempDir + "/SimulateBottleneckTest-2.png");
    assertTrue(FileUtils.contentEquals(expected, generated));
    // delete database file

    File f = new File(System.getProperty("_SIM_DB_PATH") + ".h2.db");
    if (!f.delete())
        System.err.println("unable to delete file");

}

From source file:org.activiti.crystalball.simulator.SimulatorProcessMonitorTestWithoutProcess.java

@Test
public void testProcessRun() throws Throwable {
    ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(
            "/org/activiti/crystalball/simulator/SimEngine-h2-context.xml");
    SimulationRun simRun = appContext.getBean(SimulationRun.class);
    RepositoryService repositoryService = (RepositoryService) appContext.getBean("simRepositoryService");

    List<ResultEntity> resultEventList = simRun.execute(new Date(), null);

    Collection<List<ResultEntity>> unfinishedTaskProcesses = SimulationResultsPostProcessor
            .groupProcessDefinitionKey(//from  w  w w.  j a v  a2s. c  o m
                    SimulationResultsPostProcessor.getEventType("unfinished_task", resultEventList));

    for (List<ResultEntity> eventList : unfinishedTaskProcesses) {
        String processDefinitionId = (String) eventList.get(0).getVariable("processDefinitionKey");
        List<String> highlightTasks = SimulationResultsPostProcessor.getTaskDefinitionKeys(eventList);
        Map<String, String> nodeDescription = SimulationResultsPostProcessor.getNodeDescriptions(eventList);

        File dir = new File(tempDir + "/" + eventList.get(0).getType());
        dir.mkdir();
        String reportFileName = tempDir + "/" + eventList.get(0).getType() + "/" + processDefinitionId + ".png";
        reportGraph(reportFileName, processDefinitionId, highlightTasks, nodeDescription, repositoryService);

    }

    appContext.close();

    File expected = new File(System.getProperty("baseDir", ".")
            + "/src/test/resources/org/activiti/crystalball/simulator/SimulatorProcessMonitor-unfinishedTasks-expected.png");
    File generated = new File(
            System.getProperty("tempDir", "target") + "/unfinished_task/threetasksprocess.png");
    assertTrue(FileUtils.contentEquals(expected, generated));

}

From source file:org.apache.apex.examples.recordReader.ApplicationTest.java

@Test
public void testApplication() throws IOException, Exception {
    try {// w  w w. j  a  va 2 s . co  m
        LocalMode lma = LocalMode.newInstance();
        Configuration conf = new Configuration(false);
        conf.addResource(this.getClass().getResourceAsStream("/META-INF/properties.xml"));
        conf.set("dt.application.RecordReaderExample.operator.fileOutput.prop.filePath", outputDir);
        File outputfile = FileUtils.getFile(outputDir, "output.txt_5.0");

        lma.prepareDAG(new Application(), conf);
        LocalMode.Controller lc = lma.getController();
        lc.runAsync();

        // wait for tuples to show up
        while (!outputfile.exists()) {
            Thread.sleep(1000);
        }

        lc.shutdown();
        Assert.assertTrue(FileUtils.contentEquals(
                FileUtils.getFile(
                        conf.get("dt.application.RecordReaderExample.operator.recordReader.prop.files")),
                outputfile));

    } catch (ConstraintViolationException e) {
        Assert.fail("constraint violations: " + e.getConstraintViolations());
    }
}

From source file:org.apache.archiva.converter.artifact.LegacyToDefaultConverter.java

private boolean copyArtifact(Artifact artifact, ArtifactRepository targetRepository,
        FileTransaction transaction) throws ArtifactConversionException {
    File sourceFile = artifact.getFile();

    if (sourceFile.getAbsolutePath().indexOf("/plugins/") > -1) //$NON-NLS-1$
    {/*from w ww.  j a  v a2  s . c o  m*/
        artifact.setArtifactHandler(artifactHandlerManager.getArtifactHandler("maven-plugin")); //$NON-NLS-1$
    }

    File targetFile = new File(targetRepository.getBasedir(), targetRepository.pathOf(artifact));

    boolean result = true;
    try {
        boolean matching = false;
        if (!force && targetFile.exists()) {
            matching = FileUtils.contentEquals(sourceFile, targetFile);
            if (!matching) {
                addWarning(artifact, Messages.getString("failure.target.already.exists")); //$NON-NLS-1$
                result = false;
            }
        }
        if (result) {
            if (force || !matching) {
                if (testChecksums(artifact, sourceFile)) {
                    transaction.copyFile(sourceFile, targetFile, digesters);
                } else {
                    result = false;
                }
            }
        }
    } catch (IOException e) {
        throw new ArtifactConversionException(Messages.getString("error.copying.artifact"), e); //$NON-NLS-1$
    }
    return result;
}

From source file:org.apache.archiva.converter.artifact.LegacyToDefaultConverterTest.java

@Test
public void testV4PomConvert() throws Exception {
    // test that it is copied as is

    Artifact artifact = createArtifact("test", "v4artifact", "1.0.0");
    ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata(artifact);
    File artifactMetadataFile = new File(targetRepository.getBasedir(),
            targetRepository.pathOfRemoteRepositoryMetadata(artifactMetadata));
    artifactMetadataFile.delete();/*  ww w . jav a  2 s  .  c o m*/

    ArtifactMetadata versionMetadata = new SnapshotArtifactRepositoryMetadata(artifact);
    File versionMetadataFile = new File(targetRepository.getBasedir(),
            targetRepository.pathOfRemoteRepositoryMetadata(versionMetadata));
    versionMetadataFile.delete();

    File artifactFile = new File(targetRepository.getBasedir(), targetRepository.pathOf(artifact));
    artifactFile.delete();

    artifactConverter.convert(artifact, targetRepository);
    checkSuccess(artifactConverter);

    assertTrue("Check artifact created", artifactFile.exists());
    assertTrue("Check artifact matches", FileUtils.contentEquals(artifactFile, artifact.getFile()));

    artifact = createPomArtifact(artifact);
    File pomFile = new File(targetRepository.getBasedir(), targetRepository.pathOf(artifact));
    File sourcePomFile = new File(sourceRepository.getBasedir(), sourceRepository.pathOf(artifact));
    assertTrue("Check POM created", pomFile.exists());

    compareFiles(sourcePomFile, pomFile);

    assertTrue("Check artifact metadata created", artifactMetadataFile.exists());

    File expectedMetadataFile = getTestFile("src/test/expected-files/v4-artifact-metadata.xml");

    compareFiles(expectedMetadataFile, artifactMetadataFile);

    assertTrue("Check snapshot metadata created", versionMetadataFile.exists());

    expectedMetadataFile = getTestFile("src/test/expected-files/v4-version-metadata.xml");

    compareFiles(expectedMetadataFile, versionMetadataFile);
}

From source file:org.apache.archiva.converter.artifact.LegacyToDefaultConverterTest.java

@Test
public void testV3PomConvert() throws Exception {
    // test that the pom is coverted

    Artifact artifact = createArtifact("test", "v3artifact", "1.0.0");
    ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata(artifact);
    File artifactMetadataFile = new File(targetRepository.getBasedir(),
            targetRepository.pathOfRemoteRepositoryMetadata(artifactMetadata));
    artifactMetadataFile.delete();// ww  w  . j a  v a 2 s  .c  om

    ArtifactMetadata versionMetadata = new SnapshotArtifactRepositoryMetadata(artifact);
    File versionMetadataFile = new File(targetRepository.getBasedir(),
            targetRepository.pathOfRemoteRepositoryMetadata(versionMetadata));
    versionMetadataFile.delete();

    artifactConverter.convert(artifact, targetRepository);
    checkSuccess(artifactConverter);

    File artifactFile = new File(targetRepository.getBasedir(), targetRepository.pathOf(artifact));
    assertTrue("Check artifact created", artifactFile.exists());
    assertTrue("Check artifact matches", FileUtils.contentEquals(artifactFile, artifact.getFile()));

    artifact = createPomArtifact(artifact);
    File pomFile = new File(targetRepository.getBasedir(), targetRepository.pathOf(artifact));
    File expectedPomFile = getTestFile("src/test/expected-files/converted-v3.pom");
    assertTrue("Check POM created", pomFile.exists());

    compareFiles(expectedPomFile, pomFile);

    assertTrue("Check artifact metadata created", artifactMetadataFile.exists());

    File expectedMetadataFile = getTestFile("src/test/expected-files/v3-artifact-metadata.xml");

    compareFiles(expectedMetadataFile, artifactMetadataFile);

    assertTrue("Check snapshot metadata created", versionMetadataFile.exists());

    expectedMetadataFile = getTestFile("src/test/expected-files/v3-version-metadata.xml");

    compareFiles(expectedMetadataFile, versionMetadataFile);
}

From source file:org.apache.archiva.converter.artifact.LegacyToDefaultConverterTest.java

@Test
public void testV3PomConvertWithRelocation() throws Exception {
    Artifact artifact = createArtifact("test", "relocated-v3artifact", "1.0.0");
    ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata(artifact);
    File artifactMetadataFile = new File(targetRepository.getBasedir(),
            targetRepository.pathOfRemoteRepositoryMetadata(artifactMetadata));
    artifactMetadataFile.delete();// www .  j a va2s  .c o  m

    ArtifactMetadata versionMetadata = new SnapshotArtifactRepositoryMetadata(artifact);
    File versionMetadataFile = new File(targetRepository.getBasedir(),
            targetRepository.pathOfRemoteRepositoryMetadata(versionMetadata));
    versionMetadataFile.delete();

    artifactConverter.convert(artifact, targetRepository);
    //checkSuccess();  --> commented until MNG-2100 is fixed

    File artifactFile = new File(targetRepository.getBasedir(), targetRepository.pathOf(artifact));
    assertTrue("Check if relocated artifact created", artifactFile.exists());
    assertTrue("Check if relocated artifact matches",
            FileUtils.contentEquals(artifactFile, artifact.getFile()));
    Artifact pomArtifact = createArtifact("relocated-test", "relocated-v3artifact", "1.0.0", "1.0.0", "pom");
    File pomFile = getTestFile("src/test/expected-files/" + targetRepository.pathOf(pomArtifact));
    File testFile = getTestFile("target/test-target-repository/" + targetRepository.pathOf(pomArtifact));
    compareFiles(pomFile, testFile);

    Artifact orig = createArtifact("test", "relocated-v3artifact", "1.0.0", "1.0.0", "pom");
    artifactFile = new File(targetRepository.getBasedir(), targetRepository.pathOf(orig));
    assertTrue("Check if relocation artifact pom is created", artifactFile.exists());
    testFile = getTestFile("src/test/expected-files/" + targetRepository.pathOf(orig));
    compareFiles(artifactFile, testFile);
}

From source file:org.apache.archiva.converter.artifact.LegacyToDefaultConverterTest.java

@Test
public void testV3PomWarningsOnConvert() throws Exception {
    // test that the pom is converted but that warnings are reported

    Artifact artifact = createArtifact("test", "v3-warnings-artifact", "1.0.0");
    ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata(artifact);
    File artifactMetadataFile = new File(targetRepository.getBasedir(),
            targetRepository.pathOfRemoteRepositoryMetadata(artifactMetadata));
    artifactMetadataFile.delete();/*from w ww  .ja v  a2s. c  o m*/

    ArtifactMetadata versionMetadata = new SnapshotArtifactRepositoryMetadata(artifact);
    File versionMetadataFile = new File(targetRepository.getBasedir(),
            targetRepository.pathOfRemoteRepositoryMetadata(versionMetadata));
    versionMetadataFile.delete();

    artifactConverter.convert(artifact, targetRepository);
    checkWarnings(artifactConverter, 2);

    File artifactFile = new File(targetRepository.getBasedir(), targetRepository.pathOf(artifact));
    assertTrue("Check artifact created", artifactFile.exists());
    assertTrue("Check artifact matches", FileUtils.contentEquals(artifactFile, artifact.getFile()));

    artifact = createPomArtifact(artifact);
    File pomFile = new File(targetRepository.getBasedir(), targetRepository.pathOf(artifact));
    File expectedPomFile = getTestFile("src/test/expected-files/converted-v3-warnings.pom");
    assertTrue("Check POM created", pomFile.exists());

    compareFiles(expectedPomFile, pomFile);

    // TODO: check 2 warnings (extend and versions) matched on i18n key
}