Search in sources :

Example 36 with ConfigurationImpl

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

the class XMLConfigurationProviderTest method testRemoveChainTransformations.

@Test
public void testRemoveChainTransformations() throws Exception {
    List<String> list = new LinkedList<String>();
    list.add("imports-cleaner");
    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();
        AddTransformationCommand command0 = new AddTransformationCommand("license-applier", "mychain", false, null, null, null, null, false);
        prov.addTransformationConfig("mychain", null, command0.buildTransformationCfg(), false, null, null);
        AddTransformationCommand command = new AddTransformationCommand("imports-cleaner", "mychain", false, null, null, null, null, false);
        prov.addTransformationConfig("mychain", null, command.buildTransformationCfg(), false, null, null);
        prov.removeTransformations("mychain", list, false);
        String output = FileUtils.readFileToString(xml);
        Assert.assertTrue(!output.contains("imports-cleaner"));
        Assert.assertTrue(output.contains("license-applier"));
        list.add("license-applier");
        prov.removeTransformations("mychain", list, false);
        output = FileUtils.readFileToString(xml);
        Assert.assertTrue(!output.contains("chain"));
    } finally {
        if (xml.exists()) {
            xml.delete();
        }
    }
}
Also used : Configuration(org.walkmod.conf.entities.Configuration) AddTransformationCommand(org.walkmod.commands.AddTransformationCommand) File(java.io.File) ConfigurationImpl(org.walkmod.conf.entities.impl.ConfigurationImpl) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 37 with ConfigurationImpl

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

the class YAMLConfigurationProviderTest method testAddChainTransformationWithExistingChain.

@Test
public void testAddChainTransformationWithExistingChain() throws Exception {
    Map<String, String> params = new HashMap<String, String>();
    params.put("refactoringConfigFile", "src/conf/refactoring-methods.json");
    AddTransformationCommand command = new AddTransformationCommand("walkmod:commons:method-refactor", "mychain", false, null, null, null, params, false);
    File file = new File("src/test/resources/yaml/addchain.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("mychain", null, transformationCfg, false, null, null);
        command = new AddTransformationCommand("walkmod:commons:class-refactor", "mychain", false, null, null, null, params, false);
        transformationCfg = command.buildTransformationCfg();
        provider.addTransformationConfig("mychain", null, transformationCfg, false, null, null);
        String output = FileUtils.readFileToString(file);
        Assert.assertTrue(output.contains("walkmod:commons:class-refactor") && !output.contains("default"));
    } finally {
        if (file.exists()) {
            file.delete();
        }
    }
}
Also used : Configuration(org.walkmod.conf.entities.Configuration) HashMap(java.util.HashMap) 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 38 with ConfigurationImpl

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

the class YAMLConfigurationProviderTest method testAddChainTransformationRecursively.

@Test
public void testAddChainTransformationRecursively() throws Exception {
    Map<String, String> params = new HashMap<String, String>();
    params.put("refactoringConfigFile", "src/conf/refactoring-methods.json");
    AddTransformationCommand command = new AddTransformationCommand("walkmod:commons:method-refactor", null, false, null, null, null, params, false);
    File dir = new File("src/test/resources/multimoduleyaml");
    File module1 = new File(dir, "module1");
    File module2 = new File(dir, "module2");
    dir.mkdirs();
    module1.mkdir();
    module2.mkdir();
    File file = new File(dir, "walkmod.yml");
    File file2 = new File(module1, "walkmod.yml");
    File file3 = new File(module2, "walkmod.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);
        List<String> modules = new LinkedList<String>();
        modules.add("module1");
        modules.add("module2");
        provider.addModules(modules);
        TransformationConfig transformationCfg = command.buildTransformationCfg();
        provider.addTransformationConfig(null, null, transformationCfg, true, null, null);
        String output = FileUtils.readFileToString(file);
        Assert.assertTrue(!output.contains("method-refactor"));
        output = FileUtils.readFileToString(file2);
        Assert.assertTrue(output.contains("method-refactor"));
        output = FileUtils.readFileToString(file3);
        Assert.assertTrue(output.contains("method-refactor"));
    } finally {
        FileUtils.deleteDirectory(dir);
    }
}
Also used : Configuration(org.walkmod.conf.entities.Configuration) HashMap(java.util.HashMap) TransformationConfig(org.walkmod.conf.entities.TransformationConfig) AddTransformationCommand(org.walkmod.commands.AddTransformationCommand) File(java.io.File) ConfigurationImpl(org.walkmod.conf.entities.impl.ConfigurationImpl) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 39 with ConfigurationImpl

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

the class YAMLConfigurationProviderTest method testAddConfigurationParameter2.

@Test
public void testAddConfigurationParameter2() 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", null, 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 40 with ConfigurationImpl

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

the class YAMLConfigurationProviderTest method testRemoveTranformation.

@Test
public void testRemoveTranformation() throws Exception {
    List<String> list = new LinkedList<String>();
    list.add("imports-cleaner");
    File file = new File("src/test/resources/yaml/rmTransf.yml");
    if (file.exists()) {
        file.delete();
    }
    file.createNewFile();
    String input = "transformations:\n";
    input += "- type: \"imports-cleaner\"";
    FileUtils.write(file, input);
    try {
        YAMLConfigurationProvider provider = new YAMLConfigurationProvider(file.getPath());
        Configuration conf = new ConfigurationImpl();
        provider.init(conf);
        provider.removeTransformations(null, list, false);
        String output = FileUtils.readFileToString(file);
        String desiredOutput = "transformations: []";
        Assert.assertEquals(desiredOutput, output);
    } finally {
        if (file.exists()) {
            file.delete();
        }
    }
}
Also used : Configuration(org.walkmod.conf.entities.Configuration) 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