Search in sources :

Example 6 with ConfigurationImpl

use of org.walkmod.conf.entities.impl.ConfigurationImpl in project walkmod-core by walkmod.

the class XMLConfigurationProviderTest method testVersion1_0.

@Test
public void testVersion1_0() throws Exception {
    XMLConfigurationProvider prov = new XMLConfigurationProvider("src/test/resources/testFiles/walkmod.xml", false);
    Configuration conf = new ConfigurationImpl();
    prov.init(conf);
    prov.load();
    Assert.assertEquals(1, conf.getChainConfigs().size());
    Assert.assertEquals("default", conf.getChainConfigs().iterator().next().getName());
}
Also used : Configuration(org.walkmod.conf.entities.Configuration) ConfigurationImpl(org.walkmod.conf.entities.impl.ConfigurationImpl) Test(org.junit.Test)

Example 7 with ConfigurationImpl

use of org.walkmod.conf.entities.impl.ConfigurationImpl in project walkmod-core by walkmod.

the class XMLConfigurationProviderTest method testRemovePlugin.

@Test
public void testRemovePlugin() throws Exception {
    File aux = new File("src/test/resources/xml");
    aux.mkdirs();
    File xml = new File(aux, "walkmod.xml");
    XMLConfigurationProvider prov = new XMLConfigurationProvider(xml.getPath(), false);
    try {
        Configuration conf = new ConfigurationImpl();
        prov.init(conf);
        prov.createConfig();
        List<String> plugins = new LinkedList<String>();
        plugins.add("org.walkmod:imports-cleaner");
        AddPluginCommand command = new AddPluginCommand(plugins);
        List<PluginConfig> pluginCfgs = command.build();
        prov.addPluginConfig(pluginCfgs.get(0), false);
        String output = FileUtils.readFileToString(xml);
        System.out.println(output);
        Assert.assertTrue(output.contains("imports-cleaner"));
        prov.removePluginConfig(pluginCfgs.get(0), false);
        output = FileUtils.readFileToString(xml);
        System.out.println(output);
        Assert.assertTrue(!output.contains("imports-cleaner"));
    } finally {
        if (xml.exists()) {
            xml.delete();
        }
    }
}
Also used : PluginConfig(org.walkmod.conf.entities.PluginConfig) Configuration(org.walkmod.conf.entities.Configuration) File(java.io.File) ConfigurationImpl(org.walkmod.conf.entities.impl.ConfigurationImpl) LinkedList(java.util.LinkedList) AddPluginCommand(org.walkmod.commands.AddPluginCommand) Test(org.junit.Test)

Example 8 with ConfigurationImpl

use of org.walkmod.conf.entities.impl.ConfigurationImpl in project walkmod-core by walkmod.

the class YAMLConfigurationProviderTest method testAddTransformation.

@Test
public void testAddTransformation() throws Exception {
    AddTransformationCommand command = new AddTransformationCommand("imports-cleaner", null, false, null, null, null, null, false);
    File file = new File("src/test/resources/yaml/addtransformation.yml");
    if (file.exists()) {
        file.delete();
    }
    file.createNewFile();
    FileUtils.write(file, "");
    try {
        YAMLConfigurationProvider provider = new YAMLConfigurationProvider(file.getPath());
        Configuration conf = new ConfigurationImpl();
        provider.init(conf);
        TransformationConfig transCfg = command.buildTransformationCfg();
        provider.addTransformationConfig(null, null, transCfg, false, null, null);
        String output = FileUtils.readFileToString(file);
        String desiredOutput = "transformations:\n";
        desiredOutput += "- type: \"imports-cleaner\"";
        Assert.assertEquals(desiredOutput, output);
    } finally {
        if (file.exists()) {
            file.delete();
        }
    }
}
Also used : Configuration(org.walkmod.conf.entities.Configuration) TransformationConfig(org.walkmod.conf.entities.TransformationConfig) AddTransformationCommand(org.walkmod.commands.AddTransformationCommand) File(java.io.File) ConfigurationImpl(org.walkmod.conf.entities.impl.ConfigurationImpl) Test(org.junit.Test)

Example 9 with ConfigurationImpl

use of org.walkmod.conf.entities.impl.ConfigurationImpl in project walkmod-core by walkmod.

the class YAMLConfigurationProviderTest method testAddConfigurationParameterWithCategory.

@Test
public void testAddConfigurationParameterWithCategory() throws Exception {
    AddTransformationCommand command = new AddTransformationCommand("imports-cleaner", null, false, null, null, null, null, false);
    File file = new File("src/test/resources/yaml/rmchains.yml");
    if (file.exists()) {
        file.delete();
    }
    file.createNewFile();
    FileUtils.write(file, "");
    try {
        YAMLConfigurationProvider provider = new YAMLConfigurationProvider(file.getPath());
        Configuration conf = new ConfigurationImpl();
        provider.init(conf);
        TransformationConfig transformationCfg = command.buildTransformationCfg();
        provider.addTransformationConfig(null, null, transformationCfg, false, null, null);
        provider.addConfigurationParameter("testParam", "hello", "imports-cleaner", "transformation", null, null, false);
        String output = FileUtils.readFileToString(file);
        System.out.println(output);
        Assert.assertTrue(output.contains("params") && output.contains("testParam") && output.contains("hello"));
    } finally {
        if (file.exists()) {
            file.delete();
        }
    }
}
Also used : Configuration(org.walkmod.conf.entities.Configuration) TransformationConfig(org.walkmod.conf.entities.TransformationConfig) AddTransformationCommand(org.walkmod.commands.AddTransformationCommand) File(java.io.File) ConfigurationImpl(org.walkmod.conf.entities.impl.ConfigurationImpl) Test(org.junit.Test)

Example 10 with ConfigurationImpl

use of org.walkmod.conf.entities.impl.ConfigurationImpl in project walkmod-core by walkmod.

the class YAMLConfigurationProviderTest method testRemovePlugin.

@Test
public void testRemovePlugin() throws Exception {
    List<String> list = new LinkedList<String>();
    list.add("org.walkmod:javalang");
    File file = new File("src/test/resources/yaml/removePlugin.yml");
    if (file.exists()) {
        file.delete();
    }
    file.createNewFile();
    String input = "plugins:\n";
    input += "- \"org.walkmod:imports-cleaner:2.0\"";
    FileUtils.write(file, input);
    try {
        YAMLConfigurationProvider provider = new YAMLConfigurationProvider(file.getPath());
        Configuration conf = new ConfigurationImpl();
        provider.init(conf);
        PluginConfig pc = new PluginConfigImpl();
        pc.setGroupId("org.walkmod");
        pc.setArtifactId("imports-cleaner");
        provider.removePluginConfig(pc, false);
        String output = FileUtils.readFileToString(file);
        System.out.println(output);
        Assert.assertTrue(!output.contains("imports-cleaner"));
    } finally {
        if (file.exists()) {
            file.delete();
        }
    }
}
Also used : PluginConfig(org.walkmod.conf.entities.PluginConfig) Configuration(org.walkmod.conf.entities.Configuration) PluginConfigImpl(org.walkmod.conf.entities.impl.PluginConfigImpl) File(java.io.File) ConfigurationImpl(org.walkmod.conf.entities.impl.ConfigurationImpl) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

ConfigurationImpl (org.walkmod.conf.entities.impl.ConfigurationImpl)50 Configuration (org.walkmod.conf.entities.Configuration)48 Test (org.junit.Test)43 File (java.io.File)36 AddTransformationCommand (org.walkmod.commands.AddTransformationCommand)21 LinkedList (java.util.LinkedList)20 TransformationConfig (org.walkmod.conf.entities.TransformationConfig)20 PluginConfig (org.walkmod.conf.entities.PluginConfig)9 ChainConfig (org.walkmod.conf.entities.ChainConfig)8 HashMap (java.util.HashMap)6 Document (org.w3c.dom.Document)4 Element (org.w3c.dom.Element)4 Node (org.w3c.dom.Node)4 NodeList (org.w3c.dom.NodeList)4 ProviderConfig (org.walkmod.conf.entities.ProviderConfig)4 ChainConfigImpl (org.walkmod.conf.entities.impl.ChainConfigImpl)4 PluginConfigImpl (org.walkmod.conf.entities.impl.PluginConfigImpl)4 AddCfgProviderCommand (org.walkmod.commands.AddCfgProviderCommand)3 TransformerException (javax.xml.transform.TransformerException)2 AddPluginCommand (org.walkmod.commands.AddPluginCommand)2