Search in sources :

Example 1 with ConfigViewFactory

use of org.wildfly.swarm.container.config.ConfigViewFactory 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 2 with ConfigViewFactory

use of org.wildfly.swarm.container.config.ConfigViewFactory in project wildfly-swarm by wildfly-swarm.

the class ConfigurableManagerTest method testDeploymentConfigurableUsingAlias.

@Test
public void testDeploymentConfigurableUsingAlias() throws Exception {
    Properties props = new Properties();
    Map<String, String> env = new HashMap<>();
    ConfigViewFactory factory = new ConfigViewFactory(props, env);
    factory.withProperty("swarm.http.context", "/myapp");
    ConfigView configView = factory.get(true);
    DeploymentContext context = new DeploymentContextImpl();
    ConfigurableManager manager = new ConfigurableManager(configView, context);
    Archive archive = ShrinkWrap.create(JavaArchive.class, "myapp.war");
    try {
        context.activate(archive, archive.getName(), false);
        Component component = new Component();
        manager.scan(component);
        assertThat(component.context.get()).isEqualTo("/myapp");
    } finally {
        context.deactivate();
    }
}
Also used : DeploymentContext(org.wildfly.swarm.container.runtime.cdi.DeploymentContext) Archive(org.jboss.shrinkwrap.api.Archive) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) HashMap(java.util.HashMap) ConfigView(org.wildfly.swarm.spi.api.config.ConfigView) ConfigViewFactory(org.wildfly.swarm.container.config.ConfigViewFactory) Properties(java.util.Properties) DeploymentContextImpl(org.wildfly.swarm.container.runtime.cdi.DeploymentContextImpl) Test(org.junit.Test)

Example 3 with ConfigViewFactory

use of org.wildfly.swarm.container.config.ConfigViewFactory in project wildfly-swarm by wildfly-swarm.

the class ConfigurableManagerTest method testDeploymentConfigurable.

@Test
public void testDeploymentConfigurable() throws Exception {
    Properties props = new Properties();
    Map<String, String> env = new HashMap<>();
    ConfigViewFactory factory = new ConfigViewFactory(props, env);
    factory.withProperty("swarm.deployment.[myapp.war].context", "/myapp");
    ConfigView configView = factory.get(true);
    DeploymentContext context = new DeploymentContextImpl();
    ConfigurableManager manager = new ConfigurableManager(configView, context);
    Archive archive = ShrinkWrap.create(JavaArchive.class, "myapp.war");
    try {
        context.activate(archive, archive.getName(), false);
        Component component = new Component();
        manager.scan(component);
        assertThat(component.context.get()).isEqualTo("/myapp");
    } finally {
        context.deactivate();
    }
}
Also used : DeploymentContext(org.wildfly.swarm.container.runtime.cdi.DeploymentContext) Archive(org.jboss.shrinkwrap.api.Archive) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) HashMap(java.util.HashMap) ConfigView(org.wildfly.swarm.spi.api.config.ConfigView) ConfigViewFactory(org.wildfly.swarm.container.config.ConfigViewFactory) Properties(java.util.Properties) DeploymentContextImpl(org.wildfly.swarm.container.runtime.cdi.DeploymentContextImpl) Test(org.junit.Test)

Example 4 with ConfigViewFactory

use of org.wildfly.swarm.container.config.ConfigViewFactory in project wildfly-swarm by wildfly-swarm.

the class ConfigurableManagerTest method testDeploymentConfigurableUsingBoth.

@Test
public void testDeploymentConfigurableUsingBoth() throws Exception {
    Properties props = new Properties();
    Map<String, String> env = new HashMap<>();
    ConfigViewFactory factory = new ConfigViewFactory(props, env);
    factory.withProperty("swarm.deployment.[myapp.war].context", "/my-specific-app");
    factory.withProperty("swarm.http.context", "/my-alias-app");
    ConfigView configView = factory.get(true);
    DeploymentContext context = new DeploymentContextImpl();
    ConfigurableManager manager = new ConfigurableManager(configView, context);
    Archive archive = ShrinkWrap.create(JavaArchive.class, "myapp.war");
    try {
        context.activate(archive, archive.getName(), false);
        Component component = new Component();
        manager.scan(component);
        assertThat(component.context.get()).isEqualTo("/my-specific-app");
    } finally {
        context.deactivate();
    }
    Archive archiveToo = ShrinkWrap.create(JavaArchive.class, "otherapp.war");
    try {
        context.activate(archiveToo, archiveToo.getName(), false);
        Component component = new Component();
        manager.scan(component);
        assertThat(component.context.get()).isEqualTo("/my-alias-app");
    } finally {
        context.deactivate();
    }
}
Also used : DeploymentContext(org.wildfly.swarm.container.runtime.cdi.DeploymentContext) Archive(org.jboss.shrinkwrap.api.Archive) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) HashMap(java.util.HashMap) ConfigView(org.wildfly.swarm.spi.api.config.ConfigView) ConfigViewFactory(org.wildfly.swarm.container.config.ConfigViewFactory) Properties(java.util.Properties) DeploymentContextImpl(org.wildfly.swarm.container.runtime.cdi.DeploymentContextImpl) Test(org.junit.Test)

Aggregations

Properties (java.util.Properties)4 Test (org.junit.Test)4 ConfigViewFactory (org.wildfly.swarm.container.config.ConfigViewFactory)4 HashMap (java.util.HashMap)3 Archive (org.jboss.shrinkwrap.api.Archive)3 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)3 DeploymentContext (org.wildfly.swarm.container.runtime.cdi.DeploymentContext)3 DeploymentContextImpl (org.wildfly.swarm.container.runtime.cdi.DeploymentContextImpl)3 ConfigView (org.wildfly.swarm.spi.api.config.ConfigView)3 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 URL (java.net.URL)1 List (java.util.List)1 Node (org.jboss.shrinkwrap.api.Node)1 ConfigViewImpl (org.wildfly.swarm.container.config.ConfigViewImpl)1 WARArchive (org.wildfly.swarm.undertow.WARArchive)1 UndertowExternalMountsAsset (org.wildfly.swarm.undertow.internal.UndertowExternalMountsAsset)1