Search in sources :

Example 1 with ConfigPlugin

use of org.wildfly.extras.config.ConfigPlugin in project wildfly-camel by wildfly-extras.

the class LayerConfigTest method testApplyLayerConfigChange.

@Test
public void testApplyLayerConfigChange() throws Exception {
    ConfigPlugin plugin = new ConfigPlugin() {

        @Override
        public String getConfigName() {
            return "foo";
        }

        @Override
        public List<LayerConfig> getLayerConfigs() {
            return Arrays.asList(new LayerConfig("fuse_6.2.1", Type.INSTALLING, -10), new LayerConfig("soa_6.2.1", Type.INSTALLING, -10), new LayerConfig("brms_6.2.1", Type.OPTIONAL, -11));
        }

        @Override
        public boolean applyStandaloneConfigChange(ConfigContext context, boolean enable) {
            return false;
        }

        @Override
        public boolean applyDomainConfigChange(ConfigContext context, boolean enable) {
            return false;
        }
    };
    // Install/Uninstall scenario.
    List<String> layers;
    layers = ConfigSupport.applyLayerChanges(plugin, list("foo", "example"), true);
    Assert.assertEquals(list("fuse_6.2.1", "soa_6.2.1", "foo", "example"), layers);
    layers = ConfigSupport.applyLayerChanges(plugin, layers, false);
    Assert.assertEquals(list("foo", "example"), layers);
    // Upgrade/Uninstall scenario.
    layers = list("foo", "fuse_6.1", "soa", "example");
    layers = ConfigSupport.applyLayerChanges(plugin, layers, true);
    Assert.assertEquals(list("fuse_6.2.1", "soa_6.2.1", "foo", "example"), layers);
    layers = ConfigSupport.applyLayerChanges(plugin, layers, false);
    Assert.assertEquals(list("foo", "example"), layers);
    // Another Upgrade/Uninstall scenario.
    layers = list("foo", "fuse", "example");
    layers = ConfigSupport.applyLayerChanges(plugin, layers, true);
    Assert.assertEquals(list("fuse_6.2.1", "soa_6.2.1", "foo", "example"), layers);
    layers = ConfigSupport.applyLayerChanges(plugin, layers, false);
    Assert.assertEquals(list("foo", "example"), layers);
}
Also used : ConfigPlugin(org.wildfly.extras.config.ConfigPlugin) LayerConfig(org.wildfly.extras.config.LayerConfig) ConfigContext(org.wildfly.extras.config.ConfigContext) Test(org.junit.Test)

Example 2 with ConfigPlugin

use of org.wildfly.extras.config.ConfigPlugin in project wildfly-camel by wildfly-extras.

the class StandaloneConfigTest method testStandaloneConfig.

@Test
public void testStandaloneConfig() throws Exception {
    URL resurl = StandaloneConfigTest.class.getResource("/standalone.xml");
    SAXBuilder jdom = new SAXBuilder();
    Document doc = jdom.build(resurl);
    ConfigPlugin plugin = new WildFlyCamelConfigPlugin();
    ConfigContext context = ConfigSupport.createContext(null, Paths.get(resurl.toURI()), doc);
    plugin.applyStandaloneConfigChange(context, true);
    // Verify extension
    assertElementWithAttributeValueNotNull(doc.getRootElement(), "extension", "module", "org.wildfly.extension.camel", NS_DOMAINS);
    // Verify system-properties
    Element element = ConfigSupport.findChildElement(doc.getRootElement(), "system-properties", NS_DOMAINS);
    Assert.assertNotNull("system-properties not null", element);
    assertElementWithAttributeValueNotNull(element, "property", "name", "hawtio.realm", NS_DOMAINS);
    assertElementWithAttributeValueNotNull(element, "property", "name", "ee8.preview.mode", NS_DOMAINS);
    // Verify camel
    List<Element> profiles = ConfigSupport.findProfileElements(doc, NS_DOMAINS);
    Assert.assertEquals("One profile", 1, profiles.size());
    assertElementNotNull(profiles.get(0), "subsystem", NS_CAMEL);
    // Verify hawtio-domain
    assertElementWithAttributeValueNotNull(doc.getRootElement(), "security-domain", "name", "hawtio-domain", NS_SECURITY);
// outputDocumentContent(doc, System.out);
}
Also used : ConfigPlugin(org.wildfly.extras.config.ConfigPlugin) WildFlyCamelConfigPlugin(org.wildfly.extension.camel.config.WildFlyCamelConfigPlugin) SAXBuilder(org.jdom.input.SAXBuilder) WildFlyCamelConfigPlugin(org.wildfly.extension.camel.config.WildFlyCamelConfigPlugin) Element(org.jdom.Element) Document(org.jdom.Document) URL(java.net.URL) ConfigContext(org.wildfly.extras.config.ConfigContext) Test(org.junit.Test)

Example 3 with ConfigPlugin

use of org.wildfly.extras.config.ConfigPlugin in project wildfly-camel by wildfly-extras.

the class StandaloneConfigTest method testUnsupportedNamespaceVersion.

@Test
public void testUnsupportedNamespaceVersion() throws Exception {
    URL resurl = StandaloneConfigTest.class.getResource("/standalone.xml");
    SAXBuilder jdom = new SAXBuilder();
    Document doc = jdom.build(resurl);
    doc.getRootElement().getChild("extensions", NS_DOMAIN_60).setNamespace(Namespace.getNamespace("urn:jboss:domain:99.99"));
    File modifiedConfig = new File("target/standalone-modified.xml");
    outputDocumentContent(doc, new FileOutputStream(modifiedConfig));
    jdom = new SAXBuilder();
    doc = jdom.build(modifiedConfig);
    ConfigContext context = ConfigSupport.createContext(null, modifiedConfig.toPath(), doc);
    ConfigPlugin plugin = new WildFlyCamelConfigPlugin();
    expectedException.expect(ConfigException.class);
    plugin.applyStandaloneConfigChange(context, true);
}
Also used : ConfigPlugin(org.wildfly.extras.config.ConfigPlugin) WildFlyCamelConfigPlugin(org.wildfly.extension.camel.config.WildFlyCamelConfigPlugin) SAXBuilder(org.jdom.input.SAXBuilder) WildFlyCamelConfigPlugin(org.wildfly.extension.camel.config.WildFlyCamelConfigPlugin) FileOutputStream(java.io.FileOutputStream) Document(org.jdom.Document) File(java.io.File) URL(java.net.URL) ConfigContext(org.wildfly.extras.config.ConfigContext) Test(org.junit.Test)

Example 4 with ConfigPlugin

use of org.wildfly.extras.config.ConfigPlugin in project wildfly-camel by wildfly-extras.

the class StandaloneConfigTest method testRemoveConfig.

@Test
public void testRemoveConfig() throws Exception {
    URL resurl = StandaloneConfigTest.class.getResource("/standalone.xml");
    SAXBuilder jdom = new SAXBuilder();
    Document doc = jdom.build(resurl);
    File modifiedConfig = new File("target/standalone-modified.xml");
    outputDocumentContent(doc, new FileOutputStream(modifiedConfig));
    jdom = new SAXBuilder();
    doc = jdom.build(modifiedConfig);
    ConfigPlugin plugin = new WildFlyCamelConfigPlugin();
    ConfigContext context = ConfigSupport.createContext(null, Paths.get(resurl.toURI()), doc);
    plugin.applyStandaloneConfigChange(context, false);
    // Verify extension removed
    assertElementWithAttributeValueNull(doc.getRootElement(), "extension", "module", "org.wildfly.extension.camel", NS_DOMAINS);
    // Verify system-properties removed
    Element element = ConfigSupport.findChildElement(doc.getRootElement(), "system-properties", NS_DOMAINS);
    Assert.assertNotNull("system-properties not null", element);
    assertElementWithAttributeValueNull(element, "property", "name", "hawtio.realm", NS_DOMAINS);
    assertElementWithAttributeValueNull(element, "property", "name", "hawtio.offline", NS_DOMAINS);
    assertElementWithAttributeValueNull(element, "property", "name", "hawtio.authenticationEnabled", NS_DOMAINS);
    assertElementWithAttributeValueNull(element, "property", "name", "ee8.preview.mode", NS_DOMAINS);
    List<Element> profiles = ConfigSupport.findProfileElements(doc, NS_DOMAINS);
    // Verify camel removed
    assertElementNull(profiles.get(0), "subsystem", NS_CAMEL);
    // Verify hawtio-domain removed
    assertElementWithAttributeValueNull(doc.getRootElement(), "security-domain", "name", "hawtio-domain", NS_SECURITY);
}
Also used : ConfigPlugin(org.wildfly.extras.config.ConfigPlugin) WildFlyCamelConfigPlugin(org.wildfly.extension.camel.config.WildFlyCamelConfigPlugin) SAXBuilder(org.jdom.input.SAXBuilder) WildFlyCamelConfigPlugin(org.wildfly.extension.camel.config.WildFlyCamelConfigPlugin) FileOutputStream(java.io.FileOutputStream) Element(org.jdom.Element) Document(org.jdom.Document) File(java.io.File) URL(java.net.URL) ConfigContext(org.wildfly.extras.config.ConfigContext) Test(org.junit.Test)

Example 5 with ConfigPlugin

use of org.wildfly.extras.config.ConfigPlugin in project wildfly-camel by wildfly-extras.

the class StandaloneConfigTest method testApplyConfigMultipleTimes.

@Test
public void testApplyConfigMultipleTimes() throws Exception {
    URL resurl = StandaloneConfigTest.class.getResource("/standalone.xml");
    SAXBuilder jdom = new SAXBuilder();
    Document doc = jdom.build(resurl);
    ConfigPlugin plugin = new WildFlyCamelConfigPlugin();
    ConfigContext context = ConfigSupport.createContext(null, Paths.get(resurl.toURI()), doc);
    for (int i = 0; i < 5; i++) {
        plugin.applyStandaloneConfigChange(context, true);
    }
    Assert.assertEquals(1, getElementCount(doc, "extension", null, new Attribute("module", "org.wildfly.extension.camel")));
    Assert.assertEquals(1, getElementCount(doc, "system-properties", null, null));
    Assert.assertEquals(1, getElementCount(doc, "security-domain", null, new Attribute("name", "hawtio-domain")));
    Assert.assertEquals(1, getElementCount(doc, "subsystem", NS_CAMEL, null));
}
Also used : ConfigPlugin(org.wildfly.extras.config.ConfigPlugin) WildFlyCamelConfigPlugin(org.wildfly.extension.camel.config.WildFlyCamelConfigPlugin) SAXBuilder(org.jdom.input.SAXBuilder) WildFlyCamelConfigPlugin(org.wildfly.extension.camel.config.WildFlyCamelConfigPlugin) Attribute(org.jdom.Attribute) Document(org.jdom.Document) URL(java.net.URL) ConfigContext(org.wildfly.extras.config.ConfigContext) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 ConfigContext (org.wildfly.extras.config.ConfigContext)6 ConfigPlugin (org.wildfly.extras.config.ConfigPlugin)6 URL (java.net.URL)4 Document (org.jdom.Document)4 SAXBuilder (org.jdom.input.SAXBuilder)4 WildFlyCamelConfigPlugin (org.wildfly.extension.camel.config.WildFlyCamelConfigPlugin)4 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 Element (org.jdom.Element)2 LayerConfig (org.wildfly.extras.config.LayerConfig)2 Attribute (org.jdom.Attribute)1