1 16 package scriptella.configuration; 17 18 import scriptella.AbstractTestCase; 19 20 import java.net.URL ; 21 import java.util.List ; 22 23 24 30 public class XIncludeTest extends AbstractTestCase { 31 public void testClasspathResource() { 32 URL url = getClass().getResource("XIncludeTest.xml"); 33 test(url); 34 } 35 36 public void testFileResource() { 37 URL u = getResource(getClass().getPackage().getName().replace('.','/')+"/XIncludeTest.xml"); 38 test(u); 39 } 40 41 private void test(final URL url) { 42 ConfigurationFactory cf = new ConfigurationFactory(); 43 cf.setResourceURL(url); 44 45 final ConfigurationEl c = cf.createConfiguration(); 46 final List <ScriptingElement> scripts = c.getScriptingElements(); 47 assertEquals(scripts.size(), 4); 48 49 String text = asString(scripts.get(0).getContent()); 50 String str = "insert into test(id, value) values (2,'333');"; 51 assertTrue("Script \n" + removeExtraWhitespaces(text) + 52 "\n must contain substring: " + str, text.indexOf(str) > 0); 53 text = asString(scripts.get(1).getContent()); 54 str = "insert into test2(id, value) values (3,'444');"; 55 assertTrue("Script \n" + removeExtraWhitespaces(text) + 56 "\n must contain substring: " + str, text.indexOf(str) > 0); 57 text = asString(scripts.get(2).getContent()); 58 str = "insert into test(id, value) values (2,'333');"; 59 assertTrue("Script \n" + removeExtraWhitespaces(text) + 60 "\n must contain substring: " + str, text.indexOf(str) > 0); 61 str = "--Sample1--"; 62 assertTrue("Script \n" + removeExtraWhitespaces(text) + 63 "\n must contain substring: " + str, text.indexOf(str) > 0); 64 str = "--Sample2--"; 65 assertTrue("Script \n" + removeExtraWhitespaces(text) + 66 "\n must contain substring: " + str, text.indexOf(str) > 0); 67 text = asString(scripts.get(3).getContent()); 69 str = "Fallback!"; 70 assertTrue("Script \n" + removeExtraWhitespaces(text) + 71 "\n must contain substring: " + str, text.indexOf(str) > 0); 72 73 } 74 } 75 | Popular Tags |