Refine search
protected File buildLargeJar() throws Exception { final String fileName = "large.jar"; final JavaArchive archive = ShrinkWrap.create( JavaArchive.class, fileName ); // Build a large jar by adding a lorem ipsum file repeatedly. final Path loremipsumTxtFile = Paths.get( ScannerTests.class.getResource( "/org/hibernate/jpa/test/packaging/loremipsum.txt" ).toURI() ); for ( int i = 0; i < 100; i++ ) { ArchivePath path = ArchivePaths.create( "META-INF/file" + i ); archive.addAsResource( loremipsumTxtFile.toFile(), path ); } File testPackage = new File( shrinkwrapArchiveDirectory, fileName ); archive.as( ZipExporter.class ).exportTo( testPackage, true ); return testPackage; }
/** * Creates a new {@link ArchivePath} using the specified base and specified relative context. * * @param basePath * A absolute path * @param context * A relative path to basePath * @return a new path */ public static ArchivePath create(String basePath, String context) { return createInstance(new Class<?>[] { String.class, String.class }, new Object[] { basePath, context }); }
@Deployment public static JavaArchive createTestArchive() { return ShrinkWrap .create(JavaArchive.class) .addClasses(ConversationBoundaryInterceptor.class, ConversationalBean.class, MockLogger.class, MockLoggerProducer.class) .addAsManifestResource( ConversationBoundaryInterceptorTest.class.getPackage().getName().replaceAll("\\.", "/") + "/ConversationBoundaryInterceptorTest-beans.xml", ArchivePaths.create("beans.xml")); }
@Deployment public static JavaArchive getDeployment() { JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "test.jar").addPackages(true, Root.class.getPackage()) .addPackages(true, RenderRoot.class.getPackage()).addPackages(true, SolderRoot.class.getPackage()) .addAsManifestResource("META-INF/beans.xml", ArchivePaths.create("beans.xml")); return archive; }
@Deployment public static WebArchive createDeployment() { File[] libs = Maven.resolver() .loadPomFromFile("pom.xml").resolve("org.kie:kie-spring", "com.google.protobuf:protobuf-java") .withTransitivity().asFile(); WebArchive drools = ShrinkWrap.create(WebArchive.class) .addAsLibraries(libs) .addAsResource("spring/sample.drl") .addAsResource(APL_CONTEXT) .addAsResource("META-INF/maven/pom.properties") .addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml")); System.out.println(drools.toString(true)); return drools; }
@Test public void testImportArchiveAsTypeFromArchivePath() throws Exception { String resourcePath = "/test/cl-test.jar"; GenericArchive archive = ShrinkWrap.create(GenericArchive.class).add( new FileAsset(TestIOUtil.createFileFromResourceName("cl-test.jar")), resourcePath); JavaArchive jar = archive.getAsType(JavaArchive.class, ArchivePaths.create(resourcePath), ArchiveFormat.ZIP) .add(new StringAsset("test file content"), "test.txt"); Assert.assertEquals("JAR imported with wrong name", resourcePath, jar.getName()); Assert.assertNotNull("Class in JAR not imported", jar.get("test/classloader/DummyClass.class")); Assert.assertNotNull("Inner Class in JAR not imported", jar.get("test/classloader/DummyClass$DummyInnerClass.class")); Assert.assertNotNull("Should contain an archive asset", ((ArchiveAsset) archive.get(resourcePath).getAsset()) .getArchive().get("test.txt")); }
@Deployment public static WebArchive createDeployment() { File[] libs = Maven.resolver() .loadPomFromFile("pom.xml").resolve("org.drools:drools-compiler", "com.google.protobuf:protobuf-java") .withTransitivity().asFile(); JavaArchive kjar = ShrinkWrap.create(JavaArchive.class) .addClass(TestFactDeclaredInJar.class) .addAsResource("basic/sample.drl") .addAsResource("META-INF/kmodule.xml") .addAsResource("META-INF/maven/pom.properties"); WebArchive drools = ShrinkWrap.create(WebArchive.class) .addAsLibraries(libs) .addAsLibrary(kjar) .addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml")); System.out.println(drools.toString(true)); return drools; }
@Test public void shouldBeAbleToExportArchive() throws Exception { String content = ShrinkWrap .create(WebArchive.class, "test.jar") .addAsResource(new File("src/test/resources/tooling/arquillian.xml"), ArchivePaths.create("resource.xml")) .addAsResource("tooling/arquillian.xml", ArchivePaths.create("resource2.xml")) .addAsResource(new File("src/test/resources/tooling/arquillian.xml").toURI().toURL(), ArchivePaths.create("resource3.xml")).addClass(ToolingDeploymentFormatterTestCase.class) .addAsServiceProvider(Service.class, ServiceImpl.class) .addAsLibrary(ShrinkWrap.create(JavaArchive.class, "test.jar").addClass(ToolingDeploymentFormatter.class)) .toString(new ToolingDeploymentFormatter(getClass())); // TODO: do some output Assertions.. Assert.assertNotNull(content); System.out.println(content); }
public Deployment(String archiveName, Package pkg, boolean show) { this.archiveName = archiveName; ArchivePath metaInf = ArchivePaths.create("META-INF"); archive = ShrinkWrap.create(JavaArchive.class, archiveName); archive.addPackage(pkg); File sourceMetaInf = getSourceMetaInfDir(); addFiles(archive, sourceMetaInf, metaInf); System.out.println(archive.toString(show)); realArchive = new File(getOutputDir(), archive.getName()); archive.as(ZipExporter.class).exportTo(realArchive, true); }
@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)); }
public String format(Archive<?> archive) throws IllegalArgumentException { StringBuilder xml = new StringBuilder(); xml.append("<?xml version=\"1.0\"?>\n<deployment") .append(" name=\"").append(archive.getName()).append("\"") .append(" testclass=\"").append(testClass.getName()).append("\"") .append(">\n"); formatNode(archive.get(ArchivePaths.root()), xml); xml.append("</deployment>").append("\n"); return xml.toString(); }
public Deployment(String archiveName, Package[] pkgs, boolean show) { ArchivePath metaInf = ArchivePaths.create("META-INF"); JavaArchive archive = ShrinkWrap.create(JavaArchive.class, archiveName); for(Package pkg : pkgs) { archive.addPackage(pkg); } File sourceMetaInf = getSourceMetaInfDir(archiveName); addFiles(archive, sourceMetaInf, metaInf); System.out.println(archive.toString(show)); realArchive = createArchive(archive); }
@Test public void testHandlerIsCalledWhenAddingAssetWithArchivePathAndExporter() throws Exception { final ReplaceAssetHandler handler1 = new ReplaceAssetHandler("unexpected"); final ReplaceAssetHandler handler2 = new ReplaceAssetHandler("EXPECTED"); getArchive().addHandlers(handler1, handler2); final ArchivePath path = ArchivePaths.create("/path/to/dir"); final Archive<JavaArchive> asset = ShrinkWrap .create(JavaArchive.class, "asset.zip") .add(new StringAsset("asset content"), "content.txt"); getArchive().add(asset, path, ZipExporter.class); Assert.assertTrue("Handler not called", handler1.called); Assert.assertEquals("Wrong asset received by handler", handler1.returnedAsset, handler2.savedAsset); }
/** * Ensure we can get a added Archive as a specific type * * @throws Exception */ @Test public void testGetAsTypeArchivePath() throws Exception { Archive<?> archive = getArchive(); GenericArchive child = ShrinkWrap.create(GenericArchive.class); archive.add(child, "/", ZipExporter.class); GenericArchive found = archive.getAsType(GenericArchive.class, ArchivePaths.create(child.getName())); Assert.assertNotNull(found); }
public LinkedList<Archive<?>> findNodes(final String name) { final LinkedList<Archive<?>> items = new LinkedList<>(); for (final Archive<?> a : archives) { final boolean isWar = WebArchive.class.isInstance(a); final Node node = a.get(ArchivePaths.create((isWar ? "/WEB-INF/classes/" : "") + name)); if (node != null) { items.add(a); } } return items; }
@Test public void shouldGenerateDependencies() throws Exception { Archive<?> archive = new JUnitDeploymentAppender().createAuxiliaryArchive(); Assert.assertTrue( "Should have added Extension", archive.contains( ArchivePaths.create("/META-INF/services/org.jboss.arquillian.container.test.spi.TestRunner"))); Assert.assertTrue( "Should have added TestRunner Impl", archive.contains(ArchivePaths.create("/org/jboss/arquillian/junit/container/JUnitTestRunner.class"))); } }
@Test public void testHandlerIsCalledWhenAddingAssetWithArchivePathAndName() throws Exception { final ReplaceAssetHandler handler1 = new ReplaceAssetHandler("unexpected"); final ReplaceAssetHandler handler2 = new ReplaceAssetHandler("EXPECTED"); getArchive().addHandlers(handler1, handler2); final ArchivePath path = ArchivePaths.create("/path/to/dir"); final StringAsset asset = new StringAsset("Original"); getArchive().add(asset, path, "asset.txt"); String actual = readStringAsset(ArchivePaths.create(path, "/asset.txt")); Assert.assertEquals("Handler not called", "EXPECTED", actual); Assert.assertEquals("Wrong asset received by handler", asset, handler1.savedAsset); Assert.assertEquals("Wrong asset received by handler", handler1.returnedAsset, handler2.savedAsset); }
@Override public Manifest getManifest() throws IOException { ArchivePath manifestPath = ArchivePaths.create("META-INF/MANIFEST.MF"); final Archive<?> archive = this.getArchive(); if (archive.contains(manifestPath)) { return new Manifest(archive.get(manifestPath).getAsset().openStream()); } return null; }