List of usage examples for org.apache.commons.io FileUtils contentEquals
public static boolean contentEquals(File file1, File file2) throws IOException
From source file:org.mxupdate.test.test.update.program.JPOProgramCI_3ExportTest.java
/** * Positive test that mxu and jpo file are generated. * * @param _description description (not used) * @param _origJPO original JPO file * @param _testJPO test JPO file//from ww w .j a v a 2 s . c o m * @param _testMXU test MXU file * @param _progData JPO program with defined properties * @throws Exception if test failed */ @Test(description = "positive test that mxu and jpo file are generated", dataProvider = "dataNotEmpty") public void positiveTestMxuAndJpoFile(final String _description, final File _origJPO, final File _testJPO, final File _testMXU, final JPOProgramData _progData) throws Exception { final ParameterCache_mxJPO paramCache = new ParameterCache_mxJPO(this.getContext(), false); // create JPO this.mql().cmd("escape add prog ").arg(_progData.getName()).cmd(" java").exec(this.getContext()); // update values _progData.createDependings(); final WrapperCIInstance<ProgramCI_mxJPO> wrapper = new WrapperCIInstance<>( new ProgramCI_mxJPO(_progData.getName())); wrapper.parseUpdate(_progData); wrapper.store((File) null, paramCache); // insert again to ensure that the code is defined... this.mql().cmd("escape mod prog ").arg(_progData.getName()).cmd(" code ").arg( JPOUtil_mxJPO.convertJavaToJPOCode(true, _progData.getName(), FileUtils.readFileToString(_origJPO))) .exec(this.getContext()); new ExportAdminProgramJPO_mxJPO().export(paramCache, paramCache.getMapping().getTypeDef(CI.PRG_JPO.updateType), _progData.getName(), new File(this.getTargetDir())); Assert.assertTrue(FileUtils.contentEquals(_origJPO, _testJPO), "check JPO content equal"); Assert.assertTrue(_testMXU.exists(), "MXU file exists"); _progData.setValue("file", _progData.getName().replaceAll("\\.", "/") + "_mxJPO.java") .checkExport(new ExportParser(CI.PRG_JPO, FileUtils.readFileToString(_testMXU), "")); }
From source file:org.omegat.core.team2.RebaseAndCommit.java
public static void rebaseAndCommit(Prepared prep, RemoteRepositoryProvider provider, File projectDir, String path, IRebase rebaser) throws Exception { if (!provider.isUnderMapping(path)) { throw new RuntimeException("Path is not under mapping: " + path); }/*from w w w. j a v a 2s. co m*/ Log.logDebug(LOGGER, "Rebase and commit '" + path + "'"); final String currentBaseVersion; String savedVersion = provider.getTeamSettings().get(VERSION_PREFIX + path); if (savedVersion != null) { currentBaseVersion = savedVersion; } else { // version wasn't stored - assume latest. TODO Probably need to ask ? provider.switchToVersion(path, null); currentBaseVersion = provider.getVersion(path); } final File localFile = new File(projectDir, path); final boolean fileChangedLocally; { File baseRepoFile = null; if (prep != null && prep.versionBase.equals(currentBaseVersion)) { baseRepoFile = prep.fileBase; } if (baseRepoFile == null) { baseRepoFile = provider.switchToVersion(path, currentBaseVersion); } if (!localFile.exists()) { // there is no local file - just use remote Log.logDebug(LOGGER, "local file '" + path + "' doesn't exist"); fileChangedLocally = false; } else if (FileUtils.contentEquals(baseRepoFile, localFile)) { // versioned file was not changed - no need to commit Log.logDebug(LOGGER, "local file '" + path + "' wasn't changed"); fileChangedLocally = false; } else { Log.logDebug(LOGGER, "local file '" + path + "' was changed"); fileChangedLocally = true; rebaser.parseBaseFile(baseRepoFile); } // baseRepoFile is not valid anymore because we will switch to other version } File headRepoFile = null; String headVersion = null; if (prep != null) { headVersion = prep.versionHead; headRepoFile = prep.fileHead; } if (headVersion == null) { headRepoFile = provider.switchToVersion(path, null); headVersion = provider.getVersion(path); } final boolean fileChangedRemotely; { if (!localFile.exists()) { // there is no local file - just use remote if (headRepoFile.exists()) { fileChangedRemotely = true; rebaser.parseHeadFile(headRepoFile); } else { // there is no remote file also fileChangedRemotely = false; } } else if (StringUtils.equals(currentBaseVersion, headVersion)) { Log.logDebug(LOGGER, "remote file '" + path + "' wasn't changed"); fileChangedRemotely = false; } else { // base and head versions are differ - somebody else committed changes Log.logDebug(LOGGER, "remote file '" + path + "' was changed"); fileChangedRemotely = true; rebaser.parseHeadFile(headRepoFile); } } final File tempOut = new File(projectDir, path + "#based_on_" + headVersion); if (tempOut.exists() && !tempOut.delete()) { throw new Exception("Unable to delete previous temp file"); } boolean needBackup = false; if (fileChangedLocally && fileChangedRemotely) { // rebase need only in case file was changed locally AND remotely Log.logDebug(LOGGER, "rebase and save '" + path + "'"); needBackup = true; rebaser.rebaseAndSave(tempOut); } else if (fileChangedLocally && !fileChangedRemotely) { // only local changes - just use local file Log.logDebug(LOGGER, "only local changes - just use local file '" + path + "'"); } else if (!fileChangedLocally && fileChangedRemotely) { // only remote changes - get remote Log.logDebug(LOGGER, "only remote changes - get remote '" + path + "'"); needBackup = true; if (headRepoFile.exists()) {// otherwise file was removed remotelly FileUtils.copyFile(headRepoFile, tempOut); } } else { Log.logDebug(LOGGER, "there are no changes '" + path + "'"); // there are no changes } if (needBackup) { // new file was saved, need to update version // code below tries to update file "in transaction" with update version if (localFile.exists()) { final File bakTemp = new File(projectDir, path + "#oldbased_on_" + currentBaseVersion); bakTemp.delete(); FileUtils.moveFile(localFile, bakTemp); } provider.getTeamSettings().set(VERSION_PREFIX + path, headVersion); if (tempOut.exists()) { localFile.delete(); FileUtils.moveFile(tempOut, localFile); } } if (prep != null) { prep.needToCommit = fileChangedLocally; prep.commitComment = rebaser.getCommentForCommit(); if (fileChangedLocally) { prep.charset = rebaser.getFileCharset(localFile); } // no need to commit yet - it will make other thread after return; } else if (fileChangedLocally) { // new file already saved - need to commit String comment = rebaser.getCommentForCommit(); provider.copyFilesFromProjectToRepo(path, rebaser.getFileCharset(localFile)); String newVersion = provider.commitFileAfterVersion(path, comment, headVersion, null); if (newVersion != null) { // file was committed good provider.getTeamSettings().set(VERSION_PREFIX + path, newVersion); } } }
From source file:org.omegat.filters.TestFilterBase.java
protected void translateText(IFilter filter, String resource, Map<String, String> config) throws Exception { translate(filter, resource, config); boolean result = FileUtils.contentEquals(new File(this.getClass().getResource(resource).getFile()), outFile);//from w w w. j a v a 2 s. c o m if (!result) { fails("Translated text, which should be as same as source one, is not equals with source."); } }
From source file:org.omegat.filters.TestFilterBaseNg.java
protected void translateText(IFilter filter, String resource, Map<String, String> config) throws Exception { translate(filter, resource, config); File source = FileUtils.toFile(this.getClass().getResource(resource)); if (!FileUtils.contentEquals(source, outFile)) { String sourceText = FileUtils.readFileToString(source); String targetText = FileUtils.readFileToString(outFile); assertEquals(targetText, sourceText); }/*from w w w . j av a 2 s.c o m*/ }
From source file:org.onesec.raven.ivr.vmail.impl.VMailBoxNodeTest.java
@Test public void addMessageTest() throws Exception { Date date = new Date(); vbox.addMessage(new NewVMailMessageImpl("123", "222", date, new FileDataSource(testFile))); String filename = new SimpleDateFormat(VMailBoxNode.DATE_PATTERN).format(date) + "-" + "222.wav"; File messFile = new File(manager.getVMailBoxDir(vbox).getNewMessagesDir() + File.separator + filename); assertTrue(messFile.exists());//from w w w. j a va2 s . co m assertTrue(FileUtils.contentEquals(testFile, messFile)); }
From source file:org.onesec.raven.ivr.vmail.impl.VMailBoxNodeTest.java
@Test public void saveNewMessageTest() throws Exception { Date date = new Date(); vbox.addMessage(new NewVMailMessageImpl("123", "222", date, new FileDataSource(testFile))); vbox.getNewMessages().get(0).save(); String filename = new SimpleDateFormat(VMailBoxNode.DATE_PATTERN).format(date) + "-" + "222.wav"; File savedMessFile = new File( manager.getVMailBoxDir(vbox).getSavedMessagesDir() + File.separator + filename); assertTrue(savedMessFile.exists());//ww w. ja va 2 s . c om assertTrue(FileUtils.contentEquals(testFile, savedMessFile)); assertEquals(0, vbox.getNewMessagesCount()); assertEquals(1, vbox.getSavedMessagesCount()); }
From source file:org.openmrs.module.radiology.report.template.MrrtReportTemplateServiceComponentTest.java
/** * @verifies create mrrt report template in the database and on the file system * @see MrrtReportTemplateService#importMrrtReportTemplate(String) */// ww w . j a v a 2s . c om @Test public void importMrrtReportTemplate_shouldCreateMrrtReportTemplateInTheDatabaseAndOnTheFileSystem() throws Exception { setUpTemporaryFolder(); String sourcePath = "mrrttemplates/ihe/connectathon/2015/CTChestAbdomen.html"; String template = getFileContent(sourcePath); MrrtReportTemplate saved = mrrtReportTemplateService.importMrrtReportTemplate(template); assertNotNull(saved); assertThat(saved.getDcTermsIdentifier(), is(TEMPLATE_IDENTIFIER)); File templateHome = radiologyProperties.getReportTemplateHome(); File templatePath = new File(saved.getPath()); assertThat(templatePath.getParentFile().getName(), is(templateHome.getName())); assertTrue(FileUtils.contentEquals(getFile(sourcePath), templatePath.getAbsoluteFile())); }
From source file:org.openmrs.obs.AbstractHandlerTest.java
@Test public void getOutputFileToWrite_shouldNeverOverwritePreviousFiles() throws IOException { String content1 = "A"; String content2 = "B"; File previousFile = null;/*w w w .j ava2 s . c o m*/ File currentFile = null; for (int i = 0; i <= 101; i++) { String currentData = (i % 2 == 0) ? content1 : content2; ComplexData complexData = new ComplexData(FILENAME, currentData); Obs obs = new Obs(); obs.setComplexData(complexData); currentFile = handler.getOutputFileToWrite(obs); try (BufferedWriter fout = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(currentFile), StandardCharsets.UTF_8))) { fout.write(currentData); } try (BufferedReader fin = new BufferedReader( new InputStreamReader(new FileInputStream(currentFile), StandardCharsets.UTF_8))) { String readData = fin.readLine(); assertEquals(readData, currentData); } if (i > 0) { assertFalse(FileUtils.contentEquals(previousFile, currentFile)); } previousFile = currentFile; } }
From source file:org.opennms.netmgt.rrd.model.RRDv1IT.java
/** * Test merge./*from w w w . jav a 2 s . com*/ * * @throws Exception the exception */ @Test public void testMerge() throws Exception { File sourceFile = new File("src/test/resources/rrd-temp-multids-jrb.xml"); File targetFile = new File("target/multimetric.xml"); RRDv1 multimetric = JaxbUtils.unmarshal(RRDv1.class, sourceFile); Assert.assertNotNull(multimetric); Assert.assertEquals("tempA", multimetric.getDataSource(0).getName()); Assert.assertEquals("tempB", multimetric.getDataSource(1).getName()); multimetric.getRras().stream().flatMap(rra -> rra.getRows().stream()).forEach(row -> { List<Double> values = new ArrayList<Double>(); row.getValues().forEach(d -> values.add(Double.NaN)); row.setValues(values); }); List<RRDv1> singleMetricArray = new ArrayList<RRDv1>(); RRDv1 tempA = JaxbUtils.unmarshal(RRDv1.class, new File("src/test/resources/rrd-tempA-jrb.xml")); Assert.assertNotNull(tempA); Assert.assertEquals("tempA", tempA.getDataSource(0).getName()); singleMetricArray.add(tempA); RRDv1 tempB = JaxbUtils.unmarshal(RRDv1.class, new File("src/test/resources/rrd-tempB-jrb.xml")); Assert.assertNotNull(tempB); Assert.assertEquals("tempB", tempB.getDataSource(0).getName()); singleMetricArray.add(tempB); multimetric.merge(singleMetricArray); JaxbUtils.marshal(multimetric, new FileWriter(targetFile)); Assert.assertTrue(FileUtils.contentEquals(sourceFile, targetFile)); targetFile.delete(); }
From source file:org.opennms.netmgt.rrd.model.RRDv3IT.java
/** * Test merge.//w w w.j a v a2s . c om * * @throws Exception the exception */ @Test public void testMerge() throws Exception { File sourceFile = new File("src/test/resources/rrd-temp-multids-rrd.xml"); File targetFile = new File("target/multimetric.xml"); RRDv3 multimetric = JaxbUtils.unmarshal(RRDv3.class, sourceFile); Assert.assertNotNull(multimetric); Assert.assertEquals("tempA", multimetric.getDataSource(0).getName()); Assert.assertEquals("tempB", multimetric.getDataSource(1).getName()); multimetric.reset(); List<RRDv3> singleMetricArray = new ArrayList<RRDv3>(); RRDv3 tempA = JaxbUtils.unmarshal(RRDv3.class, new File("src/test/resources/rrd-tempA-rrd.xml")); Assert.assertNotNull(tempA); Assert.assertEquals("tempA", tempA.getDataSource(0).getName()); singleMetricArray.add(tempA); RRDv3 tempB = JaxbUtils.unmarshal(RRDv3.class, new File("src/test/resources/rrd-tempB-rrd.xml")); Assert.assertNotNull(tempB); Assert.assertEquals("tempB", tempB.getDataSource(0).getName()); singleMetricArray.add(tempB); multimetric.merge(singleMetricArray); JaxbUtils.marshal(multimetric, new FileWriter(targetFile)); Assert.assertTrue(FileUtils.contentEquals(sourceFile, targetFile)); targetFile.delete(); }