1 package org.melati.poem.dbms.test;
2
3 import org.melati.poem.*;
4 import org.melati.poem.dbms.DbmsFactory;
5
6
7
8
9
10
11 public class OracleTest extends DbmsSpec {
12
13 public OracleTest(String name) {
14 super(name);
15 }
16
17 protected void setUp() throws Exception {
18 super.setUp();
19 }
20
21 protected void tearDown() throws Exception {
22 super.tearDown();
23 }
24
25 protected void setObjectUnderTest() {
26 it = DbmsFactory.getDbms("org.melati.poem.dbms.Oracle");
27 }
28
29
30
31
32
33 public void testGetStringSqlDefinition() throws Exception {
34 assertEquals("VARCHAR(0)", it.getStringSqlDefinition(0));
35 assertEquals("CLOB", it.getStringSqlDefinition(-1));
36 }
37
38
39
40
41
42
43 public void testGetSqlDefinition() throws Exception {
44 assertEquals("CHAR(1)", it.getSqlDefinition("BOOLEAN"));
45 assertEquals("DOUBLE PRECISION", it.getSqlDefinition("DOUBLE PRECISION"));
46 assertEquals("INT8", it.getSqlDefinition("INT8"));
47 assertEquals("Big Decimal", it.getSqlDefinition("Big Decimal"));
48 }
49
50
51
52
53
54 public void testGetLongSqlDefinition() {
55 assertEquals("NUMBER", it.getLongSqlDefinition());
56 }
57
58
59
60
61
62 public void testSqlBooleanValueOfRaw() {
63 assertEquals("0", it.sqlBooleanValueOfRaw(Boolean.FALSE));
64 assertEquals("1", it.sqlBooleanValueOfRaw(Boolean.TRUE));
65 }
66
67
68
69
70
71 public void testGetBinarySqlDefinition() throws Exception {
72 assertEquals("BLOB", it.getBinarySqlDefinition(0));
73 }
74
75
76
77
78
79 public void testCanDropColumns() throws Exception {
80 assertTrue(it.canDropColumns());
81 }
82
83
84
85
86 public void testMelatiName() {
87 assertEquals("name", it.melatiName("name"));
88 assertEquals(null, it.melatiName(null));
89 assertEquals("~special", it.melatiName("~Special"));
90 }
91
92
93
94
95
96 public void testUnreservedName() {
97 assertEquals("NAME", it.unreservedName("name"));
98 }
99
100
101
102
103
104 public void testCanRepresent() {
105 assertNull(it.canRepresent(StringPoemType.nullableInstance, IntegerPoemType.nullableInstance));
106 assertNull(it.canRepresent(IntegerPoemType.nullableInstance,StringPoemType.nullableInstance));
107
108 assertNull(it.canRepresent(new BigDecimalPoemType(false),new BigDecimalPoemType(true)));
109 assertTrue(it.canRepresent(new BigDecimalPoemType(true),new BigDecimalPoemType(false))
110 instanceof BigDecimalPoemType);
111
112 assertNull(it.canRepresent(new StringPoemType(true, 255), new StringPoemType(true, -1)));
113
114 assertTrue(it.canRepresent(
115 new StringPoemType(true, -1), new StringPoemType(true, -1))
116 instanceof StringPoemType);
117
118 assertNull(it.canRepresent(new TimestampPoemType(true), new DatePoemType(true)));
119
120 assertTrue(it.canRepresent(
121 new BooleanPoemType(true), new BooleanPoemType(false))
122 instanceof BooleanPoemType);
123
124 assertNull(it.canRepresent(new DoublePoemType(false), new BigDecimalPoemType(true)));
125
126 assertNull(it.canRepresent(new DoublePoemType(true), new BigDecimalPoemType(false)));
127
128 assertNull(it.canRepresent(new IntegerPoemType(false), new LongPoemType(true)));
129
130 assertTrue(it.canRepresent(new IntegerPoemType(true), new LongPoemType(false))
131 instanceof LongPoemType);
132 assertTrue(it.canRepresent(new IntegerPoemType(true), new BigDecimalPoemType(false))
133 instanceof BigDecimalPoemType);
134
135
136 assertNull(it.canRepresent(new BinaryPoemType(false,10), new BinaryPoemType(true,10)));
137 assertNull(it.canRepresent(new BinaryPoemType(true,10), new BinaryPoemType(true,11)));
138 assertTrue(it.canRepresent(
139 new BinaryPoemType(true,-1),
140 new BinaryPoemType(true,-1)) instanceof BinaryPoemType);
141 assertTrue(it.canRepresent(
142 new BinaryPoemType(true,2500),
143 new BinaryPoemType(true,10)) instanceof BinaryPoemType);
144
145
146 }
147
148
149
150
151
152
153 public void testGetForeignKeyDefinition() {
154 assertEquals(" ADD (CONSTRAINT FK_test_user) FOREIGN KEY (\"MELATI_USER\") REFERENCES " +
155 "\"MELATI_USER\"(\"ID\") ON DELETE CASCADE",
156 it.getForeignKeyDefinition("test", "user", "user", "id", "delete"));
157 assertEquals(" ADD (CONSTRAINT FK_test_user) FOREIGN KEY (\"MELATI_USER\") REFERENCES " +
158 "\"MELATI_USER\"(\"ID\") ON DELETE SET NULL",
159 it.getForeignKeyDefinition("test", "user", "user", "id", "clear"));
160 }
161
162
163
164
165
166 public void testGetPrimaryKeyDefinition() {
167 assertEquals(" ADD (CONSTRAINT PK_name PRIMARY KEY(\"NAME\"))", it.getPrimaryKeyDefinition("name"));
168 }
169
170 }