use of org.walkmod.commands.AddTransformationCommand in project walkmod-core by walkmod.
the class XMLConfigurationProviderTest method testAddTransformationRecursively.
@Test
public void testAddTransformationRecursively() throws Exception {
File aux = new File("src/test/resources/modulesxml");
File aux1 = new File(aux, "module1");
File aux2 = new File(aux, "module2");
aux.mkdirs();
aux1.mkdir();
aux2.mkdir();
File xml = new File(aux, "walkmod.xml");
File xml1 = new File(aux1, "walkmod.xml");
File xml2 = new File(aux2, "walkmod.xml");
XMLConfigurationProvider prov = new XMLConfigurationProvider(xml.getPath(), false);
try {
prov.createConfig();
List<String> modules = new LinkedList<String>();
modules.add("module1");
modules.add("module2");
prov.addModules(modules);
AddTransformationCommand command = new AddTransformationCommand("imports-cleaner", null, false, null, null, null, null, true);
prov.addTransformationConfig(null, null, command.buildTransformationCfg(), true, null, null);
String content = FileUtils.readFileToString(xml);
Assert.assertTrue(!content.contains("imports-cleaner"));
content = FileUtils.readFileToString(xml1);
Assert.assertTrue(content.contains("imports-cleaner"));
content = FileUtils.readFileToString(xml2);
Assert.assertTrue(content.contains("imports-cleaner"));
} finally {
FileUtils.deleteDirectory(aux);
}
}
use of org.walkmod.commands.AddTransformationCommand in project walkmod-core by walkmod.
the class XMLConfigurationProviderTest method testAddTransformationWithPath.
@Test
public void testAddTransformationWithPath() 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, "src", null, null, false);
prov.addTransformationConfig(null, "src", command.buildTransformationCfg(), false, null, null);
String content = FileUtils.readFileToString(xml);
Assert.assertTrue(content.contains("imports-cleaner") && content.contains("src"));
} finally {
xml.delete();
}
}
use of org.walkmod.commands.AddTransformationCommand in project walkmod-core by walkmod.
the class XMLConfigurationProviderTest method testAddTransformationAfterMultipleInDefaultChain.
@Test
public void testAddTransformationAfterMultipleInDefaultChain() 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", null, false, null, null, null, null, false, null, null);
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);
System.out.println(content);
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 XMLConfigurationProviderTest method testRemoveTransformationsRecursively.
@Test
public void testRemoveTransformationsRecursively() throws Exception {
List<String> list = new LinkedList<String>();
list.add("imports-cleaner");
File aux = new File("src/test/resources/xmlmultimodule");
aux.mkdirs();
File module0 = new File(aux, "module0");
File module1 = new File(aux, "module1");
File cfg0 = new File(module0, "walkmod.xml");
File cfg1 = new File(module1, "walkmod.xml");
module0.mkdir();
module1.mkdir();
File xml = new File(aux, "walkmod.xml");
XMLConfigurationProvider prov = new XMLConfigurationProvider(xml.getPath(), false);
try {
Configuration conf = new ConfigurationImpl();
prov.init(conf);
prov.createConfig();
prov.addModules(Arrays.asList("module0", "module1"));
AddTransformationCommand command0 = new AddTransformationCommand("license-applier", "mychain", false, null, null, null, null, true);
prov.addTransformationConfig("mychain", null, command0.buildTransformationCfg(), true, null, null);
String output = FileUtils.readFileToString(cfg0);
System.out.println(output);
AddTransformationCommand command = new AddTransformationCommand("imports-cleaner", "mychain", false, null, null, null, null, true);
prov.addTransformationConfig("mychain", null, command.buildTransformationCfg(), true, null, null);
output = FileUtils.readFileToString(cfg0);
System.out.println(output);
prov.removeTransformations("mychain", list, true);
output = FileUtils.readFileToString(cfg0);
Assert.assertTrue(!output.contains("imports-cleaner"));
Assert.assertTrue(output.contains("license-applier"));
output = FileUtils.readFileToString(cfg1);
Assert.assertTrue(!output.contains("imports-cleaner"));
Assert.assertTrue(output.contains("license-applier"));
} finally {
if (aux.exists()) {
FileUtils.deleteDirectory(aux);
}
}
}
use of org.walkmod.commands.AddTransformationCommand in project walkmod-core by walkmod.
the class XMLConfigurationProviderTest method testRemoveTranformation.
@Test
public void testRemoveTranformation() throws Exception {
List<String> list = new LinkedList<String>();
list.add("imports-cleaner");
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 {
Configuration conf = new ConfigurationImpl();
prov.init(conf);
prov.createConfig();
AddTransformationCommand command = new AddTransformationCommand("imports-cleaner", null, false, null, null, null, null, false);
prov.addTransformationConfig(null, null, command.buildTransformationCfg(), false, null, null);
prov.removeTransformations(null, list, false);
String output = FileUtils.readFileToString(xml);
Assert.assertTrue(!output.contains("imports-cleaner"));
} finally {
if (xml.exists()) {
xml.delete();
}
}
}
Aggregations