use of org.walkmod.conf.entities.Configuration 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();
}
}
}
use of org.walkmod.conf.entities.Configuration 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"));
}
use of org.walkmod.conf.entities.Configuration 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();
}
}
}
use of org.walkmod.conf.entities.Configuration 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();
}
}
}
use of org.walkmod.conf.entities.Configuration 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();
}
}
}
Aggregations