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.roda.core.storage.AbstractStorageServiceTest.java
public void testMoveBinaryToSameStorage() 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); // copy for comparison test final StoragePath copyBinaryStoragePath = StorageTestUtils .generateRandomResourceStoragePathUnder(containerStoragePath); getStorage().copy(getStorage(), sourceBinaryStoragePath, copyBinaryStoragePath); // move//from ww w. j a v a 2 s. co m final StoragePath targetBinaryStoragePath = StorageTestUtils .generateRandomResourceStoragePathUnder(containerStoragePath); getStorage().move(getStorage(), sourceBinaryStoragePath, targetBinaryStoragePath); // check with copy final Binary copyBinary = getStorage().getBinary(copyBinaryStoragePath); final Binary targetBinary = getStorage().getBinary(targetBinaryStoragePath); assertEquals(copyBinary.isDirectory(), targetBinary.isDirectory()); assertEquals(copyBinary.getContentDigest(), targetBinary.getContentDigest()); assertEquals(copyBinary.getSizeInBytes(), targetBinary.getSizeInBytes()); assertEquals(copyBinary.isReference(), targetBinary.isReference()); assertTrue(IOUtils.contentEquals(copyBinary.getContent().createInputStream(), targetBinary.getContent().createInputStream())); // test source does not exist try { getStorage().getBinary(sourceBinaryStoragePath); Assert.fail( "An exception should have been thrown while getting a binary that was moved but it didn't happened!"); } catch (NotFoundException e) { // do nothing } // cleanup getStorage().deleteContainer(containerStoragePath); }
From source file:org.roda.core.storage.AbstractStorageServiceTest.java
public void testBinaryVersions() throws RODAException, IOException { Map<String, String> properties = new HashMap<>(); properties.put(RodaConstants.VERSION_ACTION, RodaConstants.VersionAction.UPDATED.toString()); // create container final StoragePath containerStoragePath = StorageTestUtils.generateRandomContainerStoragePath(); getStorage().createContainer(containerStoragePath); // 1) create binary final StoragePath binaryStoragePath = StorageTestUtils .generateRandomResourceStoragePathUnder(containerStoragePath); final ContentPayload payload1 = new RandomMockContentPayload(); getStorage().createBinary(binaryStoragePath, payload1, false); // 2) create binary version String message1 = "v1"; properties.put(RodaConstants.VERSION_MESSAGE, message1); BinaryVersion v1 = getStorage().createBinaryVersion(binaryStoragePath, properties); // 3) update binary final ContentPayload payload2 = new RandomMockContentPayload(); getStorage().updateBinaryContent(binaryStoragePath, payload2, false, false); // 4) create binary version 2 String message2 = "v2"; properties.put(RodaConstants.VERSION_MESSAGE, message2); getStorage().createBinaryVersion(binaryStoragePath, properties); // 5) create a version with a message that already exists getStorage().createBinaryVersion(binaryStoragePath, properties); // 6) list binary versions CloseableIterable<BinaryVersion> binaryVersions = getStorage().listBinaryVersions(binaryStoragePath); List<BinaryVersion> reusableBinaryVersions = new ArrayList<>(); Iterables.addAll(reusableBinaryVersions, binaryVersions); assertEquals(3, reusableBinaryVersions.size()); // 7) get binary version BinaryVersion binaryVersion1 = getStorage().getBinaryVersion(binaryStoragePath, v1.getId()); // TODO compare properties assertEquals(message1, binaryVersion1.getProperties().get(RodaConstants.VERSION_MESSAGE)); if (!(getStorage() instanceof FedoraStorageService)) { assertNotNull(binaryVersion1.getCreatedDate()); }/*from www .ja va 2 s . c o m*/ assertTrue(IOUtils.contentEquals(payload1.createInputStream(), binaryVersion1.getBinary().getContent().createInputStream())); // 8) revert to previous version getStorage().revertBinaryVersion(binaryStoragePath, v1.getId()); Binary binary = getStorage().getBinary(binaryStoragePath); testBinaryContent(binary, payload1); // 9) delete binary version getStorage().deleteBinaryVersion(binaryStoragePath, v1.getId()); try { getStorage().getBinaryVersion(binaryStoragePath, v1.getId()); Assert.fail("Should have thrown NotFoundException"); } catch (NotFoundException e) { // do nothing } // 10) delete binary and all its history getStorage().deleteResource(binaryStoragePath); try { getStorage().getBinaryVersion(binaryStoragePath, v1.getId()); Assert.fail("Should have thrown NotFoundException"); } catch (NotFoundException e) { // do nothing } // cleanup getStorage().deleteContainer(containerStoragePath); }
From source file:org.roda.core.storage.StorageTestUtils.java
public static void testEntityEqualRecursively(StorageService sourceStorage, StoragePath sourceEntityStoragePath, StorageService targetStorage, StoragePath targetEntityStoragePath) throws NotFoundException, GenericException, AuthorizationDeniedException, RequestNotValidException, IOException { assertEquals(sourceEntityStoragePath.isFromAContainer(), targetEntityStoragePath.isFromAContainer()); Class<? extends Entity> sourceEntity = sourceStorage.getEntity(sourceEntityStoragePath); Class<? extends Entity> targetEntity = targetStorage.getEntity(targetEntityStoragePath); Iterable<Resource> sourceResourceList = null; if (Container.class.isAssignableFrom(sourceEntity) && Container.class.isAssignableFrom(targetEntity)) { sourceResourceList = sourceStorage.listResourcesUnderContainer(sourceEntityStoragePath, false); } else if (Directory.class.isAssignableFrom(sourceEntity) && Directory.class.isAssignableFrom(targetEntity)) { Directory sourceDirectory = sourceStorage.getDirectory(sourceEntityStoragePath); Directory targetDirectory = targetStorage.getDirectory(targetEntityStoragePath); assertEquals(sourceDirectory.isDirectory(), targetDirectory.isDirectory()); sourceResourceList = sourceStorage.listResourcesUnderDirectory(sourceEntityStoragePath, false); } else if (Binary.class.isAssignableFrom(sourceEntity) && Binary.class.isAssignableFrom(targetEntity)) { Binary sourceBinary = sourceStorage.getBinary(sourceEntityStoragePath); Binary targetBinary = targetStorage.getBinary(targetEntityStoragePath); 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())); } else {/*w w w .j a va2s. c o m*/ Assert.fail("Compared entities are not of the same type. source=" + sourceEntity + " target=" + targetEntity); } // Recursive call if (sourceResourceList != null) { for (Resource r : sourceResourceList) { StoragePath targetResourceStoragePath = DefaultStoragePath.parse(targetEntityStoragePath, r.getStoragePath().getName()); testEntityEqualRecursively(sourceStorage, r.getStoragePath(), targetStorage, targetResourceStoragePath); } } }
From source file:org.silverpeas.web.directory.servlets.ImageProfilTest.java
@Test public void testExtractImage() throws IOException { ImageProfil imageProfil = new ImageProfil("SilverAdmin.jpg"); try (InputStream fis = this.getClass().getResourceAsStream("/SilverAdmin.jpg")) { imageProfil.saveImage(fis);// w w w . j ava2 s. c om } try (InputStream image = imageProfil.getImage(); InputStream fis = this.getClass().getResourceAsStream("/SilverAdmin.jpg")) { IOUtils.contentEquals(fis, image); } }
From source file:org.sipfoundry.sipxconfig.components.SkinServletTestUi.java
private void assertAssetEquals(String assetPath, String expectedAsset) throws Exception { URL logoUrl = new URL(SiteTestHelper.getBaseUrl() + assetPath); InputStream actual = logoUrl.openStream(); InputStream expected = getClass().getResourceAsStream(expectedAsset); assertTrue(IOUtils.contentEquals(expected, actual)); }
From source file:org.sipfoundry.sipxconfig.phone.polycom.PolycomPhoneTest.java
public void testFormat() throws Exception { InputStream in = getClass().getResourceAsStream("unformatted.xml"); ByteArrayOutputStream out = new ByteArrayOutputStream(); FormatFilter format = new PolycomPhone.FormatFilter(); format.copy(in, out);//www. j a v a 2 s . c om Reader expected = new InputStreamReader(getClass().getResourceAsStream("formatted.xml")); Reader actual = new StringReader(out.toString()); IOUtils.contentEquals(expected, actual); }
From source file:org.sipfoundry.sipxconfig.upload.ZipUploadTest.java
public void testDeployUndeploy() throws Exception { Upload.deployZipFile(m_expandDir, m_zipFile, new FileSetting()); File file1 = new File(m_expandDir, "zip-test/subdir/file1.txt"); assertTrue(file1.exists());/*from www.j a va 2 s .c om*/ assertTrue(IOUtils.contentEquals(getClass().getResourceAsStream("file1.txt"), new FileInputStream(file1))); File file3 = new File(m_expandDir, "zip-test/file3.bin"); assertTrue(file3.exists()); InputStream stream3 = getClass().getResourceAsStream("file3.bin"); assertTrue(IOUtils.contentEquals(stream3, new FileInputStream(file3))); Upload.undeployZipFile(m_expandDir, m_zipFile, new FileSetting()); assertFalse(file1.exists()); }
From source file:org.sonatype.nexus.configuration.application.source.AbstractApplicationConfigurationSourceTest.java
@Test public void testConfigStream() throws Exception { configurationSource = getConfigurationSource(); // not using load here since File config would load it and store it // thus changing it (but no content change!) copyDefaultConfigToPlace();// www. java 2 s . c o m try (InputStream configStream = configurationSource.getConfigurationAsStream(); InputStream originalStream = getOriginatingConfigurationInputStream()) { assertTrue(IOUtils.contentEquals(configStream, originalStream)); } }
From source file:org.sonatype.nexus.plugins.lvo.strategy.AbstractRemoteDiscoveryStrategyTest.java
@Test public void testDirect() throws Exception { server = Server.withPort(0).serve("/test.properties").withBehaviours(content(content)).start(); AbstractRemoteDiscoveryStrategy underTest = create(); AbstractRemoteDiscoveryStrategy.RequestResult result = underTest .handleRequest(server.getUrl().toString() + "/test.properties"); assertThat(result.getInputStream(), notNullValue()); assertThat("content did not match", IOUtils.contentEquals(result.getInputStream(), new ByteArrayInputStream(content.getBytes())), is(true));/*from www . j a v a 2 s . c o m*/ }
From source file:org.sonatype.nexus.plugins.lvo.strategy.AbstractRemoteDiscoveryStrategyTest.java
@Test public void testProxy() throws Exception { server = Proxy.withPort(0).serve("/test.properties").withBehaviours(content(content)).start(); RemoteProxySettings remoteCfg = remoteStorageContext.getRemoteProxySettings(); remoteCfg.setHostname("localhost"); remoteCfg.setPort(server.getPort()); AbstractRemoteDiscoveryStrategy underTest = create(); result = underTest.handleRequest("http://invalid.url/test.properties"); assertThat(result.getInputStream(), notNullValue()); assertThat("content did not match", IOUtils.contentEquals(result.getInputStream(), new ByteArrayInputStream(content.getBytes())), is(true));/*ww w . j ava 2 s . c om*/ }