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

The following examples show how to use org.jboss.shrinkwrap.api.spec.WebArchive#addClass() . 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(Archive<?> applicationArchive, TestClass testClass) {
    if (applicationArchive instanceof WebArchive) {
        WebArchive testDeployment = (WebArchive) applicationArchive;
        // Register SmallRyeBeanArchiveHandler using the ServiceLoader mechanism
        testDeployment.addClass(SmallRyeBeanArchiveHandler.class);
        testDeployment.addAsServiceProvider(BeanArchiveHandler.class, SmallRyeBeanArchiveHandler.class);

        String[] deps = {
                "io.smallrye:smallrye-health",
                "io.smallrye.config:smallrye-config",
                "io.smallrye:smallrye-health-tck",
                "org.eclipse.microprofile.health:microprofile-health-tck",
                "org.jboss.weld.servlet:weld-servlet-core" };

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

        testDeployment.addAsLibraries(dependencies);
    }
}
 
Example 2
@Override
public void process(Archive<?> applicationArchive, TestClass testClass) {
    if (applicationArchive instanceof WebArchive) {
        WebArchive testDeployment = (WebArchive) applicationArchive;
        // Register SmallRyeBeanArchiveHandler using the ServiceLoader mechanism
        testDeployment.addClass(SmallRyeBeanArchiveHandler.class);
        testDeployment.addAsServiceProvider(BeanArchiveHandler.class, SmallRyeBeanArchiveHandler.class);

        String[] deps = {
                "io.smallrye:smallrye-health",
                "io.smallrye.config:smallrye-config",
                "io.smallrye:smallrye-health-tck",
                "org.eclipse.microprofile.health:microprofile-health-tck",
                "org.jboss.weld.servlet:weld-servlet-core" };

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

        testDeployment.addAsLibraries(dependencies);
    }
}
 
Example 3
Source Project: thorntail   File: DeploymentIndexTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testIndexAttached() throws IOException {
    WebArchive war = ShrinkWrap.create(WebArchive.class);
    war.addClass(Foo.class);
    war.add(createIndexAsset(Foo.class, Baz.class), DeploymentProducer.INDEX_LOCATION);
    JavaArchive lib1 = ShrinkWrap.create(JavaArchive.class).addClass(Bar.class);
    lib1.add(createIndexAsset(Delta.class), DeploymentProducer.INDEX_LOCATION);
    war.addAsLibraries(lib1);
    IndexView index = new DeploymentProducer().createDeploymentIndex(war);
    assertContains(index, Foo.class);
    // Baz should be found in the attached index
    assertContains(index, Baz.class);
    assertContains(index, Delta.class);
    // Bar is not in the attached index
    assertDoesNotContain(index, Bar.class);
}
 
Example 4
Source Project: deltaspike   File: TestDeployments.java    License: Apache License 2.0 6 votes vote down vote up
public static WebArchive initDeployment(boolean addDefaultEntityManagerProducer)
{
    Logging.reconfigure();

    WebArchive archive = ShrinkWrap
            .create(WebArchive.class, "test.war")
            // used by many tests, shouldn't interfere with others
            .addClasses(TransactionalTestCase.class, TestData.class)
            .addPackages(true, AuditedEntity.class.getPackage())
            .addAsLibraries(getDeltaSpikeDataWithDependencies())
            .addAsWebInfResource("test-persistence.xml", "classes/META-INF/persistence.xml")
            .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
            .addAsWebInfResource(new StringAsset(DS_PROPERTIES_WITH_ENV_AWARE_TX_STRATEGY),
                    "classes/META-INF/apache-deltaspike.properties");

    if (addDefaultEntityManagerProducer)
    {
        archive.addClass(EntityManagerProducer.class);
    }
    
    return archive;
}
 
Example 5
Source Project: tomee   File: TestSetup.java    License: Apache License 2.0 6 votes vote down vote up
public WebArchive createDeployment(Class...archiveClasses) {
    WebAppDescriptor descriptor = Descriptors.create(WebAppDescriptor.class)
            .version("3.0");
    decorateDescriptor(descriptor);

    WebArchive archive = ShrinkWrap.create(WebArchive.class, getTestContextName() + ".war")
            .setWebXML(new StringAsset(descriptor.exportAsString()))
            .addAsLibraries(JarLocation.jarLocation(Test.class))
            .addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"));
    
    if (archiveClasses != null) {
        for (Class c: archiveClasses) {
            archive.addClass(c);
        }
    }
    decorateArchive(archive);

    return archive;
}
 
Example 6
@Deployment
public static WebArchive getDeployment() {
    WebArchive war = getBaseDeployment();
    war.addClass(BlobstoreUploadTestBase.class);

    LibUtils libUtils = new LibUtils();
    libUtils.addLibrary(war, "com.google.appengine.tools", "appengine-gcs-client");
    libUtils.addLibrary(war, "com.google.guava", "guava");
    libUtils.addLibrary(war, "joda-time", "joda-time");
    libUtils.addLibrary(war, "com.google.api-client", "google-api-client");
    libUtils.addLibrary(war, "com.google.http-client", "google-http-client");
    libUtils.addLibrary(war, "com.google.http-client", "google-http-client-appengine");
    libUtils.addLibrary(war, "com.google.http-client", "google-http-client-jackson2");
    libUtils.addLibrary(war, "com.google.api-client", "google-api-client-appengine");
    libUtils.addLibrary(war, "com.google.apis", "google-api-services-storage");
    libUtils.addLibrary(war, "com.fasterxml.jackson.core", "jackson-core");

    return war;
}
 
Example 7
Source Project: appengine-tck   File: LibTest.java    License: Apache License 2.0 6 votes vote down vote up
@Deployment
public static EnterpriseArchive getDeployment() {
    WebArchive module1 = getTckSubDeployment(1);
    module1.addClass(LibTest.class);

    // dummy module
    WebArchive module2 = getTckSubDeployment(2);

    final EnterpriseArchive ear = getEarDeployment(module1, module2);

    JavaArchive lib = ShrinkWrap.create(JavaArchive.class);
    lib.addClass(LibHelper.class);

    new LibUtils().addGaeAsLibrary(ear);
    ear.addAsLibraries(lib);

    return ear;
}
 
Example 8
@Override
public void process(Archive<?> applicationArchive, TestClass testClass) {
    if (applicationArchive instanceof WebArchive) {
        WebArchive war = (WebArchive) applicationArchive;
        war.addClass(OptionalAwareSmallRyeJWTAuthCDIExtension.class);
        war.addClass(SmallRyeJWTAuthJaxRsFeature.class);
        war.addAsServiceProvider(Extension.class, OptionalAwareSmallRyeJWTAuthCDIExtension.class);

        if (!war.contains("META-INF/microprofile-config.properties")) {
            war.addAsManifestResource("microprofile-config-local.properties", "microprofile-config.properties");
        }

        // A few tests require the apps to be deployed in the root. Check PublicKeyAsJWKLocationURLTest and PublicKeyAsPEMLocationURLTest
        // Both tests set the public key location url to be in root.
        war.addAsWebInfResource("jboss-web.xml");

        String[] deps = {
                "io.smallrye:smallrye-jwt",
                "io.smallrye.config:smallrye-config",
                "org.jboss.resteasy:resteasy-servlet-initializer",
                "org.jboss.resteasy:resteasy-jaxrs",
                "org.jboss.resteasy:resteasy-client",
                "org.jboss.resteasy:resteasy-cdi",
                "org.jboss.resteasy:resteasy-json-binding-provider",
                "org.jboss.weld.servlet:weld-servlet-core"
        };
        File[] dependencies = Maven.resolver()
                .loadPomFromFile(new File("pom.xml"))
                .resolve(deps)
                .withTransitivity()
                .asFile();

        war.addAsLibraries(dependencies);
    }
}
 
Example 9
@Override
public void process(TestDeployment testDeployment, Archive<?> archive) {
    WebArchive war = (WebArchive) archive;

    String[] deps = {
            "io.smallrye:smallrye-config",
            "io.smallrye:smallrye-metrics",
            "io.smallrye:smallrye-metrics-testsuite-common",
            "org.eclipse.microprofile.metrics:microprofile-metrics-api",
            "org.eclipse.microprofile.config:microprofile-config-api"
    };
    File[] dependencies = Maven.resolver().loadPomFromFile(new File("pom.xml")).resolve(deps).withTransitivity().asFile();
    war.addAsLibraries(dependencies);

    war.addClass(MetricsHttpServlet.class);
    war.addClass(JaxRsMetricsFilter.class);
    war.addClass(JaxRsMetricsServletFilter.class);

    // change application context root to '/' because the TCK assumes that the metrics
    // will be available at '/metrics', and in our case the metrics servlet is located
    // within the application itself, we don't use WildFly's built-in support for metrics
    war.addAsWebInfResource("WEB-INF/jboss-web.xml", "jboss-web.xml");

    // activate the servlet filter
    war.setWebXML("WEB-INF/web.xml");

    // activate the JAX-RS request filter
    war.addAsServiceProvider(Providers.class.getName(), JaxRsMetricsFilter.class.getName());

    // exclude built-in Metrics and Config from WildFly
    war.addAsManifestResource("META-INF/jboss-deployment-structure.xml", "jboss-deployment-structure.xml");
}
 
Example 10
protected static Archive getDeploymentWithLoggingLevelSetTo(Level level) {
    TestContext context = newTestContext().setAppEngineWebXmlFile("appengine-web-with-logging-properties.xml");
    WebArchive war = getDefaultDeployment(context);
    war.addClass(LoggingConfigurationTestBase.class);
    war.addAsWebInfResource(new StringAsset(".level=" + level.getName()), "logging.properties");
    return war;
}
 
Example 11
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 12
Source Project: appengine-tck   File: BytemanTestBase.java    License: Apache License 2.0 5 votes vote down vote up
protected static WebArchive getBytemanDeployment() {
    TestContext context = new TestContext();
    context.setWebXmlFile("bm-web.xml");
    context.setAppEngineWebXmlFile("bm-appengine-web.xml");

    WebArchive war = getTckDeployment(context);
    war.addClass(BytemanTestBase.class);
    war.addClasses(ConcurrentTxServlet.class, Poke.class);
    return war;
}
 
Example 13
Source Project: appengine-tck   File: DatastoreTestBase.java    License: Apache License 2.0 5 votes vote down vote up
@Deployment
public static WebArchive getDeployment() {
    WebArchive war = getHelperDeployment();
    war.addClass(DatastoreTestBase.class);
    war.addAsWebInfResource("datastore-indexes.xml");
    return war;
}
 
Example 14
Source Project: appengine-tck   File: WarmupTest.java    License: Apache License 2.0 5 votes vote down vote up
@Deployment
public static EnterpriseArchive getWarmupDeployment() {
    WebArchive module3 = getTckSubDeployment(3);
    module3.addClass(WarmupTest.class);

    WebArchive module4 = getTckSubDeployment(4);
    module4.addClass(WarmupTest.class);

    return getEarDeployment("warmup-application.xml", module3, module4);
}
 
Example 15
protected static WebArchive getBaseDeployment(boolean enabled) {
    System.setProperty("appengine.warmup.enabled", Boolean.toString(enabled));
    try {
        TestContext context = new TestContext();
        context.setWebXmlFile("web-warmup.xml");
        context.setAppEngineWebXmlFile("appengine-web-warmup.xml");
        WebArchive war = getTckDeployment(context);
        war.addClass(AbstractWarmupTestBase.class);
        war.addClass(WarmupServlet.class);
        war.addClass(WarmupData.class);
        return war;
    } finally {
        System.clearProperty("appengine.warmup.enabled");
    }
}
 
Example 16
@Override
public void process(final Archive<?> applicationArchive, final TestClass testClass) {
    if (!(applicationArchive instanceof WebArchive)) {
        return;
    }
    final WebArchive war = WebArchive.class.cast(applicationArchive);

    // Add Required Libraries
    war.addAsLibrary(JarLocation.jarLocation(TokenUtils.class))
       .addAsLibrary(JarLocation.jarLocation(JWSSigner.class))
       .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");

    // Provide keys required for tests (vendor specific way)
    war.addClass(JWTAuthContextInfoProvider.class);

    // Spec says that vendor specific ways to load the keys take precedence, so we need to remove it in test
    // cases that use the Config approach.
    Stream.of(
            PublicKeyAsPEMTest.class,
            PublicKeyAsPEMLocationTest.class,
            PublicKeyAsFileLocationURLTest.class,
            PublicKeyAsJWKTest.class,
            PublicKeyAsBase64JWKTest.class,
            PublicKeyAsJWKLocationTest.class,
            PublicKeyAsJWKLocationURLTest.class,
            PublicKeyAsJWKSTest.class,
            PublicKeyAsJWKSLocationTest.class,
            IssValidationTest.class,
            ExpClaimValidationTest.class,
            ExpClaimAllowMissingExpValidationTest.class,
            org.apache.tomee.microprofile.tck.jwt.config.PublicKeyAsPEMLocationTest.class,
            org.apache.tomee.microprofile.tck.jwt.config.PublicKeyAsJWKLocationURLTest.class)
          .filter(c -> c.equals(testClass.getJavaClass()))
          .findAny()
          .ifPresent(c -> war.deleteClass(JWTAuthContextInfoProvider.class));

    // MP Config in wrong place - See https://github.com/eclipse/microprofile/issues/46.
    final Map<ArchivePath, Node> content = war.getContent(object -> object.get().matches(".*META-INF/.*"));
    content.forEach((archivePath, node) -> war.addAsResource(node.getAsset(), node.getPath()));

    // Rewrite the correct server port in configuration
    final Container container = containerRegistry.get().getContainer(TargetDescription.DEFAULT);
    if (container.getDeployableContainer() instanceof RemoteTomEEContainer) {
        final RemoteTomEEContainer remoteTomEEContainer =
                (RemoteTomEEContainer) container.getDeployableContainer();
        final RemoteTomEEConfiguration configuration = remoteTomEEContainer.getConfiguration();
        final String httpPort = configuration.getHttpPort() + "";

        final Map<ArchivePath, Node> microprofileProperties = war.getContent(
                object -> object.get().matches(".*META-INF/microprofile-config\\.properties"));
        microprofileProperties.forEach((archivePath, node) -> {
            try {
                final Properties properties = new Properties();
                properties.load(node.getAsset().openStream());
                properties.replaceAll((key, value) -> ((String) value).replaceAll("8080", httpPort + "/" + "KeyEndpoint.war".replaceAll("\\.war", "")));
                final StringWriter stringWriter = new StringWriter();
                properties.store(stringWriter, null);
                war.delete(archivePath);
                war.add(new StringAsset(stringWriter.toString()), node.getPath());
            } catch (final IOException e) {
                e.printStackTrace();
            }
        });
    }

    System.out.println(war.toString(true));
}
 
Example 17
Source Project: appengine-tck   File: TestBase.java    License: Apache License 2.0 4 votes vote down vote up
protected static WebArchive getTckDeployment(TestContext context) {
    enhanceTestContext(context);

    final WebArchive war;

    String archiveName = context.getArchiveName();
    if (archiveName != null) {
        if (archiveName.endsWith(".war") == false) archiveName += ".war";
        war = ShrinkWrap.create(WebArchive.class, archiveName);
    } else {
        war = ShrinkWrap.create(WebArchive.class);
    }

    // this package
    war.addPackage(TestBase.class.getPackage());
    // categories
    war.addPackage(IgnoreMultisuite.class.getPackage());
    // events
    war.addPackage(TestLifecycles.class.getPackage());
    // temp data
    war.addPackage(TempData.class.getPackage());
    // mail
    war.addPackage(EmailAddressFormatter.class.getPackage());
    // env
    war.addClass(Environment.class);

    // web.xml
    if (context.getWebXmlFile() != null) {
        war.setWebXML(context.getWebXmlFile());
    } else {
        war.setWebXML(new StringAsset(context.getWebXmlContent()));
    }

    // context-root
    if (context.getContextRoot() != null) {
        war.addAsWebInfResource(context.getContextRoot().getDescriptor());
    }

    // appengine-web.xml
    String appengineWebXmlFile = "appengine-web.xml";
    if (context.getAppEngineWebXmlFile() != null) {
        appengineWebXmlFile = context.getAppEngineWebXmlFile();
    }
    Asset gaeWebXml = new ClassLoaderAsset(appengineWebXmlFile);
    war.addAsWebInfResource(rewriteAsset(gaeWebXml), "appengine-web.xml");

    if (context.hasCallbacks()) {
        war.addAsWebInfResource("META-INF/datastorecallbacks.xml", "classes/META-INF/datastorecallbacks.xml");
    }

    if (context.getCompatibilityProperties() != null && (context.getProperties().isEmpty() == false || context.isUseSystemProperties())) {
        Properties properties = new Properties();

        if (context.isUseSystemProperties()) {
            properties.putAll(System.getProperties());
        }
        properties.putAll(context.getProperties());

        final StringWriter writer = new StringWriter();
        try {
            properties.store(writer, "GAE TCK testing!");
        } catch (IOException e) {
            throw new RuntimeException("Cannot write compatibility properties.", e);
        }

        final StringAsset asset = new StringAsset(writer.toString());
        war.addAsWebInfResource(asset, "classes/" + context.getCompatibilityProperties());
    }

    if (context.isIgnoreTimestamp() == false) {
        war.addAsWebInfResource(new StringAsset(String.valueOf(context.getTimestamp())), "classes/" + TIMESTAMP_TXT);
    }

    return war;
}
 
Example 18
protected static void addClasses(WebArchive war, Class<?> current) {
    while (current != null && current != Object.class && "junit.framework.TestCase".equals(current.getName()) == false) {
        war.addClass(current);
        current = current.getSuperclass();
    }
}
 
Example 19
@Deployment
public static WebArchive getDeployment() {
    WebArchive war = getBaseDeployment();
    war.addClass(BlobstoreUploadTestBase.class);
    return war;
}
 
Example 20
Source Project: appengine-tck   File: SearchTestBase.java    License: Apache License 2.0 4 votes vote down vote up
@Deployment
public static WebArchive getDeployment() {
    WebArchive war = getTckDeployment();
    war.addClass(SearchTestBase.class);
    return war;
}