Example usage for org.apache.commons.io IOUtils contentEquals

List of usage examples for org.apache.commons.io IOUtils contentEquals

Introduction

In this page you can find the example usage for org.apache.commons.io IOUtils contentEquals.

Prototype

public static boolean contentEquals(Reader input1, Reader input2) throws IOException 

Source Link

Document

Compare the contents of two Readers to determine if they are equal or not.

Usage

From source file:at.tfr.securefs.util.TestMain.java

@Test
public void testMainEncryptWithSalt() throws Exception {

    Main main = new Main();
    main.parseOpts(new String[] { "-t", "-s", "test_main", "-o", "test_main.enc", "test_main.txt" });
    main.execute();//from  ww  w . j  a  v  a  2 s.  c om

    main = new Main();
    main.parseOpts(new String[] { "-t", "-s", "test_main", "-d", "-o", "test_main.out.txt", "test_main.enc" });
    main.execute();

    Assert.assertTrue("encryption/decryption failed",
            IOUtils.contentEquals(this.getClass().getResourceAsStream("/" + "test_main.txt"),
                    this.getClass().getResourceAsStream("/" + "test_main.out.txt")));

}

From source file:com.collective.celos.ci.testing.fixtures.compare.PlainFileComparer.java

public FixObjectCompareResult check(TestRun testRun) throws Exception {
    if (!IOUtils.contentEquals(content, file.getContent())) {
        return FixObjectCompareResult.failed("File contents differed");
    }// ww  w .  j  av  a  2 s.co  m
    return FixObjectCompareResult.SUCCESS;
}

From source file:gov.nih.nci.caarray.plugins.agilent.EndOfLineCorrectingReaderTest.java

@Test
public void replacesCrCrLfWithCrLf() throws IOException {
    File testFile = createTestFile();

    EndOfLineCorrectingReader sut = new EndOfLineCorrectingReader(testFile);

    StringReader expectedDataReader = new StringReader(expectedData);

    assertTrue(IOUtils.contentEquals(expectedDataReader, sut));
}

From source file:at.tfr.securefs.util.TestMain.java

@Test
public void testMainDecrypt() throws Exception {

    Main main = new Main();
    main.parseOpts(new String[] { "-t", "-o", "test_main.enc", "test_main.txt" });
    main.execute();//from w w w.  jav a  2  s. c  o  m

    main = new Main();
    main.parseOpts(new String[] { "-t", "-d", "-o", "test_main.out.txt", "test_main.enc" });
    main.execute();

    Assert.assertTrue("encryption/decryption failed",
            IOUtils.contentEquals(this.getClass().getResourceAsStream("/" + "test_main.txt"),
                    this.getClass().getResourceAsStream("/" + "test_main.out.txt")));

}

From source file:com.consol.citrus.ws.validation.BinarySoapAttachmentValidator.java

@Override
protected void validateAttachmentContent(SoapAttachment receivedAttachment, SoapAttachment controlAttachment) {
    if (log.isDebugEnabled()) {
        log.debug("Validating binary SOAP attachment content ...");
    }/* w  w w .  ja v  a2 s  .c o m*/

    try {
        Assert.isTrue(
                IOUtils.contentEquals(receivedAttachment.getInputStream(), controlAttachment.getInputStream()),
                "Values not equal for binary attachment content '" + controlAttachment.getContentId() + "'");
    } catch (IOException e) {
        throw new CitrusRuntimeException("Binary SOAP attachment validation failed", e);
    }

    if (log.isDebugEnabled()) {
        log.debug("Validating binary SOAP attachment content: OK");
    }
}

From source file:com.cloudant.sync.datastore.encryption.EncryptedAttachmentInputStreamTest.java

@Test
public void testReadingValidFile() throws IOException, InvalidKeyException {
    File encryptedAttachmentBlob = TestUtils.loadFixture("fixture/EncryptedAttachmentTest_cipherText_aes128");
    File expectedPlainText = TestUtils.loadFixture("fixture/EncryptedAttachmentTest_plainText");

    InputStream encryptedInputStream = new EncryptedAttachmentInputStream(
            new FileInputStream(encryptedAttachmentBlob), EncryptionTestConstants.key16Byte);

    InputStream plainTextInputStream = new FileInputStream(expectedPlainText);

    Assert.assertTrue("Reading encrypted stream didn't give expected plain text",
            IOUtils.contentEquals(encryptedInputStream, plainTextInputStream));
}

From source file:eu.planets_project.services.utils.DigitalObjectUtilsTests.java

@Test
public void toFileDigitalObjectFile() throws IOException {
    DigitalObject object = new DigitalObject.Builder(Content.byReference(testZip)).build();
    File file = File.createTempFile("planets", null);
    DigitalObjectUtils.toFile(object, file);
    Assert.assertTrue(//from w ww.  ja v a2s .  co  m
            IOUtils.contentEquals(object.getContent().getInputStream(), file.toURI().toURL().openStream()));
}

From source file:com.barchart.netty.server.http.handlers.TestStaticResourceHandler.java

@Test
public void testChunked() throws Exception {

    final HttpGet get = new HttpGet("http://localhost:" + port + "/file/test.jpg");
    final HttpResponse response = client.execute(get);

    final File file = new File(System.getProperty("user.dir") + "/src/test/resources/files/test.jpg");

    assertEquals(200, response.getStatusLine().getStatusCode());
    assertEquals(null, response.getFirstHeader(HttpHeaders.CONTENT_LENGTH));
    assertTrue(IOUtils.contentEquals(new FileInputStream(file), response.getEntity().getContent()));
}

From source file:com.cloudant.sync.datastore.encryption.EncryptedAttachmentOutputStreamTest.java

@Test
public void testWritingValidFile() throws IOException, InvalidAlgorithmParameterException,
        NoSuchAlgorithmException, InvalidKeyException, NoSuchPaddingException {
    File expectedCipherText = TestUtils.loadFixture("fixture/EncryptedAttachmentTest_cipherText_aes128");
    File plainText = TestUtils.loadFixture("fixture/EncryptedAttachmentTest_plainText");

    ByteArrayOutputStream actualEncryptedOutput = new ByteArrayOutputStream();

    OutputStream encryptedOutputStream = new EncryptedAttachmentOutputStream(actualEncryptedOutput,
            EncryptionTestConstants.key16Byte, EncryptionTestConstants.iv);
    IOUtils.copy(new FileInputStream(plainText), encryptedOutputStream);
    encryptedOutputStream.close();/*  w  ww . j a  va  2  s . com*/
    actualEncryptedOutput.close();

    Assert.assertTrue("Writing to encrypted stream didn't give expected cipher text",
            IOUtils.contentEquals(new ByteArrayInputStream(actualEncryptedOutput.toByteArray()),
                    new FileInputStream(expectedCipherText)));
}

From source file:de.cosmocode.palava.store.FileSystemStoreTest.java

/**
 * Tests whether {@link FileSystemStore#delete(String)} automatically deletes
 * empty parent directories./*  w ww.  j a  va  2s.  c  o  m*/
 * 
 * @throws IOException should not happen 
 */
@Test
public void deleteEmptyDirectories() throws IOException {
    final Store unit = unit();
    final InputStream stream = getClass().getClassLoader().getResourceAsStream("willi.png");
    final String identifier = unit.create(stream);
    Assert.assertTrue(IOUtils.contentEquals(getClass().getClassLoader().getResourceAsStream("willi.png"),
            unit.read(identifier)));
    unit.delete(identifier);
    Assert.assertTrue(directory.list().length == 0);
    Assert.assertTrue(directory.exists());
}