KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > torque > engine > database > model > HypersonicDomainTest


1 package org.apache.torque.engine.database.model;
2
3 /*
4  * Copyright 2003-2005 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import junit.framework.TestCase;
20
21 import org.apache.torque.engine.database.transform.XmlToAppData;
22
23 /**
24  * Tests for domain handling (for HSQLDB formerly known as Hypersonic).
25  *
26  * @author <a HREF="mailto:mkalen@apache.org">Martin Kal&eacute;n</a>
27  * @version $Id: HypersonicDomainTest.java,v 1.1 2005/05/20 20:19:18 tfischer Exp $
28  */

29 public class HypersonicDomainTest extends TestCase
30 {
31
32     private XmlToAppData xmlToAppData;
33     private Database db;
34
35     public HypersonicDomainTest(String JavaDoc name)
36     {
37         super(name);
38     }
39
40     protected void setUp() throws Exception JavaDoc
41     {
42         super.setUp();
43         xmlToAppData = new XmlToAppData("hypersonic", "defaultpackage");
44         db = xmlToAppData.parseFile(
45             "src/test/org/apache/torque/engine/database/model/domaintest-schema.xml");
46     }
47
48     protected void tearDown() throws Exception JavaDoc
49     {
50         xmlToAppData = null;
51         super.tearDown();
52     }
53
54     /**
55      * test if the tables get the package name from the properties file
56      */

57     public void testDomainColumn() throws Exception JavaDoc
58     {
59         Table table = db.getTable("product");
60         Column name = table.getColumn("name");
61         assertEquals("VARCHAR", name.getDomain().getSqlType());
62         assertEquals("40", name.getSize());
63         assertEquals("name VARCHAR(40) ", name.getSqlString());
64         Column price = table.getColumn("price");
65         assertEquals("NUMERIC", price.getTorqueType());
66         assertEquals("NUMERIC", price.getDomain().getSqlType());
67         assertEquals("10", price.getSize());
68         assertEquals("2", price.getScale());
69         assertEquals("0", price.getDefaultValue());
70         assertEquals("(10,2)", price.printSize());
71         assertEquals("price NUMERIC(10,2) default 0 ", price.getSqlString());
72     }
73
74     /**
75      * test if the tables get the package name from the properties file
76      */

77     public void testExtendedDomainColumn() throws Exception JavaDoc
78     {
79         Table table = db.getTable("article");
80         Column price = table.getColumn("price");
81         assertEquals("NUMERIC", price.getTorqueType());
82         assertEquals("NUMERIC", price.getDomain().getSqlType());
83         assertEquals("12", price.getSize());
84         assertEquals("2", price.getScale());
85         assertEquals("1000", price.getDefaultValue());
86         assertEquals("(12,2)", price.printSize());
87         assertEquals("price NUMERIC(12,2) default 1000 ", price.getSqlString());
88     }
89
90     public void testDecimalColumn() throws Exception JavaDoc
91     {
92         Table table = db.getTable("article");
93         Column col = table.getColumn("decimal_col");
94         assertEquals("DECIMAL", col.getTorqueType());
95         assertEquals("DECIMAL", col.getDomain().getSqlType());
96         assertEquals("10", col.getSize());
97         assertEquals("3", col.getScale());
98         assertEquals("(10,3)", col.printSize());
99         assertEquals("decimal_col DECIMAL(10,3) ", col.getSqlString());
100     }
101
102     public void testDateColumn() throws Exception JavaDoc
103     {
104         Table table = db.getTable("article");
105         Column col = table.getColumn("date_col");
106         assertEquals("DATE", col.getTorqueType());
107         assertEquals("DATE", col.getDomain().getSqlType());
108         assertEquals("", col.printSize());
109         assertEquals("date_col DATE ", col.getSqlString());
110     }
111
112     public void testNativeAutoincrement() throws Exception JavaDoc
113     {
114         Table table = db.getTable("native");
115         Column col = table.getColumn("native_id");
116         assertEquals("IDENTITY", col.getAutoIncrementString());
117         assertEquals("native_id INTEGER NOT NULL IDENTITY", col.getSqlString());
118         col = table.getColumn("name");
119         assertEquals("", col.getAutoIncrementString());
120     }
121
122     public void testIdBrokerAutoincrement() throws Exception JavaDoc
123     {
124         Table table = db.getTable("article");
125         Column col = table.getColumn("article_id");
126         assertEquals("", col.getAutoIncrementString());
127         assertEquals("article_id INTEGER NOT NULL ", col.getSqlString());
128         col = table.getColumn("name");
129         assertEquals("", col.getAutoIncrementString());
130     }
131
132     public void testBooleanint() throws Exception JavaDoc
133     {
134         Table table = db.getTable("types");
135         Column col = table.getColumn("cbooleanint");
136         assertEquals("", col.getAutoIncrementString());
137         assertEquals("BOOLEANINT", col.getTorqueType());
138         assertEquals("INTEGER", col.getDomain().getSqlType());
139         assertEquals("cbooleanint INTEGER ", col.getSqlString());
140     }
141
142     public void testBlob() throws Exception JavaDoc
143     {
144         Table table = db.getTable("types");
145         Column col = table.getColumn("cblob");
146         assertEquals("", col.getAutoIncrementString());
147         assertEquals("BLOB", col.getTorqueType());
148         assertEquals("BINARY", col.getDomain().getSqlType());
149         assertEquals("cblob BINARY ", col.getSqlString());
150     }
151
152 }
153
Popular Tags