Example usage for org.apache.commons.io IOUtils contentEquals

List of usage examples for org.apache.commons.io IOUtils contentEquals

Introduction

In this page you can find the example usage for org.apache.commons.io IOUtils contentEquals.

Prototype

public static boolean contentEquals(Reader input1, Reader input2) throws IOException 

Source Link

Document

Compare the contents of two Readers to determine if they are equal or not.

Usage

From source file:org.dataconservancy.packaging.tool.impl.generator.BagItPackageAssemblerTest.java

@Test
public void testCreateResourceForOneDataFile() throws IOException, URISyntaxException {
    // Prepare and create the resource

    InputStream df1IS = this.getClass()
            .getResourceAsStream("/TestContent/ProjectOne/Collection One/DataItem One/Data File One.txt");
    URL df1URL = this.getClass()
            .getResource("/TestContent/ProjectOne/Collection One/DataItem One/Data File One.txt");
    URI result = underTest.createResource("/ProjectOne/Collection One/DataItem One/Data File One.txt",
            PackageResourceType.DATA, df1IS);
    // Verify that the URI is as expected
    String expectedURI = "file:///" + packageName + "/data/"
            + contentLocationURI.relativize(df1URL.toURI()).toString();
    assertTrue(expectedURI.equals(result.toString()));

    // Verify the content of the URI is as expected
    URI contentURI = underTest.getResolvableURI(result);
    File fileWithContent = new File(contentURI);
    InputStream inputStream = new FileInputStream(fileWithContent);

    IOUtils.contentEquals(inputStream, df1IS);
    inputStream.close();//from   w  w w.j a  va 2  s  .c  o  m
}

From source file:org.dataconservancy.packaging.tool.impl.generator.BagItPackageAssemblerTest.java

@Test
public void testCreateResourceForTwoDataFilesWithSameName() throws IOException, URISyntaxException {
    // Prepare and create the resource
    InputStream df1ISa = this.getClass()
            .getResourceAsStream("/TestContent/ProjectOne/Collection One/DataItem One/Data File One.txt");
    URL df1URLa = this.getClass()
            .getResource("/TestContent/ProjectOne/Collection One/DataItem One/Data File One.txt");
    URI resulta = underTest.createResource("/ProjectOne/Collection One/DataItem One/Data File One.txt",
            PackageResourceType.DATA, df1ISa);

    InputStream df1ISb = this.getClass()
            .getResourceAsStream("/TestContent/ProjectOne/CollectionTwo/DataItemTwo/DataFileOne.txt");
    URL df1URLb = this.getClass()
            .getResource("/TestContent/ProjectOne/CollectionTwo/DataItemTwo/DataFileOne.txt");
    URI resultb = underTest.createResource("/ProjectOne/CollectionTwo/DataItemTwo/DataFileOne.txt",
            PackageResourceType.DATA, df1ISb);

    // Verify that the URI is as expected
    String expectedURIa = "file:///" + packageName + "/data/"
            + contentLocationURI.relativize(df1URLa.toURI()).toString();
    assertTrue(expectedURIa.equals(resulta.toString()));

    // Verify that the URI is as expected
    String expectedURIb = "file:///" + packageName + "/data/"
            + contentLocationURI.relativize(df1URLb.toURI()).toString();
    assertTrue(expectedURIb.equals(resultb.toString()));

    // Verify the content of the URI is as expected
    URI contentURIa = underTest.getResolvableURI(resulta);
    URI contentURIb = underTest.getResolvableURI(resultb);
    File fileWithContenta = new File(contentURIa);
    File fileWithContentb = new File(contentURIb);
    InputStream inputStreama = new FileInputStream(fileWithContenta);
    InputStream inputStreamb = new FileInputStream(fileWithContentb);

    IOUtils.contentEquals(inputStreama, df1ISa);
    IOUtils.contentEquals(inputStreamb, df1ISa);

    inputStreama.close();//from w  ww  .ja  va2s  .c  o  m
    inputStreamb.close();
}

From source file:org.eclipse.hawkbit.mgmt.rest.resource.MgmtSoftwareModuleResourceTest.java

private void assertArtifact(final SoftwareModule sm, final byte[] random) throws IOException {
    // check result in db...
    // repo//from   ww  w .j a  va 2  s  .  c om
    assertThat(artifactManagement.count()).as("Wrong artifact size").isEqualTo(1);

    // binary
    try (InputStream fileInputStream = artifactManagement
            .loadArtifactBinary(
                    softwareModuleManagement.get(sm.getId()).get().getArtifacts().get(0).getSha1Hash())
            .get().getFileInputStream()) {
        assertTrue("Wrong artifact content",
                IOUtils.contentEquals(new ByteArrayInputStream(random), fileInputStream));
    }

    // hashes
    assertThat(artifactManagement.getByFilename("origFilename").get().getSha1Hash()).as("Wrong sha1 hash")
            .isEqualTo(HashGeneratorUtils.generateSHA1(random));

    assertThat(artifactManagement.getByFilename("origFilename").get().getMd5Hash()).as("Wrong md5 hash")
            .isEqualTo(HashGeneratorUtils.generateMD5(random));

    // metadata
    assertThat(softwareModuleManagement.get(sm.getId()).get().getArtifacts().get(0).getFilename())
            .as("wrong metadata of the filename").isEqualTo("origFilename");
}

From source file:org.eclipse.hawkbit.repository.jpa.ArtifactManagementTest.java

@Test
@Description("Loads an artifact binary based on given ID.")
public void loadStreamOfArtifact() throws NoSuchAlgorithmException, IOException {
    final int artifactSize = 5 * 1024;
    final byte[] randomBytes = randomBytes(artifactSize);
    try (final InputStream input = new ByteArrayInputStream(randomBytes)) {
        final Artifact artifact = createArtifactForSoftwareModule("file1",
                testdataFactory.createSoftwareModuleOs().getId(), artifactSize, input);
        try (final InputStream inputStream = artifactManagement.loadArtifactBinary(artifact.getSha1Hash()).get()
                .getFileInputStream()) {
            assertTrue("The stored binary matches the given binary",
                    IOUtils.contentEquals(new ByteArrayInputStream(randomBytes), inputStream));
        }/*from www.  j a va2  s .co  m*/
    }
}

From source file:org.eclipse.mylyn.internal.context.breakpoints.BreakpointsContextUtilTest.java

@Test
public void testExportBreakpoints() throws Exception {
    createProject();// w  ww. ja  va  2s .c  o m
    InputStream expectedResult = new FileInputStream(new File("testdata/breakpointFile.xml")); //$NON-NLS-1$
    IBreakpoint breakpoint = createTestBreakpoint();
    List<IBreakpoint> breakpoints = new ArrayList<IBreakpoint>();
    breakpoints.add(breakpoint);
    InputStream exportedBreakpoints = BreakpointsContextUtil.exportBreakpoints(breakpoints);
    assertTrue(IOUtils.contentEquals(expectedResult, exportedBreakpoints));
}

From source file:org.eclipse.mylyn.internal.context.breakpoints.WorkspaceSaveParticipantTest.java

@Test
public void testSaveStateWithBreakpoints() throws Exception {
    createProject();/*from   ww w . j  av a  2  s  .  c om*/
    File breakpointFile = new File("testdata/breakpointFile.xml"); //$NON-NLS-1$
    IBreakpoint breakpoint = createTestBreakpoint();
    List<IBreakpoint> breakpoints = new ArrayList<IBreakpoint>();
    breakpoints.add(breakpoint);
    breakpointsContextManager.setContextBreakpoints(breakpoints);

    participant.saving(saveContext);

    assertTrue(getStateFile().exists());
    IOUtils.contentEquals(new FileInputStream(getStateFile()), new FileInputStream(breakpointFile));
    verify(saveContext).needSaveNumber();
}

From source file:org.eclipse.mylyn.internal.debug.ui.BreakpointsStateUtilTest.java

@Test
public void testSaveState() throws Exception {
    breakpointManager.addBreakpoint(breakpoint);
    assertEquals(1, breakpointManager.getBreakpoints().length);

    objectUnderTest.saveState();//from   w ww  .  j  a  va  2s .co m

    assertTrue(pluginStateFile.exists());
    FileInputStream stateFile = new FileInputStream(pluginStateFile);
    InputStream expectedResult = new FileInputStream(new File("testdata/breakpointFile.xml")); //$NON-NLS-1$
    assertTrue(IOUtils.contentEquals(expectedResult, stateFile));
}

From source file:org.geoserver.gwc.ConfigurableBlobStoreTest.java

/**
 * Checks if the streams are equals, note that the {@link InputStream}s are also closed.
 *//*from  w  w w.j ava2s. c o  m*/
private void checkInputStreams(InputStream is, InputStream is2) throws IOException {
    try {
        assertTrue(IOUtils.contentEquals(is, is2));
    } finally {
        try {
            is.close();
        } catch (IOException e) {
            LOGGER.log(Level.SEVERE, e.getMessage(), e);
            assertTrue(false);
        }
        try {
            is2.close();
        } catch (IOException e) {
            LOGGER.log(Level.SEVERE, e.getMessage(), e);
            assertTrue(false);
        }
    }
}

From source file:org.geowebcache.blobstore.memory.distributed.HazelcastCacheProviderTest.java

/**
 * Checks if the streams are equals, note that this method also closes the {@link InputStream}
 *///from  w  ww.j  av  a  2  s  .  c  o  m
private void checkInputStreams(InputStream is, InputStream is2) throws IOException {
    try {
        // Ensure the two contents are equal
        assertTrue(IOUtils.contentEquals(is, is2));
    } finally {
        // Closing streams
        try {
            is.close();
        } catch (IOException e) {
            LOG.error(e.getMessage(), e);
            assertTrue(false);
        }
        try {
            is2.close();
        } catch (IOException e) {
            LOG.error(e.getMessage(), e);
            assertTrue(false);
        }
    }
}

From source file:org.geowebcache.sqlite.MbtilesPBFTest.java

@Test
public void testGetTileDefaultUnzip() throws Exception {
    MbtilesConfiguration configuration = getDefaultConfiguration();
    MbtilesBlobStore store = new MbtilesBlobStore(configuration);
    addStoresToClean(store);//from w w w. j a v  a2 s.  co m
    TileObject tile = TileObject.createQueryTileObject(layer, new long[] { 0, 0, 0 }, "EPSG:900913",
            ApplicationMime.mapboxVector.getFormat(), null);
    assertThat(store.get(tile), is(true));
    try (InputStream is = MBTilesFileVectorTileTest.class.getResourceAsStream("tile_data.pbf.gz")) {
        assertTrue(IOUtils.contentEquals(tile.getBlob().getInputStream(), is));
    }
}