Search in sources :

Example 16 with ConfigurationImpl

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

the class YAMLConfigurationProviderTest method testAddConfigurationParameterToWriter.

@Test
public void testAddConfigurationParameterToWriter() 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.setWriter(null, "eclipse-writer", null, false, null);
        provider.addConfigurationParameter("testParam", "hello", "eclipse-writer", 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 17 with ConfigurationImpl

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

the class YAMLConfigurationProviderTest method testRemoveProvider.

@Test
public void testRemoveProvider() throws Exception {
    AddCfgProviderCommand command = new AddCfgProviderCommand("maven", null);
    File file = new File("src/test/resources/yaml/addcfgproviders.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);
        ProviderConfig provCfg = command.build();
        provider.addProviderConfig(provCfg, false);
        List<String> providers = new LinkedList<String>();
        providers.add("maven");
        provider.removeProviders(providers, false);
        String output = FileUtils.readFileToString(file);
        System.out.println(output);
        Assert.assertTrue(!output.contains("maven"));
    } finally {
        if (file.exists()) {
            file.delete();
        }
    }
}
Also used : Configuration(org.walkmod.conf.entities.Configuration) AddCfgProviderCommand(org.walkmod.commands.AddCfgProviderCommand) ProviderConfig(org.walkmod.conf.entities.ProviderConfig) File(java.io.File) ConfigurationImpl(org.walkmod.conf.entities.impl.ConfigurationImpl) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 18 with ConfigurationImpl

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

the class YAMLConfigurationProviderTest method testChainsYaml.

@Test
public void testChainsYaml() {
    YAMLConfigurationProvider provider = new YAMLConfigurationProvider("src/test/resources/yaml/chains.yml");
    Configuration conf = new ConfigurationImpl();
    provider.init(conf);
    provider.load();
    Assert.assertNotNull(conf.getChainConfigs());
    ChainConfig cc = conf.getChainConfigs().iterator().next();
    Iterator<TransformationConfig> it = cc.getWalkerConfig().getTransformations().iterator();
    TransformationConfig first = it.next();
    Assert.assertEquals("walkmod:commons:method-refactor", first.getType());
    Assert.assertNotNull(cc.getReaderConfig());
    Assert.assertNotNull(cc.getWriterConfig());
}
Also used : Configuration(org.walkmod.conf.entities.Configuration) TransformationConfig(org.walkmod.conf.entities.TransformationConfig) ConfigurationImpl(org.walkmod.conf.entities.impl.ConfigurationImpl) ChainConfig(org.walkmod.conf.entities.ChainConfig) Test(org.junit.Test)

Example 19 with ConfigurationImpl

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

the class YAMLConfigurationProviderTest method testSetWriter.

@Test
public void testSetWriter() throws Exception {
    List<String> list = new LinkedList<String>();
    list.add("javalang:string-writer");
    File file = new File("src/test/resources/yaml/setWriter.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.setWriter(null, list.get(0), null, false, null);
        String output = FileUtils.readFileToString(file);
        System.out.println(output);
        Assert.assertTrue(output.contains("javalang:string-writer"));
    } 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)

Example 20 with ConfigurationImpl

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

the class YAMLConfigurationProviderTest method testRemoveTranformationRecursively.

@Test
public void testRemoveTranformationRecursively() throws Exception {
    AddTransformationCommand command = new AddTransformationCommand("imports-cleaner", null, false, null, null, null, null, false);
    List<String> list = new LinkedList<String>();
    list.add("imports-cleaner");
    File dir = new File("src/test/resources/yamlmultimodule");
    dir.mkdirs();
    File module0 = new File(dir, "module0");
    module0.mkdir();
    File module1 = new File(dir, "module1");
    module1.mkdir();
    File file = new File(dir, "walkmod.yml");
    if (file.exists()) {
        file.delete();
    }
    File cfg0 = new File(module0, "walkmod.yml");
    try {
        YAMLConfigurationProvider provider = new YAMLConfigurationProvider(file.getPath());
        Configuration conf = new ConfigurationImpl();
        provider.init(conf);
        provider.createConfig();
        provider.addModules(Arrays.asList("module0", "module1"));
        provider.addTransformationConfig(null, null, command.buildTransformationCfg(), true, null, null);
        String output = FileUtils.readFileToString(cfg0);
        Assert.assertTrue(output.contains("imports-cleaner"));
        provider.removeTransformations(null, list, true);
        output = FileUtils.readFileToString(cfg0);
        Assert.assertTrue(!output.contains("imports-cleaner"));
    } finally {
        if (file.exists()) {
            FileUtils.deleteDirectory(dir);
        }
    }
}
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)

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