List of usage examples for org.apache.commons.io IOUtils contentEquals
public static boolean contentEquals(Reader input1, Reader input2) throws IOException
From source file:io.github.tsabirgaliev.ZipperInputStreamTest.java
public void testJDKCompatibility() throws IOException { ZipperInputStream lzis = new ZipperInputStream(enumerate(file1, file2)); ZipInputStream zis = new ZipInputStream(lzis); {/*from w w w . j av a 2 s. co m*/ ZipEntry entry1 = zis.getNextEntry(); assert file1.getPath().equals(entry1.getName()); assert IOUtils.contentEquals(zis, file1.getStream()); zis.closeEntry(); } { ZipEntry entry2 = zis.getNextEntry(); assert file2.getPath().equals(entry2.getName()); assert IOUtils.contentEquals(zis, file2.getStream()); zis.closeEntry(); } }
From source file:com.collective.celos.ci.deploy.JScpWorkerTest.java
@Test public void testGetFileObjectByUri() throws Exception { JScpWorker worker = new JScpWorker("uname"); URL res = Thread.currentThread().getContextClassLoader() .getResource("com/collective/celos/ci/testing/config/target.json"); FileObject object = worker.getFileObjectByUri(res.toURI()); IOUtils.contentEquals(object.getContent().getInputStream(), new FileInputStream(res.getFile())); }
From source file:com.cloudant.sync.datastore.AttachmentStreamFactoryTest.java
@Test /**/*from w ww . j a v a2s .c o m*/ * Assert passing an AttachmentStreamFactory with no key writes an unencrypted file to disk. */ public void testPreparedAttachmentWritesUnencryptedUnencodedStream() 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, un-encoded stream didn't give correct output", IOUtils .contentEquals(new FileInputStream(preparedAttachment.tempFile), new FileInputStream(plainText))); }
From source file:com.cognifide.aet.job.common.comparators.layout.utils.ImageComparisonTest.java
@Test public void test_sameScreenshot_expectNoDifferencesInResultAndTransparentMask() throws Exception { InputStream sampleStream = null; InputStream patternStream = null; InputStream maskStream = null; InputStream expectedMaskStream = null; try {/*from ww w .j a v a 2 s . c om*/ // given sampleStream = getClass().getResourceAsStream("/mock/LayoutComparator/image.png"); patternStream = getClass().getResourceAsStream("/mock/LayoutComparator/image.png"); BufferedImage sample = ImageIO.read(sampleStream); BufferedImage pattern = ImageIO.read(patternStream); // when ImageComparisonResult imageComparisonResult = ImageComparison.compare(pattern, sample); // then assertThat(imageComparisonResult.isMatch(), is(true)); assertThat(imageComparisonResult.getHeightDifference(), is(0)); assertThat(imageComparisonResult.getWidthDifference(), is(0)); assertThat(imageComparisonResult.getPixelDifferenceCount(), is(0)); maskStream = imageToStream(imageComparisonResult.getResultImage()); expectedMaskStream = getClass().getResourceAsStream("/mock/LayoutComparator/mask-identical.png"); assertThat(IOUtils.contentEquals(expectedMaskStream, maskStream), is(true)); } finally { closeInputStreams(sampleStream, patternStream, maskStream, expectedMaskStream); } }
From source file:eu.planets_project.services.utils.DigitalObjectUtilsTests.java
@Test public void toFileDigitalObject() throws MalformedURLException, IOException { DigitalObject object = new DigitalObject.Builder(Content.byReference(testZip)).build(); File file = DigitalObjectUtils.toFile(object); Assert.assertTrue(//from www . j av a 2s . co m IOUtils.contentEquals(object.getContent().getInputStream(), file.toURI().toURL().openStream())); }
From source file:com.xpn.xwiki.doc.XWikiAttachmentTest.java
/** * Create an attachment, populate it with enough data to make it flush to disk cache, * read back data and make sure it's the same. *//*w w w .ja v a 2 s. c o m*/ @Test public void testStoreContentInDiskCache() throws Exception { int attachLength = 20000; // Check for data dependent errors. int seed = (int) System.currentTimeMillis(); final XWikiAttachment attach = new XWikiAttachment(); final InputStream ris = new RandomInputStream(attachLength, seed); attach.setContent(ris); Assert.assertEquals("Not all of the stream was read", 0, ris.available()); Assert.assertTrue(IOUtils.contentEquals(new RandomInputStream(attachLength, seed), attach.getAttachment_content().getContentInputStream())); }
From source file:net.ontopia.topicmaps.xml.AbstractCanonicalTests.java
@Test public void testFile() throws IOException { TestFileUtils.verifyDirectory(base, "out"); // setup canonicalization filenames File out = new File(base + File.separator + "out" + File.separator + getOutFilename(filename)); // produce canonical output canonicalize(inputFile, out);//w ww . j a v a2 s . c o m // compare results URL baselineURL = new URL(inputFile, "../baseline/" + getOutFilename(filename)); try (InputStream baselineIn = baselineURL.openStream(); FileInputStream in = new FileInputStream(out)) { Assert.assertTrue("test file " + filename + " canonicalized wrongly", IOUtils.contentEquals(in, baselineIn)); } }
From source file:com.barchart.netty.server.http.handlers.TestStaticResourceHandler.java
@Test public void testFileNotCached() throws Exception { final HttpGet get = new HttpGet("http://localhost:" + port + "/file/test.css"); final HttpResponse response = client.execute(get); final File file = new File(System.getProperty("user.dir") + "/src/test/resources/files/test.css"); assertEquals(200, response.getStatusLine().getStatusCode()); assertEquals(file.length(),//from w w w . j a va 2 s . c om Integer.parseInt(response.getFirstHeader(HttpHeaders.CONTENT_LENGTH).getValue())); assertTrue(IOUtils.contentEquals(new FileInputStream(file), response.getEntity().getContent())); }
From source file:com.collective.celos.ci.deploy.JScpWorkerTest.java
@Test public void testGetFileObjectByUriStringParam() throws Exception { JScpWorker worker = new JScpWorker("uname"); URL res = Thread.currentThread().getContextClassLoader() .getResource("com/collective/celos/ci/testing/config/target.json"); FileObject object = worker.getFileObjectByUri(res.toURI().toString()); IOUtils.contentEquals(object.getContent().getInputStream(), new FileInputStream(res.getFile())); }
From source file:com.silverpeas.directory.servlets.ImageProfilTest.java
@Test public void testExtractImage() throws IOException { ImageProfil imageProfil = new ImageProfil("SilverAdmin.jpg"); imageProfil.saveImage(this.getClass().getResourceAsStream("SilverAdmin.jpg")); IOUtils.contentEquals(this.getClass().getResourceAsStream("SilverAdmin.jpg"), imageProfil.getImage()); }