Search in sources :

Example 1 with WARArchive

use of org.wildfly.swarm.undertow.WARArchive in project wildfly-swarm by wildfly-swarm.

the class ContextPathArchivePreparerTest method testContextPathProperty.

@Test
public void testContextPathProperty() throws Exception {
    WARArchive archive = DefaultWarDeploymentFactory.archiveFromCurrentApp();
    assertThat(archive.getContextRoot()).isNull();
    ContextPathArchivePreparer preparer = new ContextPathArchivePreparer(archive);
    preparer.contextPath.set("/another-root");
    preparer.process();
    assertThat(archive.getContextRoot()).isNotNull();
    assertThat(archive.getContextRoot()).isEqualTo("/another-root");
}
Also used : WARArchive(org.wildfly.swarm.undertow.WARArchive) Test(org.junit.Test)

Example 2 with WARArchive

use of org.wildfly.swarm.undertow.WARArchive in project wildfly-swarm by wildfly-swarm.

the class ContextPathArchivePreparerTest method testDefaultContextRootWontOverride.

@Test
public void testDefaultContextRootWontOverride() throws Exception {
    WARArchive archive = DefaultWarDeploymentFactory.archiveFromCurrentApp();
    assertThat(archive.getContextRoot()).isNull();
    archive.setContextRoot("myRoot");
    assertThat(archive.getContextRoot()).isNotNull();
    assertThat(archive.getContextRoot()).isEqualTo("myRoot");
    new ContextPathArchivePreparer(archive).process();
    assertThat(archive.getContextRoot()).isNotNull();
    assertThat(archive.getContextRoot()).isEqualTo("myRoot");
}
Also used : WARArchive(org.wildfly.swarm.undertow.WARArchive) Test(org.junit.Test)

Example 3 with WARArchive

use of org.wildfly.swarm.undertow.WARArchive in project wildfly-swarm by wildfly-swarm.

the class ContextPathArchivePreparerTest method testDefaultContextRoot.

@Test
public void testDefaultContextRoot() throws Exception {
    WARArchive archive = DefaultWarDeploymentFactory.archiveFromCurrentApp();
    assertThat(archive.getContextRoot()).isNull();
    ContextPathArchivePreparer processor = new ContextPathArchivePreparer(archive);
    processor.process();
    assertThat(archive.getContextRoot()).isNotNull();
    assertThat(archive.getContextRoot()).isEqualTo("/");
}
Also used : WARArchive(org.wildfly.swarm.undertow.WARArchive) Test(org.junit.Test)

Example 4 with WARArchive

use of org.wildfly.swarm.undertow.WARArchive in project wildfly-swarm by wildfly-swarm.

the class ContextPathArchivePreparerTest method testExternalMount.

@SuppressWarnings("unchecked")
@Test
public void testExternalMount() throws Exception {
    WARArchive archive = DefaultWarDeploymentFactory.archiveFromCurrentApp();
    assertThat(archive.getContextRoot()).isNull();
    URL url = getClass().getClassLoader().getResource("mounts.yml");
    ConfigViewFactory factory = new ConfigViewFactory(new Properties());
    factory.load("test", url);
    factory.withProfile("test");
    ConfigViewImpl view = factory.get(true);
    List<String> mounts = view.resolve("swarm.context.mounts").as(List.class).getValue();
    ContextPathArchivePreparer preparer = new ContextPathArchivePreparer(archive);
    preparer.mounts = mounts;
    preparer.process();
    Node externalMount = archive.get(WARArchive.EXTERNAL_MOUNT_PATH);
    assertThat(externalMount).isNotNull();
    assertThat(externalMount.getAsset()).isInstanceOf(UndertowExternalMountsAsset.class);
    UndertowExternalMountsAsset externalMountAsset = (UndertowExternalMountsAsset) externalMount.getAsset();
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(externalMountAsset.openStream()))) {
        assertThat(reader.readLine()).endsWith("external1");
        assertThat(reader.readLine()).endsWith("external2");
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) Node(org.jboss.shrinkwrap.api.Node) Properties(java.util.Properties) WARArchive(org.wildfly.swarm.undertow.WARArchive) URL(java.net.URL) ConfigViewImpl(org.wildfly.swarm.container.config.ConfigViewImpl) UndertowExternalMountsAsset(org.wildfly.swarm.undertow.internal.UndertowExternalMountsAsset) ConfigViewFactory(org.wildfly.swarm.container.config.ConfigViewFactory) BufferedReader(java.io.BufferedReader) List(java.util.List) Test(org.junit.Test)

Example 5 with WARArchive

use of org.wildfly.swarm.undertow.WARArchive in project wildfly-swarm by wildfly-swarm.

the class SecuredTest method testExistingWebXml.

@Test
public void testExistingWebXml() {
    WARArchive archive = ShrinkWrap.create(WARArchive.class);
    ClassLoaderAsset asset = new ClassLoaderAsset("test-web.xml");
    archive.addAsWebInfResource(asset, "web.xml");
    archive.as(Secured.class).protect("/cheddar");
    Node webXml = archive.get("WEB-INF/web.xml");
    Asset newAsset = webXml.getAsset();
    InputStream in = newAsset.openStream();
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    List<String> lines = reader.lines().map(String::trim).collect(Collectors.toList());
    assertThat(lines).contains("<servlet-name>comingsoon</servlet-name>");
    assertThat(lines).contains("<url-pattern>/cheddar</url-pattern>");
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Node(org.jboss.shrinkwrap.api.Node) BufferedReader(java.io.BufferedReader) ClassLoaderAsset(org.jboss.shrinkwrap.api.asset.ClassLoaderAsset) Asset(org.jboss.shrinkwrap.api.asset.Asset) ClassLoaderAsset(org.jboss.shrinkwrap.api.asset.ClassLoaderAsset) WARArchive(org.wildfly.swarm.undertow.WARArchive) Test(org.junit.Test)

Aggregations

WARArchive (org.wildfly.swarm.undertow.WARArchive)39 Deployment (org.jboss.arquillian.container.test.api.Deployment)15 Test (org.junit.Test)8 WebXmlAsset (org.wildfly.swarm.undertow.descriptors.WebXmlAsset)5 Produces (javax.enterprise.inject.Produces)4 Node (org.jboss.shrinkwrap.api.Node)4 URL (java.net.URL)3 ClassLoaderAsset (org.jboss.shrinkwrap.api.asset.ClassLoaderAsset)3 MockTracer (io.opentracing.mock.MockTracer)2 BufferedReader (java.io.BufferedReader)2 File (java.io.File)2 InputStreamReader (java.io.InputStreamReader)2 List (java.util.List)2 Map (java.util.Map)2 Module (org.jboss.modules.Module)2 ArchivePath (org.jboss.shrinkwrap.api.ArchivePath)2 Asset (org.jboss.shrinkwrap.api.asset.Asset)2 StringAsset (org.jboss.shrinkwrap.api.asset.StringAsset)2 JBossWebAsset (org.wildfly.swarm.undertow.descriptors.JBossWebAsset)2 UndertowExternalMountsAsset (org.wildfly.swarm.undertow.internal.UndertowExternalMountsAsset)2