Search in sources :

Example 41 with ConfigurationImpl

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

the class YAMLConfigurationProviderTest method testAddChainTransformationWithNewChain.

@Test
public void testAddChainTransformationWithNewChain() 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);
        String output = FileUtils.readFileToString(file);
        Assert.assertTrue(output.contains("mychain"));
    } 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 42 with ConfigurationImpl

use of org.walkmod.conf.entities.impl.ConfigurationImpl 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 43 with ConfigurationImpl

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

the class YAMLConfigurationProviderTest method testRemoveModule.

@Test
public void testRemoveModule() throws Exception {
    List<String> list = new LinkedList<String>();
    list.add("module1");
    File file = new File("src/test/resources/yaml/removeModule.yml");
    if (file.exists()) {
        file.delete();
    }
    file.createNewFile();
    String input = "modules:\n";
    input += "- \"module1\"";
    FileUtils.write(file, input);
    try {
        YAMLConfigurationProvider provider = new YAMLConfigurationProvider(file.getPath());
        Configuration conf = new ConfigurationImpl();
        provider.init(conf);
        provider.removeModules(list);
        String output = FileUtils.readFileToString(file);
        System.out.println(output);
        Assert.assertTrue(!output.contains("module1"));
    } 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 44 with ConfigurationImpl

use of org.walkmod.conf.entities.impl.ConfigurationImpl 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 45 with ConfigurationImpl

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

the class YAMLConfigurationProviderTest method testAddChainTransformationToChainAfterTranfList.

@Test
public void testAddChainTransformationToChainAfterTranfList() 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 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(null, 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("mychain") && 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)

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