1 package org.apache.torque.engine.database.model;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import junit.framework.TestCase;
23
24 import org.apache.torque.engine.database.transform.XmlToAppData;
25
26 /***
27 * Tests for domain handling (for HSQLDB formerly known as Hypersonic).
28 *
29 * @author <a href="mailto:mkalen@apache.org">Martin Kalén</a>
30 * @version $Id: HypersonicDomainTest.java 473814 2006-11-11 22:30:30Z tv $
31 */
32 public class HypersonicDomainTest extends TestCase
33 {
34
35 private XmlToAppData xmlToAppData;
36 private Database db;
37
38 public HypersonicDomainTest(String name)
39 {
40 super(name);
41 }
42
43 protected void setUp() throws Exception
44 {
45 super.setUp();
46 xmlToAppData = new XmlToAppData("hypersonic", "defaultpackage");
47 db = xmlToAppData.parseFile(
48 "src/test/org/apache/torque/engine/database/model/domaintest-schema.xml");
49 }
50
51 protected void tearDown() throws Exception
52 {
53 xmlToAppData = null;
54 super.tearDown();
55 }
56
57 /***
58 * test if the tables get the package name from the properties file
59 */
60 public void testDomainColumn() throws Exception
61 {
62 Table table = db.getTable("product");
63 Column name = table.getColumn("name");
64 assertEquals("VARCHAR", name.getDomain().getSqlType());
65 assertEquals("40", name.getSize());
66 assertEquals("name VARCHAR(40)", name.getSqlString());
67 Column price = table.getColumn("price");
68 assertEquals("NUMERIC", price.getTorqueType());
69 assertEquals("NUMERIC", price.getDomain().getSqlType());
70 assertEquals("10", price.getSize());
71 assertEquals("2", price.getScale());
72 assertEquals("0", price.getDefaultValue());
73 assertEquals("(10,2)", price.printSize());
74 assertEquals("price NUMERIC(10,2) default 0", price.getSqlString());
75 }
76
77 /***
78 * test if the tables get the package name from the properties file
79 */
80 public void testExtendedDomainColumn() throws Exception
81 {
82 Table table = db.getTable("article");
83 Column price = table.getColumn("price");
84 assertEquals("NUMERIC", price.getTorqueType());
85 assertEquals("NUMERIC", price.getDomain().getSqlType());
86 assertEquals("12", price.getSize());
87 assertEquals("2", price.getScale());
88 assertEquals("1000", price.getDefaultValue());
89 assertEquals("(12,2)", price.printSize());
90 assertEquals("price NUMERIC(12,2) default 1000", price.getSqlString());
91 }
92
93 public void testDecimalColumn() throws Exception
94 {
95 Table table = db.getTable("article");
96 Column col = table.getColumn("decimal_col");
97 assertEquals("DECIMAL", col.getTorqueType());
98 assertEquals("DECIMAL", col.getDomain().getSqlType());
99 assertEquals("10", col.getSize());
100 assertEquals("3", col.getScale());
101 assertEquals("(10,3)", col.printSize());
102 assertEquals("decimal_col DECIMAL(10,3)", col.getSqlString());
103 }
104
105 public void testDateColumn() throws Exception
106 {
107 Table table = db.getTable("article");
108 Column col = table.getColumn("date_col");
109 assertEquals("DATE", col.getTorqueType());
110 assertEquals("DATE", col.getDomain().getSqlType());
111 assertEquals("", col.printSize());
112 assertEquals("date_col DATE", col.getSqlString());
113 }
114
115 public void testNativeAutoincrement() throws Exception
116 {
117 Table table = db.getTable("native");
118 Column col = table.getColumn("native_id");
119 assertEquals("GENERATED BY DEFAULT AS IDENTITY (START WITH 1)",
120 col.getAutoIncrementString());
121 assertEquals("native_id INTEGER GENERATED BY DEFAULT AS IDENTITY "
122 + "(START WITH 1) NOT NULL",
123 col.getSqlString());
124 col = table.getColumn("name");
125 assertEquals("", col.getAutoIncrementString());
126 }
127
128 public void testIdBrokerAutoincrement() throws Exception
129 {
130 Table table = db.getTable("article");
131 Column col = table.getColumn("article_id");
132 assertEquals("", col.getAutoIncrementString());
133 assertEquals("article_id INTEGER NOT NULL", col.getSqlString());
134 col = table.getColumn("name");
135 assertEquals("", col.getAutoIncrementString());
136 }
137
138 public void testBooleanint() throws Exception
139 {
140 Table table = db.getTable("types");
141 Column col = table.getColumn("cbooleanint");
142 assertEquals("", col.getAutoIncrementString());
143 assertEquals("BOOLEANINT", col.getTorqueType());
144 assertEquals("INTEGER", col.getDomain().getSqlType());
145 assertEquals("cbooleanint INTEGER", col.getSqlString());
146 }
147
148 public void testBlob() throws Exception
149 {
150 Table table = db.getTable("types");
151 Column col = table.getColumn("cblob");
152 assertEquals("", col.getAutoIncrementString());
153 assertEquals("BLOB", col.getTorqueType());
154 assertEquals("BINARY", col.getDomain().getSqlType());
155 assertEquals("cblob BINARY", col.getSqlString());
156 }
157
158 }