Java Code Examples for org.jboss.shrinkwrap.api.spec.WebArchive#addAsResource()

The following examples show how to use org.jboss.shrinkwrap.api.spec.WebArchive#addAsResource() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public void process(TestDeployment testDeployment, Archive<?> protocolArchive) {
    WebArchive war = (WebArchive) protocolArchive;
    war.addAsWebInfResource("WEB-INF/jboss-web.xml", "jboss-web.xml");
    String[] deps = {
            "io.smallrye:smallrye-config",
            "io.smallrye:smallrye-metrics",
            "io.smallrye:smallrye-metrics-testsuite-common",
            "org.eclipse.microprofile.metrics:microprofile-metrics-api",
            "org.jboss.weld.servlet:weld-servlet-core"
    };

    File[] dependencies = Maven.resolver().loadPomFromFile(new File("pom.xml")).resolve(deps).withTransitivity().asFile();

    war.addAsLibraries(dependencies);

    war.addClass(SmallRyeBeanArchiveHandler.class);
    war.addClass(MetricsHttpServlet.class);
    war.addClass(MetricsInitializer.class);
    war.addAsResource("io/smallrye/metrics/base-metrics.properties", "/io/smallrye/metrics/base-metrics.properties");
    war.addAsServiceProvider(BeanArchiveHandler.class, SmallRyeBeanArchiveHandler.class);
    war.addAsServiceProvider(Extension.class, ConfigExtension.class);
    war.addAsServiceProvider(ConfigProviderResolver.class, SmallRyeConfigProviderResolver.class);
}
 
Example 2
public void process(WebArchive webArchive) {
    Node metaInfConfig = webArchive.get("/META-INF/microprofile-config.properties");
    
    if (metaInfConfig == null) {
        if (webArchive.get("/WEB-INF/classes/publicKey.pem") != null) {
            webArchive.addAsResource("META-INF/public-key.properties", "META-INF/microprofile-config.properties");
        } else {
            webArchive.addAsResource("META-INF/microprofile-config.properties");
        }
    } else {
        webArchive.addAsResource(metaInfConfig.getAsset(), "META-INF/microprofile-config.properties");
        webArchive.delete("/META-INF/microprofile-config.properties");
    }
    
    System.out.printf("WebArchive: %s\n", webArchive.toString(true));
}
 
Example 3
public AutoDeployTestSupport(String testId) {

        File tmp = new File(System.getProperty("java.io.tmpdir"));
        tmpDir = new File(tmp, testId);
        cleanFile(tmpDir);
        tmpDir.mkdirs();
        tmpDir.deleteOnExit();

        ClassLoader tccl = Thread.currentThread().getContextClassLoader();
        URL webxml = tccl.getResource("basic.war/web.xml");
        WebArchive war = ShrinkWrap.create(WebArchive.class, "basic.war");
        URL resource = tccl.getResource("basic.war/index.html");
        if (resource == null)
            throw new IllegalStateException("basic.war/index.html not found");
        war.addAsResource(resource, "index.html");
        war.setWebXML(webxml);

        basicWar = new File(tmpDir, "basic.war");
        basicWar.deleteOnExit();
        war.as(ZipExporter.class).exportTo(basicWar, true);
    }
 
Example 4
@Deployment
public static WebArchive deployment() {
    final WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxb-integration-tests.war");
    archive.addPackage(Customer.class.getPackage());
    archive.addClasses(XMLUtils.class);
    archive.addAsResource(new StringAsset("Customer"), "org/wildfly/camel/test/jaxb/model/jaxb.index");
    archive.addAsResource("jaxb/customer.xml", "customer.xml");
    archive.setManifest(new Asset() {
        @Override
        public InputStream openStream() {
            ManifestBuilder builder = new ManifestBuilder();
            builder.addManifestHeader("Dependencies", "org.jdom2");
            return builder.openStream();
        }
    });
    return archive;
}
 
Example 5
@Override
public void process(Archive<?> applicationArchive, TestClass testClass) {

    if (applicationArchive instanceof WebArchive) {
        LOG.info("\n ================================================================================"
                + "\n Testing [" + testClass.getName() + "]"
                + "\n ================================================================================"
                + "\n");

        WebArchive testDeployment = (WebArchive) applicationArchive;

        final File[] dependencies = Maven.resolver()
                .loadPomFromFile("pom.xml")
                .resolve("io.smallrye:smallrye-graphql-servlet")
                .withTransitivity()
                .asFile();

        // Make sure it's unique
        Set<File> dependenciesSet = new LinkedHashSet<>(Arrays.asList(dependencies));
        testDeployment.addAsLibraries(dependenciesSet.toArray(new File[] {}));

        // MicroProfile properties
        testDeployment.addAsResource(
                SmallRyeGraphQLArchiveProcessor.class.getClassLoader()
                        .getResource("META-INF/microprofile-config.properties"),
                "META-INF/microprofile-config.properties");

        // Add our own test app
        testDeployment.addPackage(ProfileGraphQLApi.class.getPackage());
        testDeployment.addPackage(AdditionalScalarsApi.class.getPackage());
        testDeployment.addPackage(AsyncApi.class.getPackage());
        testDeployment.addPackage(ErrorApi.class.getPackage());
    }
}
 
Example 6
Source Project: quarkus   File: RestClientProcessor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void process(Archive<?> applicationArchive, TestClass testClass) {
    // Only apply the processor to SSL tests
    if (testClass.getName().contains("SslHostnameVerifierTest") ||
            testClass.getName().contains("SslMutualTest") ||
            testClass.getName().contains("SslTrustStoreTest") ||
            testClass.getName().contains("SslContextTest")) {

        if (!(applicationArchive instanceof WebArchive)) {
            return;
        }

        WebArchive war = applicationArchive.as(WebArchive.class);
        war.addAsResource(new StringAsset("quarkus.ssl.native=true"), "application.properties");
    }

    // Make sure the test class and all of its superclasses are added to the test deployment
    // This ensures that all the classes from the hierarchy are loaded by the RuntimeClassLoader
    if (ClassContainer.class.isInstance(applicationArchive) && testClass.getJavaClass().getSuperclass() != null) {
        ClassContainer<?> classContainer = ClassContainer.class.cast(applicationArchive);
        Class<?> clazz = testClass.getJavaClass().getSuperclass();
        while (clazz != Object.class && clazz != null) {
            classContainer.addClass(clazz);
            clazz = clazz.getSuperclass();
        }

    }
}
 
Example 7
@Deployment
public static WebArchive getDeployment() {
    TestContext context = new TestContext();
    WebArchive war = getTckDeployment(context);

    war.addClasses(ImagesServiceTestBase.class, ImageRequest.class);

    for (String fName : TEST_FILES) {
        war.addAsResource("testdata/" + fName, fName);
    }

    return war;
}
 
Example 8
public static WebArchive buildArchive(String clazz) {
    WebArchive war = createWar();
    addClasses(war, clazz, AppEngineDataNucleusTransformer.class.getClassLoader());

    war.addPackage("com.google.appengine.datanucleus");

    war.addClass("com.google.appengine.datanucleus.jpa.JPATestCase$EntityManagerFactoryName");
    war.addClass("com.google.appengine.datanucleus.jdo.JDOTestCase$PersistenceManagerFactoryName");

    war.addPackage("com.google.appengine.datanucleus.query");

    war.addPackage("com.google.appengine.datanucleus.test.jdo");
    war.addPackage("com.google.appengine.datanucleus.test.jpa");

    war.setWebXML(new org.jboss.shrinkwrap.api.asset.StringAsset("<web/>"));
    war.addAsWebInfResource("appengine-web.xml");
    war.addAsWebInfResource("META-INF/persistence.xml", "classes/META-INF/persistence.xml");
    war.addAsWebInfResource("META-INF/jdoconfig.xml", "classes/META-INF/jdoconfig.xml");
    war.addAsResource(new StringAsset("ignore.logging=true\n"), "capedwarf-compatibility.properties");

    final PomEquippedResolveStage resolver = getResolver("pom.xml");
    // GAE DN libs
    war.addAsLibraries(resolve(resolver, "com.google.appengine.orm:datanucleus-appengine"));
    war.addAsLibraries(resolve(resolver, "com.google.appengine:appengine-api-1.0-sdk"));
    war.addAsLibraries(resolve(resolver, "com.google.appengine:appengine-testing"));
    war.addAsLibraries(resolve(resolver, "com.google.appengine:appengine-api-stubs"));
    war.addAsLibraries(resolve(resolver, "org.datanucleus:datanucleus-core"));
    war.addAsLibraries(resolve(resolver, "org.datanucleus:datanucleus-api-jdo"));
    war.addAsLibraries(resolve(resolver, "org.datanucleus:datanucleus-api-jpa"));
    war.addAsLibraries(resolve(resolver, "javax.jdo:jdo-api"));
    war.addAsLibraries(resolve(resolver, "org.apache.geronimo.specs:geronimo-jpa_2.0_spec"));
    war.addAsLibraries(resolve(resolver, "org.easymock:easymock"));
    war.addAsLibraries(resolve(resolver, "org.easymock:easymockclassextension"));
    // TCK Internals
    war.addAsLibraries(resolve(resolver, "com.google.appengine.tck:appengine-tck-transformers")); // cleanup dep
    war.addAsLibraries(resolve(resolver, "com.google.appengine.tck:appengine-tck-base")); // lifecycle dep

    return war;
}
 
Example 9
@Override
public void process(final Archive<?> archive, final TestClass testClass) {
    if (archive instanceof WebArchive) {

        WebArchive webArchive = (WebArchive) archive;
        final Map<ArchivePath, Node> content = webArchive.getContent();

        final Node node = content.get(new BasicPath("META-INF/certificates-dir.txt"));
        if (node != null) {
            webArchive.addAsResource(node.getAsset(), "META-INF/certificates-dir.txt");
        }
    }
}
 
Example 10
Source Project: wildfly-camel   File: CXFEndpointTest.java    License: Apache License 2.0 5 votes vote down vote up
@Deployment(testable = false)
public static WebArchive deployment() {
    final WebArchive archive = ShrinkWrap.create(WebArchive.class, "cxf-ws-consumer.war");
    archive.addClasses(Endpoint.class);
    archive.addAsResource("cxf/cxfws-consumer-camel-context.xml");
    return archive;
}
 
Example 11
@Deployment
public static WebArchive createDeployment() {
    WebArchive archive = ShrinkWrap.create(WebArchive.class, "camel-warprops.war");
    archive.addAsWebInfResource("classloading/jboss-camel-context.xml", "jboss-camel-context.xml");
    archive.addAsResource("classloading/psetA.properties", "psetAA.properties");
    archive.addAsResource("classloading/psetB.properties", "psetBA.properties");
    archive.addClasses(HttpRequest.class, CamelServlet.class);
    System.out.println(archive.toString(true));
    return archive;
}
 
Example 12
@Deployment
public static WebArchive createdeployment() {
    WebArchive archive = ShrinkWrap.create(WebArchive.class, "ahc-wss-test.war");
    archive.addClasses(WebSocketServerEndpoint.class);
    archive.addAsResource("ahc/application.keystore", "application.keystore");
    archive.addAsWebResource("ahc/websocket.js", "websocket.js");
    archive.addAsWebResource("ahc/index.jsp", "index.jsp");
    archive.addAsWebInfResource("ahc/web.xml", "web.xml");
    return archive;
}
 
Example 13
@Deployment
public static WebArchive createdeployment() throws IOException {
    File[] libraryDependencies = Maven.configureResolverViaPlugin().
        resolve("org.apache.ftpserver:ftpserver-core").
        withTransitivity().
        asFile();

    final WebArchive archive = ShrinkWrap.create(WebArchive.class, "camel-ftp-tests.war");
    archive.addAsResource(new StringAsset(System.getProperty("basedir")), FILE_BASEDIR);
    archive.addClasses(AvailablePortFinder.class, TestUtils.class, FileUtils.class);
    archive.addAsLibraries(libraryDependencies);
    return archive;
}
 
Example 14
@Deployment
public static WebArchive deployment() {
    final WebArchive archive = ShrinkWrap.create(WebArchive.class, "cxf-ws-consumer-tests.war");
    archive.addClasses(Endpoint.class);
    archive.addAsResource("cxf/spring/cxfws-consumer-camel-context.xml", "cxfws-consumer-camel-context.xml");
    return archive;
}
 
Example 15
@Deployment(name = SIMPLE_WAR, managed = false)
public static Archive<?> getSimpleWar() {
    final WebArchive archive = ShrinkWrap.create(WebArchive.class, SIMPLE_WAR);
    final StringAsset jbossWebAsset = new StringAsset("<jboss-web><security-domain>cxf-security-domain</security-domain></jboss-web>");
    archive.addClasses(Endpoint.class, SecureEndpointImpl.class);
    archive.addAsResource("cxf/secure/cxf-roles.properties", "cxf-roles.properties");
    archive.addAsResource("cxf/secure/cxf-users.properties", "cxf-users.properties");
    archive.addAsWebInfResource(jbossWebAsset, "jboss-web.xml");
    return archive;
}
 
Example 16
@Deployment(name = CXFRSUndeployIntegrationTest_WAR, managed = false, testable = false)
public static WebArchive deployment() {
    final WebArchive archive = ShrinkWrap.create(WebArchive.class, "cxfrs-consumer-tests.war");
    archive.addClasses(GreetingService.class);
    archive.addAsResource("cxf/spring/cxfrs-consumer-camel-context.xml", "cxfrs-consumer-camel-context.xml");
    archive.setManifest(new Asset() {
        @Override
        public InputStream openStream() {
            ManifestBuilder builder = new ManifestBuilder();
            builder.addManifestHeader("Dependencies", "org.jboss.resteasy.resteasy-jaxrs");
            return builder.openStream();
        }
    });
    return archive;
}
 
Example 17
@Deployment
public static WebArchive deployment() {
    final WebArchive archive = ShrinkWrap.create(WebArchive.class, "cxfrs-consumer-tests.war");
    archive.addClasses(GreetingService.class);
    archive.addAsResource("cxf/spring/cxfrs-consumer-camel-context.xml", "cxfrs-consumer-camel-context.xml");
    archive.setManifest(new Asset() {
        @Override
        public InputStream openStream() {
            ManifestBuilder builder = new ManifestBuilder();
            builder.addManifestHeader("Dependencies", "org.jboss.resteasy.resteasy-jaxrs");
            return builder.openStream();
        }
    });
    return archive;
}
 
Example 18
Source Project: appengine-tck   File: Log4jTest.java    License: Apache License 2.0 4 votes vote down vote up
@Deployment
public static WebArchive getDeployment() throws Exception {
    WebArchive war = getDefaultDeployment(newTestContext());
    war.addAsResource("log4j-test.properties", "log4j.properties");
    return war;
}
 
Example 19
/**
 * Initializes the https server and prepares a directory with certificates for testing
 * usage of certificates stored on disk.
 * Additionally, to pass the information about the directory with the certificates to the container, creates a
 * <code>META-INF/certificates-dir.txt</code> file in the web archive with the location
 *
 * @param webArchive performs a test-specific configuration of the https server
 * @param serverInitializer performs a test-specific configuration of the https server
 * @return the disk directory containing certificates
 */
static void initializeTest(WebArchive webArchive, Consumer<HttpsServer> serverInitializer) {
    Path certificatesDirectory = prepareCertificates();
    initializeCertPaths(certificatesDirectory.toAbsolutePath().toString());

    startServer(serverInitializer);

    webArchive.addAsResource(new StringAsset(certificatesDirectory.toAbsolutePath().toString()), "META-INF/" + CERT_LOCATION_FILE);
}