Search in sources :

Example 6 with ConfigView

use of org.wildfly.swarm.spi.api.config.ConfigView in project wildfly-swarm by wildfly-swarm.

the class ProjectStagesTest method testPropertyBasedConfigStagesFileOnlyDefault.

@Test
public void testPropertyBasedConfigStagesFileOnlyDefault() throws Exception {
    try {
        URL projectStages = getClass().getClassLoader().getResource("multi-project-stages.yml");
        System.setProperty(SwarmProperties.PROJECT_STAGE_FILE, projectStages.toExternalForm());
        Swarm swarm = new Swarm(new Properties());
        ConfigView view = swarm.configView();
        assertThat(view.resolve("foo.bar.baz").getValue()).isEqualTo("cheddar");
    } finally {
        System.clearProperty(SwarmProperties.PROJECT_STAGE_FILE);
    }
}
Also used : ConfigView(org.wildfly.swarm.spi.api.config.ConfigView) Properties(java.util.Properties) SwarmProperties(org.wildfly.swarm.spi.api.SwarmProperties) URL(java.net.URL) Test(org.junit.Test)

Example 7 with ConfigView

use of org.wildfly.swarm.spi.api.config.ConfigView in project wildfly-swarm by wildfly-swarm.

the class ProjectStagesTest method testPropertiesPreferredToEnvironmentVars.

@Test
public void testPropertiesPreferredToEnvironmentVars() throws Exception {
    Map<String, String> environment = new HashMap<>();
    Properties properties = new Properties();
    environment.put("swarm.myname", "from_env");
    properties.setProperty("swarm.myname", "from_props");
    Swarm swarm = new Swarm(properties, environment);
    ConfigView view = swarm.configView();
    assertThat(view.resolve("swarm.myname").getValue()).isEqualTo("from_props");
}
Also used : HashMap(java.util.HashMap) ConfigView(org.wildfly.swarm.spi.api.config.ConfigView) Properties(java.util.Properties) SwarmProperties(org.wildfly.swarm.spi.api.SwarmProperties) Test(org.junit.Test)

Example 8 with ConfigView

use of org.wildfly.swarm.spi.api.config.ConfigView in project wildfly-swarm by wildfly-swarm.

the class ProjectStagesTest method testSwarmAPIToLoadConfig.

@Test
public void testSwarmAPIToLoadConfig() throws Exception {
    Swarm swarm = new Swarm(new Properties());
    swarm.withProfile("foo");
    ConfigView view = swarm.configView();
    assertThat(view.resolve("swarm.myname").getValue()).isEqualTo("foo");
    swarm.withProfile("bar");
    assertThat(view.resolve("swarm.myname").getValue()).isEqualTo("foo");
    assertThat(view.resolve("swarm.mydottednumber").as(Double.class).getValue()).isEqualTo(2.82);
}
Also used : ConfigView(org.wildfly.swarm.spi.api.config.ConfigView) Properties(java.util.Properties) SwarmProperties(org.wildfly.swarm.spi.api.SwarmProperties) Test(org.junit.Test)

Example 9 with ConfigView

use of org.wildfly.swarm.spi.api.config.ConfigView in project wildfly-swarm by wildfly-swarm.

the class StageConfigTest method testPropertyBasedConfigStagesFile.

@Test
public void testPropertyBasedConfigStagesFile() throws Exception {
    try {
        URL projectStages = getClass().getClassLoader().getResource("simple-project-stages.yml");
        System.setProperty(SwarmProperties.PROJECT_STAGE_FILE, projectStages.toExternalForm());
        Swarm swarm = new Swarm(new Properties());
        ConfigView view = swarm.configView();
        assertThat(view.resolve("foo.bar.baz").getValue()).isEqualTo("cheddar");
        StageConfig stageConfig = swarm.stageConfig();
        assertThat(stageConfig.resolve("foo.bar.baz").getValue()).isEqualTo("cheddar");
    } finally {
        System.clearProperty(SwarmProperties.PROJECT_STAGE_FILE);
    }
}
Also used : ConfigView(org.wildfly.swarm.spi.api.config.ConfigView) Properties(java.util.Properties) SwarmProperties(org.wildfly.swarm.spi.api.SwarmProperties) URL(java.net.URL) StageConfig(org.wildfly.swarm.spi.api.StageConfig) Test(org.junit.Test)

Example 10 with ConfigView

use of org.wildfly.swarm.spi.api.config.ConfigView 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

Test (org.junit.Test)16 ConfigView (org.wildfly.swarm.spi.api.config.ConfigView)16 Properties (java.util.Properties)15 SwarmProperties (org.wildfly.swarm.spi.api.SwarmProperties)12 HashMap (java.util.HashMap)6 URL (java.net.URL)4 Archive (org.jboss.shrinkwrap.api.Archive)3 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)3 ConfigViewFactory (org.wildfly.swarm.container.config.ConfigViewFactory)3 DeploymentContext (org.wildfly.swarm.container.runtime.cdi.DeploymentContext)3 DeploymentContextImpl (org.wildfly.swarm.container.runtime.cdi.DeploymentContextImpl)3 AfterBeanDiscovery (javax.enterprise.inject.spi.AfterBeanDiscovery)1 BeanManager (javax.enterprise.inject.spi.BeanManager)1 StageConfig (org.wildfly.swarm.spi.api.StageConfig)1 CommonBean (org.wildfly.swarm.spi.api.cdi.CommonBean)1 ConfigKey (org.wildfly.swarm.spi.api.config.ConfigKey)1 SimpleKey (org.wildfly.swarm.spi.api.config.SimpleKey)1