1 64 65 package com.jcorporate.expresso.core.dbobj.tests; 66 67 import com.jcorporate.expresso.core.db.DBException; 68 import com.jcorporate.expresso.core.dbobj.DBIndex; 69 import com.jcorporate.expresso.services.test.ExpressoTestCase; 70 import junit.framework.Test; 71 import junit.framework.TestSuite; 72 73 74 80 public class DBIndexTest 81 extends ExpressoTestCase { 82 static final String [] tests = { 83 "CREATE UNIQUE INDEX index1 ON table1(field1);", 84 "CREATE INDEX index2 ON table2(fieldA,fieldB);" 85 }; 86 87 public DBIndexTest(String testName) 88 throws Exception { 89 super(testName); 90 } 91 92 public static void main(String [] args) 93 throws Exception { 94 95 junit.textui.TestRunner.run(suite()); 97 } 98 99 105 public static Test suite() 106 throws Exception { 107 return new TestSuite(DBIndexTest.class); 108 } 109 110 111 public void testUniqueIndex() 112 throws Exception { 113 114 DBIndex dbi = new DBIndex(); 116 dbi.setTableName("table1"); 117 dbi.setIndexName("index1"); 118 dbi.setFieldNames("field1"); 119 dbi.setUnique(true); 120 121 String result = dbi.constructSQL(); 122 assertTrue("First DBIndex Test", result.equals(tests[0])); 123 } 124 125 public void testNonUniqueIndex() 126 throws Exception { 127 128 DBIndex dbi = new DBIndex("index2", "table2", "fieldA,fieldB", false); 130 String result = dbi.constructSQL(); 131 assertTrue("Second DBIndex Test", result.equals(tests[1])); 132 } 133 134 public void testBadInputs() { 135 136 DBIndex dbi = new DBIndex(null, null, null, false); 138 139 try { 140 String result = dbi.constructSQL(); 141 fail("Created bad SQL given bad inputs"); 142 } catch (DBException e) { 143 144 } catch (NullPointerException e) { 146 e.printStackTrace(); 147 fail("Caught NULL Pointer Exception should have been handled"); 148 } 149 } 150 } | Popular Tags |