1
2
3
4 package org.melati.test;
5
6 import java.util.Properties;
7 import java.util.Vector;
8
9 import org.melati.LogicalDatabase;
10 import org.melati.poem.Database;
11 import org.melati.poem.DatabaseInitialisationPoemException;
12 import org.melati.poem.test.PoemTestCase;
13 import org.melati.util.DatabaseInitException;
14 import org.melati.util.NoSuchPropertyException;
15
16
17
18
19
20
21 public class LogicalDatabaseTest extends PoemTestCase {
22
23
24
25
26
27 public LogicalDatabaseTest(String name) {
28 super(name);
29 }
30
31
32
33
34
35 @Override
36 protected void setUp() throws Exception {
37 super.setUp();
38 }
39
40
41
42
43
44 @Override
45 protected void tearDown() throws Exception {
46 super.tearDown();
47 }
48
49
50
51
52
53
54
55 public void testInitialisedDatabases() {
56 Vector<Database> them = LogicalDatabase.initialisedDatabases();
57 assertTrue(them.size()> 0);
58 }
59
60
61
62
63
64
65 public void testGetInitialisedDatabaseNames() {
66 Vector<String> them = LogicalDatabase.getInitialisedDatabaseNames();
67 assertTrue(them.size() > 0);
68 boolean found = false;
69 for (int i = 0; i < them.size(); i++)
70 if ((them.get(i)).equals("melatijunit"))
71 found = true;
72 assertTrue(found);
73
74 }
75
76
77
78
79
80 public void testGetDatabase() throws Exception {
81 try {
82 LogicalDatabase.getDatabase(null);
83 fail("Should have blown up");
84 } catch (NullPointerException e) {
85 e = null;
86 }
87 try {
88 LogicalDatabase.getDatabase("bad");
89 fail("Should have blown up");
90 } catch (DatabaseInitialisationPoemException e) {
91 e = null;
92 }
93 try {
94 LogicalDatabase.getDatabase("unknown");
95 fail("Should have blown up");
96 } catch (DatabaseInitException e) {
97 e = null;
98 }
99 }
100
101
102
103
104 public void testPropertiesFileNotFound() throws Exception {
105 LogicalDatabase.setDatabaseDefs(null);
106 try {
107 LogicalDatabase.getDatabase("unknown");
108 fail("Should have blown up");
109 } catch (DatabaseInitException e) {
110
111 e = null;
112 }
113 LogicalDatabase.setDatabaseDefs(null);
114 }
115
116
117
118
119 public void testSetDatabaseDefs() {
120 Properties empty = new Properties();
121 LogicalDatabase.setDatabaseDefs(empty);
122 try {
123 Database ld = LogicalDatabase.getDatabase("unknown");
124 fail("Should have blown up but LD = " + ld);
125 } catch (DatabaseInitException e) {
126 assertTrue(e.subException instanceof NoSuchPropertyException);
127 e = null;
128 }
129 LogicalDatabase.setDatabaseDefs(null);
130 }
131
132
133
134
135
136 public void testGetDefaultPropertiesName() {
137 assertEquals("org.melati.LogicalDatabase.properties", LogicalDatabase.getPropertiesName());
138 }
139
140 }