1 23 24 30 31 package com.sun.enterprise.admin.monitor.callflow; 32 import com.sun.enterprise.admin.monitor.callflow.RequestType; 33 import java.sql.DatabaseMetaData ; 34 import java.sql.PreparedStatement ; 35 import junit.framework.*; 36 import java.sql.Connection ; 37 import java.sql.DriverManager ; 38 import java.sql.ResultSet ; 39 40 44 public class RequestStartAccessObjectImplTest extends TestCase { 45 46 Connection con = null; 47 TableAccessObject rs = null; 48 PreparedStatement pstmt = null; 49 RequestStartTO[] requestStart = new RequestStartTO[10]; 50 51 public RequestStartAccessObjectImplTest(String testName) { 52 super(testName); 53 54 } 55 56 public void testCreateTable() { 57 System.out.println("RequestStart: testCreateTable"); 58 boolean result = false; 59 try{ 60 result = rs.createTable(con); 61 System.out.println("Create Table returned = "+ result); 62 }catch (Exception e){ 63 e.printStackTrace(); 64 } 65 assertTrue(result); 66 } 67 public void testInsert (){ 68 System.out.println(" testStoreRequestStart"); 69 try{ 70 String insertSQL = rs.getInsertSQL(); 71 System.out.println (" Insert SQL :"+ insertSQL); 72 pstmt = con.prepareStatement(insertSQL); 73 for (int i = 0; i < requestStart.length; i++) { 74 requestStart[i] = new RequestStartTO(); 75 requestStart[i].requestId = "RequestID_"+i; 76 requestStart[i].timeStamp = System.nanoTime(); 77 requestStart[i].requestType = RequestType.REMOTE_EJB; 78 requestStart[i].timeStampMillis = System.currentTimeMillis(); 79 requestStart[i].ipAddress = "129.129.129.129"; 80 } 81 } catch (Exception e) { 82 e.printStackTrace(); 83 } 84 boolean result = rs.insert (pstmt, requestStart); 85 System.out.println("testStoreRequestStart returned = "+result); 86 assertTrue (result); 87 } 88 89 public void testDropTable () { 90 System.out.println("RequestStart : testDropTable"); 91 boolean result = rs.dropTable(con); 92 System.out.println("Drop Table returned = "+result); 93 assertTrue (result); 94 } 95 protected void setUp(){ 96 try{ 97 String url="jdbc:derby://localhost:1527/sun-callflow;retrieveMessagesFromServerOnGetMessage=true;create=true;"; 99 Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance(); 100 con = DriverManager.getConnection(url, "APP", "APP"); 101 rs = RequestStartAccessObjectImpl.getInstance(); 103 } catch (Exception e){ 104 e.printStackTrace(); 105 } 106 } 107 108 protected void tearDown() { 109 try{ 110 con.close(); 111 } catch (Exception e){ 112 e.printStackTrace(); 113 } 114 finally { 115 con = null; 116 } 117 } 118 public static void main(String args[]) { 119 junit.textui.TestRunner.run(RequestStartAccessObjectImplTest.class); 120 } 121 122 123 } 124 | Popular Tags |