1   package org.apache.torque.engine.database.model;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import junit.framework.TestCase;
23  
24  import org.apache.torque.engine.database.transform.XmlToAppData;
25  
26  /***
27   * Tests for domain handling (for Oracle).
28   *
29   * @author <a href="mailto:mpoeschl@marmot.at>Martin Poeschl</a>
30   * @version $Id: MssqlDomainTest.java 473814 2006-11-11 22:30:30Z tv $
31   */
32  public class MssqlDomainTest extends TestCase
33  {
34      private XmlToAppData xmlToAppData = null;
35      private Database db = null;
36  
37      public MssqlDomainTest(String name)
38      {
39          super(name);
40      }
41  
42      protected void setUp() throws Exception
43      {
44          super.setUp();
45          xmlToAppData = new XmlToAppData("mssql", "defaultpackage");
46          db = xmlToAppData.parseFile(
47              "src/test/org/apache/torque/engine/database/model/domaintest-schema.xml");
48      }
49  
50      protected void tearDown() throws Exception
51      {
52          xmlToAppData = null;
53          super.tearDown();
54      }
55  
56      /***
57       * test if the tables get the package name from the properties file
58       */
59      public void testDomainColumn() throws Exception
60      {
61          Table table = db.getTable("product");
62          Column name = table.getColumn("name");
63          assertEquals("VARCHAR", name.getDomain().getSqlType());
64          assertEquals("40", name.getSize());
65          assertEquals("name VARCHAR(40) NULL", name.getSqlString());
66          Column price = table.getColumn("price");
67          assertEquals("NUMERIC", price.getTorqueType());
68          assertEquals("NUMERIC", price.getDomain().getSqlType());
69          assertEquals("10", price.getSize());
70          assertEquals("2", price.getScale());
71          assertEquals("0", price.getDefaultValue());
72          assertEquals("(10,2)", price.printSize());
73          assertEquals("price NUMERIC(10,2) default 0 NULL", price.getSqlString());
74      }
75  
76      /***
77       * test if the tables get the package name from the properties file
78       */
79      public void testExtendedDomainColumn() throws Exception
80      {
81          Table table = db.getTable("article");
82          Column price = table.getColumn("price");
83          assertEquals("NUMERIC", price.getTorqueType());
84          assertEquals("NUMERIC", price.getDomain().getSqlType());
85          assertEquals("12", price.getSize());
86          assertEquals("2", price.getScale());
87          assertEquals("1000", price.getDefaultValue());
88          assertEquals("(12,2)", price.printSize());
89          assertEquals("price NUMERIC(12,2) default 1000 NULL", price.getSqlString());
90      }
91  
92      public void testDecimalColumn() throws Exception
93      {
94          Table table = db.getTable("article");
95          Column col = table.getColumn("decimal_col");
96          assertEquals("DECIMAL", col.getTorqueType());
97          assertEquals("DECIMAL", col.getDomain().getSqlType());
98          assertEquals("10", col.getSize());
99          assertEquals("3", col.getScale());
100         assertEquals("(10,3)", col.printSize());
101         assertEquals("decimal_col DECIMAL(10,3) NULL", col.getSqlString());
102     }
103 
104     public void testDateColumn() throws Exception
105     {
106         Table table = db.getTable("article");
107         Column col = table.getColumn("date_col");
108         assertEquals("DATE", col.getTorqueType());
109         assertEquals("DATETIME", col.getDomain().getSqlType());
110         assertEquals("", col.printSize());
111         assertEquals("date_col DATETIME NULL", col.getSqlString());
112     }
113 
114     public void testNativeAutoincrement() throws Exception
115     {
116         Table table = db.getTable("native");
117         Column col = table.getColumn("native_id");
118         assertEquals("IDENTITY", col.getAutoIncrementString());
119         assertEquals("native_id INT NOT NULL IDENTITY", col.getSqlString());
120         col = table.getColumn("name");
121         assertEquals("", col.getAutoIncrementString());
122     }
123 
124     public void testIdBrokerAutoincrement() throws Exception
125     {
126         Table table = db.getTable("article");
127         Column col = table.getColumn("article_id");
128         assertEquals("", col.getAutoIncrementString());
129         assertEquals("article_id INT NOT NULL", col.getSqlString());
130         col = table.getColumn("name");
131         assertEquals("", col.getAutoIncrementString());
132     }
133 
134     public void testBooleanint() throws Exception
135     {
136         Table table = db.getTable("types");
137         Column col = table.getColumn("cbooleanint");
138         assertEquals("", col.getAutoIncrementString());
139         assertEquals("BOOLEANINT", col.getTorqueType());
140         assertEquals("INT", col.getDomain().getSqlType());
141         assertEquals("cbooleanint INT NULL", col.getSqlString());
142     }
143 
144 }