List of usage examples for org.apache.commons.io IOUtils contentEquals
public static boolean contentEquals(Reader input1, Reader input2) throws IOException
From source file:org.pentaho.di.job.entries.sftp.SFTPClientIT.java
@Test public void putFile() throws Exception { final byte[] data = "putFile()".getBytes(); client.put(new ByteArrayInputStream(data), "uploaded.txt"); ByteArrayOutputStream uploaded = new ByteArrayOutputStream(); channel.connect();/*from w w w . j a va 2 s .co m*/ InputStream inputStream = channel.get("uploaded.txt"); try { IOUtils.copy(inputStream, uploaded); } finally { inputStream.close(); } assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(data), new ByteArrayInputStream(uploaded.toByteArray()))); }
From source file:org.pentaho.di.job.entries.sftp.SFTPClientIT.java
@Test public void getFile() throws Exception { final byte[] data = "getFile()".getBytes(); channel.connect();/* w ww.j a v a 2 s . c o m*/ channel.put(new ByteArrayInputStream(data), "downloaded.txt"); client.get(KettleVFS.getFileObject("ram://downloaded.txt"), "downloaded.txt"); FileObject downloaded = KettleVFS.getFileObject("ram://downloaded.txt"); assertTrue(downloaded.exists()); assertTrue(IOUtils.contentEquals(downloaded.getContent().getInputStream(), new ByteArrayInputStream(data))); }
From source file:org.pentaho.platform.plugin.services.importer.SolutionImportHandlerNamingIT.java
private void assertFileContentEquals(File expected, RepositoryFile actual) throws IOException { FileInputStream inExp = null; InputStream inAct = null;/*from www .j a va2 s. c om*/ try { inExp = new FileInputStream(expected); try { inAct = repo.getDataForRead(actual.getId(), SimpleRepositoryFileData.class).getInputStream(); final String msg = "src{ " + expected.getName() + " } == repo{ " + actual.getName() + " }"; assertTrue(msg, IOUtils.contentEquals(inExp, inAct)); } finally { if (inAct != null) { inAct.close(); } } } finally { if (inExp != null) { inExp.close(); } } }
From source file:org.roda.core.model.ModelServiceTest.java
@Test public void testCreateDescriptiveMetadata() throws RODAException, IOException { // set up//from w w w . java2 s . co m final String aipId = IdUtils.createUUID(); model.createAIP(aipId, corporaService, DefaultStoragePath.parse(CorporaConstants.SOURCE_AIP_CONTAINER, CorporaConstants.SOURCE_AIP_ID), RodaConstants.ADMIN); final String newDescriptiveMetadataId = IdUtils.createUUID(); final Binary binary = corporaService .getBinary(DefaultStoragePath.parse(CorporaConstants.OTHER_DESCRIPTIVE_METADATA_STORAGEPATH)); final DescriptiveMetadata newDescriptiveMetadata = model.createDescriptiveMetadata(aipId, newDescriptiveMetadataId, binary.getContent(), CorporaConstants.OTHER_DESCRIPTIVE_METADATA_TYPE, CorporaConstants.OTHER_DESCRIPTIVE_METADATA_VERSION); // check if it is connected DescriptiveMetadata retrievedDescriptiveMetadata = model.retrieveDescriptiveMetadata(aipId, newDescriptiveMetadataId); assertEquals(newDescriptiveMetadata, retrievedDescriptiveMetadata); // check content Binary newDescriptiveMetadataBinary = storage .getBinary(ModelUtils.getDescriptiveMetadataStoragePath(newDescriptiveMetadata)); assertTrue(IOUtils.contentEquals(binary.getContent().createInputStream(), newDescriptiveMetadataBinary.getContent().createInputStream())); // cleanup model.deleteAIP(aipId); }
From source file:org.roda.core.model.ModelServiceTest.java
@Test public void testUpdateDescriptiveMetadata() throws RODAException, IOException { // set up//ww w . ja v a 2 s. c o m final String aipId = IdUtils.createUUID(); model.createAIP(aipId, corporaService, DefaultStoragePath.parse(CorporaConstants.SOURCE_AIP_CONTAINER, CorporaConstants.SOURCE_AIP_ID), RodaConstants.ADMIN); final Binary binary = corporaService .getBinary(DefaultStoragePath.parse(CorporaConstants.OTHER_DESCRIPTIVE_METADATA_STORAGEPATH)); Map<String, String> properties = new HashMap<>(); properties.put(RodaConstants.VERSION_ACTION, RodaConstants.VersionAction.UPDATED.toString()); final DescriptiveMetadata updatedDescriptiveMetadata = model.updateDescriptiveMetadata(aipId, CorporaConstants.DESCRIPTIVE_METADATA_ID, binary.getContent(), CorporaConstants.OTHER_DESCRIPTIVE_METADATA_TYPE, CorporaConstants.OTHER_DESCRIPTIVE_METADATA_VERSION, properties); // check if it is connected DescriptiveMetadata retrievedDescriptiveMetadata = model.retrieveDescriptiveMetadata(aipId, CorporaConstants.DESCRIPTIVE_METADATA_ID); assertEquals(updatedDescriptiveMetadata, retrievedDescriptiveMetadata); // check content StoragePath storagePath = ModelUtils.getDescriptiveMetadataStoragePath(updatedDescriptiveMetadata); Binary updatedDescriptiveMetadataBinary = storage.getBinary(storagePath); assertTrue(IOUtils.contentEquals(binary.getContent().createInputStream(), updatedDescriptiveMetadataBinary.getContent().createInputStream())); // check if binary version was created assertEquals(1, Iterables.size(storage.listBinaryVersions(storagePath))); // check if binary version message collisions are well treated model.updateDescriptiveMetadata(aipId, CorporaConstants.DESCRIPTIVE_METADATA_ID, binary.getContent(), CorporaConstants.OTHER_DESCRIPTIVE_METADATA_TYPE, CorporaConstants.OTHER_DESCRIPTIVE_METADATA_VERSION, properties); model.updateDescriptiveMetadata(aipId, CorporaConstants.DESCRIPTIVE_METADATA_ID, binary.getContent(), CorporaConstants.OTHER_DESCRIPTIVE_METADATA_TYPE, CorporaConstants.OTHER_DESCRIPTIVE_METADATA_VERSION, properties); model.updateDescriptiveMetadata(aipId, CorporaConstants.DESCRIPTIVE_METADATA_ID, binary.getContent(), CorporaConstants.OTHER_DESCRIPTIVE_METADATA_TYPE, CorporaConstants.OTHER_DESCRIPTIVE_METADATA_VERSION, properties); assertEquals(4, Iterables.size(storage.listBinaryVersions(storagePath))); // cleanup model.deleteAIP(aipId); }
From source file:org.roda.core.model.ModelServiceTest.java
@Test public void testCreateFile() throws RODAException, IOException { // set up/*w ww . j a va 2 s . c o m*/ final String aipId = IdUtils.createUUID(); model.createAIP(aipId, corporaService, DefaultStoragePath.parse(CorporaConstants.SOURCE_AIP_CONTAINER, CorporaConstants.SOURCE_AIP_ID), RodaConstants.ADMIN); final String newFileId = IdUtils.createUUID(); final List<String> newFileDirectoryPath = new ArrayList<>(); final StoragePath corporaFilePath = DefaultStoragePath.parse(CorporaConstants.OTHER_FILE_STORAGEPATH); final Binary binary = corporaService.getBinary(corporaFilePath); File createdFile = model.createFile(aipId, CorporaConstants.REPRESENTATION_1_ID, newFileDirectoryPath, newFileId, binary.getContent(), true); // check if it is connected File retrievedFile = model.retrieveFile(aipId, CorporaConstants.REPRESENTATION_1_ID, newFileDirectoryPath, newFileId); assertEquals(createdFile, retrievedFile); // check content Binary createdFileBinary = storage.getBinary(ModelUtils.getFileStoragePath(createdFile)); assertTrue(IOUtils.contentEquals(binary.getContent().createInputStream(), createdFileBinary.getContent().createInputStream())); // cleanup model.deleteAIP(aipId); }
From source file:org.roda.core.model.ModelServiceTest.java
@Test public void testUpdateFile() throws RODAException, IOException { // set up/*from w w w.ja v a 2s .c o m*/ final String aipId = IdUtils.createUUID(); model.createAIP(aipId, corporaService, DefaultStoragePath.parse(CorporaConstants.SOURCE_AIP_CONTAINER, CorporaConstants.SOURCE_AIP_ID), RodaConstants.ADMIN); final StoragePath corporaFilePath = DefaultStoragePath.parse(CorporaConstants.OTHER_FILE_STORAGEPATH); final Binary binary = corporaService.getBinary(corporaFilePath); final boolean createIfNotExists = false; final boolean notify = false; File createdFile = model.updateFile(aipId, CorporaConstants.REPRESENTATION_1_ID, CorporaConstants.REPRESENTATION_1_FILE_1_PATH, CorporaConstants.REPRESENTATION_1_FILE_1_ID, binary.getContent(), createIfNotExists, notify); // check if it is connected File retrievedFile = model.retrieveFile(aipId, CorporaConstants.REPRESENTATION_1_ID, CorporaConstants.REPRESENTATION_1_FILE_1_PATH, CorporaConstants.REPRESENTATION_1_FILE_1_ID); assertEquals(createdFile, retrievedFile); // check content Binary createdFileBinary = storage.getBinary(ModelUtils.getFileStoragePath(createdFile)); assertTrue(IOUtils.contentEquals(binary.getContent().createInputStream(), createdFileBinary.getContent().createInputStream())); // cleanup model.deleteAIP(aipId); }
From source file:org.roda.core.storage.AbstractStorageServiceTest.java
@Test(enabled = false) protected void testBinaryContent(Binary binary, ContentPayload providedPayload) throws IOException, GenericException { // check if content is the same assertTrue(IOUtils.contentEquals(providedPayload.createInputStream(), binary.getContent().createInputStream())); Path tempFile = Files.createTempFile("test", ".tmp"); Files.copy(binary.getContent().createInputStream(), tempFile, StandardCopyOption.REPLACE_EXISTING); // check size in bytes assertEquals(Long.valueOf(Files.size(tempFile)), binary.getSizeInBytes()); if (binary.getContentDigest() != null) { for (Entry<String, String> entry : binary.getContentDigest().entrySet()) { String digest = FSUtils.computeContentDigest(tempFile, entry.getKey()); assertEquals(digest, entry.getValue()); }//from www . ja v a2 s . c o m } // delete temp file Files.delete(tempFile); }
From source file:org.roda.core.storage.AbstractStorageServiceTest.java
public void testUpdateBinaryContent() throws RODAException, IOException { // create container final StoragePath containerStoragePath = StorageTestUtils.generateRandomContainerStoragePath(); getStorage().createContainer(containerStoragePath); // create binary final StoragePath binaryStoragePath = StorageTestUtils .generateRandomResourceStoragePathUnder(containerStoragePath); final ContentPayload payload = new RandomMockContentPayload(); getStorage().createBinary(binaryStoragePath, payload, false); // get created binary and save content to file final Binary binaryCreated = getStorage().getBinary(binaryStoragePath); assertNotNull(binaryCreated);//from w w w . j a v a 2 s . c o m final Path original = Files.createTempFile(binaryCreated.getStoragePath().getName(), ".tmp"); binaryCreated.getContent().writeToPath(original); // 1) update binary content final ContentPayload newPayload = new RandomMockContentPayload(); final Binary binaryUpdated = getStorage().updateBinaryContent(binaryStoragePath, newPayload, false, false); assertNotNull(binaryUpdated); try (InputStream stream = Files.newInputStream(original)) { assertFalse(IOUtils.contentEquals(stream, binaryUpdated.getContent().createInputStream())); } testBinaryContent(binaryUpdated, newPayload); // cleanup getStorage().deleteContainer(containerStoragePath); }
From source file:org.roda.core.storage.AbstractStorageServiceTest.java
public void testCopyBinaryToSameStorage() throws RODAException, IOException { // create container final StoragePath containerStoragePath = StorageTestUtils.generateRandomContainerStoragePath(); getStorage().createContainer(containerStoragePath); // create binary final StoragePath sourceBinaryStoragePath = StorageTestUtils .generateRandomResourceStoragePathUnder(containerStoragePath); final ContentPayload sourcePayload = new RandomMockContentPayload(); getStorage().createBinary(sourceBinaryStoragePath, sourcePayload, false); final StoragePath targetBinaryStoragePath = StorageTestUtils .generateRandomResourceStoragePathUnder(containerStoragePath); getStorage().copy(getStorage(), sourceBinaryStoragePath, targetBinaryStoragePath); final Binary sourceBinary = getStorage().getBinary(sourceBinaryStoragePath); final Binary targetBinary = getStorage().getBinary(targetBinaryStoragePath); assertEquals(sourceBinary.isDirectory(), targetBinary.isDirectory()); assertEquals(sourceBinary.getContentDigest(), targetBinary.getContentDigest()); assertEquals(sourceBinary.getSizeInBytes(), targetBinary.getSizeInBytes()); assertEquals(sourceBinary.isReference(), targetBinary.isReference()); assertTrue(IOUtils.contentEquals(sourceBinary.getContent().createInputStream(), targetBinary.getContent().createInputStream())); // cleanup/*from ww w . java 2 s . c o m*/ getStorage().deleteContainer(containerStoragePath); }