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 Oracle).
028: *
029: * @author <a href="mailto:mpoeschl@marmot.at>Martin Poeschl</a>
030: * @version $Id: MssqlDomainTest.java 473814 2006-11-11 22:30:30Z tv $
031: */
032: public class MssqlDomainTest extends TestCase {
033: private XmlToAppData xmlToAppData = null;
034: private Database db = null;
035:
036: public MssqlDomainTest(String name) {
037: super (name);
038: }
039:
040: protected void setUp() throws Exception {
041: super .setUp();
042: xmlToAppData = new XmlToAppData("mssql", "defaultpackage");
043: db = xmlToAppData
044: .parseFile("src/test/org/apache/torque/engine/database/model/domaintest-schema.xml");
045: }
046:
047: protected void tearDown() throws Exception {
048: xmlToAppData = null;
049: super .tearDown();
050: }
051:
052: /**
053: * test if the tables get the package name from the properties file
054: */
055: public void testDomainColumn() throws Exception {
056: Table table = db.getTable("product");
057: Column name = table.getColumn("name");
058: assertEquals("VARCHAR", name.getDomain().getSqlType());
059: assertEquals("40", name.getSize());
060: assertEquals("name VARCHAR(40) NULL", name.getSqlString());
061: Column price = table.getColumn("price");
062: assertEquals("NUMERIC", price.getTorqueType());
063: assertEquals("NUMERIC", price.getDomain().getSqlType());
064: assertEquals("10", price.getSize());
065: assertEquals("2", price.getScale());
066: assertEquals("0", price.getDefaultValue());
067: assertEquals("(10,2)", price.printSize());
068: assertEquals("price NUMERIC(10,2) default 0 NULL", price
069: .getSqlString());
070: }
071:
072: /**
073: * test if the tables get the package name from the properties file
074: */
075: public void testExtendedDomainColumn() throws Exception {
076: Table table = db.getTable("article");
077: Column price = table.getColumn("price");
078: assertEquals("NUMERIC", price.getTorqueType());
079: assertEquals("NUMERIC", price.getDomain().getSqlType());
080: assertEquals("12", price.getSize());
081: assertEquals("2", price.getScale());
082: assertEquals("1000", price.getDefaultValue());
083: assertEquals("(12,2)", price.printSize());
084: assertEquals("price NUMERIC(12,2) default 1000 NULL", price
085: .getSqlString());
086: }
087:
088: public void testDecimalColumn() throws Exception {
089: Table table = db.getTable("article");
090: Column col = table.getColumn("decimal_col");
091: assertEquals("DECIMAL", col.getTorqueType());
092: assertEquals("DECIMAL", col.getDomain().getSqlType());
093: assertEquals("10", col.getSize());
094: assertEquals("3", col.getScale());
095: assertEquals("(10,3)", col.printSize());
096: assertEquals("decimal_col DECIMAL(10,3) NULL", col
097: .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("DATETIME", col.getDomain().getSqlType());
105: assertEquals("", col.printSize());
106: assertEquals("date_col DATETIME NULL", 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("IDENTITY", col.getAutoIncrementString());
113: assertEquals("native_id INT NOT NULL IDENTITY", col
114: .getSqlString());
115: col = table.getColumn("name");
116: assertEquals("", col.getAutoIncrementString());
117: }
118:
119: public void testIdBrokerAutoincrement() throws Exception {
120: Table table = db.getTable("article");
121: Column col = table.getColumn("article_id");
122: assertEquals("", col.getAutoIncrementString());
123: assertEquals("article_id INT NOT NULL", col.getSqlString());
124: col = table.getColumn("name");
125: assertEquals("", col.getAutoIncrementString());
126: }
127:
128: public void testBooleanint() throws Exception {
129: Table table = db.getTable("types");
130: Column col = table.getColumn("cbooleanint");
131: assertEquals("", col.getAutoIncrementString());
132: assertEquals("BOOLEANINT", col.getTorqueType());
133: assertEquals("INT", col.getDomain().getSqlType());
134: assertEquals("cbooleanint INT NULL", col.getSqlString());
135: }
136:
137: }
|