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 MySql).
028: *
029: * @version $Id: DomainTest.java 473814 2006-11-11 22:30:30Z tv $
030: */
031: public class DomainTest extends TestCase {
032: private XmlToAppData xmlToAppData = null;
033: private Database db = null;
034:
035: public DomainTest(String name) {
036: super (name);
037: }
038:
039: protected void setUp() throws Exception {
040: super .setUp();
041: xmlToAppData = new XmlToAppData("mysql", "defaultpackage");
042: db = xmlToAppData
043: .parseFile("src/test/org/apache/torque/engine/database/model/domaintest-schema.xml");
044: }
045:
046: protected void tearDown() throws Exception {
047: xmlToAppData = null;
048: super .tearDown();
049: }
050:
051: /**
052: * test if the tables get the package name from the properties file
053: */
054: public void testAllAttributes() throws Exception {
055: Domain amount = db.getDomain("amount");
056: assertEquals(SchemaType.NUMERIC, amount.getType());
057: assertEquals("DECIMAL", amount.getSqlType());
058: assertEquals("10", amount.getSize());
059: assertEquals("2", amount.getScale());
060: assertEquals("0", amount.getDefaultValue());
061: assertEquals("amount domain", amount.getDescription());
062: }
063:
064: /**
065: * test if the tables get the package name from the properties file
066: */
067: public void testDomainColumn() throws Exception {
068: Table table = db.getTable("product");
069: Column name = table.getColumn("name");
070: assertEquals("VARCHAR", name.getDomain().getSqlType());
071: assertEquals("40", name.getSize());
072: assertEquals("name VARCHAR(40)", name.getSqlString());
073: Column price = table.getColumn("price");
074: assertEquals("NUMERIC", price.getTorqueType());
075: assertEquals("DECIMAL", price.getDomain().getSqlType());
076: assertEquals("10", price.getSize());
077: assertEquals("2", price.getScale());
078: assertEquals("0", price.getDefaultValue());
079: assertEquals("(10,2)", price.printSize());
080: assertEquals("price DECIMAL(10,2) default 0", price
081: .getSqlString());
082: }
083:
084: /**
085: * test if the tables get the package name from the properties file
086: */
087: public void testExtendedDomainColumn() throws Exception {
088: Table table = db.getTable("article");
089: Column price = table.getColumn("price");
090: assertEquals("NUMERIC", price.getTorqueType());
091: assertEquals("DECIMAL", price.getDomain().getSqlType());
092: assertEquals("12", price.getSize());
093: assertEquals("2", price.getScale());
094: assertEquals("1000", price.getDefaultValue());
095: assertEquals("(12,2)", price.printSize());
096: assertEquals("price DECIMAL(12,2) default 1000", price
097: .getSqlString());
098: }
099:
100: public void testDecimalColumn() throws Exception {
101: Table table = db.getTable("article");
102: Column col = table.getColumn("decimal_col");
103: assertEquals("DECIMAL", col.getTorqueType());
104: assertEquals("DECIMAL", col.getDomain().getSqlType());
105: assertEquals("10", col.getSize());
106: assertEquals("3", col.getScale());
107: assertEquals("(10,3)", col.printSize());
108: assertEquals("decimal_col DECIMAL(10,3)", col.getSqlString());
109: }
110:
111: public void testDateColumn() throws Exception {
112: Table table = db.getTable("article");
113: Column col = table.getColumn("date_col");
114: assertEquals("DATE", col.getTorqueType());
115: assertEquals("DATETIME", col.getDomain().getSqlType());
116: assertEquals("", col.printSize());
117: assertEquals("date_col DATETIME", col.getSqlString());
118: }
119:
120: public void testNativeAutoincrement() throws Exception {
121: Table table = db.getTable("native");
122: Column col = table.getColumn("native_id");
123: assertEquals("AUTO_INCREMENT", col.getAutoIncrementString());
124: assertEquals("native_id INTEGER NOT NULL AUTO_INCREMENT", col
125: .getSqlString());
126: col = table.getColumn("name");
127: assertEquals("", col.getAutoIncrementString());
128: }
129:
130: public void testIdBrokerAutoincrement() throws Exception {
131: Table table = db.getTable("article");
132: Column col = table.getColumn("article_id");
133: assertEquals("", col.getAutoIncrementString());
134: assertEquals("article_id INTEGER NOT NULL", col.getSqlString());
135: col = table.getColumn("name");
136: assertEquals("", col.getAutoIncrementString());
137: }
138:
139: public void testBooleanint() throws Exception {
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: Table table = db.getTable("types");
150: Column col = table.getColumn("cblob");
151: assertEquals("", col.getAutoIncrementString());
152: assertEquals("BLOB", col.getTorqueType());
153: assertEquals("LONGBLOB", col.getDomain().getSqlType());
154: assertEquals("cblob LONGBLOB", col.getSqlString());
155: }
156:
157: }
|