List of usage examples for org.apache.commons.io IOUtils contentEquals
public static boolean contentEquals(Reader input1, Reader input2) throws IOException
From source file:com.spartasystems.holdmail.mapper.MessageSummaryMapperTest.java
@Test public void shouldMapToMessageSummary() throws Exception { MimeBodyParts expectedBodyParts = mock(MimeBodyParts.class); ArgumentCaptor<InputStream> streamCaptor = ArgumentCaptor.forClass(InputStream.class); when(mimeBodyParserMock.findAllBodyParts(streamCaptor.capture())).thenReturn(expectedBodyParts); Message message = new Message(MESSAGE_ID, IDENTIFIER, SUBJECT, SENDER_MAIL, RECEIVED, SENDER_HOST, MESSAGE_SIZE, RAW_CONTENT, RECIPIENTS, HEADERS); MessageSummary summary = messageSummaryMapper.toMessageSummary(message); assertThat(summary.getMessageId()).isEqualTo(MESSAGE_ID); assertThat(summary.getIdentifier()).isEqualTo(IDENTIFIER); assertThat(summary.getSubject()).isEqualTo(SUBJECT); assertThat(summary.getSenderEmail()).isEqualTo(SENDER_MAIL); assertThat(summary.getReceivedDate()).isEqualTo(RECEIVED); assertThat(summary.getSenderHost()).isEqualTo(SENDER_HOST); assertThat(summary.getMessageSize()).isEqualTo(MESSAGE_SIZE); assertThat(summary.getRecipients()).isEqualTo("recip1,recip2"); assertThat(summary.getMessageRaw()).isEqualTo(RAW_CONTENT); assertThat(summary.getMessageHeaders()).isEqualTo(HEADERS); assertThat(IOUtils.contentEquals(streamCaptor.getValue(), IOUtils.toInputStream(RAW_CONTENT, UTF_8))); MimeBodyParts actualParts = Whitebox.getInternalState(summary, "mimeBodyParts"); assertThat(actualParts).isEqualTo(expectedBodyParts); }
From source file:com.cognifide.aet.job.common.comparators.layout.utils.ImageComparisonTest.java
@Test public void testCompare_different() throws Exception { InputStream sampleStream = null; InputStream patternStream = null; InputStream maskStream = null; InputStream expectedMaskStream = null; try {// w w w.jav a2 s .c om // given sampleStream = getClass().getResourceAsStream("/mock/LayoutComparator/image.png"); patternStream = getClass().getResourceAsStream("/mock/LayoutComparator/image2.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(0)); assertThat(imageComparisonResult.getWidthDifference(), is(0)); assertThat(imageComparisonResult.getPixelDifferenceCount(), is(15600)); maskStream = imageToStream(imageComparisonResult.getResultImage()); expectedMaskStream = getClass().getResourceAsStream("/mock/LayoutComparator/mask-different.png"); assertThat(IOUtils.contentEquals(maskStream, expectedMaskStream), is(true)); } finally { closeInputStreams(sampleStream, patternStream, maskStream, expectedMaskStream); } }
From source file:net.ontopia.topicmaps.xml.AbstractCanonicalExporterTests.java
@Test public void testExport() throws IOException { TestFileUtils.verifyDirectory(base, "out"); // setup canonicalization filenames File tmp = new File(base + File.separator + "out" + File.separator + "tmp-" + filename); File out = new File(base + File.separator + "out" + File.separator + "exp-" + filename); // produce canonical output try {/*w ww. ja v a 2 s . co m*/ canonicalize(inputFile, tmp, out); } catch (Throwable e) { throw new OntopiaRuntimeException("Error processing file '" + filename + "': " + e, e); } // compare results URL baseline = new URL(inputFile, "../baseline/" + filename); try (InputStream baselineIn = baseline.openStream(); FileInputStream in = new FileInputStream(out)) { Assert.assertTrue("test file " + filename + " canonicalized wrongly (" + baseline + " != " + out + "), tmp=" + tmp, IOUtils.contentEquals(in, baselineIn)); } // NOTE: we compare out/exp-* and baseline/* }
From source file:com.cloudant.sync.datastore.AttachmentStreamFactoryTest.java
@Test /**//from w w w . ja v a 2 s .com * Assert passing an AttachmentStreamFactory with no key to both a PreparedAttachment (writer) * and SavedAttachment (reader) round trips the data correctly. */ public void testSavedAttachmentReadsPreparedAttachmentUnencryptedUnencodedStream() throws AttachmentException, IOException { AttachmentStreamFactory asf = new AttachmentStreamFactory(new NullKeyProvider()); File plainText = f("fixture/EncryptedAttachmentTest_plainText"); UnsavedFileAttachment usf = new UnsavedFileAttachment(plainText, "text/plain"); PreparedAttachment preparedAttachment = new PreparedAttachment(usf, datastore_manager_dir, 0, asf); Assert.assertTrue("Writing to unencrypted, unencoded stream didn't give correct output", IOUtils .contentEquals(new FileInputStream(preparedAttachment.tempFile), new FileInputStream(plainText))); SavedAttachment savedAttachment = new SavedAttachment(0, "test", null, "text/plain", Attachment.Encoding.Plain, 0, 0, 0, preparedAttachment.tempFile, asf); Assert.assertTrue("Reading from written unencrypted, unencoded blob didn't give correct output", IOUtils.contentEquals(savedAttachment.getInputStream(), new FileInputStream(plainText))); }
From source file:com.barchart.netty.server.http.handlers.TestStaticResourceHandler.java
@Test public void testFileCacheControl() throws Exception { HttpGet get = new HttpGet("http://localhost:" + port + "/file/test.css"); HttpResponse response = client.execute(get); final String modified = response.getFirstHeader(HttpHeaders.LAST_MODIFIED).getValue(); get = new HttpGet("http://localhost:" + port + "/file/test.css"); get.addHeader(HttpHeaders.CACHE_CONTROL, "no-cache"); get.addHeader(HttpHeaders.IF_MODIFIED_SINCE, modified); response = client.execute(get);/*from w w w . java2s .c om*/ assertEquals(200, response.getStatusLine().getStatusCode()); assertTrue(IOUtils.contentEquals( new FileInputStream( new File(System.getProperty("user.dir") + "/src/test/resources/files/test.css")), response.getEntity().getContent())); }
From source file:de.brendamour.jpasskit.signing.PKPassTemplateInMemoryTest.java
@Test public void addFile_asString() throws IOException { StringBuffer stringBuffer = new StringBuffer("Hi"); pkPassTemplateInMemory.addFile(PKPassTemplateInMemory.PK_ICON_RETINA, stringBuffer); Map<String, InputStream> files = pkPassTemplateInMemory.getFiles(); Assert.assertEquals(files.size(), 1); Assert.assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(stringBuffer.toString().getBytes()), files.get(PKPassTemplateInMemory.PK_ICON_RETINA))); }
From source file:de.brendamour.jpasskit.signing.PKPassTemplateInMemoryTest.java
@Test public void addFile_asString_withLocale() throws IOException { StringBuffer stringBuffer = new StringBuffer("Hi"); pkPassTemplateInMemory.addFile(PKPassTemplateInMemory.PK_ICON_RETINA, Locale.ENGLISH, stringBuffer); Map<String, InputStream> files = pkPassTemplateInMemory.getFiles(); Assert.assertEquals(files.size(), 1); Assert.assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(stringBuffer.toString().getBytes()), files.get("en.lproj/" + PKPassTemplateInMemory.PK_ICON_RETINA))); }
From source file:com.jaxio.celerio.util.IOUtil.java
public boolean contentEquals(Reader reader1, Reader reader2) { try {/*from ww w . j a v a 2 s . c o m*/ return IOUtils.contentEquals(reader1, reader2); } catch (Exception e) { return false; } finally { closeQuietly(reader1); closeQuietly(reader2); } }
From source file:com.spartasystems.holdmail.mime.MimeBodyPartTest.java
@Test public void shouldGetContentStream() throws Exception { MimeBodyPart mimeBodyPart = new MimeBodyPart(); assertThat(mimeBodyPart.getContentStream()).isNull(); byte[] bytes = NON_ASCII_STR.getBytes("UTF-8"); mimeBodyPart.setContent(new ByteArrayInputStream(bytes)); assertThat(IOUtils.contentEquals(mimeBodyPart.getContentStream(), new ByteArrayInputStream(bytes))); }
From source file:com.barchart.netty.server.http.handlers.TestStaticResourceHandler.java
@Test public void testFileCacheExpired() throws Exception { HttpGet get = new HttpGet("http://localhost:" + port + "/file/test.css"); HttpResponse response = client.execute(get); final String modified = response.getFirstHeader(HttpHeaders.LAST_MODIFIED).getValue(); final long modtime = DateUtils.parseDate(modified).getTime(); get = new HttpGet("http://localhost:" + port + "/file/test.css"); get.addHeader(HttpHeaders.IF_MODIFIED_SINCE, DateUtils.formatDate(new Date(modtime - 1000))); response = client.execute(get);/*from w ww . j ava 2 s .c om*/ assertEquals(200, response.getStatusLine().getStatusCode()); assertTrue(IOUtils.contentEquals( new FileInputStream( new File(System.getProperty("user.dir") + "/src/test/resources/files/test.css")), response.getEntity().getContent())); }