1 package org.apache.torque.engine.database.model; 2 3 18 19 import junit.framework.TestCase; 20 21 import org.apache.torque.engine.database.transform.XmlToAppData; 22 23 29 public class OracleDomainTest extends TestCase 30 { 31 private XmlToAppData xmlToAppData = null; 32 private Database db = null; 33 34 public OracleDomainTest(String name) 35 { 36 super(name); 37 } 38 39 protected void setUp() throws Exception 40 { 41 super.setUp(); 42 xmlToAppData = new XmlToAppData("oracle", "defaultpackage"); 43 db = xmlToAppData.parseFile( 44 "src/test/org/apache/torque/engine/database/model/domaintest-schema.xml"); 45 } 46 47 protected void tearDown() throws Exception 48 { 49 xmlToAppData = null; 50 super.tearDown(); 51 } 52 53 56 public void testDomainColumn() throws Exception 57 { 58 Table table = db.getTable("product"); 59 Column name = table.getColumn("name"); 60 assertEquals("VARCHAR2", name.getDomain().getSqlType()); 61 assertEquals("40", name.getSize()); 62 assertEquals("name VARCHAR2(40) ", name.getSqlString()); 63 Column price = table.getColumn("price"); 64 assertEquals("NUMERIC", price.getTorqueType()); 65 assertEquals("NUMBER", price.getDomain().getSqlType()); 66 assertEquals("10", price.getSize()); 67 assertEquals("2", price.getScale()); 68 assertEquals("0", price.getDefaultValue()); 69 assertEquals("(10,2)", price.printSize()); 70 assertEquals("price NUMBER(10,2) default 0 ", price.getSqlString()); 71 } 72 73 76 public void testExtendedDomainColumn() throws Exception 77 { 78 Table table = db.getTable("article"); 79 Column price = table.getColumn("price"); 80 assertEquals("NUMERIC", price.getTorqueType()); 81 assertEquals("NUMBER", price.getDomain().getSqlType()); 82 assertEquals("12", price.getSize()); 83 assertEquals("2", price.getScale()); 84 assertEquals("1000", price.getDefaultValue()); 85 assertEquals("(12,2)", price.printSize()); 86 assertEquals("price NUMBER(12,2) default 1000 ", price.getSqlString()); 87 } 88 89 public void testDecimalColumn() throws Exception 90 { 91 Table table = db.getTable("article"); 92 Column col = table.getColumn("decimal_col"); 93 assertEquals("DECIMAL", col.getTorqueType()); 94 assertEquals("NUMBER", col.getDomain().getSqlType()); 95 assertEquals("10", col.getSize()); 96 assertEquals("3", col.getScale()); 97 assertEquals("(10,3)", col.printSize()); 98 assertEquals("decimal_col NUMBER(10,3) ", col.getSqlString()); 99 } 100 101 public void testDateColumn() throws Exception 102 { 103 Table table = db.getTable("article"); 104 Column col = table.getColumn("date_col"); 105 assertEquals("DATE", col.getTorqueType()); 106 assertEquals("DATE", col.getDomain().getSqlType()); 107 assertEquals("", col.printSize()); 108 assertEquals("date_col DATE ", col.getSqlString()); 109 } 110 111 public void testNativeAutoincrement() throws Exception 112 { 113 Table table = db.getTable("native"); 114 Column col = table.getColumn("native_id"); 115 assertEquals("", col.getAutoIncrementString()); 116 assertEquals("native_id NUMBER(10,0) NOT NULL ", col.getSqlString()); 117 col = table.getColumn("name"); 118 assertEquals("", col.getAutoIncrementString()); 119 } 120 121 public void testIdBrokerAutoincrement() throws Exception 122 { 123 Table table = db.getTable("article"); 124 Column col = table.getColumn("article_id"); 125 assertEquals("", col.getAutoIncrementString()); 126 assertEquals("article_id NUMBER(10,0) NOT NULL ", col.getSqlString()); 127 col = table.getColumn("name"); 128 assertEquals("", col.getAutoIncrementString()); 129 } 130 131 public void testBooleanint() throws Exception 132 { 133 Table table = db.getTable("types"); 134 Column col = table.getColumn("cbooleanint"); 135 assertEquals("", col.getAutoIncrementString()); 136 assertEquals("BOOLEANINT", col.getTorqueType()); 137 assertEquals("NUMBER", col.getDomain().getSqlType()); 138 assertEquals("cbooleanint NUMBER(1,0) ", col.getSqlString()); 139 } 140 141 } 142 | Popular Tags |