KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > scriptella > configuration > XIncludeTest


1 /*
2  * Copyright 2006-2007 The Scriptella Project Team.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package scriptella.configuration;
17
18 import scriptella.AbstractTestCase;
19
20 import java.net.URL JavaDoc;
21 import java.util.List JavaDoc;
22
23
24 /**
25  * TODO: Add documentation
26  *
27  * @author Fyodor Kupolov
28  * @version 1.0
29  */

30 public class XIncludeTest extends AbstractTestCase {
31     public void testClasspathResource() {
32         URL JavaDoc url = getClass().getResource("XIncludeTest.xml");
33         test(url);
34     }
35
36     public void testFileResource() {
37         URL JavaDoc u = getResource(getClass().getPackage().getName().replace('.','/')+"/XIncludeTest.xml");
38         test(u);
39     }
40
41     private void test(final URL JavaDoc url) {
42         ConfigurationFactory cf = new ConfigurationFactory();
43         cf.setResourceURL(url);
44
45         final ConfigurationEl c = cf.createConfiguration();
46         final List JavaDoc<ScriptingElement> scripts = c.getScriptingElements();
47         assertEquals(scripts.size(), 4);
48
49         String JavaDoc text = asString(scripts.get(0).getContent());
50         String JavaDoc 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         //Fallback test
68
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