Search in sources :

Example 21 with Configuration

use of org.walkmod.conf.entities.Configuration 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 22 with Configuration

use of org.walkmod.conf.entities.Configuration 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 23 with Configuration

use of org.walkmod.conf.entities.Configuration 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 24 with Configuration

use of org.walkmod.conf.entities.Configuration 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)

Example 25 with Configuration

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

the class YAMLConfigurationProviderTest method testAddConfigurationParameter.

@Test
public void testAddConfigurationParameter() throws Exception {
    AddTransformationCommand command = new AddTransformationCommand("imports-cleaner", "mychain", 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("mychain", 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)

Aggregations

Configuration (org.walkmod.conf.entities.Configuration)58 ConfigurationImpl (org.walkmod.conf.entities.impl.ConfigurationImpl)48 Test (org.junit.Test)43 File (java.io.File)38 TransformationConfig (org.walkmod.conf.entities.TransformationConfig)23 LinkedList (java.util.LinkedList)21 AddTransformationCommand (org.walkmod.commands.AddTransformationCommand)21 ChainConfig (org.walkmod.conf.entities.ChainConfig)11 PluginConfig (org.walkmod.conf.entities.PluginConfig)10 HashMap (java.util.HashMap)6 WalkModException (org.walkmod.exceptions.WalkModException)6 V2_AsciiTable (de.vandermeer.asciitable.v2.V2_AsciiTable)5 IOException (java.io.IOException)5 WalkModFacade (org.walkmod.WalkModFacade)5 ConfigurationManager (org.walkmod.conf.ConfigurationManager)5 ProviderConfig (org.walkmod.conf.entities.ProviderConfig)5 PluginConfigImpl (org.walkmod.conf.entities.impl.PluginConfigImpl)5 Document (org.w3c.dom.Document)4 NodeList (org.w3c.dom.NodeList)4 InvalidConfigurationException (org.walkmod.exceptions.InvalidConfigurationException)4