1 package org.melati.example.contacts;
2
3 import org.melati.example.contacts.Contact.DescendantParentException;
4 import org.melati.poem.*;
5 import org.melati.poem.test.PoemTestCase;
6
7
8
9
10 public class ContactTest extends PoemTestCase {
11
12 private static String databaseName = "contacts";
13
14 private Contact rootContact = null;
15 private Contact a = null;
16 private Contact b = null;
17 private Contact c = null;
18 private Contact r = null;
19 private Contact s = null;
20 private Contact x = null;
21 private Contact y = null;
22 private Contact z = null;
23
24
25
26
27 public ContactTest(String arg0) {
28 super(arg0);
29 }
30
31 protected void setUp() throws Exception {
32 super.setUp();
33 User guestUser = getDb().getUserTable().guestUser();
34 setUserToRunAs(guestUser);
35 getDb().inSession(AccessToken.root,
36 new PoemTask() {
37 public void run() {
38 try {
39 rootContact = (Contact) ((ContactsDatabase) getDb()).getContactTable().newPersistent();
40 rootContact.setAddress("Oxford");
41 rootContact.setName("rootContact");
42 rootContact = (Contact) ((ContactsDatabase) getDb()).getContactTable().getNameColumn().ensure(rootContact);
43
44 a = ((ContactsDatabase) getDb()).getContactTable().ensure("a", rootContact, "Oxford");
45 b = ((ContactsDatabase) getDb()).getContactTable().ensure("b", rootContact, "Oxford");
46 c = ((ContactsDatabase) getDb()).getContactTable().ensure("c", rootContact, "Oxford");
47
48 r = ((ContactsDatabase)getDb()).getContactTable().ensure("r", a, "Oxford");
49 s = ((ContactsDatabase)getDb()).getContactTable().ensure("s", a, "Oxford");
50
51 x = ((ContactsDatabase)getDb()).getContactTable().ensure("x", s, "Oxford");
52 y = ((ContactsDatabase)getDb()).getContactTable().ensure("y", x, "Oxford");
53 z = ((ContactsDatabase)getDb()).getContactTable().ensure("z", y, "Oxford");
54 PoemThread.commit();
55 } catch (Throwable e) {
56
57 throw new RuntimeException(e);
58 }
59 }
60 });
61
62 }
63
64 protected void tearDown() throws Exception {
65 super.tearDown();
66 }
67
68
69
70
71 protected String getDbName() {
72 return databaseName;
73 }
74
75 public Database getDb(String dbNameP) {
76 if (dbNameP == null)
77 throw new NullPointerException();
78 return getPoemDatabase();
79 }
80
81
82
83
84 public Database getPoemDatabase() {
85 maxTrans = 4;
86 return PoemDatabaseFactory.getDatabase(databaseName,
87 "jdbc:hsqldb:mem:" + databaseName,
88 "sa",
89 "","org.melati.example.contacts.ContactsDatabase",
90 "org.melati.poem.dbms.Hsqldb",false,false,false,4);
91 }
92 protected void databaseUnchanged() {
93 assertEquals("Setting changed", 0, getDb().getSettingTable().count());
94 assertEquals("Group changed", 1, getDb().getGroupTable().count());
95 assertEquals("GroupMembership changed", 1, getDb().getGroupMembershipTable().count());
96 assertEquals("Capability changed", 5, getDb().getCapabilityTable().count());
97 assertEquals("GroupCapability changed", 1, getDb().getGroupCapabilityTable().count());
98 assertEquals("TableCategory changed", 5, getDb().getTableCategoryTable().count());
99 assertEquals("User changed", 2, getDb().getUserTable().count());
100 assertEquals("ColumnInfo changed", 81, getDb().getColumnInfoTable().count());
101 assertEquals("TableInfo changed", 12, getDb().getTableInfoTable().count());
102 checkTablesAndColumns(12,81);
103 }
104
105
106
107
108 public void testSetOwner() {
109 try {
110 rootContact.setOwner(z);
111 fail("Should have bombed");
112 } catch (DescendantParentException e) {
113 e = null;
114 }
115 }
116
117
118
119
120 public void testIsIn() {
121
122 }
123
124
125
126
127 public void testGetChildren() {
128 assertTrue(rootContact.getChildren().length == 3);
129 }
130
131
132
133
134 public void testGetAncestors() {
135 assertTrue(z.getAncestors().toArray().length == 5);
136 assertTrue(b.getAncestors().toArray().length == 1);
137 assertTrue(c.getAncestors().toArray().length == 1);
138 assertTrue(r.getAncestors().toArray().length == 2);
139 assertTrue(s.getAncestors().toArray().length == 2);
140 }
141
142
143
144
145 public void testArrayOfVector() {
146
147 }
148
149
150
151
152 public void testArrayOfEnumeration() {
153
154 }
155
156 }