KickJava   Java API By Example, From Geeks To Geeks.

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


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  * DbAccessObjectTest.java
26  * JUnit based test
27  *
28  * Created on July 15, 2005, 5:33 PM
29  */

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

43 public class DbAccessObjectTest extends TestCase {
44 // Connection con = null;
45
DbAccessObject dbao = null;
46     int DATA_SIZE = 2;
47     RequestStartTO[] requestStart = new RequestStartTO[DATA_SIZE];
48     MethodStartTO[] methodStart = new MethodStartTO[DATA_SIZE*2];
49     RequestEndTO[] requestEnd = new RequestEndTO[DATA_SIZE];
50     MethodEndTO[] methodEnd = new MethodEndTO[DATA_SIZE *2];
51
52     // Start Time and End Time Objects. They need not be the same
53
// size as other TransferObjects
54

55     int DATA_SIZE_FOR_TIMES = 7;
56     EndTimeTO[] endTime = new EndTimeTO [DATA_SIZE_FOR_TIMES];
57     StartTimeTO[] startTime = new StartTimeTO [DATA_SIZE_FOR_TIMES];
58     
59     public DbAccessObjectTest(String JavaDoc testName) {
60         super(testName);
61     }
62
63     protected void setUp() throws Exception JavaDoc {
64       try{
65             dbao = DbAccessObjectImpl.getInstance();
66         } catch (Exception JavaDoc e){
67             e.printStackTrace();
68         }
69                 
70     }
71
72     protected void tearDown() throws Exception JavaDoc {
73     }
74  
75     /**
76      * Test of enable method, of class com.sun.enterprise.admin.monitor.callflow.DbAccessObject.
77      */

78     public void testEnable() {
79         System.out.println("DB Access Object testEnable");
80         boolean result = dbao.enable();
81         assertTrue(result);
82     }
83
84     public void testInsertRequestStart() {
85         System.out.println(" testInsertRequestStart");
86         long timestamp = 0;
87         for (int i = 0; i < requestStart.length; i++) {
88             requestStart[i] = new RequestStartTO();
89             requestStart[i].requestId = "RequestID_"+(i+1);
90             timestamp = timestamp + 10;
91             requestStart[i].timeStamp = timestamp;
92             requestStart[i].requestType = RequestType.REMOTE_EJB;
93         }
94         boolean result = dbao.insert(requestStart);
95         System.out.println("testInsertRequestStart returned = "+result);
96         assertTrue(result);
97     }
98     
99     public void testInsertMethodStart() {
100       System.out.println(" testInsertMethodStart");
101       long timestamp = 11;
102       for (int i = 0; i < DATA_SIZE; i++) {
103           methodStart[i] = new MethodStartTO();
104           methodStart[i].requestId = "RequestID_"+(i+1);
105           methodStart[i].timeStamp = timestamp;
106           timestamp = timestamp + 10;
107           methodStart[i].componentType = ComponentType.SERVLET;
108           methodStart[i].componentName = "Component_Name_"+ (i+1);
109           methodStart[i].appName = "APP_NAME";
110           methodStart[i].methodName = "Method_Name_" +(i+1);
111           methodStart[i].moduleName = "Module_Name_" +(i+1);
112           methodStart[i].transactionId = "Transaction_Id_"+(i+1);
113           methodStart[i].threadId = "Thread_Id_"+(i+1);
114           methodStart[i].securityId = "watchman_"+(i+1);
115       }
116        // generate duplicate rows with different timestamps
117
timestamp = 12;
118       int j = 0;
119       for (int i = DATA_SIZE; i < (DATA_SIZE * 2); i++) {
120           methodStart[i] = new MethodStartTO();
121           methodStart[i].requestId = "RequestID_"+(j+1);
122           methodStart[i].timeStamp = timestamp;
123           timestamp = timestamp + 10;
124           methodStart[i].componentType = ComponentType.SERVLET;
125           methodStart[i].componentName = "Component_Name_"+ (j+1);
126           methodStart[i].appName = "APP_NAME";
127           methodStart[i].methodName = "Method_Name_" +(j+1);
128           methodStart[i].moduleName = "Module_Name_" +(j+1);
129           methodStart[i].transactionId = "Transaction_Id_"+(j+1);
130           methodStart[i].threadId = "Thread_Id_"+(j+1);
131           methodStart[i].securityId = "watchman_"+(j+1);
132           j++;
133       }
134       
135       boolean result = dbao.insert( methodStart);
136       System.out.println("testInsertMethodStart returned = "+result);
137       assertTrue(result);
138     }
139
140     public void testInsertME() {
141         System.out.println("testInsertMethodEnd returned ");
142         long timestamp = 13;
143
144         methodEnd[0] = new MethodEndTO();
145         methodEnd[0].requestId = "RequestID_1";
146         methodEnd[0].timeStamp = timestamp;
147         methodEnd[0].exception = "exe_1";
148         
149         methodEnd[1] = new MethodEndTO();
150         methodEnd[1].requestId = "RequestID_1";
151         methodEnd[1].timeStamp = timestamp + 1;
152         methodEnd[1].exception = "exe_1";
153         
154         methodEnd[2] = new MethodEndTO();
155         methodEnd[2].requestId = "RequestID_2";
156         methodEnd[2].timeStamp = timestamp + 10;
157         methodEnd[2].exception = "exe_2";
158         
159         methodEnd[3] = new MethodEndTO();
160         methodEnd[3].requestId = "RequestID_2";
161         methodEnd[3].timeStamp = timestamp + 11;
162         methodEnd[3].exception = "exe_2";
163
164             boolean result = dbao.insert(methodEnd);
165         System.out.println("testInsertMethodEnd returned = "+result);
166         assertTrue(result);
167     }
168
169     public void testInsertRequestEnd() {
170         System.out.println(" testInsertRequestEnd");
171         long timestamp = 5;
172         for (int i = 0; i < requestEnd.length; i++) {
173             requestEnd[i] = new RequestEndTO();
174             requestEnd[i].requestId = "RequestID_"+(i+1);
175             timestamp = timestamp + 10;
176             requestEnd[i].timeStamp = timestamp;
177         }
178         boolean result = dbao.insert(requestEnd);
179         System.out.println("testInsertRequestEnd returned = "+result);
180         assertTrue(result);
181     }
182     
183
184     
185     public void testInsertStartTime () {
186         System.out.println(" testInsertStartTime");
187     createStartTime ();
188         boolean result = dbao.insert(startTime);
189         System.out.println("testInsertStartTime returned = "+result);
190         assertTrue(result);
191     }
192     
193     
194     public void testInsertEndTime () {
195         System.out.println(" testInsertEndTime");
196     createEndTime ();
197         boolean result = dbao.insert(endTime);
198         System.out.println("testInsertEndTime returned = "+result);
199         assertTrue(result);
200     }
201     
202     /**
203      * Test of disable method, of class com.sun.enterprise.admin.monitor.callflow.DbAccessObject.
204      */

205     public void testDisable() {
206         System.out.println("DB Access Object testDisable");
207         boolean result = dbao.disable();
208         assertTrue(result);
209     }
210     
211     public void testGetRequestInformation () {
212         System.out.println("DB Access Object testGetRequestInformation");
213         List JavaDoc<Map JavaDoc<String JavaDoc, String JavaDoc>> list = dbao.getRequestInformation ();
214         
215         for (Map JavaDoc<String JavaDoc, String JavaDoc>map : list) {
216             StringBuffer JavaDoc sbuf = new StringBuffer JavaDoc();
217             for (String JavaDoc key : map.keySet()) {
218                 sbuf.append(map.get(key)+",");
219             }
220             System.out.println(sbuf.toString());
221             sbuf = null;
222         }
223         int resultSize = list.size ();
224         int CORRECT_RESULT_SIZE = 2;
225         if (resultSize == CORRECT_RESULT_SIZE)
226             assertTrue (true);
227         
228     }
229     public void testGetCallStackInformation (){
230         System.out.println("DB Access Object testGetCallStackInformation");
231         try{
232         List JavaDoc<Map JavaDoc<String JavaDoc, String JavaDoc>> list = dbao.getCallStackInformation ("RequestID_1");
233         int i= 0;
234
235         StringBuffer JavaDoc sbuf1 = new StringBuffer JavaDoc();
236         
237         for (Map JavaDoc<String JavaDoc, String JavaDoc>map : list) {
238             sbuf1.append ("\n" + i++ +" >");
239             StringBuffer JavaDoc sbuf = new StringBuffer JavaDoc();
240             for (String JavaDoc key : map.keySet()) {
241                 if (map.get(key).equals("RequestStart"))
242                     sbuf.insert (0, "\n" + map.get(key)+" -->");
243                 else if (map.get(key).equals ("RequestEnd"))
244                     sbuf.insert (0, "\n" + map.get(key)+" -->");
245                 else if (map.get(key).equals ("MethodStart"))
246                     sbuf.insert (0, "\n\t" + map.get(key)+" -->");
247                 else if (map.get(key).equals ("MethodEnd"))
248                     sbuf.insert (0, "\n\t" + map.get(key)+" -->");
249                 else
250                     sbuf.append(map.get(key)+"," );
251               
252             }
253                 sbuf1.append( sbuf);
254                 sbuf1.append ("\n");
255         }
256         System.out.println(sbuf1.toString());
257         sbuf1 = null;
258         
259         int resultSize = list.size ();
260         int CORRECT_RESULT_SIZE = 2;
261         if (resultSize == CORRECT_RESULT_SIZE)
262             assertTrue (true);
263         } catch (Exception JavaDoc e){
264             e.printStackTrace();
265         }
266     }
267
268     public void testGetPIEInformation () {
269         System.out.println("DB Access Object testGetPIEInformation");
270         Map JavaDoc<String JavaDoc, String JavaDoc> map = dbao.getPieInformation ("Request_ID1");
271         int i= 0;
272
273         StringBuffer JavaDoc sbuf1 = new StringBuffer JavaDoc();
274         
275         for (String JavaDoc key : map.keySet()) {
276             sbuf1.append ("\n" + i++ +" > "+ key + " = ");
277             sbuf1.append(map.get(key)+"," );
278             sbuf1.append ("\n");
279         }
280         System.out.println(sbuf1.toString());
281         sbuf1 = null;
282         assertTrue(true);
283     }
284     /**
285      * Test of clearData method, of class com.sun.enterprise.admin.monitor.callflow.DbAccessObject.
286      */

287     public void testClearData() {
288         System.out.println("DB Access Object. testClearData");
289         boolean result = dbao.clearData();
290         assertTrue(result);
291     }
292
293     private void createStartTime () {
294     
295     for (int i = 0; i < DATA_SIZE_FOR_TIMES; i++ ){
296         startTime[i] = new StartTimeTO ();
297         startTime[i].requestId = "Request_ID1";
298     }
299     
300     startTime[0].containerTypeOrApplicationType = "EJB";
301     startTime[0].timeStamp = 10;
302
303     startTime[1].containerTypeOrApplicationType = "EJBAPP";
304     startTime[1].timeStamp = 13;
305
306     startTime[2].containerTypeOrApplicationType = "ORB";
307     startTime[2].timeStamp = 19;
308
309     startTime[3].containerTypeOrApplicationType = "WEB";
310     startTime[3].timeStamp = 5;
311
312     startTime[4].containerTypeOrApplicationType = "WEBAPP";
313     startTime[4].timeStamp = 8;
314
315     startTime[5].containerTypeOrApplicationType = "WEB";
316     startTime[5].timeStamp = 1;
317
318     startTime[6].containerTypeOrApplicationType = "WEBAPP";
319     startTime[6].timeStamp = 3;
320     }
321
322     private void createEndTime () {
323     
324     for (int i = 0; i < DATA_SIZE_FOR_TIMES; i++ ){
325         endTime[i] = new EndTimeTO ();
326         endTime[i].requestId = "Request_ID1";
327     }
328     
329     endTime[0].containerTypeOrApplicationType = "EJB";
330     endTime[0].timeStamp = 12;
331
332     endTime[1].containerTypeOrApplicationType = "EJBAPP";
333     endTime[1].timeStamp = 18;
334
335     endTime[2].containerTypeOrApplicationType = "ORB";
336     endTime[2].timeStamp = 20;
337
338     endTime[3].containerTypeOrApplicationType = "WEB";
339     endTime[3].timeStamp = 7;
340
341     endTime[4].containerTypeOrApplicationType = "WEBAPP";
342     endTime[4].timeStamp = 9;
343
344     endTime[5].containerTypeOrApplicationType = "WEB";
345     endTime[5].timeStamp = 2;
346
347     endTime[6].containerTypeOrApplicationType = "WEBAPP";
348     endTime[6].timeStamp = 4;
349
350     }
351
352     public static void main(java.lang.String JavaDoc[] argList) {
353
354     }
355
356
357     
358 }
359
Popular Tags