KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.apache.torque.engine.database.model;
2
3 /*
4  * Copyright 2003,2004 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 Postgresql).
25  *
26  * @author <a HREF="mailto:mpoeschl@marmot.at>Martin Poeschl</a>
27  * @version $Id: PostgresqlDomainTest.java,v 1.4 2004/02/22 06:29:38 jmcnally Exp $
28  */

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

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

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