Search in sources :

Example 1 with ConfigView

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

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

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

the class InterfaceExtensionTest method testAfterBeanDiscovery.

@Test
public void testAfterBeanDiscovery() throws Exception {
    ConfigView configView = mock(ConfigView.class);
    List<SimpleKey> interfaces = Arrays.asList(new SimpleKey("test"));
    when(configView.simpleSubkeys(any(ConfigKey.class))).thenReturn(interfaces);
    when(configView.valueOf(any(ConfigKey.class))).thenReturn("192.168.1.1");
    ext = new InterfaceExtension(configView);
    BeanManager beanManager = mock(BeanManager.class);
    AfterBeanDiscovery abd = mock(AfterBeanDiscovery.class);
    @SuppressWarnings("unchecked") ArgumentCaptor<CommonBean<Interface>> captor = ArgumentCaptor.forClass(CommonBean.class);
    ext.afterBeanDiscovery(abd, beanManager);
    verify(abd, times(1)).addBean(captor.capture());
    assertThat(captor.getValue().create(null).getName()).isEqualTo("test");
    assertThat(captor.getValue().create(null).getExpression()).isEqualTo("192.168.1.1");
}
Also used : ConfigKey(org.wildfly.swarm.spi.api.config.ConfigKey) ConfigView(org.wildfly.swarm.spi.api.config.ConfigView) AfterBeanDiscovery(javax.enterprise.inject.spi.AfterBeanDiscovery) CommonBean(org.wildfly.swarm.spi.api.cdi.CommonBean) BeanManager(javax.enterprise.inject.spi.BeanManager) SimpleKey(org.wildfly.swarm.spi.api.config.SimpleKey) Test(org.junit.Test)

Example 4 with ConfigView

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

the class ProjectStagesTest method testCLIToLoadConfig.

@Test
public void testCLIToLoadConfig() throws Exception {
    Swarm swarm = new Swarm(new Properties(), "-Sfoo");
    ConfigView view = swarm.configView();
    assertThat(view.resolve("swarm.myname").getValue()).isEqualTo("foo");
}
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 5 with ConfigView

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

the class ProjectStagesTest method testPseudoPropertiesToSelectProjectStage.

@Test
public void testPseudoPropertiesToSelectProjectStage() throws Exception {
    Swarm swarm = new Swarm(new Properties(), "-Dswarm.project.stage=production");
    ConfigView view = swarm.configView();
    assertThat(view.resolve("foo.bar.baz").getValue()).isEqualTo("brie");
}
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)

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