3062 |
15 Jan 07 |
nicklas |
1 |
/* |
3062 |
15 Jan 07 |
nicklas |
$Id$ |
3062 |
15 Jan 07 |
nicklas |
3 |
|
3675 |
16 Aug 07 |
jari |
Copyright (C) 2007 Nicklas Nordborg |
3062 |
15 Jan 07 |
nicklas |
5 |
|
3062 |
15 Jan 07 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
3062 |
15 Jan 07 |
nicklas |
Available at http://base.thep.lu.se/ |
3062 |
15 Jan 07 |
nicklas |
8 |
|
3062 |
15 Jan 07 |
nicklas |
BASE is free software; you can redistribute it and/or |
3062 |
15 Jan 07 |
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 |
3062 |
15 Jan 07 |
nicklas |
of the License, or (at your option) any later version. |
3062 |
15 Jan 07 |
nicklas |
13 |
|
3062 |
15 Jan 07 |
nicklas |
BASE is distributed in the hope that it will be useful, |
3062 |
15 Jan 07 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
3062 |
15 Jan 07 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3062 |
15 Jan 07 |
nicklas |
GNU General Public License for more details. |
3062 |
15 Jan 07 |
nicklas |
18 |
|
3062 |
15 Jan 07 |
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/>. |
3062 |
15 Jan 07 |
nicklas |
21 |
*/ |
3062 |
15 Jan 07 |
nicklas |
22 |
import net.sf.basedb.core.Presets; |
3062 |
15 Jan 07 |
nicklas |
23 |
import net.sf.basedb.core.Presets.Preset; |
3062 |
15 Jan 07 |
nicklas |
24 |
|
3062 |
15 Jan 07 |
nicklas |
25 |
public class TestPresets |
3062 |
15 Jan 07 |
nicklas |
26 |
{ |
3062 |
15 Jan 07 |
nicklas |
27 |
|
3062 |
15 Jan 07 |
nicklas |
28 |
static boolean ok = true; |
3062 |
15 Jan 07 |
nicklas |
29 |
public static void main(String[] args) |
3062 |
15 Jan 07 |
nicklas |
30 |
{ |
3062 |
15 Jan 07 |
nicklas |
31 |
TestUtil.checkArgs(args); |
3062 |
15 Jan 07 |
nicklas |
32 |
TestUtil.begin(); |
3062 |
15 Jan 07 |
nicklas |
33 |
ok = test_all(); |
3062 |
15 Jan 07 |
nicklas |
34 |
TestUtil.stop(); |
3062 |
15 Jan 07 |
nicklas |
35 |
} |
3062 |
15 Jan 07 |
nicklas |
36 |
|
3062 |
15 Jan 07 |
nicklas |
37 |
static boolean test_all() |
3062 |
15 Jan 07 |
nicklas |
38 |
{ |
3062 |
15 Jan 07 |
nicklas |
39 |
write("++Testing XML presets"); |
3062 |
15 Jan 07 |
nicklas |
40 |
|
3062 |
15 Jan 07 |
nicklas |
41 |
Presets presets = new Presets(); |
3062 |
15 Jan 07 |
nicklas |
42 |
test_create(presets, "one", "first"); |
3062 |
15 Jan 07 |
nicklas |
43 |
test_create(presets, "two", "second"); |
3062 |
15 Jan 07 |
nicklas |
44 |
test_to_xml(presets); |
3062 |
15 Jan 07 |
nicklas |
45 |
write("++Testing XML presets "+(ok ? "OK" : "Failed")+"\n"); |
3062 |
15 Jan 07 |
nicklas |
46 |
return ok; |
3062 |
15 Jan 07 |
nicklas |
47 |
} |
3062 |
15 Jan 07 |
nicklas |
48 |
|
3062 |
15 Jan 07 |
nicklas |
49 |
static Preset test_create(Presets presets, String name, String value) |
3062 |
15 Jan 07 |
nicklas |
50 |
{ |
3062 |
15 Jan 07 |
nicklas |
51 |
if (presets == null) return null; |
3062 |
15 Jan 07 |
nicklas |
52 |
Preset p = null; |
3062 |
15 Jan 07 |
nicklas |
53 |
try |
3062 |
15 Jan 07 |
nicklas |
54 |
{ |
3062 |
15 Jan 07 |
nicklas |
55 |
p = presets.getPreset(name); |
3062 |
15 Jan 07 |
nicklas |
56 |
p.setSetting("testing", value); |
3062 |
15 Jan 07 |
nicklas |
57 |
write("--Create preset: "+name+" OK"); |
3062 |
15 Jan 07 |
nicklas |
58 |
} |
3062 |
15 Jan 07 |
nicklas |
59 |
catch (Throwable ex) |
3062 |
15 Jan 07 |
nicklas |
60 |
{ |
3062 |
15 Jan 07 |
nicklas |
61 |
write("--Create preset: "+name+" FAILED"); |
3062 |
15 Jan 07 |
nicklas |
62 |
ex.printStackTrace(); |
3062 |
15 Jan 07 |
nicklas |
63 |
ok = false; |
3062 |
15 Jan 07 |
nicklas |
64 |
} |
3062 |
15 Jan 07 |
nicklas |
65 |
return p; |
3062 |
15 Jan 07 |
nicklas |
66 |
} |
3062 |
15 Jan 07 |
nicklas |
67 |
|
3062 |
15 Jan 07 |
nicklas |
68 |
static void test_to_xml(Presets presets) |
3062 |
15 Jan 07 |
nicklas |
69 |
{ |
3062 |
15 Jan 07 |
nicklas |
70 |
if (presets == null) return; |
3062 |
15 Jan 07 |
nicklas |
71 |
try |
3062 |
15 Jan 07 |
nicklas |
72 |
{ |
3062 |
15 Jan 07 |
nicklas |
73 |
String xml = presets.asXml(); |
3062 |
15 Jan 07 |
nicklas |
74 |
if (!TestUtil.getSilent()) |
3062 |
15 Jan 07 |
nicklas |
75 |
{ |
3062 |
15 Jan 07 |
nicklas |
76 |
write(xml); |
3062 |
15 Jan 07 |
nicklas |
77 |
} |
3062 |
15 Jan 07 |
nicklas |
78 |
write("--Create XML from preset: OK"); |
3062 |
15 Jan 07 |
nicklas |
79 |
} |
3062 |
15 Jan 07 |
nicklas |
80 |
catch (Throwable ex) |
3062 |
15 Jan 07 |
nicklas |
81 |
{ |
3062 |
15 Jan 07 |
nicklas |
82 |
write("--Create XML from preset: FAILED"); |
3062 |
15 Jan 07 |
nicklas |
83 |
ex.printStackTrace(); |
3062 |
15 Jan 07 |
nicklas |
84 |
ok = false; |
3062 |
15 Jan 07 |
nicklas |
85 |
} |
3062 |
15 Jan 07 |
nicklas |
86 |
} |
3062 |
15 Jan 07 |
nicklas |
87 |
|
3062 |
15 Jan 07 |
nicklas |
88 |
static void write(String message) |
3062 |
15 Jan 07 |
nicklas |
89 |
{ |
3062 |
15 Jan 07 |
nicklas |
90 |
System.out.println(message); |
3062 |
15 Jan 07 |
nicklas |
91 |
} |
3062 |
15 Jan 07 |
nicklas |
92 |
|
3062 |
15 Jan 07 |
nicklas |
93 |
} |
3062 |
15 Jan 07 |
nicklas |
94 |
|