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

The following examples show how to use org.jboss.shrinkwrap.api.spec.WebArchive#add() . 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
Source File: DeploymentIndexTest.java    From thorntail with 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 2
Source File: MoviesSeleniumTest.java    From tomee with Apache License 2.0 6 votes vote down vote up
private static void addResources(String source, String target, WebArchive archive) {
	File sourceFile = new File(source);
	if (! sourceFile.exists()) return;
	if (sourceFile.isFile()) {
		archive.add(new FileAsset(sourceFile), target);
	}
	
	if (sourceFile.isDirectory()) {
           final File[] files = sourceFile.listFiles();
           if (files != null) {
               for (File file : files) {
                   if (file.getName().startsWith(".")) continue;
                   addResources(source + File.separator + file.getName(), target + File.separator + file.getName(), archive);
               }
           }
       }
}
 
Example 3
Source File: URLFetchTestBase.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
@Deployment
public static Archive getDeployment() {
    TestContext context = new TestContext();
    context.setWebXmlFile("uf-web.xml");
    WebArchive war = getTckDeployment(context);
    war.addClasses(URLFetchTestBase.class);
    war.addPackage(FetchServlet.class.getPackage());
    war.add(new StringAsset("<html><body>Google AppEngine TCK</body></html>"), "index.html");
    return war;
}
 
Example 4
Source File: RpcTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
@Deployment
public static WebArchive getDeployment() {
    TestContext context = new TestContext().setWebXmlFile("rpc-web.xml");
    WebArchive war = getDefaultDeployment(context);
    war.addClasses(RpcEndpoint.class, TestData.class);
    war.add(new ClassLoaderAsset("xindex.html"), "index.html");
    war.add(new ClassLoaderAsset("js/base.js"), "js/base.js");
    war.addAsWebInfResource("rpcendpoint-v1-rest.discovery");
    war.addAsWebInfResource("rpcendpoint-v1-rpc.discovery");
    return war;
}
 
Example 5
Source File: LoaderTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
@Deployment
public static WebArchive getDeployment() {
    TestContext context = new TestContext();
    context.setWebXmlFile("web-error-page.xml");
    WebArchive war = getTckDeployment(context);
    war.addClass(Exceptions.class);
    war.add(new StringAsset(content), "error.html");
    return war;
}
 
Example 6
Source File: AbstractServletsAdapterTest.java    From keycloak with Apache License 2.0 4 votes vote down vote up
public static WebArchive samlServletDeployment(String name, String customArchiveName, String webXMLPath, Integer clockSkewSec, Class... servletClasses) {
    String baseSAMLPath = "/adapter-test/keycloak-saml/";
    String webInfPath = baseSAMLPath + name + "/WEB-INF/";

    URL keycloakSAMLConfig = AbstractServletsAdapterTest.class.getResource(webInfPath + "keycloak-saml.xml");
    Assert.assertNotNull("keycloak-saml.xml should be in " + webInfPath, keycloakSAMLConfig);

    URL webXML = AbstractServletsAdapterTest.class.getResource(baseSAMLPath + webXMLPath);
    Assert.assertNotNull("web.xml should be in " + baseSAMLPath + webXMLPath, keycloakSAMLConfig);

    WebArchive deployment = ShrinkWrap.create(WebArchive.class, customArchiveName + ".war")
            .addClasses(servletClasses)
            .addAsWebInfResource(jbossDeploymentStructure, JBOSS_DEPLOYMENT_STRUCTURE_XML);

    // if a role-mappings.properties file exist in WEB-INF, include it in the deployment.
    URL roleMappingsConfig = AbstractServletsAdapterTest.class.getResource(webInfPath + "role-mappings.properties");
    if(roleMappingsConfig != null) {
        deployment.addAsWebInfResource(roleMappingsConfig, "role-mappings.properties");
    }

    String webXMLContent;
    try {
        webXMLContent = IOUtils.toString(webXML.openStream(), Charset.forName("UTF-8"))
                .replace("%CONTEXT_PATH%", name);

        if (clockSkewSec != null) {
            String keycloakSamlXMLContent = IOUtils.toString(keycloakSAMLConfig.openStream(), Charset.forName("UTF-8"))
                .replace("%CLOCK_SKEW%", "${allowed.clock.skew:" + String.valueOf(clockSkewSec) + "}");
            deployment.addAsWebInfResource(new StringAsset(keycloakSamlXMLContent), "keycloak-saml.xml");
        } else {
            deployment.addAsWebInfResource(keycloakSAMLConfig, "keycloak-saml.xml");
        }

    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    deployment.add(new StringAsset(webXMLContent), "/WEB-INF/web.xml");

    URL keystore = AbstractServletsAdapterTest.class.getResource(webInfPath + "keystore.jks");
    if (keystore != null) {
        deployment.addAsWebInfResource(keystore, "keystore.jks");
    }

    addContextXml(deployment, name);

    return deployment;
}
 
Example 7
Source File: AbstractServletsAdapterTest.java    From keycloak with Apache License 2.0 4 votes vote down vote up
public static WebArchive samlServletDeploymentMultiTenant(String name, String webXMLPath, 
        String config1, String config2,
        String keystore1, String keystore2, Class... servletClasses) {
    String baseSAMLPath = "/adapter-test/keycloak-saml/";
    String webInfPath = baseSAMLPath + name + "/WEB-INF/";

    URL webXML = AbstractServletsAdapterTest.class.getResource(baseSAMLPath + webXMLPath);
    Assert.assertNotNull("web.xml should be in " + baseSAMLPath + webXMLPath, webXML);

    WebArchive deployment = ShrinkWrap.create(WebArchive.class, name + ".war")
            .addClasses(servletClasses)
            .addAsWebInfResource(jbossDeploymentStructure, JBOSS_DEPLOYMENT_STRUCTURE_XML);

    String webXMLContent;
    try {
        webXMLContent = IOUtils.toString(webXML.openStream(), Charset.forName("UTF-8"))
                .replace("%CONTEXT_PATH%", name);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    deployment.add(new StringAsset(webXMLContent), "/WEB-INF/web.xml");

    // add the xml for each tenant in classes
    URL config1Url = AbstractServletsAdapterTest.class.getResource(webInfPath + config1);
    Assert.assertNotNull("config1Url should be in " + webInfPath + config1, config1Url);
    deployment.add(new UrlAsset(config1Url), "/WEB-INF/classes/" + config1);
    URL config2Url = AbstractServletsAdapterTest.class.getResource(webInfPath + config2);
    Assert.assertNotNull("config2Url should be in " + webInfPath + config2, config2Url);
    deployment.add(new UrlAsset(config2Url), "/WEB-INF/classes/" + config2);
    
    // add the keystores for each tenant in classes
    URL keystore1Url = AbstractServletsAdapterTest.class.getResource(webInfPath + keystore1);
    Assert.assertNotNull("keystore1Url should be in " + webInfPath + keystore1, keystore1Url);
    deployment.add(new UrlAsset(keystore1Url), "/WEB-INF/classes/" + keystore1);
    URL keystore2Url = AbstractServletsAdapterTest.class.getResource(webInfPath + keystore2);
    Assert.assertNotNull("keystore2Url should be in " + webInfPath + keystore2, keystore2Url);
    deployment.add(new UrlAsset(keystore2Url), "/WEB-INF/classes/" + keystore2);

    addContextXml(deployment, name);

    return deployment;
}