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:de.brendamour.jpasskit.signing.PKPassTemplateInMemoryTest.java

@Test
public void addFile_fromURL() throws IOException {
    URL url = new URL(
            "https://upload.wikimedia.org/wikipedia/commons/2/22/Big.Buck.Bunny.-.Bunny.Portrait.png");
    pkPassTemplateInMemory.addFile(PKPassTemplateInMemory.PK_ICON_RETINA, url);
    Map<String, InputStream> files = pkPassTemplateInMemory.getFiles();
    Assert.assertEquals(files.size(), 1);
    Assert.assertTrue(/* ww  w.  j  a va 2s  .  com*/
            IOUtils.contentEquals(url.openStream(), files.get(PKPassTemplateInMemory.PK_ICON_RETINA)));
}

From source file:com.spartasystems.holdmail.domain.MessageContentPartTest.java

@Test
public void shouldGetContentStream() throws Exception {

    MessageContentPart messageContentPart = new MessageContentPart();
    assertThat(messageContentPart.getContentStream()).isNull();

    byte[] bytes = NON_ASCII_STR.getBytes("UTF-8");
    messageContentPart.setContent(new ByteArrayInputStream(bytes));
    assertThat(IOUtils.contentEquals(messageContentPart.getContentStream(), new ByteArrayInputStream(bytes)));

}

From source file:com.cognifide.aet.job.common.comparators.layout.utils.ImageComparisonTest.java

@Test
public void compare_differentSizeScreenshots_expectSizeDifferenceMarkedWithYellow() throws Exception {
    InputStream sampleStream = null;
    InputStream patternStream = null;
    InputStream maskStream = null;
    InputStream expectedMaskStream = null;
    try {//w w  w. j a  va2  s. c  o m
        // given
        sampleStream = getClass().getResourceAsStream("/mock/LayoutComparator/canvasSizeDiff/collected.png");
        patternStream = getClass().getResourceAsStream("/mock/LayoutComparator/canvasSizeDiff/pattern.png");

        BufferedImage sample = ImageIO.read(sampleStream);
        BufferedImage pattern = ImageIO.read(patternStream);
        // when
        ImageComparisonResult imageComparisonResult = ImageComparison.compare(pattern, sample);
        // then
        assertThat(imageComparisonResult.isMatch(), is(false));
        assertThat(imageComparisonResult.getHeightDifference(), is(100));
        assertThat(imageComparisonResult.getWidthDifference(), is(20));
        assertThat(imageComparisonResult.getPixelDifferenceCount(), is(14399));

        maskStream = imageToStream(imageComparisonResult.getResultImage());
        expectedMaskStream = getClass().getResourceAsStream("/mock/LayoutComparator/canvasSizeDiff/mask.png");
        assertThat(IOUtils.contentEquals(maskStream, expectedMaskStream), is(true));
    } finally {
        closeInputStreams(sampleStream, patternStream, maskStream, expectedMaskStream);
    }
}

From source file:com.hortonworks.streamline.streams.service.CustomProcessorUploadHandlerTest.java

@Test
public void testSuccessfulUpload() throws IOException, ComponentConfigException {
    String fileName = "consolecustomprocessor.tar";
    URL url = classLoader.getResource(resourceDirectoryPrefix + fileName);
    String consoleCustomProcessorTarString = url.getFile();
    File consoleCustomProcessorTar = new File(consoleCustomProcessorTarString);
    FileUtils.copyFileToDirectory(consoleCustomProcessorTar, new File(uploadWatchDirectory), false);
    this.customProcessorUploadHandler.created(Paths.get(uploadWatchDirectory).resolve(fileName));
    new VerificationsInOrder() {
        {//from   w w  w . j  a  va2 s .  c  o  m
            InputStream jarFileActual;
            catalogService.addCustomProcessorInfoAsBundle(withEqual(customProcessorInfo),
                    jarFileActual = withCapture());
            times = 1;
            Assert.assertTrue(IOUtils.contentEquals(jarFileActual, jarFile));
        }
    };
}

From source file:fr.ortolang.diffusion.store.binary.BinaryStoreServiceTest.java

@Test
public void testInsertUnexistingObject() {
    final byte[] content = "Sample Digital Content v1.0".getBytes();

    try {// ww w. j a va 2s . c om
        String identifier = service.put(new ByteArrayInputStream(content));
        InputStream is = service.get(identifier);
        assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(content), is));
    } catch (Exception e) {
        fail(e.getMessage());
    }
}

From source file:com.cloudant.sync.datastore.AttachmentStreamFactoryTest.java

@Test
/**/*from w  w  w.j a va 2  s  .  c om*/
 * Assert passing an AttachmentStreamFactory with no key writes an unencrypted and
 * gzipped file to disk.
 */
public void testPreparedAttachmentWritesUnencryptedEncodedStream() throws AttachmentException, IOException {

    // We can't create a GZipped file right now using the attachment classes,
    // so test using factory directly.

    AttachmentStreamFactory asf = new AttachmentStreamFactory(new NullKeyProvider());

    File plainText = f("fixture/EncryptedAttachmentTest_plainText");
    File zippedPlainText = f("fixture/EncryptedAttachmentTest_plainText.gz");

    File actualOutput = new File(datastore_manager_dir, "temp" + UUID.randomUUID());
    OutputStream out = asf.getOutputStream(actualOutput, Attachment.Encoding.Gzip);

    IOUtils.copy(new FileInputStream(plainText), out);
    out.close();

    Assert.assertTrue("Writing to unencrypted, encoded stream didn't give correct output",
            IOUtils.contentEquals(new FileInputStream(actualOutput), new FileInputStream(zippedPlainText)));

}

From source file:de.brendamour.jpasskit.signing.PKPassTemplateInMemoryTest.java

@Test
public void addFile_fromURL_withLocale() throws IOException {
    URL url = new URL(
            "https://upload.wikimedia.org/wikipedia/commons/2/22/Big.Buck.Bunny.-.Bunny.Portrait.png");
    pkPassTemplateInMemory.addFile(PKPassTemplateInMemory.PK_ICON_RETINA, Locale.ENGLISH, url);
    Map<String, InputStream> files = pkPassTemplateInMemory.getFiles();
    Assert.assertEquals(files.size(), 1);
    Assert.assertTrue(IOUtils.contentEquals(url.openStream(),
            files.get("en.lproj/" + PKPassTemplateInMemory.PK_ICON_RETINA)));
}

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

/**
 * Tests {@link Store#create(InputStream, String)}.
 * //from   w w  w. j  a  v a  2  s .c o m
 * @throws IOException should not happen
 */
@Test
public void createStreamIdentifier() throws IOException {
    final Store unit = unit();
    final InputStream stream = getClass().getClassLoader().getResourceAsStream("willi.png");
    Assert.assertNotNull(stream);
    final String identifier = Long.toString(System.currentTimeMillis());
    unit.create(stream, identifier);
    stream.close();
    Assert.assertTrue(IOUtils.contentEquals(getClass().getClassLoader().getResourceAsStream("willi.png"),
            unit.read(identifier)));
}

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

@Test
public void testClasspathNotCached() throws Exception {

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

    final URLConnection conn = getClass().getResource("/files/test.css").openConnection();

    assertEquals(200, response.getStatusLine().getStatusCode());
    assertEquals(conn.getContentLength(),
            Integer.parseInt(response.getFirstHeader(HttpHeaders.CONTENT_LENGTH).getValue()));
    assertTrue(IOUtils.contentEquals(conn.getInputStream(), response.getEntity().getContent()));

}

From source file:de.neofonie.aiko.yaml.ResponseDefinition.java

private boolean isByteContentIncorrect(final ClientResponse response, final Context context)
        throws IOException {
    boolean bodyIncorrect = false;

    if (body != null) {
        try (InputStream responseBody = response.getEntityInputStream();
                InputStream expectedBody = context.expandBodyField(body)) {

            if (!IOUtils.contentEquals(responseBody, expectedBody)) {
                System.out.println("\t\t*****************************************");
                System.out.println("\t\tThe response differs from expected result");
                System.out.println("\t\t*****************************************");
                System.out.println("\t[ERROR] Byte content did not match!");
                bodyIncorrect = true;//from   w  w w.ja v a 2 s.  com
            }
        }
    }
    return bodyIncorrect;
}