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: OracleDomainTest.java 473814 2006-11-11 22:30:30Z tv $
031: */
032: public class OracleDomainTest extends TestCase {
033: private XmlToAppData xmlToAppData = null;
034: private Database db = null;
035:
036: public OracleDomainTest(String name) {
037: super (name);
038: }
039:
040: protected void setUp() throws Exception {
041: super .setUp();
042: xmlToAppData = new XmlToAppData("oracle", "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("VARCHAR2", name.getDomain().getSqlType());
059: assertEquals("40", name.getSize());
060: assertEquals("name VARCHAR2(40)", name.getSqlString());
061: Column price = table.getColumn("price");
062: assertEquals("NUMERIC", price.getTorqueType());
063: assertEquals("NUMBER", 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 NUMBER(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("NUMBER", 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 NUMBER(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("NUMBER", col.getDomain().getSqlType());
093: assertEquals("10", col.getSize());
094: assertEquals("3", col.getScale());
095: assertEquals("(10,3)", col.printSize());
096: assertEquals("decimal_col NUMBER(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 NUMBER(10,0) NOT NULL", col
113: .getSqlString());
114: col = table.getColumn("name");
115: assertEquals("", col.getAutoIncrementString());
116: }
117:
118: public void testIdBrokerAutoincrement() throws Exception {
119: Table table = db.getTable("article");
120: Column col = table.getColumn("article_id");
121: assertEquals("", col.getAutoIncrementString());
122: assertEquals("article_id NUMBER(10,0) NOT NULL", col
123: .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("NUMBER", col.getDomain().getSqlType());
134: assertEquals("cbooleanint NUMBER(1,0)", col.getSqlString());
135: }
136:
137: }
|