1 package net.sf.voruta; 2 3 import java.util.*; 4 import java.lang.reflect.*; 5 import java.sql.*; 6 import java.io.*; 7 import junit.framework.*; 8 9 10 /*** 11 * 12 * @author baliuka 13 */ 14 public class ProcedureUtilsTest extends TestCase { 15 16 17 18 public ProcedureUtilsTest(java.lang.String testName) { 19 super(testName); 20 } 21 22 public static void main(java.lang.String[] args) throws Exception{ 23 24 TestAll.configure(); 25 26 try{ 27 28 junit.textui.TestRunner.run(suite()); 29 30 }finally{ 31 32 Db.close(); 33 34 } 35 } 36 37 public static Test suite() throws Exception{ 38 39 create(); 40 41 TestSuite suite = new TestSuite(ProcedureUtilsTest.class); 42 43 44 return suite; 45 } 46 47 private static AbstractDemo getDemo(){ 48 49 AbstractDemo ad = (AbstractDemo)Db.getProcedures(AbstractDemo.class); 50 51 return ad; 52 } 53 54 public static void create() { 55 56 AbstractDemo demo = getDemo(); 57 58 try{ 59 60 demo.drop(Demo.TABLE_NAME); 61 62 }catch(Exception e){ 63 64 DbUtils.getLog().debug(e); 65 66 } 67 demo.create(); 68 } 69 70 71 public void testGetInstance() throws Exception { 72 73 74 75 AbstractDemo demo = getDemo(); 76 77 demo.clear(); 78 79 assertTrue( !demo.exists(1) ); 80 assertTrue( demo.add(1,"test") == 1 ); 81 assertTrue( demo.exists(1) ); 82 83 try{ 84 85 demo.checkExists(1); 86 87 }catch(Exception e){ 88 89 fail( e.getMessage() ); 90 } 91 92 try{ 93 94 demo.checkExists(-1); 95 fail("checkExists"); 96 97 }catch(Exception ok){ 98 99 } 100 101 102 for( int i = 100; i < 110;i++){ 103 demo.add(new DemoBean(i, "test" + i)); 104 } 105 106 assertTrue("inserted beans", 100 < demo.maxId(Demo.TABLE_NAME).intValue() ); 107 108 demo.print(System.out); 109 110 demo.clear(); 111 112 for( int i = 0; i< 10;i++){ 113 demo.add(i + 2,"test" + i); 114 } 115 116 demo.print(System.out); 117 demo.dynamicPrint(System.out,Demo.TABLE_NAME,Demo.PRIMARY_KEY,8); 118 119 Integer max = demo.maxId(Demo.TABLE_NAME); 120 121 122 assertEquals(demo.concat("A","B"), "AB" ); 123 assertTrue(demo.getRow(max.intValue()).length == 2 ); 124 125 int ints[] = demo.getRowOfInts(max.intValue()); 126 127 for(int i = 0, len = ints.length; i < len; i++){ 128 assertEquals(max.intValue(), ints[i] ); 129 } 130 131 assertTrue(demo.getRowAsMap(max.intValue()).size() == 2 ); 132 assertTrue(demo.getAll(Demo.TABLE_NAME).size() > 2 ); 133 assertTrue(demo.getColumnAsArray().length == demo.getColumn().size()); 134 135 DemoBean bean = new DemoBean(); 136 137 demo.getRowAsBean(bean, max.intValue()); 138 assertTrue( bean.getId() == max.intValue() ); 139 assertTrue( bean.getName() != null ); 140 141 142 bean = demo.getRowAsBean( max.intValue() ); 143 assertTrue( bean.getId() == max.intValue() ); 144 assertTrue( bean.getName() != null ); 145 146 Collection col = demo.getBeans(); 147 148 assertEquals( demo.getArrayOfBeans().length , col.size()); 149 demo.clear(); 150 151 try{ 152 153 demo.checkExists(1); 154 fail("delete"); 155 156 }catch(Exception ok){ 157 158 } 159 160 161 } 162 163 public void testUDF() throws Exception { 164 165 AbstractDemo demo = getDemo(); 166 assertEquals(demo.concatText("A","B"),"AB"); 167 168 } 169 170 public void testPlain() throws Exception { 171 172 AbstractDemo demo = getDemo(); 173 assertEquals(demo.plain(),777); 174 175 } 176 public void testDynamicParameter() throws Exception{ 177 178 AbstractDemo demo = getDemo(); 179 180 assertTrue("dynamicParameter", ! demo.exists(Demo.PRIMARY_KEY, Demo.TABLE_NAME, -1) ); 181 182 } 183 184 185 } 186

This page was automatically generated by Maven