List of usage examples for org.apache.commons.io IOUtils contentEquals
public static boolean contentEquals(Reader input1, Reader input2) throws IOException
From source file:it.AsynchronousIssueRestClientTest.java
@Test public void testAddFileAttachmentWithUtf8InNameAndBody() throws IOException { final IssueRestClient issueClient = client.getIssueClient(); final Issue issue = issueClient.getIssue("TST-5").claim(); assertFalse(issue.getAttachments().iterator().hasNext()); final File tempFile = File.createTempFile(UTF8_FILE_NAME, ".txt"); tempFile.deleteOnExit();//from w w w . j ava 2 s . c o m FileWriter writer = new FileWriter(tempFile); writer.write(UTF8_FILE_BODY); writer.close(); issueClient.addAttachments(issue.getAttachmentsUri(), tempFile).claim(); final Issue issueWithAttachments = issueClient.getIssue("TST-5").claim(); final Iterable<Attachment> attachments = issueWithAttachments.getAttachments(); assertEquals(1, Iterables.size(attachments)); final Attachment firstAttachment = attachments.iterator().next(); assertTrue(IOUtils.contentEquals(new FileInputStream(tempFile), issueClient.getAttachment(firstAttachment.getContentUri()).claim())); assertThat(firstAttachment.getFilename(), equalTo(tempFile.getName())); }
From source file:org.apache.gobblin.hive.avro.HiveAvroSerDeManagerTest.java
private void validateSchemaUrl(State state, String targetSchemaFileName, boolean createConflictingFile) throws IOException { HiveAvroSerDeManager manager = new HiveAvroSerDeManager(state); HiveRegistrationUnit registrationUnit = (new HiveTable.Builder()).withDbName(TEST_DB) .withTableName(TEST_TABLE).build(); // Clean up existing file String targetPathStr = new Path(this.testBasePath, targetSchemaFileName).toString(); File targetFile = new File(targetPathStr); targetFile.delete();/*from w w w .j a v a 2 s.c om*/ // create a conflicting file if (createConflictingFile) { targetFile.createNewFile(); } manager.addSerDeProperties(this.testBasePath, registrationUnit); Assert.assertNull(registrationUnit.getSerDeProps().getProp(HiveAvroSerDeManager.SCHEMA_LITERAL)); String schemaUrl = registrationUnit.getSerDeProps().getProp(HiveAvroSerDeManager.SCHEMA_URL); Assert.assertEquals(schemaUrl, targetPathStr); Assert.assertTrue( IOUtils.contentEquals(this.getClass().getResourceAsStream("/test-hive-table/hive-test.avsc"), new FileInputStream(schemaUrl))); }
From source file:org.apache.jackrabbit.oak.jcr.CompatibilityIssuesTest.java
@Test public void testBinaryCoercion() throws RepositoryException, IOException { Session session = getAdminSession(); // node type with default child-node type of to nt:base String ntName = "binaryCoercionTest"; NodeTypeManager ntm = session.getWorkspace().getNodeTypeManager(); NodeTypeTemplate ntt = ntm.createNodeTypeTemplate(); ntt.setName(ntName);// w w w . j a v a 2s . c o m PropertyDefinitionTemplate propertyWithType = ntm.createPropertyDefinitionTemplate(); propertyWithType.setName("javaObject"); propertyWithType.setRequiredType(PropertyType.STRING); PropertyDefinitionTemplate unnamed = ntm.createPropertyDefinitionTemplate(); unnamed.setName("*"); unnamed.setRequiredType(PropertyType.UNDEFINED); List<PropertyDefinition> properties = ntt.getPropertyDefinitionTemplates(); properties.add(propertyWithType); properties.add(unnamed); ntm.registerNodeType(ntt, false); Node node = session.getRootNode().addNode("testNodeForBinary", ntName); ByteArrayOutputStream bos = serializeObject("testValue"); node.setProperty("javaObject", session.getValueFactory().createBinary(new ByteArrayInputStream(bos.toByteArray()))); Assert.assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(bos.toByteArray()), node.getProperty("javaObject").getStream())); }
From source file:org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStoreTest.java
@Test public void testInlineBinary() throws DataStoreException, IOException { int maxInlineSize = 300; DataStore mockedDS = mock(DataStore.class); when(mockedDS.getMinRecordLength()).thenReturn(maxInlineSize); DataStoreBlobStore ds = new DataStoreBlobStore(mockedDS); byte[] data = new byte[maxInlineSize]; new Random().nextBytes(data); DataRecord dr = ds.addRecord(new ByteArrayInputStream(data)); assertTrue(InMemoryDataRecord.isInstance(dr.getIdentifier().toString())); assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(data), dr.getStream())); assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(data), new BlobStoreInputStream(ds, dr.getIdentifier().toString(), 0))); assertEquals(dr, ds.getRecordIfStored(dr.getIdentifier())); assertEquals(dr, ds.getRecord(dr.getIdentifier())); //Check for BlobStore methods assertEquals(maxInlineSize, ds.getBlobLength(dr.getIdentifier().toString())); assertEquals(dr.getIdentifier().toString(), BlobId.of(ds.writeBlob(new ByteArrayInputStream(data))).blobId); }
From source file:org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStoreTest.java
@Test public void testExternalBinary() throws DataStoreException, IOException { int maxInlineSize = 300; int actualSize = maxInlineSize + 10; byte[] data = new byte[actualSize]; new Random().nextBytes(data); DataIdentifier testDI = new DataIdentifier("test"); DataRecord testDR = new ByteArrayDataRecord(data, testDI, "testReference"); DataStore mockedDS = mock(DataStore.class); when(mockedDS.getMinRecordLength()).thenReturn(maxInlineSize); when(mockedDS.getRecord(testDI)).thenReturn(testDR); when(mockedDS.getRecordIfStored(testDI)).thenReturn(testDR); when(mockedDS.addRecord(any(InputStream.class))).thenReturn(testDR); DataStoreBlobStore ds = new DataStoreBlobStore(mockedDS); DataRecord dr = ds.addRecord(new ByteArrayInputStream(data)); assertFalse(InMemoryDataRecord.isInstance(dr.getIdentifier().toString())); assertEquals(testDI, dr.getIdentifier()); assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(data), dr.getStream())); assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(data), new BlobStoreInputStream(ds, dr.getIdentifier().toString(), 0))); assertEquals(dr, ds.getRecordIfStored(dr.getIdentifier())); assertEquals(dr, ds.getRecord(dr.getIdentifier())); // assertTrue(ds.getInputStream(dr.getIdentifier().toString()) instanceof BufferedInputStream); assertEquals(actualSize, ds.getBlobLength(dr.getIdentifier().toString())); assertEquals(testDI.toString(), BlobId.of(ds.writeBlob(new ByteArrayInputStream(data))).blobId); }
From source file:org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreTextWriterTest.java
@Test public void basicOperation() throws Exception { File fdsDir = temporaryFolder.newFolder(); FileDataStore fds = DataStoreUtils.createFDS(fdsDir, 0); ByteArrayInputStream is = new ByteArrayInputStream("hello".getBytes()); DataRecord dr = fds.addRecord(is);/*ww w .j a va 2 s . co m*/ File writerDir = temporaryFolder.newFolder(); TextWriter writer = new DataStoreTextWriter(writerDir, false); writer.write(dr.getIdentifier().toString(), "hello"); FileDataStore fds2 = DataStoreUtils.createFDS(writerDir, 0); DataRecord dr2 = fds2.getRecordIfStored(dr.getIdentifier()); is.reset(); assertTrue(IOUtils.contentEquals(is, dr2.getStream())); }
From source file:org.apache.jackrabbit.oak.plugins.blob.datastore.InMemoryDataRecordTest.java
@Test public void testGetInstance() throws Exception { int length = 400; byte[] data = new byte[length]; new Random().nextBytes(data); DataRecord dr = InMemoryDataRecord.getInstance(data); assertTrue(InMemoryDataRecord.isInstance(dr.getIdentifier().toString())); DataRecord dr2 = InMemoryDataRecord.getInstance(dr.getIdentifier().toString()); assertTrue(IOUtils.contentEquals(dr.getStream(), dr2.getStream())); assertTrue(IOUtils.contentEquals(dr.getStream(), new ByteArrayInputStream(data))); assertEquals(length, dr.getLength()); assertEquals(dr2.getLength(), dr.getLength()); assertEquals(dr, dr2);// www . j a v a 2 s .co m }
From source file:org.apache.jackrabbit.oak.plugins.segment.ExternalBlobIT.java
@Test public void testDataStoreBlob() throws Exception { FileDataStore fds = createFileDataStore(); DataStoreBlobStore dbs = new DataStoreBlobStore(fds); nodeStore = getNodeStore(dbs);/*from w ww . j a va 2 s. co m*/ //Test for Blob which get inlined Blob b1 = testCreateAndRead(createBlob(fds.getMinRecordLength() - 2)); assertTrue(b1 instanceof SegmentBlob); assertNull(((SegmentBlob) b1).getBlobId()); //Test for Blob which need to be pushed to BlobStore byte[] data2 = new byte[Segment.MEDIUM_LIMIT + 1]; new Random().nextBytes(data2); Blob b2 = testCreateAndRead(nodeStore.createBlob(new ByteArrayInputStream(data2))); assertTrue(b2 instanceof SegmentBlob); assertNotNull(b2.getReference()); assertEquals(b2.getContentIdentity(), ((SegmentBlob) b2).getBlobId()); InputStream is = dbs.getInputStream(((SegmentBlob) b2).getBlobId()); assertNotNull(IOUtils.contentEquals(new ByteArrayInputStream(data2), is)); is.close(); }
From source file:org.apache.sling.commons.contentdetection.internal.it.ContentAwareMimeTypeServiceImplIT.java
@Test public void detectFromContent() throws IOException { final String filename = "this-is-actually-a-wav-file.mp3"; final String path = "/" + filename; final InputStream s = new BufferedInputStream(getClass().getResourceAsStream(path)); assertNotNull("Expecting stream to be found:" + filename, s); InputStream originalStream = null; try {// ww w . j ava 2s . co m assertEquals("audio/x-wav", contentAwaremimeTypeService.getMimeType(filename, s)); originalStream = getClass().getResourceAsStream(path); assertNotNull("Expecting stream to be found:" + filename, originalStream); assertTrue("Expecting content to be unchanged", IOUtils.contentEquals(s, originalStream)); } finally { IOUtils.closeQuietly(s); IOUtils.closeQuietly(originalStream); } }
From source file:org.apache.sling.distribution.packaging.impl.SimpleDistributionPackageTest.java
@Test public void testCreatedAndReadPackagesEquality() throws Exception { DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.DELETE, "/abc"); SimpleDistributionPackage createdPackage = new SimpleDistributionPackage(request, "VOID"); SimpleDistributionPackage readPackage = SimpleDistributionPackage .fromStream(new ByteArrayInputStream(("DSTRPCK:DELETE|/abc").getBytes()), "VOID"); assertNotNull(readPackage);/*from ww w . j a v a 2 s. c o m*/ assertEquals(createdPackage.getType(), readPackage.getType()); assertEquals(createdPackage.getInfo().getRequestType(), readPackage.getInfo().getRequestType()); assertEquals(Arrays.toString(createdPackage.getInfo().getPaths()), Arrays.toString(readPackage.getInfo().getPaths())); assertEquals(createdPackage.getId(), readPackage.getId()); assertTrue(IOUtils.contentEquals(createdPackage.createInputStream(), readPackage.createInputStream())); }