745 |
10 Jun 05 |
nicklas |
1 |
/* |
745 |
10 Jun 05 |
nicklas |
$Id$ |
745 |
10 Jun 05 |
nicklas |
3 |
|
3675 |
16 Aug 07 |
jari |
Copyright (C) 2005 Nicklas Nordborg |
4889 |
06 Apr 09 |
nicklas |
Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg |
745 |
10 Jun 05 |
nicklas |
6 |
|
2304 |
22 May 06 |
jari |
This file is part of BASE - BioArray Software Environment. |
2304 |
22 May 06 |
jari |
Available at http://base.thep.lu.se/ |
745 |
10 Jun 05 |
nicklas |
9 |
|
745 |
10 Jun 05 |
nicklas |
BASE is free software; you can redistribute it and/or |
745 |
10 Jun 05 |
nicklas |
modify it under the terms of the GNU General Public License |
4480 |
05 Sep 08 |
jari |
as published by the Free Software Foundation; either version 3 |
745 |
10 Jun 05 |
nicklas |
of the License, or (at your option) any later version. |
745 |
10 Jun 05 |
nicklas |
14 |
|
745 |
10 Jun 05 |
nicklas |
BASE is distributed in the hope that it will be useful, |
745 |
10 Jun 05 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
745 |
10 Jun 05 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
745 |
10 Jun 05 |
nicklas |
GNU General Public License for more details. |
745 |
10 Jun 05 |
nicklas |
19 |
|
745 |
10 Jun 05 |
nicklas |
You should have received a copy of the GNU General Public License |
4514 |
11 Sep 08 |
jari |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
745 |
10 Jun 05 |
nicklas |
22 |
*/ |
6473 |
11 Jun 14 |
nicklas |
23 |
import net.sf.basedb.util.XmlUtil2; |
745 |
10 Jun 05 |
nicklas |
24 |
|
745 |
10 Jun 05 |
nicklas |
25 |
public class TestXMLUtil |
745 |
10 Jun 05 |
nicklas |
26 |
{ |
745 |
10 Jun 05 |
nicklas |
27 |
|
745 |
10 Jun 05 |
nicklas |
28 |
static boolean ok = true; |
745 |
10 Jun 05 |
nicklas |
29 |
public static void main(String[] args) |
745 |
10 Jun 05 |
nicklas |
30 |
{ |
745 |
10 Jun 05 |
nicklas |
31 |
TestUtil.checkArgs(args); |
745 |
10 Jun 05 |
nicklas |
32 |
TestUtil.begin(); |
745 |
10 Jun 05 |
nicklas |
33 |
ok = test_all(); |
745 |
10 Jun 05 |
nicklas |
34 |
TestUtil.stop(); |
745 |
10 Jun 05 |
nicklas |
35 |
} |
745 |
10 Jun 05 |
nicklas |
36 |
|
745 |
10 Jun 05 |
nicklas |
37 |
static boolean test_all() |
745 |
10 Jun 05 |
nicklas |
38 |
{ |
745 |
10 Jun 05 |
nicklas |
39 |
write("++Testing XMLUtil"); |
2959 |
27 Nov 06 |
nicklas |
40 |
test_create_dom(TestXMLUtil.class.getResource("data/extended-properties.xml"), TestXMLUtil.class.getResource("data/extended-properties.dtd")); |
4160 |
26 Feb 08 |
nicklas |
41 |
|
4160 |
26 Feb 08 |
nicklas |
42 |
String schema = TestXMLUtil.class.getResource("data/test.schema.xsd").toString(); |
4160 |
26 Feb 08 |
nicklas |
43 |
test_create_schema_validated_dom( |
4160 |
26 Feb 08 |
nicklas |
44 |
TestXMLUtil.class.getResource("data/test.schema.xml"), |
4160 |
26 Feb 08 |
nicklas |
45 |
"http://base.thep.lu.se/test.schema.xsd", schema); |
745 |
10 Jun 05 |
nicklas |
46 |
write("++Testing XMLUtil "+(ok ? "OK" : "Failed")+"\n"); |
745 |
10 Jun 05 |
nicklas |
47 |
return ok; |
745 |
10 Jun 05 |
nicklas |
48 |
} |
745 |
10 Jun 05 |
nicklas |
49 |
|
745 |
10 Jun 05 |
nicklas |
50 |
|
745 |
10 Jun 05 |
nicklas |
51 |
static void test_create_dom(java.net.URL xmlFile, java.net.URL dtdFile) |
745 |
10 Jun 05 |
nicklas |
52 |
{ |
745 |
10 Jun 05 |
nicklas |
53 |
try |
745 |
10 Jun 05 |
nicklas |
54 |
{ |
6473 |
11 Jun 14 |
nicklas |
55 |
org.jdom2.Document dom = XmlUtil2.getValidatedXml(xmlFile, dtdFile); |
745 |
10 Jun 05 |
nicklas |
56 |
if (!TestUtil.getSilent()) write(dom.toString()); |
745 |
10 Jun 05 |
nicklas |
57 |
write("--Create DOM OK"); |
745 |
10 Jun 05 |
nicklas |
58 |
} |
745 |
10 Jun 05 |
nicklas |
59 |
catch (Throwable ex) |
745 |
10 Jun 05 |
nicklas |
60 |
{ |
745 |
10 Jun 05 |
nicklas |
61 |
write("--Create DOM FAILED"); |
745 |
10 Jun 05 |
nicklas |
62 |
ex.printStackTrace(); |
745 |
10 Jun 05 |
nicklas |
63 |
ok = false; |
745 |
10 Jun 05 |
nicklas |
64 |
} |
745 |
10 Jun 05 |
nicklas |
65 |
} |
745 |
10 Jun 05 |
nicklas |
66 |
|
4160 |
26 Feb 08 |
nicklas |
67 |
static void test_create_schema_validated_dom(java.net.URL xmlFile, String... schemaFiles) |
4160 |
26 Feb 08 |
nicklas |
68 |
{ |
4160 |
26 Feb 08 |
nicklas |
69 |
try |
4160 |
26 Feb 08 |
nicklas |
70 |
{ |
6473 |
11 Jun 14 |
nicklas |
71 |
org.jdom2.Document dom = XmlUtil2.getSchemaValidatedXML(xmlFile, schemaFiles); |
4160 |
26 Feb 08 |
nicklas |
72 |
if (!TestUtil.getSilent()) write(dom.toString()); |
4160 |
26 Feb 08 |
nicklas |
73 |
write("--Create schema validated DOM OK"); |
4160 |
26 Feb 08 |
nicklas |
74 |
} |
4160 |
26 Feb 08 |
nicklas |
75 |
catch (Throwable ex) |
4160 |
26 Feb 08 |
nicklas |
76 |
{ |
4160 |
26 Feb 08 |
nicklas |
77 |
write("--Create schema validated DOM FAILED"); |
4160 |
26 Feb 08 |
nicklas |
78 |
ex.printStackTrace(); |
4160 |
26 Feb 08 |
nicklas |
79 |
ok = false; |
4160 |
26 Feb 08 |
nicklas |
80 |
} |
4160 |
26 Feb 08 |
nicklas |
81 |
} |
4160 |
26 Feb 08 |
nicklas |
82 |
|
745 |
10 Jun 05 |
nicklas |
83 |
|
745 |
10 Jun 05 |
nicklas |
84 |
static void write(String message) |
745 |
10 Jun 05 |
nicklas |
85 |
{ |
745 |
10 Jun 05 |
nicklas |
86 |
System.out.println(message); |
745 |
10 Jun 05 |
nicklas |
87 |
} |
745 |
10 Jun 05 |
nicklas |
88 |
|
745 |
10 Jun 05 |
nicklas |
89 |
} |
745 |
10 Jun 05 |
nicklas |
90 |
|