Search in sources :

Example 16 with WebAppDescriptor

use of org.jboss.shrinkwrap.descriptor.api.webapp31.WebAppDescriptor in project wildfly-swarm by wildfly-swarm.

the class HttpSecurityPreparerTest method set_2_methods.

@Test
public void set_2_methods() throws Exception {
    Map<String, Object> deploymentConfig = createConfigStub();
    Map<String, Object> webConfig = findWebConfig(deploymentConfig);
    Map<String, Object> securityConstraint = new HashMap<>();
    securityConstraint.put("methods", Arrays.asList("GET", "POST"));
    webConfig.put("security-constraints", Collections.singletonList(securityConstraint));
    preparer.deploymentConfigs = deploymentConfig;
    preparer.process();
    WebAppDescriptor webXml = Descriptors.importAs(WebAppDescriptor.class).fromStream(archive.get(WebXmlAsset.NAME).getAsset().openStream());
    assertThat(webXml.getAllSecurityConstraint().size()).isEqualTo(1);
    assertThat(webXml.getAllSecurityConstraint().get(0).getAllWebResourceCollection().get(0).getAllHttpMethod().get(0)).isEqualTo("GET");
    assertThat(webXml.getAllSecurityConstraint().get(0).getAllWebResourceCollection().get(0).getAllHttpMethod().get(1)).isEqualTo("POST");
}
Also used : WebAppDescriptor(org.jboss.shrinkwrap.descriptor.api.webapp31.WebAppDescriptor) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 17 with WebAppDescriptor

use of org.jboss.shrinkwrap.descriptor.api.webapp31.WebAppDescriptor in project wildfly-swarm by wildfly-swarm.

the class HttpSecurityPreparerTest method yaml_parsing.

@SuppressWarnings("unchecked")
@Test
public void yaml_parsing() throws Exception {
    InputStream in = getClass().getClassLoader().getResourceAsStream("security.yml");
    assertThat(in).isNotNull().as("security.yml is null");
    Yaml yaml = new Yaml();
    Map<String, Object> httpConfig = (Map<String, Object>) yaml.load(in);
    preparer.deploymentConfigs = (Map) ((Map) httpConfig.get("swarm")).get("deployment");
    preparer.process();
    WebAppDescriptor webXml = Descriptors.importAs(WebAppDescriptor.class).fromStream(archive.get(WebXmlAsset.NAME).getAsset().openStream());
    assertThat(webXml.getAllSecurityConstraint().size()).isEqualTo(1);
    assertThat(webXml.getAllSecurityConstraint().get(0).getAllWebResourceCollection().get(0).getAllUrlPattern().get(0)).isEqualTo("/protected");
}
Also used : WebAppDescriptor(org.jboss.shrinkwrap.descriptor.api.webapp31.WebAppDescriptor) InputStream(java.io.InputStream) HashMap(java.util.HashMap) Map(java.util.Map) Yaml(org.yaml.snakeyaml.Yaml) Test(org.junit.Test)

Example 18 with WebAppDescriptor

use of org.jboss.shrinkwrap.descriptor.api.webapp31.WebAppDescriptor in project wildfly-swarm by wildfly-swarm.

the class HttpSecurityPreparerTest method set_1_method.

@Test
public void set_1_method() throws Exception {
    Map<String, Object> deploymentConfig = createConfigStub();
    Map<String, Object> webConfig = findWebConfig(deploymentConfig);
    Map<String, Object> securityConstraint = new HashMap<>();
    securityConstraint.put("methods", Arrays.asList("GET"));
    webConfig.put("security-constraints", Collections.singletonList(securityConstraint));
    preparer.deploymentConfigs = deploymentConfig;
    preparer.process();
    WebAppDescriptor webXml = Descriptors.importAs(WebAppDescriptor.class).fromStream(archive.get(WebXmlAsset.NAME).getAsset().openStream());
    assertThat(webXml.getAllSecurityConstraint().size()).isEqualTo(1);
    assertThat(webXml.getAllSecurityConstraint().get(0).getAllWebResourceCollection().get(0).getAllHttpMethod().get(0)).isEqualTo("GET");
}
Also used : WebAppDescriptor(org.jboss.shrinkwrap.descriptor.api.webapp31.WebAppDescriptor) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 19 with WebAppDescriptor

use of org.jboss.shrinkwrap.descriptor.api.webapp31.WebAppDescriptor in project tomee by apache.

the class ConnectorWithApplicationResourcesInWarTest method createDeployment.

@Deployment(testable = false)
public static WebArchive createDeployment() {
    final WebAppDescriptor webAppDescriptor = Descriptors.create(WebAppDescriptor.class);
    webAppDescriptor.version("3.0");
    final WebArchive webArchive = ShrinkWrap.create(WebArchive.class, "connector-sample-war.war");
    webArchive.addPackage("org.superbiz.connector.api");
    webArchive.addPackage("org.superbiz.connector.adapter");
    webArchive.addPackage("org.superbiz.application");
    webArchive.addAsWebInfResource(ConnectorWithApplicationResourcesInEarTest.class.getResource("/connector/resources.xml"), "resources.xml");
    webArchive.setWebXML(new StringAsset(webAppDescriptor.exportAsString()));
    System.out.println("Webapp:\n" + webArchive.toString(true));
    return webArchive;
}
Also used : WebAppDescriptor(org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor) StringAsset(org.jboss.shrinkwrap.api.asset.StringAsset) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Example 20 with WebAppDescriptor

use of org.jboss.shrinkwrap.descriptor.api.webapp31.WebAppDescriptor in project tomee by apache.

the class ServletCdiInjectionTest method createDeployment.

@Deployment(testable = false)
public static WebArchive createDeployment() {
    WebAppDescriptor descriptor = Descriptors.create(WebAppDescriptor.class).version(WebAppVersionType._3_0).createServlet().servletName("servlet").servletClass(SimpleServlet.class.getName()).up().createServletMapping().servletName("servlet").urlPattern("/" + TEST_NAME).up();
    WebArchive archive = ShrinkWrap.create(WebArchive.class, TEST_NAME + ".war").addClass(TestRun.class).addClass(SimpleServlet.class).addClass(Car.class).setWebXML(new StringAsset(descriptor.exportAsString())).addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"));
    return archive;
}
Also used : WebAppDescriptor(org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor) StringAsset(org.jboss.shrinkwrap.api.asset.StringAsset) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Aggregations

WebAppDescriptor (org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor)28 StringAsset (org.jboss.shrinkwrap.api.asset.StringAsset)26 WebArchive (org.jboss.shrinkwrap.api.spec.WebArchive)25 Deployment (org.jboss.arquillian.container.test.api.Deployment)21 Test (org.junit.Test)14 HashMap (java.util.HashMap)7 Runner (org.apache.openejb.arquillian.tests.Runner)7 WebAppDescriptor (org.jboss.shrinkwrap.descriptor.api.webapp31.WebAppDescriptor)7 ClassLoaderAsset (org.jboss.shrinkwrap.api.asset.ClassLoaderAsset)6 EnterpriseArchive (org.jboss.shrinkwrap.api.spec.EnterpriseArchive)4 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)4 ResourceAdapterArchive (org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive)4 ApplicationDescriptor (org.jboss.shrinkwrap.descriptor.api.application6.ApplicationDescriptor)4 File (java.io.File)2 InputStream (java.io.InputStream)2 Map (java.util.Map)2 Yaml (org.yaml.snakeyaml.Yaml)2 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 GatewayServlet (org.apache.knox.gateway.GatewayServlet)1