Search in sources :

Example 46 with ConfigurationImpl

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

the class YAMLConfigurationProviderTest method testAddModulesToConfig.

@Test
public void testAddModulesToConfig() throws Exception {
    List<String> list = new LinkedList<String>();
    list.add("module1");
    File file = new File("src/test/resources/yaml/addmodules.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);
        provider.addModules(list);
        String output = FileUtils.readFileToString(file);
        String desiredOutput = "modules:\n";
        desiredOutput += "- \"module1\"";
        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)

Example 47 with ConfigurationImpl

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

the class YAMLConfigurationProviderTest method testAddConfigurationParameterWithChain.

@Test
public void testAddConfigurationParameterWithChain() 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, "mychain", false);
        String output = FileUtils.readFileToString(file);
        System.out.println(output);
        Assert.assertTrue(output.contains("params") && output.contains("testParam") && output.contains("hello"));
        provider.addConfigurationParameter("testParam", "bye", "imports-cleaner", null, null, "mychain2", false);
        output = FileUtils.readFileToString(file);
        System.out.println(output);
        Assert.assertFalse(output.contains("params") && output.contains("testParam") && output.contains("bye"));
        provider.addConfigurationParameter("testParam", "bye", "imports-cleaner", null, null, "mychain", false);
        output = FileUtils.readFileToString(file);
        System.out.println(output);
        Assert.assertTrue(output.contains("params") && output.contains("testParam") && output.contains("bye") && !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 48 with ConfigurationImpl

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

the class YAMLConfigurationProviderTest method testConfigProvidersConfig.

@Test
public void testConfigProvidersConfig() 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);
        String output = FileUtils.readFileToString(file);
        String desiredOutput = "conf-providers:\n";
        desiredOutput += "- type: \"maven\"";
        Assert.assertEquals(desiredOutput, output);
    } 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) Test(org.junit.Test)

Example 49 with ConfigurationImpl

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

the class YAMLConfigurationProviderTest method testConfigProvidersConfigRecursive.

@Test
public void testConfigProvidersConfigRecursive() throws Exception {
    AddCfgProviderCommand command = new AddCfgProviderCommand("maven", null);
    File parentDir = new File("src/test/resources/multimoduleyaml");
    parentDir.mkdirs();
    File module0 = new File(parentDir, "module0");
    module0.mkdir();
    File file = new File(parentDir, "walkmod.yml");
    if (file.exists()) {
        file.delete();
    }
    file.createNewFile();
    FileUtils.write(file, "");
    File cfg0 = new File(module0, "walkmod.yml");
    try {
        YAMLConfigurationProvider provider = new YAMLConfigurationProvider(file.getPath());
        Configuration conf = new ConfigurationImpl();
        provider.init(conf);
        ProviderConfig provCfg = command.build();
        provider.addModules(Arrays.asList("module0"));
        provider.addProviderConfig(provCfg, true);
        String output = FileUtils.readFileToString(cfg0);
        String desiredOutput = "conf-providers:\n";
        desiredOutput += "- type: \"maven\"";
        Assert.assertEquals(desiredOutput, output);
    } finally {
        if (parentDir.exists()) {
            FileUtils.deleteDirectory(parentDir);
        }
    }
}
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) Test(org.junit.Test)

Example 50 with ConfigurationImpl

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

the class YAMLConfigurationProviderTest method testEmptyChain.

@Test
public void testEmptyChain() throws Exception {
    File file = new File("src/test/resources/yaml/addEmptychain.yml");
    if (file.exists()) {
        file.delete();
    }
    file.createNewFile();
    FileUtils.write(file, "");
    YAMLConfigurationProvider provider = new YAMLConfigurationProvider(file.getPath());
    Configuration conf = new ConfigurationImpl();
    provider.init(conf);
    ChainConfig chainCfg = new ChainConfigImpl();
    try {
        provider.addChainConfig(chainCfg, false, null);
        String output = FileUtils.readFileToString(file);
        Assert.assertEquals("", output);
    } finally {
        if (file.exists()) {
            file.delete();
        }
    }
}
Also used : Configuration(org.walkmod.conf.entities.Configuration) ChainConfigImpl(org.walkmod.conf.entities.impl.ChainConfigImpl) File(java.io.File) ConfigurationImpl(org.walkmod.conf.entities.impl.ConfigurationImpl) ChainConfig(org.walkmod.conf.entities.ChainConfig) 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