/** * Assert an asset is actually in the file * * @throws IOException * @throws IllegalArgumentException */ private void assertAssetInTar(final File archive, final ArchivePath path, final Asset asset) throws IllegalArgumentException, IOException { final InputStream in = this.getEntryFromTarFile(archive, path); byte[] expectedContents = IOUtil.asByteArray(asset.openStream()); byte[] actualContents = IOUtil.asByteArray(in); Assert.assertArrayEquals(expectedContents, actualContents); }
/** * Assert an asset is actually in the Zip file * * @throws IOException * @throws IllegalArgumentException */ private void assertAssetInZip(ZipFile expectedZip, ArchivePath path, Asset asset) throws IllegalArgumentException, IOException { final ZipEntry entry = this.getEntryFromZip(expectedZip, path); final byte[] expectedContents = IOUtil.asByteArray(asset.openStream()); final byte[] actualContents = IOUtil.asByteArray(expectedZip.getInputStream(entry)); Assert.assertArrayEquals(expectedContents, actualContents); }
/** * Assert an asset is actually in the Zip file * * @throws IOException * @throws IllegalArgumentException */ private void assertAssetInZip(ZipFile expectedZip, ArchivePath path, Asset asset) throws IllegalArgumentException, IOException { final ZipEntry entry = this.getEntryFromZip(expectedZip, path); final byte[] expectedContents = IOUtil.asByteArray(asset.openStream()); final byte[] actualContents = IOUtil.asByteArray(expectedZip.getInputStream(entry)); Assert.assertArrayEquals(expectedContents, actualContents); }
/** * {@inheritDoc} * * @see org.jboss.shrinkwrap.impl.base.exporter.StreamExporterTestBase#getContentsFromExportedFile(java.io.File, * org.jboss.shrinkwrap.api.ArchivePath) */ @Override protected InputStream getContentsFromExportedFile(final File file, final ArchivePath path) throws IOException { // Precondition checks assert file != null : "file must be specified"; assert path != null : "path must be specified"; // Get as Zip File final ZipFile zipFile = new ZipFile(file); final ZipEntry entry = zipFile.getEntry(PathUtil.optionallyRemovePrecedingSlash(path.get())); if (entry == null) { return null; } final byte[] actualContents = IOUtil.asByteArray(zipFile.getInputStream(entry)); return new ByteArrayInputStream(actualContents); }
/** * {@inheritDoc} * * @see org.jboss.shrinkwrap.impl.base.exporter.StreamExporterTestBase#getContentsFromExportedFile(java.io.File, * org.jboss.shrinkwrap.api.ArchivePath) */ @Override protected InputStream getContentsFromExportedFile(final File file, final ArchivePath path) throws IOException { // Precondition checks assert file != null : "file must be specified"; assert path != null : "path must be specified"; // Get as Zip File final ZipFile zipFile = new ZipFile(file); final ZipEntry entry = zipFile.getEntry(PathUtil.optionallyRemovePrecedingSlash(path.get())); if (entry == null) { return null; } final byte[] actualContents = IOUtil.asByteArray(zipFile.getInputStream(entry)); return new ByteArrayInputStream(actualContents); }
/** * {@inheritDoc} * * @see org.jboss.shrinkwrap.impl.base.exporter.StreamExporterTestBase#ensureAssetInExportedFile(java.io.File, * org.jboss.shrinkwrap.api.ArchivePath, org.jboss.shrinkwrap.api.asset.Asset) */ protected final void ensureAssetInExportedFile(final File file, final ArchivePath path, final Asset asset) throws IOException { // Precondition checks assert file != null : "file must be specified"; assert path != null : "path must be specified"; assert asset != null : "asset must be specified"; // Get as Exported File final InputStream actualStream = this.getContentsFromExportedFile(file, path); assert actualStream != null : "No contents found at path " + path + " in " + file.getAbsolutePath(); byte[] actualContents = IOUtil.asByteArray(actualStream); byte[] expectedContents = IOUtil.asByteArray(asset.openStream()); Assert.assertArrayEquals(expectedContents, actualContents); } }
@Test public void shouldCreateServiceProviderFile() throws Exception { Asset asset = new ServiceProviderAsset(TestImpl1.class, TestImpl2.class); byte[] expectedContent = (TestImpl1.class.getName() + "\n" + TestImpl2.class.getName() + "\n").getBytes(); byte[] content = IOUtil.asByteArray(asset.openStream()); Assert.assertArrayEquals(expectedContent, content); }
/** * Assert an asset is actually in the exploded directory * * @throws FileNotFoundException * @throws IOException * @throws IllegalArgumentException */ private void assertAssetInExploded(File explodedDirectory, ArchivePath path, Asset asset) throws FileNotFoundException { File assetFile = new File(explodedDirectory, path.get()); Assert.assertNotNull(assetFile); Assert.assertTrue(assetFile.exists()); byte[] expectedContents = IOUtil.asByteArray(asset.openStream()); InputStream inputStream = new FileInputStream(assetFile); byte[] actualContents = IOUtil.asByteArray(inputStream); Assert.assertArrayEquals(expectedContents, actualContents); } }
/** * Compare two Asset with each other. <br/> * Does not check instances but content. * * @param one * Asset to compare * @param two * Asset to compare * @return true if they are equal * @throws IllegalArgumentException * If either asset is not specified */ private boolean compareAssets(final Asset one, final Asset two) throws IllegalArgumentException { // Precondition check Validate.notNull(one, "Asset one must be specified"); Validate.notNull(two, "Asset two must be specified"); byte[] oneData = IOUtil.asByteArray(one.openStream()); byte[] twoData = IOUtil.asByteArray(two.openStream()); return Arrays.equals(oneData, twoData); }
importedArchive.contains(new BasicPath(originalEntry.getName()))); byte[] originalContent = IOUtil.asByteArray(testZip.getInputStream(originalEntry)); final Node node = importedArchive.get(new BasicPath(originalEntry.getName())); byte[] importedContent = IOUtil.asByteArray(node.getAsset().openStream());
@Test public void shouldExportToStoredZip() throws IOException { final File target = new File("target"); ShrinkWrap.create(JavaArchive.class).addClass(ZipStoredExporterTestCase.class) .add(new StringAsset("My file content"), "content.txt") .as(ZipStoredExporter.class).exportTo(new File(target, "test-exporter.zip"), true); final File generatedFile = new File(target, "test-exporter.zip"); Assert.assertTrue(generatedFile.length() > 0); final InputStream contentsFromExportedFile = getContentsFromExportedFile(generatedFile, ArchivePaths.create("/org/jboss/shrinkwrap/impl/base/exporter/ZipStoredExporterTestCase.class")); final byte[] content = IOUtil.asByteArray(contentsFromExportedFile); Assert.assertTrue(content.length > 0); final InputStream contentsFromExportedFile2 = getContentsFromExportedFile(generatedFile, ArchivePaths.create("/content.txt")); final byte[] content2 = IOUtil.asByteArray(contentsFromExportedFile2); Assert.assertTrue(content.length > 0); Assert.assertEquals("My file content", new String(content2)); }
byte[] importedContent = IOUtil.asByteArray(node.getAsset().openStream());
byte[] importedContent = IOUtil.asByteArray(node.getAsset().openStream());
byte[] importedContent = IOUtil.asByteArray(node.getAsset().openStream());