KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > monitor > callflow > RequestStartAccessObjectImplTest


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * RequestStartAccessObjectImplTest.java
26  * JUnit based test
27  *
28  * Created on July 13, 2005, 9:32 AM
29  */

30
31 package com.sun.enterprise.admin.monitor.callflow;
32 import com.sun.enterprise.admin.monitor.callflow.RequestType;
33 import java.sql.DatabaseMetaData JavaDoc;
34 import java.sql.PreparedStatement JavaDoc;
35 import junit.framework.*;
36 import java.sql.Connection JavaDoc;
37 import java.sql.DriverManager JavaDoc;
38 import java.sql.ResultSet JavaDoc;
39
40 /**
41  *
42  * @author Harpreet Singh
43  */

44 public class RequestStartAccessObjectImplTest extends TestCase {
45     
46     Connection JavaDoc con = null;
47     TableAccessObject rs = null;
48     PreparedStatement JavaDoc pstmt = null;
49     RequestStartTO[] requestStart = new RequestStartTO[10];
50     
51     public RequestStartAccessObjectImplTest(String JavaDoc 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 JavaDoc e){
63             e.printStackTrace();
64         }
65         assertTrue(result);
66     }
67     public void testInsert (){
68         System.out.println(" testStoreRequestStart");
69         try{
70             String JavaDoc 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 JavaDoc 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             // TODO code application logic here
98
String JavaDoc 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             // drop request start table
102
rs = RequestStartAccessObjectImpl.getInstance();
103         } catch (Exception JavaDoc e){
104             e.printStackTrace();
105         }
106     }
107    
108     protected void tearDown() {
109         try{
110             con.close();
111         } catch (Exception JavaDoc e){
112             e.printStackTrace();
113         }
114         finally {
115             con = null;
116         }
117     }
118     public static void main(String JavaDoc args[]) {
119         junit.textui.TestRunner.run(RequestStartAccessObjectImplTest.class);
120     }
121
122     
123 }
124
Popular Tags