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.prorefactor.core.unittest.TP01Test.java

@Test
public void test01() throws Exception {
    Injector injector = Guice.createInjector(new UnitTestSportsModule());
    RefactorSession session = injector.getInstance(RefactorSession.class);
    outFile.getParentFile().mkdirs();/*from ww w  .  j a  va 2 s.c  o m*/

    AttributedWriter writer = new AttributedWriter();
    writer.write(inName, outFile, session);
    assertTrue(FileUtils.contentEquals(new File(expectName), outFile));
}

From source file:org.prorefactor.core.unittest.TP01Test01.java

public void test01() throws Exception {
    RefactorSession.getInstance().loadProject("unittest");
    Schema schema = Schema.getInstance();
    schema.clear();//from   w w  w  . ja  va 2 s. c  om
    schema.loadSchema(schemaName);
    AttributedWriter writer = new AttributedWriter();
    writer.write(inName, outName);
    assertTrue(FileUtils.contentEquals(new File(expectName), new File(outName)));
}

From source file:org.prorefactor.core.unittest.TP01Test02.java

public void test01() throws Exception {
    BufferedReader reader = null;
    BufferedWriter writer = null;
    try {/*from   w  w w . j av a  2  s .c  om*/
        Schema schema = Schema.getInstance();
        schema.clear();
        schema.loadSchema(schemaName);
        outFile.delete();
        reader = new BufferedReader(new FileReader(inName));
        String line = null;
        snippet_loop: for (;;) {
            writer = new BufferedWriter(new FileWriter(snippetFile));
            for (;;) {
                line = reader.readLine();
                if (line == null || line.startsWith("--"))
                    break;
                writer.write(line);
                writer.newLine();
            }
            writer.close();
            AttributedWriter attWriter = new AttributedWriter();
            attWriter.write(snippetName, snippetOutName);
            Util.fileAppend(outName, snippetOutName);
            Util.fileAppendString(outName, snippetSep);
            if (line == null)
                break snippet_loop;
        } // snippet_loop
        snippetFile.delete();
    } finally {
        if (reader != null)
            try {
                reader.close();
            } catch (IOException e1) {
            }
    }
    assertTrue(FileUtils.contentEquals(new File(expectName), new File(outName)));
}

From source file:org.prorefactor.core.unittest.TP02Test.java

@Test
public void test01() throws Exception {
    BufferedWriter writer = null;
    try (BufferedReader reader = new BufferedReader(new FileReader(inName))) {
        outFile.delete();/*from www  .  ja v  a  2s. c  o m*/
        String line = null;
        snippet_loop: for (;;) {
            writer = new BufferedWriter(new FileWriter(snippetFile));
            for (;;) {
                line = reader.readLine();
                if (line == null || line.startsWith("--"))
                    break;
                writer.write(line);
                writer.newLine();
            }
            writer.close();
            AttributedWriter attWriter = new AttributedWriter();
            attWriter.write(snippetName, snippetOutFile, session);
            fileAppend(outName, snippetOutName);
            fileAppendString(outName, snippetSep);
            if (line == null)
                break snippet_loop;
        } // snippet_loop
        snippetFile.delete();
    }
    assertTrue(FileUtils.contentEquals(new File(expectName), new File(outName)));
}

From source file:org.prorefactor.core.unittest.UnitTestBase2.java

/** Compare two files.
 * @return String error message on first difference or missing file,
 * null if no differences found.// w  w  w . ja v a2 s  . c  om
 */
public String testCompareSingle(File first, File second) {
    boolean equal;
    try {
        equal = FileUtils.contentEquals(first, second);
    } catch (Exception e) {
        return e.getMessage();
    }
    if (!equal)
        return "Files are different: " + first.toString() + " " + second.toString();
    return null;
}

From source file:org.silverpeas.admin.domain.SQLDomainServiceTest.java

@Test
@Transactional/* w ww .ja  v a 2 s.co  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
    boolean domainPropFileFound = false;
    boolean authenticationPropFileFound = false;
    for (File file : tmpFile.listFiles()) {
        if (file.getName().equals("Domain3TestCrea.properties")) {
            domainPropFileFound = true;
            assertThat("domain properties files generated content is incorrect",
                    FileUtils.contentEquals(file, expectedDomainPropertiesFile), is(true));
        } else if (file.getName().equals("autDomain3TestCrea.properties")) {
            authenticationPropFileFound = true;
            assertThat("domain authentication properties files generated content is incorrect",
                    FileUtils.contentEquals(file, expectedDomainAuthenticationPropertiesFile), is(true));
        }
    }
    assertThat("domain properties files has not been generated", domainPropFileFound, is(true));
    assertThat("domain authentication properties files has not been generated", authenticationPropFileFound,
            is(true));

    // Performs checks on generated tables
    testTablesExistence(true);
}

From source file:org.silverpeas.attachment.AttachmentServiceTest.java

/**
 * Test of addContent method, of class AttachmentService.
 *//*from  ww w.j  a  v  a2  s.c o  m*/
@Test
public void testAddFileContent() throws URISyntaxException, IOException {
    File file = new File(this.getClass().getResource("/LibreOffice.odt").toURI());
    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.attachment.AttachmentServiceTest.java

/**
 * Test of addContent method, of class AttachmentService.
 *//*from  www.ja  v a  2  s  . c  o m*/
@Test
public void testUpdateFileContent() throws URISyntaxException, IOException {
    File file = new File(this.getClass().getResource("/LibreOffice.odt").toURI());
    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.attachment.AttachmentServiceTest.java

/**
 * Test of cloneDocument method, of class AttachmentService.
 *///from   w  ww  .j  av a  2 s.  c  om
@Test
public void testCloneDocument() throws IOException {
    String language = "fr";
    String foreignCloneId = "node59";
    SimpleDocument original = instance.searchDocumentById(existingFrDoc, language);
    SimpleDocumentPK clonePk = instance.cloneDocument(original, foreignCloneId);
    SimpleDocument clone = instance.searchDocumentById(clonePk, language);
    original.setCloneId(original.getId());
    SimpleDocument updatedOriginal = instance.searchDocumentById(existingFrDoc, language);
    assertThat(updatedOriginal, SimpleDocumentMatcher.matches(original));
    original.setCloneId(null);
    original.setForeignId(foreignCloneId);
    original.setPK(clonePk);
    assertThat(clone, SimpleDocumentMatcher.matches(original));
    assertThat(FileUtils.contentEquals(new File(original.getAttachmentPath()),
            new File(clone.getAttachmentPath())), is(true));
}

From source file:org.silverpeas.attachment.HistorisedAttachmentServiceTest.java

/**
 * Test of addContent method, of class AttachmentService.
 *//*from ww w.ja  va2  s  .  com*/
@Test
public void testAddFileContent() throws URISyntaxException, IOException {
    File file = new File(this.getClass().getClassLoader().getResource("LibreOffice.odt").toURI());
    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"));
}