Search in sources :

Example 46 with TransformationConfig

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

the class YAMLConfigurationProviderTest method testRemoveChains.

@Test
public void testRemoveChains() 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);
        List<String> chains = new LinkedList<String>();
        chains.add("mychain");
        provider.removeChains(chains, false);
        String output = FileUtils.readFileToString(file);
        System.out.println(output);
        Assert.assertTrue(!output.contains("mychain"));
    } 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) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 47 with TransformationConfig

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

the class YAMLConfigurationProviderTest method testAddExcludes.

@Test
public void testAddExcludes() throws Exception {
    AddTransformationCommand command = new AddTransformationCommand("imports-cleaner", "mychain", false, null, null, null, null, false);
    File file = new File("src/test/resources/yaml/addExcludes.yml");
    if (file.exists()) {
        file.delete();
    }
    file.createNewFile();
    FileUtils.write(file, "");
    YAMLConfigurationProvider prov = new YAMLConfigurationProvider(file.getPath());
    try {
        prov.createConfig();
        TransformationConfig transfCfg = command.buildTransformationCfg();
        prov.addTransformationConfig("mychain", null, transfCfg, false, null, null);
        prov.setWriter("mychain", "eclipse-writer", null, false, null);
        prov.addExcludesToChain("mychain", Arrays.asList("foo"), false, true, false);
        String output = FileUtils.readFileToString(file);
        System.out.println(output);
        Assert.assertTrue(output.contains("foo"));
    } finally {
        if (file.exists()) {
            file.delete();
        }
    }
}
Also used : TransformationConfig(org.walkmod.conf.entities.TransformationConfig) AddTransformationCommand(org.walkmod.commands.AddTransformationCommand) File(java.io.File) Test(org.junit.Test)

Example 48 with TransformationConfig

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

the class YAMLConfigurationProviderTest method testRemoveIncludes.

@Test
public void testRemoveIncludes() throws Exception {
    AddTransformationCommand command = new AddTransformationCommand("imports-cleaner", "mychain", false, null, null, null, null, false);
    File file = new File("src/test/resources/yaml/addIncludesInDefault.yml");
    if (file.exists()) {
        file.delete();
    }
    file.createNewFile();
    FileUtils.write(file, "");
    YAMLConfigurationProvider prov = new YAMLConfigurationProvider(file.getPath());
    try {
        prov.createConfig();
        TransformationConfig transfCfg = command.buildTransformationCfg();
        prov.addTransformationConfig("mychain", null, transfCfg, false, null, null);
        command = new AddTransformationCommand("imports-cleaner", null, false, null, null, null, null, false);
        transfCfg = command.buildTransformationCfg();
        prov.addTransformationConfig(null, null, transfCfg, false, null, null);
        prov.addIncludesToChain(null, Arrays.asList("foo"), false, true, false);
        prov.removeIncludesFromChain("default", Arrays.asList("foo"), false, true, false);
        String output = FileUtils.readFileToString(file);
        System.out.println(output);
        Assert.assertTrue(!output.contains("foo"));
    } finally {
        if (file.exists()) {
            file.delete();
        }
    }
}
Also used : TransformationConfig(org.walkmod.conf.entities.TransformationConfig) AddTransformationCommand(org.walkmod.commands.AddTransformationCommand) File(java.io.File) Test(org.junit.Test)

Example 49 with TransformationConfig

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

the class YAMLConfigurationProviderTest method testCompleteYaml.

@Test
public void testCompleteYaml() {
    YAMLConfigurationProvider provider = new YAMLConfigurationProvider("src/test/resources/yaml/walkmod.yml");
    Configuration conf = new ConfigurationImpl();
    provider.init(conf);
    provider.load();
    Assert.assertEquals(2, conf.getPlugins().size());
    Iterator<PluginConfig> itPluginCfg = conf.getPlugins().iterator();
    PluginConfig firstPlugin = itPluginCfg.next();
    Assert.assertEquals("org.walkmod", firstPlugin.getGroupId());
    Assert.assertEquals("walkmod-maven-plugin", firstPlugin.getArtifactId());
    Assert.assertEquals("[1.0, 2.0)", firstPlugin.getVersion());
    Assert.assertEquals(1, conf.getProviderConfigurations().size());
    Iterator<ProviderConfig> itProvCfg = conf.getProviderConfigurations().iterator();
    Assert.assertEquals("walkmod:commons:maven", itProvCfg.next().getType());
    Assert.assertEquals(1, conf.getChainConfigs().size());
    ChainConfig cc = conf.getChainConfigs().iterator().next();
    Assert.assertEquals("main-chain", cc.getName());
    Assert.assertNotNull(cc.getReaderConfig());
    Assert.assertNull(cc.getReaderConfig().getPath());
    Assert.assertEquals(2, cc.getWalkerConfig().getTransformations().size());
    Assert.assertNotNull(cc.getWriterConfig());
    Assert.assertNull(cc.getWriterConfig().getPath());
    Iterator<TransformationConfig> it = cc.getWalkerConfig().getTransformations().iterator();
    TransformationConfig transCfg = it.next();
    Assert.assertEquals("walkmod:commons:method-refactor", transCfg.getType());
    Assert.assertNotNull(transCfg.getParameters());
    Assert.assertEquals("src/conf/refactoring-methods.json", transCfg.getParameters().get("refactoringConfigFile"));
}
Also used : PluginConfig(org.walkmod.conf.entities.PluginConfig) Configuration(org.walkmod.conf.entities.Configuration) ProviderConfig(org.walkmod.conf.entities.ProviderConfig) TransformationConfig(org.walkmod.conf.entities.TransformationConfig) ConfigurationImpl(org.walkmod.conf.entities.impl.ConfigurationImpl) ChainConfig(org.walkmod.conf.entities.ChainConfig) Test(org.junit.Test)

Example 50 with TransformationConfig

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

the class YAMLConfigurationProviderTest method testAddIncludesToWriter.

@Test
public void testAddIncludesToWriter() throws Exception {
    AddTransformationCommand command = new AddTransformationCommand("imports-cleaner", "mychain", false, null, null, null, null, false);
    File file = new File("src/test/resources/yaml/addIncludes.yml");
    if (file.exists()) {
        file.delete();
    }
    file.createNewFile();
    FileUtils.write(file, "");
    YAMLConfigurationProvider prov = new YAMLConfigurationProvider(file.getPath());
    try {
        prov.createConfig();
        TransformationConfig transfCfg = command.buildTransformationCfg();
        prov.addTransformationConfig("mychain", null, transfCfg, false, null, null);
        prov.setWriter("mychain", "eclipse-writer", null, false, null);
        prov.addIncludesToChain("mychain", Arrays.asList("foo"), false, false, true);
        String output = FileUtils.readFileToString(file);
        System.out.println(output);
        Assert.assertTrue(output.contains("foo"));
    } finally {
        if (file.exists()) {
            file.delete();
        }
    }
}
Also used : TransformationConfig(org.walkmod.conf.entities.TransformationConfig) AddTransformationCommand(org.walkmod.commands.AddTransformationCommand) File(java.io.File) Test(org.junit.Test)

Aggregations

TransformationConfig (org.walkmod.conf.entities.TransformationConfig)52 Test (org.junit.Test)40 File (java.io.File)36 AddTransformationCommand (org.walkmod.commands.AddTransformationCommand)36 Configuration (org.walkmod.conf.entities.Configuration)23 ConfigurationImpl (org.walkmod.conf.entities.impl.ConfigurationImpl)20 ChainConfig (org.walkmod.conf.entities.ChainConfig)11 LinkedList (java.util.LinkedList)7 HashMap (java.util.HashMap)5 WalkerConfig (org.walkmod.conf.entities.WalkerConfig)5 Element (org.w3c.dom.Element)3 ReaderConfig (org.walkmod.conf.entities.ReaderConfig)3 WriterConfig (org.walkmod.conf.entities.WriterConfig)3 ChainConfigImpl (org.walkmod.conf.entities.impl.ChainConfigImpl)3 TransformationConfigImpl (org.walkmod.conf.entities.impl.TransformationConfigImpl)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 TextNode (com.fasterxml.jackson.databind.node.TextNode)2