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.silverpeas.core.admin.domain.SQLDomainServiceIT.java
@SuppressWarnings("ConstantConditions") @Test/* w ww. ja va 2 s .c o m*/ public void testCreateDomain() throws Exception { Domain domain = new Domain(); domain.setName("TestCreation"); // create domain String domainId = service.createDomain(domain); // Performs checks on id returned assertThat("domainId returned is NULL", domainId, is(notNullValue())); assertThat("domainId returned = -1", domainId, is(not("-1"))); assertThat("domainId returned is empty", domainId, is(not(""))); // Performs checks on generated properties files File[] domainPropertyFiles = domainPropertyPath.listFiles(); assertThat(domainPropertyFiles, arrayWithSize(1)); assertThat("domain properties files has not been generated", domainPropertyFiles[0].getName(), is("domain3TestCrea.properties")); assertThat(FileUtils.contentEquals(domainPropertyFiles[0], expectedDomainPropertiesFile), is(true)); File[] autDomainPropertyFiles = autDomainPropertyPath.listFiles(); assertThat(autDomainPropertyFiles, arrayWithSize(1)); assertThat("domain authentication properties files has not been generated", autDomainPropertyFiles[0].getName(), is("autDomain3TestCrea.properties")); assertThat(FileUtils.contentEquals(autDomainPropertyFiles[0], expectedDomainAuthenticationPropertiesFile), is(true)); // Performs checks on generated tables testTablesExistence("3TestCrea", true); }
From source file:org.silverpeas.core.contribution.attachment.AttachmentServiceIntegrationTest.java
/** * Test of addContent method, of class AttachmentService. *//*from w w w . ja va2 s . c om*/ @Test public void testAddFileContent() throws URISyntaxException, IOException { File file = getDocumentNamed("/LibreOffice.odt"); String currentLang = "fr"; SimpleDocument document = instance.searchDocumentById(existingFrDoc, currentLang); ByteArrayOutputStream out = new ByteArrayOutputStream(); instance.getBinaryContent(out, existingFrDoc, currentLang); assertThat(out.toString(CharEncoding.UTF_8), is("Ceci est un test")); currentLang = "en"; document.setLanguage(currentLang); instance.updateAttachment(document, file, false, false); File tempFile = File.createTempFile("LibreOffice", ".odt"); instance.getBinaryContent(tempFile, existingFrDoc, currentLang); assertThat(FileUtils.contentEquals(file, tempFile), is(true)); currentLang = "fr"; out = new ByteArrayOutputStream(); instance.getBinaryContent(out, existingFrDoc, currentLang); assertThat(out.toString(CharEncoding.UTF_8), is("Ceci est un test")); }
From source file:org.silverpeas.core.contribution.attachment.AttachmentServiceIntegrationTest.java
/** * Test of addContent method, of class AttachmentService. *//*from www . j av a 2s .c o m*/ @Test public void testUpdateFileContent() throws URISyntaxException, IOException { File file = getDocumentNamed("/LibreOffice.odt"); String currentLang = "fr"; SimpleDocument document = instance.searchDocumentById(existingFrDoc, currentLang); instance.updateAttachment(document, file, false, false); File tempFile = File.createTempFile("LibreOffice", ".odt"); instance.getBinaryContent(tempFile, existingFrDoc, currentLang); assertThat(FileUtils.contentEquals(file, tempFile), is(true)); }
From source file:org.silverpeas.core.contribution.attachment.HistorisedAttachmentServiceIntegrationTest.java
/** * Test of addContent method, of class AttachmentService. *///from w w w.j a v a2s .c o m @Test public void testAddFileContent() throws URISyntaxException, IOException { File file = getDocumentNamed("LibreOffice.odt"); String currentLang = "fr"; SimpleDocument document = instance.searchDocumentById(existingFrDoc, currentLang); ByteArrayOutputStream out = new ByteArrayOutputStream(); instance.getBinaryContent(out, existingFrDoc, currentLang); assertThat(out.toString(CharEncoding.UTF_8), is("Ceci est un test")); currentLang = "en"; document.setLanguage(currentLang); instance.updateAttachment(document, file, false, false); File tempFile = File.createTempFile("LibreOffice", ".odt"); instance.getBinaryContent(tempFile, existingFrDoc, currentLang); assertThat(FileUtils.contentEquals(file, tempFile), is(true)); currentLang = "fr"; out = new ByteArrayOutputStream(); instance.getBinaryContent(out, existingFrDoc, currentLang); assertThat(out.toString(CharEncoding.UTF_8), is("Ceci est un test")); }
From source file:org.silverpeas.core.process.io.file.FileHandler.java
/** * Both of given files are handled//from ww w .j a va2s . co m * @see FileUtils */ protected boolean contentEquals(final FileBasePath basePath, final File file1, final File file2) throws Exception { verify(basePath, file1); verify(basePath, file2); return FileUtils.contentEquals(getExistingFile(basePath, file1), getExistingFile(basePath, file2)); }
From source file:org.silverpeas.core.process.io.file.FileHandler.java
/** * The first given file is not handled. It have to exist in an other path than the one that is * handled. The second given file is handled. Both files are handled * @see FileUtils//from w w w .j av a2 s . c o m */ protected boolean contentEquals(final File file1, final FileBasePath basePath, final File file2) throws Exception { verify(basePath, file2); return FileUtils.contentEquals(file1, getExistingFile(basePath, file2)); }
From source file:org.silverpeas.core.workflow.engine.model.ProcessModelManagerImplTest.java
/** * Test of saveProcessModel method, of class ProcessModelManagerImpl. *//*w ww . j a va2 s . co m*/ @Test public void testSaveProcessModel() throws Exception { System.out.println("saveProcessModel"); String processFileName = "DemandeCongesSimple.xml"; ProcessModel process = instance.loadProcessModel(processFileName); String resultFileName = "DemandeCongesSimpleSerial.xml"; instance.saveProcessModel(process, resultFileName); FileUtils.contentEquals(new File(instance.getProcessPath(processFileName)), new File(instance.getProcessPath(resultFileName))); }
From source file:org.sonar.cxx.sensors.other.CxxOtherXsltTest.java
@Test public void transformReport_shouldTransformReport() throws java.io.IOException, javax.xml.transform.TransformerException { System.out.print("Starting transformReport_shouldTransformReport"); String stylesheetFile = "externalrules-reports" + File.separator + "externalrules-xslt-stylesheet.xslt"; String inputFile = "externalrules-reports" + File.separator + "externalrules-xslt-input.xml"; String outputFile = "externalrules-reports" + File.separator + "externalrules-xslt-output.xml"; // when(language.getStringOption(CxxOtherSensor.REPORT_PATH_KEY)).thenReturn("externalrules-xslt-output.xml"); // when(language.getStringOption(language.getPluginProperty(CxxOtherSensor.OTHER_XSLT_KEY + "1" + CxxOtherSensor.STYLESHEET_KEY))).thenReturn(stylesheetFile); // when(language.getStringArrayOption(language.getPluginProperty(CxxOtherSensor.OTHER_XSLT_KEY + "1" + CxxOtherSensor.INPUT_KEY))).thenReturn(new String[] {inputFile}); // when(language.getStringArrayOption(language.getPluginProperty(CxxOtherSensor.OTHER_XSLT_KEY + "1" + CxxOtherSensor.OUTPUT_KEY))).thenReturn(new String[] {outputFile}); SensorContextTester context = SensorContextTester.create(fs.baseDir()); settings.setProperty(language.getPluginProperty(CxxOtherSensor.REPORT_PATH_KEY), "externalrules-xslt-output.xml"); settings.setProperty(/*from w w w . j ava 2 s . co m*/ language.getPluginProperty(CxxOtherSensor.OTHER_XSLT_KEY + "1" + CxxOtherSensor.STYLESHEET_KEY), stylesheetFile); settings.setProperty( language.getPluginProperty(CxxOtherSensor.OTHER_XSLT_KEY + "1" + CxxOtherSensor.INPUT_KEY), inputFile); settings.setProperty( language.getPluginProperty(CxxOtherSensor.OTHER_XSLT_KEY + "1" + CxxOtherSensor.OUTPUT_KEY), outputFile); context.setSettings(settings); CxxOtherSensor sensor = new CxxOtherSensor(language); sensor.transformFiles(fs.baseDir(), context); File reportBefore = new File(fs.baseDir() + "/" + inputFile); File reportAfter = new File(fs.baseDir() + "/" + outputFile); Assert.assertTrue("The output file does not exist!", reportAfter.exists() && reportAfter.isFile()); Assert.assertTrue("The input and output file is equal!", !FileUtils.contentEquals(reportBefore, reportAfter)); }
From source file:org.sonar.server.computation.step.ExtractReportStepTest.java
@Test public void unzip_report() throws Exception { File zipDir = tempFolder.newDir(); final File metadataFile = new File(zipDir, "metadata.pb"); FileUtils.write(metadataFile, "{report}"); File zip = tempFolder.newFile(); ZipUtils.zipDir(zipDir, zip);/*from w w w .j a v a2 s .co m*/ when(reportFiles.fileForUuid(TASK_UUID)).thenReturn(zip); underTest.execute(); verify(reportDirectoryHolder).setDirectory(argThat(new TypeSafeMatcher<File>() { @Override protected boolean matchesSafely(File dir) { try { return dir.isDirectory() && dir.exists() && // directory contains the uncompressed report (which contains only metadata.pb in this test) dir.listFiles().length == 1 && FileUtils.contentEquals(dir.listFiles()[0], metadataFile); } catch (IOException e) { throw new IllegalStateException(e); } } @Override public void describeTo(Description description) { } })); }
From source file:org.sonatype.nexus.proxy.SimplePullTest.java
@Test public void testSimplePush() throws Exception { ResourceStoreRequest request = new ResourceStoreRequest( "/repositories/inhouse/activemq/activemq-core/1.2/activemq-core-1.2.jar", true); StorageFileItem item = (StorageFileItem) getRootRouter().retrieveItem(new ResourceStoreRequest( "/repositories/repo1/activemq/activemq-core/1.2/activemq-core-1.2.jar", false)); getRootRouter().storeItem(request, item.getInputStream(), null); assertTrue(FileUtils.contentEquals( getFile(getRepositoryRegistry().getRepository("repo1"), "/activemq/activemq-core/1.2/activemq-core-1.2.jar"), getFile(getRepositoryRegistry().getRepository("inhouse"), "/activemq/activemq-core/1.2/activemq-core-1.2.jar"))); }