1 package org.melati.poem.test;
2
3
4 import java.util.Enumeration;
5
6 import org.melati.poem.Group;
7 import org.melati.poem.NullTypeMismatchPoemException;
8 import org.melati.poem.StringKeyReferencePoemType;
9 import org.melati.poem.TypeMismatchPoemException;
10 import org.melati.poem.ValidationPoemException;
11
12
13
14
15
16
17 public class NotNullableStringKeyReferencePoemTypeTest extends SQLPoemTypeSpec<String> {
18
19 public NotNullableStringKeyReferencePoemTypeTest() {
20 }
21
22 public NotNullableStringKeyReferencePoemTypeTest(String name) {
23 super(name);
24 }
25
26 void setObjectUnderTest() {
27 it = new StringKeyReferencePoemType(getDb().getCapabilityTable(),
28 "name",
29 false,
30 60);
31 }
32
33 public void testAssertValidCooked() {
34 if(it.getNullable())
35 super.testAssertValidCooked();
36 else
37 try {
38 it.assertValidCooked(null);
39 fail("Should have blown up");
40 } catch (NullTypeMismatchPoemException e) {
41 e = null;
42 }
43 try {
44 it.assertValidCooked(new Exception("Random class"));
45 fail("Should have blown up");
46 } catch (TypeMismatchPoemException e) {
47 e = null;
48 }
49 it.assertValidCooked(
50 it.cookedOfRaw("_administer_"));
51
52 Group g = (Group) getDb().getGroupTable().firstSelection(null);
53 try {
54 it.assertValidCooked(g);
55 fail("Should have blown up");
56 } catch (ValidationPoemException e) {
57 e = null;
58 }
59 }
60
61 public void testPossibleRaws() {
62 super.testPossibleRaws();
63 Enumeration<String> them = it.possibleRaws();
64 them = it.possibleRaws();
65 int count = 0;
66 while(them.hasMoreElements()) {
67 them.nextElement();
68 count++;
69 }
70 if (it.getNullable())
71 assertEquals(6,count);
72 else {
73 Enumeration<String> them2 = it.possibleRaws();
74 while (them2.hasMoreElements()) {
75 String raw = them2.nextElement();
76 System.err.println(raw);
77 }
78 assertEquals(5,count);
79 }
80
81 }
82
83 public void testRawOfCooked() {
84 super.testRawOfCooked();
85 assertEquals("_administer_", it.rawOfCooked(getDb().administerCapability()));
86
87 }
88
89
90
91
92 public void testToDsdType() {
93 assertEquals("Capability StringKeyReference on name", it.toDsdType());
94
95 }
96
97
98
99
100 public void testBadConstructor() {
101 try {
102 new StringKeyReferencePoemType(null, "name", false, 1);
103 fail("Should have blown up");
104 } catch (NullPointerException e) {
105 e = null;
106 }
107 try {
108 new StringKeyReferencePoemType(getDb().getCapabilityTable(), null, false, 1);
109 fail("Should have blown up");
110 } catch (NullPointerException e) {
111 e = null;
112 }
113 }
114 }