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 Postgresql).
028: *
029: * @author <a href="mailto:mpoeschl@marmot.at>Martin Poeschl</a>
030: * @version $Id: PostgresqlDomainTest.java 473814 2006-11-11 22:30:30Z tv $
031: */
032: public class PostgresqlDomainTest extends TestCase {
033: private XmlToAppData xmlToAppData = null;
034: private Database db = null;
035:
036: public PostgresqlDomainTest(String name) {
037: super (name);
038: }
039:
040: protected void setUp() throws Exception {
041: super .setUp();
042: xmlToAppData = new XmlToAppData("postgresql", "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)", 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", 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", 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)", col.getSqlString());
097: }
098:
099: public void testDateColumn() throws Exception {
100: Table table = db.getTable("article");
101: Column col = table.getColumn("date_col");
102: assertEquals("DATE", col.getTorqueType());
103: assertEquals("DATE", col.getDomain().getSqlType());
104: assertEquals("", col.printSize());
105: assertEquals("date_col DATE", col.getSqlString());
106: }
107:
108: public void testNativeAutoincrement() throws Exception {
109: Table table = db.getTable("native");
110: Column col = table.getColumn("native_id");
111: assertEquals("", col.getAutoIncrementString());
112: assertEquals("native_id INTEGER NOT NULL", col.getSqlString());
113: col = table.getColumn("name");
114: assertEquals("", col.getAutoIncrementString());
115: }
116:
117: public void testIdBrokerAutoincrement() throws Exception {
118: Table table = db.getTable("article");
119: Column col = table.getColumn("article_id");
120: assertEquals("", col.getAutoIncrementString());
121: assertEquals("article_id INTEGER NOT NULL", col.getSqlString());
122: col = table.getColumn("name");
123: assertEquals("", col.getAutoIncrementString());
124: }
125:
126: public void testBooleanint() throws Exception {
127: Table table = db.getTable("types");
128: Column col = table.getColumn("cbooleanint");
129: assertEquals("", col.getAutoIncrementString());
130: assertEquals("BOOLEANINT", col.getTorqueType());
131: assertEquals("INT2", col.getDomain().getSqlType());
132: assertEquals("cbooleanint INT2", col.getSqlString());
133: }
134:
135: }
|