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 protected void setUp() throws Exception {
36 super.setUp();
37 }
38
39
40
41
42
43 protected void tearDown() throws Exception {
44 super.tearDown();
45 }
46
47
48
49
50
51
52
53 public void testInitialisedDatabases() {
54 Vector them = LogicalDatabase.initialisedDatabases();
55 assertTrue(them.size()> 0);
56 }
57
58
59
60
61
62
63 public void testGetInitialisedDatabaseNames() {
64 Vector them = LogicalDatabase.getInitialisedDatabaseNames();
65 assertTrue(them.size() > 0);
66 boolean found = false;
67 for (int i = 0; i < them.size(); i++)
68 if (((String)them.get(i)).equals("melatijunit"))
69 found = true;
70 assertTrue(found);
71
72 }
73
74
75
76
77
78 public void testGetDatabase() throws Exception {
79 try {
80 LogicalDatabase.getDatabase(null);
81 fail("Should have blown up");
82 } catch (NullPointerException e) {
83 e = null;
84 }
85 try {
86 LogicalDatabase.getDatabase("bad");
87 fail("Should have blown up");
88 } catch (DatabaseInitialisationPoemException e) {
89 e = null;
90 }
91 try {
92 LogicalDatabase.getDatabase("unknown");
93 fail("Should have blown up");
94 } catch (DatabaseInitException e) {
95 e = null;
96 }
97 }
98
99
100
101
102 public void testPropertiesFileNotFound() throws Exception {
103 LogicalDatabase.setDatabaseDefs(null);
104 try {
105 LogicalDatabase.getDatabase("unknown");
106 fail("Should have blown up");
107 } catch (DatabaseInitException e) {
108
109 e = null;
110 }
111 LogicalDatabase.setDatabaseDefs(null);
112 }
113
114
115
116
117 public void testSetDatabaseDefs() {
118 Properties empty = new Properties();
119 LogicalDatabase.setDatabaseDefs(empty);
120 try {
121 Database ld = LogicalDatabase.getDatabase("unknown");
122 fail("Should have blown up but LD = " + ld);
123 } catch (DatabaseInitException e) {
124 assertTrue(e.subException instanceof NoSuchPropertyException);
125 e = null;
126 }
127 LogicalDatabase.setDatabaseDefs(null);
128 }
129
130
131
132
133
134 public void testGetDefaultPropertiesName() {
135 assertEquals("org.melati.LogicalDatabase.properties", LogicalDatabase.getPropertiesName());
136 }
137
138 }