ConfigurableManager implements AutoCloseable { public void scan(Object instance) throws Exception { try (AutoCloseable handle = Performance.accumulate("ConfigurableManager#scan")) { this.deferred.add(instance); scanInternal(instance); } } ConfigurableManager(ConfigView configView, DeploymentContext deploymentContext); ConfigView configView(); List<ConfigurableHandle> configurables(); void rescan(); void scan(Object instance); boolean hasConfiguration(Fraction fraction); void subresourceAdded(ConfigKey itemPrefix, Object object); void log(); void close();  }
@Test public void testDeploymentConfigurable() throws Exception { Properties props = new Properties(); Map<String, String> env = new HashMap<>(); ConfigViewFactory factory = new ConfigViewFactory(props, env); factory.withProperty("thorntail.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(); } }
@Test public void testDeploymentConfigurableBackwardCompatibility() 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); BackwardCompatibleComponent component = new BackwardCompatibleComponent(); manager.scan(component); assertThat(component.context.get()).isEqualTo("/myapp"); } finally { context.deactivate(); } }
@Test public void testDeploymentConfigurableUsingAlias() throws Exception { Properties props = new Properties(); Map<String, String> env = new HashMap<>(); ConfigViewFactory factory = new ConfigViewFactory(props, env); factory.withProperty("thorntail.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(); } }
@Test public void testDeploymentConfigurableUsingAliasBackwardCompatibility() 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); BackwardCompatibleComponent component = new BackwardCompatibleComponent(); manager.scan(component); assertThat(component.context.get()).isEqualTo("/myapp"); } finally { context.deactivate(); } }
@Test public void testDeploymentConfigurableUsingBoth() throws Exception { Properties props = new Properties(); Map<String, String> env = new HashMap<>(); ConfigViewFactory factory = new ConfigViewFactory(props, env); factory.withProperty("thorntail.deployment.[myapp.war].context", "/my-specific-app"); factory.withProperty("thorntail.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(); } }
@Test public void testDeploymentConfigurableUsingBothBackwardCompatible() 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); BackwardCompatibleComponent component = new BackwardCompatibleComponent(); 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); BackwardCompatibleComponent component = new BackwardCompatibleComponent(); manager.scan(component); assertThat(component.context.get()).isEqualTo("/my-alias-app"); } finally { context.deactivate(); } }