use of org.walkmod.commands.AddTransformationCommand in project walkmod-core by walkmod.
the class XMLConfigurationProviderTest method testAddConfigurationParameterToWriter.
@Test
public void testAddConfigurationParameterToWriter() throws Exception {
AddTransformationCommand command = new AddTransformationCommand("imports-cleaner", "mychain", false, null, null, null, null, false);
File aux = new File("src/test/resources/xmlparams");
aux.mkdirs();
File xml = new File(aux, "walkmod.xml");
XMLConfigurationProvider prov = new XMLConfigurationProvider(xml.getPath(), false);
try {
prov.createConfig();
TransformationConfig transfCfg = command.buildTransformationCfg();
prov.addTransformationConfig("mychain", null, transfCfg, false, null, null);
prov.setWriter("mychain", "eclipse-writer", null, false, null);
prov.addConfigurationParameter("testParam", "hello", "eclipse-writer", null, null, null, false);
String output = FileUtils.readFileToString(xml);
System.out.println(output);
Assert.assertTrue(output.contains("testParam") && output.contains("hello"));
} finally {
FileUtils.deleteDirectory(aux);
}
}
use of org.walkmod.commands.AddTransformationCommand in project walkmod-core by walkmod.
the class XMLConfigurationProviderTest method testAddTransformationWithBefore.
@Test
public void testAddTransformationWithBefore() throws Exception {
File aux = new File("src/test/resources/xml");
aux.mkdirs();
File xml = new File(aux, "walkmod.xml");
XMLConfigurationProvider prov = new XMLConfigurationProvider(xml.getPath(), false);
try {
prov.createConfig();
AddTransformationCommand command = new AddTransformationCommand("imports-cleaner", null, false, null, null, null, null, false);
prov.addTransformationConfig(null, null, command.buildTransformationCfg(), false, null, null);
command = new AddTransformationCommand("setter-getter", "common", false, null, null, null, null, false, null, "default");
prov.addTransformationConfig("common", null, command.buildTransformationCfg(), false, null, "default");
String content = FileUtils.readFileToString(xml);
Assert.assertTrue(content.contains("imports-cleaner"));
Assert.assertTrue(content.contains("common"));
Assert.assertTrue(content.contains("setter-getter"));
Assert.assertTrue(content.indexOf("common") < content.indexOf("default"));
} finally {
xml.delete();
}
}
use of org.walkmod.commands.AddTransformationCommand in project walkmod-core by walkmod.
the class YAMLConfigurationProviderTest method testAddChainTransformationWithExistingChain.
@Test
public void testAddChainTransformationWithExistingChain() 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);
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("walkmod:commons:class-refactor") && !output.contains("default"));
} finally {
if (file.exists()) {
file.delete();
}
}
}
use of org.walkmod.commands.AddTransformationCommand in project walkmod-core by walkmod.
the class YAMLConfigurationProviderTest method testAddChainTransformationRecursively.
@Test
public void testAddChainTransformationRecursively() 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 dir = new File("src/test/resources/multimoduleyaml");
File module1 = new File(dir, "module1");
File module2 = new File(dir, "module2");
dir.mkdirs();
module1.mkdir();
module2.mkdir();
File file = new File(dir, "walkmod.yml");
File file2 = new File(module1, "walkmod.yml");
File file3 = new File(module2, "walkmod.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);
List<String> modules = new LinkedList<String>();
modules.add("module1");
modules.add("module2");
provider.addModules(modules);
TransformationConfig transformationCfg = command.buildTransformationCfg();
provider.addTransformationConfig(null, null, transformationCfg, true, null, null);
String output = FileUtils.readFileToString(file);
Assert.assertTrue(!output.contains("method-refactor"));
output = FileUtils.readFileToString(file2);
Assert.assertTrue(output.contains("method-refactor"));
output = FileUtils.readFileToString(file3);
Assert.assertTrue(output.contains("method-refactor"));
} finally {
FileUtils.deleteDirectory(dir);
}
}
use of org.walkmod.commands.AddTransformationCommand in project walkmod-core by walkmod.
the class YAMLConfigurationProviderTest method testAddConfigurationParameter2.
@Test
public void testAddConfigurationParameter2() throws Exception {
AddTransformationCommand command = new AddTransformationCommand("imports-cleaner", null, 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(null, 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();
}
}
}
Aggregations