001: package org.apache.torque.engine.database.model;
002:
003: /*
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: import junit.framework.TestCase;
023:
024: import org.apache.torque.engine.database.transform.XmlToAppData;
025:
026: /**
027: * Tests for domain handling (for HSQLDB formerly known as Hypersonic).
028: *
029: * @author <a href="mailto:mkalen@apache.org">Martin Kalén</a>
030: * @version $Id: HypersonicDomainTest.java 473814 2006-11-11 22:30:30Z tv $
031: */
032: public class HypersonicDomainTest extends TestCase {
033:
034: private XmlToAppData xmlToAppData;
035: private Database db;
036:
037: public HypersonicDomainTest(String name) {
038: super (name);
039: }
040:
041: protected void setUp() throws Exception {
042: super .setUp();
043: xmlToAppData = new XmlToAppData("hypersonic", "defaultpackage");
044: db = xmlToAppData
045: .parseFile("src/test/org/apache/torque/engine/database/model/domaintest-schema.xml");
046: }
047:
048: protected void tearDown() throws Exception {
049: xmlToAppData = null;
050: super .tearDown();
051: }
052:
053: /**
054: * test if the tables get the package name from the properties file
055: */
056: public void testDomainColumn() throws Exception {
057: Table table = db.getTable("product");
058: Column name = table.getColumn("name");
059: assertEquals("VARCHAR", name.getDomain().getSqlType());
060: assertEquals("40", name.getSize());
061: assertEquals("name VARCHAR(40)", name.getSqlString());
062: Column price = table.getColumn("price");
063: assertEquals("NUMERIC", price.getTorqueType());
064: assertEquals("NUMERIC", price.getDomain().getSqlType());
065: assertEquals("10", price.getSize());
066: assertEquals("2", price.getScale());
067: assertEquals("0", price.getDefaultValue());
068: assertEquals("(10,2)", price.printSize());
069: assertEquals("price NUMERIC(10,2) default 0", price
070: .getSqlString());
071: }
072:
073: /**
074: * test if the tables get the package name from the properties file
075: */
076: public void testExtendedDomainColumn() throws Exception {
077: Table table = db.getTable("article");
078: Column price = table.getColumn("price");
079: assertEquals("NUMERIC", price.getTorqueType());
080: assertEquals("NUMERIC", price.getDomain().getSqlType());
081: assertEquals("12", price.getSize());
082: assertEquals("2", price.getScale());
083: assertEquals("1000", price.getDefaultValue());
084: assertEquals("(12,2)", price.printSize());
085: assertEquals("price NUMERIC(12,2) default 1000", price
086: .getSqlString());
087: }
088:
089: public void testDecimalColumn() throws Exception {
090: Table table = db.getTable("article");
091: Column col = table.getColumn("decimal_col");
092: assertEquals("DECIMAL", col.getTorqueType());
093: assertEquals("DECIMAL", col.getDomain().getSqlType());
094: assertEquals("10", col.getSize());
095: assertEquals("3", col.getScale());
096: assertEquals("(10,3)", col.printSize());
097: assertEquals("decimal_col DECIMAL(10,3)", col.getSqlString());
098: }
099:
100: public void testDateColumn() throws Exception {
101: Table table = db.getTable("article");
102: Column col = table.getColumn("date_col");
103: assertEquals("DATE", col.getTorqueType());
104: assertEquals("DATE", col.getDomain().getSqlType());
105: assertEquals("", col.printSize());
106: assertEquals("date_col DATE", col.getSqlString());
107: }
108:
109: public void testNativeAutoincrement() throws Exception {
110: Table table = db.getTable("native");
111: Column col = table.getColumn("native_id");
112: assertEquals("GENERATED BY DEFAULT AS IDENTITY (START WITH 1)",
113: col.getAutoIncrementString());
114: assertEquals(
115: "native_id INTEGER GENERATED BY DEFAULT AS IDENTITY "
116: + "(START WITH 1) NOT NULL", col.getSqlString());
117: col = table.getColumn("name");
118: assertEquals("", col.getAutoIncrementString());
119: }
120:
121: public void testIdBrokerAutoincrement() throws Exception {
122: Table table = db.getTable("article");
123: Column col = table.getColumn("article_id");
124: assertEquals("", col.getAutoIncrementString());
125: assertEquals("article_id INTEGER NOT NULL", col.getSqlString());
126: col = table.getColumn("name");
127: assertEquals("", col.getAutoIncrementString());
128: }
129:
130: public void testBooleanint() throws Exception {
131: Table table = db.getTable("types");
132: Column col = table.getColumn("cbooleanint");
133: assertEquals("", col.getAutoIncrementString());
134: assertEquals("BOOLEANINT", col.getTorqueType());
135: assertEquals("INTEGER", col.getDomain().getSqlType());
136: assertEquals("cbooleanint INTEGER", col.getSqlString());
137: }
138:
139: public void testBlob() throws Exception {
140: Table table = db.getTable("types");
141: Column col = table.getColumn("cblob");
142: assertEquals("", col.getAutoIncrementString());
143: assertEquals("BLOB", col.getTorqueType());
144: assertEquals("BINARY", col.getDomain().getSqlType());
145: assertEquals("cblob BINARY", col.getSqlString());
146: }
147:
148: }
|