KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sape > carbon > services > sql > test > StatementFactoryTest


1 /*
2  * The contents of this file are subject to the Sapient Public License
3  * Version 1.0 (the "License"); you may not use this file except in compliance
4  * with the License. You may obtain a copy of the License at
5  * http://carbon.sf.net/License.html.
6  *
7  * Software distributed under the License is distributed on an "AS IS" basis,
8  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9  * the specific language governing rights and limitations under the License.
10  *
11  * The Original Code is The Carbon Component Framework.
12  *
13  * The Initial Developer of the Original Code is Sapient Corporation
14  *
15  * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.
16  */

17
18 package org.sape.carbon.services.sql.test;
19
20 import java.sql.CallableStatement JavaDoc;
21 import java.sql.Connection JavaDoc;
22 import java.sql.DatabaseMetaData JavaDoc;
23 import java.sql.PreparedStatement JavaDoc;
24 import java.sql.ResultSet JavaDoc;
25 import java.sql.SQLException JavaDoc;
26 import java.util.Random JavaDoc;
27
28 import org.sape.carbon.core.component.Lookup;
29 import org.sape.carbon.core.config.Config;
30 import org.sape.carbon.services.sql.StatementFactory;
31 import org.sape.carbon.services.sql.StatementFactoryConfiguration;
32 import org.sape.carbon.services.sql.StatementFactoryException;
33
34 import junit.framework.Test;
35 import junit.framework.TestCase;
36 import junit.framework.TestSuite;
37
38 import org.apache.commons.logging.Log;
39 import org.apache.commons.logging.LogFactory;
40
41 /**
42  * <p>jUnit test harness for SqlSevice.</p>
43  *
44  * Copyright 2002 Sapient
45  * @since carbon 1.0
46  * @author Vivekanand Kirubanandan, June 2002
47  * @version $Revision: 1.10 $($Author: dvoet $ / $Date: 2003/11/05 17:45:16 $)
48  */

49 public class StatementFactoryTest extends TestCase {
50
51     /**
52      * Provides a handle to Apache-commons logger
53      */

54     private Log log = LogFactory.getLog(this.getClass());
55
56     public static final String JavaDoc STATEMENT_FACTORY
57         = "/sql/test/DefaultStatementFactoryTest";
58     public static final String JavaDoc CREATE_TABLE_ONE_QUERY = "CreateTableOne";
59     public static final String JavaDoc CREATE_TABLE_TWO_QUERY = "CreateTableTwo";
60     public static final String JavaDoc CREATE_TABLE_THREE_QUERY = "CreateTableThree";
61     public static final String JavaDoc CREATE_TABLE_FOUR_QUERY = "CreateTableFour";
62     public static final String JavaDoc POPULATE_DATA_ONE_QUERY = "PopulateDataOne";
63     public static final String JavaDoc POPULATE_DATA_TWO_QUERY = "PopulateDataTwo";
64     public static final String JavaDoc POPULATE_DATA_THREE_QUERY
65         = "PopulateDataThree";
66     public static final String JavaDoc POPULATE_DATA_FOUR_QUERY = "PopulateDataFour";
67     public static final String JavaDoc DROP_TABLE_ONE_QUERY = "DropTableOne";
68     public static final String JavaDoc DROP_TABLE_TWO_QUERY = "DropTableTwo";
69     public static final String JavaDoc DROP_TABLE_THREE_QUERY = "DropTableThree";
70     public static final String JavaDoc DROP_TABLE_FOUR_QUERY = "DropTableFour";
71     public static final String JavaDoc PREPARED_STATEMENT_ONE_ROW_QUERY = "PSOR";
72     public static final String JavaDoc PSOR_NAME_FIELD = "name";
73     public static final String JavaDoc PSOR_VALUE_FIELD = "value";
74     public static final String JavaDoc PSOR_NAME_EXPECTED = "testname";
75     public static final int PSOR_VALUE_EXPECTED = 12345;
76     public static final String JavaDoc PREPARED_STATEMENT_MULTI_ROWS_QUERY = "PSMR";
77     public static final int PSMR_ROWS_EXPECTED = 101;
78     public static final String JavaDoc FUNCTION_CALLABLE_QUERY = "FunctionCallable";
79     public static final String JavaDoc PROCEDURE_CALLABLE_QUERY = "ProcedureCallable";
80     public static final String JavaDoc NULL_READ_QUERY = "NullRead";
81     public static final String JavaDoc MAX_ROWS_QUERY= "MaxRows";
82     public static final int MR_ROWS_EXPECTED = 10;
83     public static final String JavaDoc FIELD_SIZE_QUERY = "FieldSize";
84     public static final int FS_EXPECTED = 20;
85     public static final String JavaDoc SCROLL_INSENSITIVE_QUERY= "ScrollInsensitive";
86     public static final String JavaDoc SCROLL_SENSITIVE_QUERY= "ScrollSensitive";
87     public static final String JavaDoc CONCUR_UPDATABLE_QUERY= "ConcurUpdatable";
88     public static final String JavaDoc CONCUR_READONLY_QUERY= "ConcurReadonly";
89     public static final String JavaDoc CREATE_PACKAGE_DEFINITION_QUERY
90         = "CreatePackageDefinition";
91     public static final String JavaDoc CREATE_PACKAGE_BODY_QUERY="CreatePackageBody";
92
93     public StatementFactoryTest(String JavaDoc name) {
94         super(name);
95     }
96
97
98
99     /*
100      * Print out the basic database and driver info. Could be useful debugging
101      * and support. We can just ask teams to execute this and give us the
102      * the printed information.
103      */

104     public void getDriverInfo() {
105         try {
106             StatementFactoryConfiguration sfConfig = (StatementFactoryConfiguration)
107                 Config.getInstance().fetchConfiguration(STATEMENT_FACTORY);
108             Connection JavaDoc conn = (sfConfig.getConnectionFactory()).getConnection();
109             DatabaseMetaData JavaDoc dbmd = conn.getMetaData();
110
111             if (log.isInfoEnabled()) {
112                 log.info("Database Metadata: ");
113                 log.info("\tDatabase: " + dbmd.getDatabaseProductName());
114                 log.info("Driver Metadata: ");
115                 log.info("\tDriver: " + dbmd.getDriverName());
116                 log.info("\tDriver Version: " + dbmd.getDriverVersion());
117                 log.info("\tDefault Transaction Isolation: "
118                     + conn.getTransactionIsolation());
119                 log.info("\tTypes Map: " + conn.getTypeMap());
120             }
121         } catch (SQLException JavaDoc se) {
122             se.printStackTrace();
123         }
124     }
125
126
127     /**
128      * Method cleanUpBeforeStart.
129      */

130     public void cleanUpBeforeStart() {
131         PreparedStatement JavaDoc preparedStatement=null;
132         try {
133             StatementFactory sf = (StatementFactory)
134             Lookup.getInstance().fetchComponent(STATEMENT_FACTORY);
135
136             try {
137                 preparedStatement =
138                     sf.createPreparedStatement(DROP_TABLE_ONE_QUERY);
139                 preparedStatement.executeUpdate();
140             } catch (SQLException JavaDoc se) {
141                 //eat the exception
142
}
143
144             try {
145                 preparedStatement =
146                     sf.createPreparedStatement(DROP_TABLE_TWO_QUERY);
147                 preparedStatement.executeUpdate();
148             } catch (SQLException JavaDoc se) {
149                 // eat the exception
150
}
151             try {
152                 preparedStatement =
153                     sf.createPreparedStatement(DROP_TABLE_THREE_QUERY);
154                 preparedStatement.executeUpdate();
155             } catch (SQLException JavaDoc se) {
156                 // eat the exception
157
}
158             try {
159                 preparedStatement =
160                     sf.createPreparedStatement(DROP_TABLE_FOUR_QUERY);
161                 preparedStatement.executeUpdate();
162             } catch (SQLException JavaDoc se) {
163                 // eat the exception
164
}
165         } catch (StatementFactoryException sfe) {
166             fail("Clean up before start operation failed due to "+sfe);
167         }
168     }
169
170
171     /**
172      * Method createTestTables.
173      */

174
175     public void createTestTables() {
176         PreparedStatement JavaDoc preparedStatement=null;
177
178         try {
179
180              StatementFactory sf = (StatementFactory)
181                 Lookup.getInstance().fetchComponent(STATEMENT_FACTORY);
182
183             preparedStatement =
184                 sf.createPreparedStatement(CREATE_TABLE_ONE_QUERY);
185             preparedStatement.executeUpdate();
186             preparedStatement =
187                 sf.createPreparedStatement(CREATE_TABLE_TWO_QUERY);
188             preparedStatement.executeUpdate();
189             preparedStatement =
190                 sf.createPreparedStatement(CREATE_TABLE_THREE_QUERY);
191             preparedStatement.executeUpdate();
192             preparedStatement =
193                 sf.createPreparedStatement(CREATE_TABLE_FOUR_QUERY);
194             preparedStatement.executeUpdate();
195
196         } catch (StatementFactoryException sfe) {
197             fail("Cannot create Test Tables:"+sfe);
198         } catch (SQLException JavaDoc se) {
199             fail("Cannot create Test Tables"+se);
200         }
201
202     }
203
204     /**
205      * Method createTestData.
206      */

207     public void createTestData() {
208
209         PreparedStatement JavaDoc preparedStatement=null;
210         int result;
211         Random JavaDoc rand = new Random JavaDoc();
212
213         try {
214             StatementFactory sf = (StatementFactory)
215                 Lookup.getInstance().fetchComponent(STATEMENT_FACTORY);
216
217             preparedStatement =
218                 sf.createPreparedStatement(POPULATE_DATA_FOUR_QUERY);
219             preparedStatement.setString(1,PSOR_NAME_EXPECTED);
220             preparedStatement.setInt(2,PSOR_VALUE_EXPECTED);
221             result = preparedStatement.executeUpdate();
222             for (int i=0;i<100;i++) {
223                 preparedStatement =
224                     sf.createPreparedStatement(POPULATE_DATA_FOUR_QUERY);
225                 int id = rand.nextInt(1000);
226                 preparedStatement.setString(1,"Statement ID:"+i);
227                 preparedStatement.setInt(2,id);
228                 result = preparedStatement.executeUpdate();
229                 if (result!=1) {
230                     fail("Insert operation Failed");
231                 }
232                 preparedStatement.close();
233             }
234
235         } catch (StatementFactoryException sfe) {
236             fail("Cannot insert Test Data:"+sfe);
237         } catch (SQLException JavaDoc se) {
238             fail("Cannot insert Test Data:"+se);
239         }
240
241     }
242
243     /**
244      * Method cleanUp.
245      */

246     public void cleanUp() {
247         PreparedStatement JavaDoc preparedStatement=null;
248         try {
249             StatementFactory sf = (StatementFactory)
250                 Lookup.getInstance().fetchComponent(STATEMENT_FACTORY);
251
252             preparedStatement =
253                 sf.createPreparedStatement(DROP_TABLE_ONE_QUERY);
254             preparedStatement.executeUpdate();
255             preparedStatement =
256                 sf.createPreparedStatement(DROP_TABLE_TWO_QUERY);
257             preparedStatement.executeUpdate();
258             preparedStatement =
259                 sf.createPreparedStatement(DROP_TABLE_THREE_QUERY);
260             preparedStatement.executeUpdate();
261             preparedStatement =
262                 sf.createPreparedStatement(DROP_TABLE_FOUR_QUERY);
263             preparedStatement.executeUpdate();
264
265         } catch (StatementFactoryException sfe) {
266             fail("Clean up operation failed due to "+sfe);
267         } catch (SQLException JavaDoc se) {
268             fail("Clean up operation failed due to "+se);
269         }
270     }
271
272
273     /**
274      * Method testPreparedStatementOneRow.
275      */

276     public void testPreparedStatementOneRow() {
277         PreparedStatement JavaDoc preparedStatement=null;
278         ResultSet JavaDoc resultSet;
279         try {
280             StatementFactory sf = (StatementFactory)
281                 Lookup.getInstance().fetchComponent(STATEMENT_FACTORY);
282
283             preparedStatement =
284                 sf.createPreparedStatement(PREPARED_STATEMENT_ONE_ROW_QUERY);
285
286             preparedStatement.setString(1,PSOR_NAME_EXPECTED);
287             resultSet = preparedStatement.executeQuery();
288
289             if (resultSet.next()) {
290                 String JavaDoc name = resultSet.getString(PSOR_NAME_FIELD);
291                 int value = resultSet.getInt(PSOR_VALUE_FIELD);
292                 if (!name.equals(PSOR_NAME_EXPECTED)) {
293                     fail("Prepared Statement test returned name='"+name+
294                           "' but '"+PSOR_NAME_EXPECTED+"' was expected ");
295                 }
296                 if (value!=PSOR_VALUE_EXPECTED) {
297                     fail("Prepared Statement test returned value='"+value+
298                           "' but '"+PSOR_VALUE_EXPECTED+"' was expected ");
299                 }
300             } else {
301                 fail("Prepared Statement test :Query returned no rows");
302             }
303
304         } catch (StatementFactoryException sfe) {
305             fail("Failed due to "+sfe);
306         } catch (SQLException JavaDoc se) {
307             fail("Failed due to "+se);
308         }
309     }
310
311     /**
312      * Method testPreparedStatementMultiRow.
313      */

314     public void testPreparedStatementMultiRow() {
315
316         try {
317             StatementFactory sf = (StatementFactory)
318                 Lookup.getInstance().fetchComponent(STATEMENT_FACTORY);
319
320             PreparedStatement JavaDoc preparedStatement =
321                 sf.createPreparedStatement(PREPARED_STATEMENT_MULTI_ROWS_QUERY);
322
323             ResultSet JavaDoc resultSet = preparedStatement.executeQuery();
324
325             int numberofRows = 0;
326             while (resultSet.next()){
327                 numberofRows ++;
328             }
329             if (numberofRows!=PSMR_ROWS_EXPECTED) {
330                 fail("Prepared Statement multi row, number of rows ='"+
331                       numberofRows+"' but '"+PSMR_ROWS_EXPECTED+
332                       "' were expected ");
333             }
334
335         } catch (StatementFactoryException sfe) {
336             fail("Failed due to "+sfe);
337         } catch (SQLException JavaDoc se) {
338             fail("Failed due to "+se);
339         }
340     }
341
342     /**
343      * Method createTestPackage.
344      */

345     public void createTestPackage() throws StatementFactoryException, SQLException JavaDoc {
346         PreparedStatement JavaDoc preparedStatement=null;
347         int result;
348         try {
349             StatementFactory sf = (StatementFactory)
350                 Lookup.getInstance().fetchComponent(STATEMENT_FACTORY);
351             preparedStatement =
352                 sf.createPreparedStatement(CREATE_PACKAGE_DEFINITION_QUERY);
353             preparedStatement.executeUpdate();
354             preparedStatement.close();
355             preparedStatement =
356                 sf.createPreparedStatement(CREATE_PACKAGE_BODY_QUERY);
357             preparedStatement.executeUpdate();
358         } finally {
359             try {
360                 if (preparedStatement!=null) {
361                     preparedStatement.close();
362                 }
363             } catch (SQLException JavaDoc se) {
364                     // Eat Exception
365
}
366         }
367
368
369     }
370
371     /**
372      * Method testFunctionCallableStatement.
373      */

374     public void testFunctionCallableStatement() {
375         CallableStatement JavaDoc callableStatement = null;
376         try {
377             StatementFactory sf = (StatementFactory)
378                 Lookup.getInstance().fetchComponent(STATEMENT_FACTORY);
379
380             callableStatement =
381                 sf.createCallableStatement(FUNCTION_CALLABLE_QUERY);
382             callableStatement.registerOutParameter(1,java.sql.Types.VARCHAR);
383             String JavaDoc data = "Hello World!";
384             callableStatement.setString(2,data);
385             callableStatement.executeQuery();
386             String JavaDoc result = (String JavaDoc) callableStatement.getObject(1);
387             if (!result.equals("prefix."+data)) {
388                 fail ("testFunctionCallableStatement failed , expected 'prefix."
389                       +data+"' got '"+result+"'");
390             }
391         } catch (StatementFactoryException sfe) {
392             fail("Clean up operation failed due to "+sfe);
393         } catch (SQLException JavaDoc se) {
394             fail("Clean up operation failed due to "+se);
395         } finally {
396             try {
397                 if (callableStatement!=null) {
398                     callableStatement.close();
399                 }
400             } catch (SQLException JavaDoc se) {
401                     // Eat Exception
402
}
403         }
404     }
405
406     /**
407      * Method testProcedureCallableStatement.
408      */

409     public void testProcedureCallableStatement() {
410         CallableStatement JavaDoc callableStatement = null;
411         try {
412             StatementFactory sf = (StatementFactory)
413                 Lookup.getInstance().fetchComponent(STATEMENT_FACTORY);
414
415             callableStatement =
416                 sf.createCallableStatement(PROCEDURE_CALLABLE_QUERY);
417
418             callableStatement.registerOutParameter(2,java.sql.Types.VARCHAR);
419             callableStatement.registerOutParameter(3,java.sql.Types.VARCHAR);
420             String JavaDoc data = "Hello World!";
421             callableStatement.setString(1,data);
422             callableStatement.executeQuery();
423             String JavaDoc resultA = (String JavaDoc) callableStatement.getObject(2);
424             String JavaDoc resultB = (String JavaDoc) callableStatement.getObject(3);
425             if (!(resultA.equals("H") && resultB.equals("e"))) {
426                 fail("Got some error resultA='"+resultA+"' and resultB='"
427                      +resultB+"'");
428             }
429
430         } catch (StatementFactoryException sfe) {
431             fail("Clean up operation failed due to "+sfe);
432         } catch (SQLException JavaDoc se) {
433             fail("Clean up operation failed due to "+se);
434         } finally {
435             try {
436                 if (callableStatement!=null) {
437                     callableStatement.close();
438                 }
439
440             } catch (SQLException JavaDoc se) { // Eat Exception
441
}
442         }
443     }
444
445     /**
446      * Method testNullReads.
447      */

448     public void testNullReads() {
449         ResultSet JavaDoc resultSet;
450         PreparedStatement JavaDoc preparedStatement=null;
451         try {
452
453             StatementFactory sf = (StatementFactory)
454                 Lookup.getInstance().fetchComponent(STATEMENT_FACTORY);
455
456             preparedStatement =
457                 sf.createPreparedStatement(NULL_READ_QUERY);
458
459             resultSet = preparedStatement.executeQuery();
460
461             if (resultSet.next()) {
462                 if (( resultSet.getInt(1) != 0 ) || (!resultSet.wasNull())) {
463                     fail("Null read test failed.");
464                 }
465             }
466
467         } catch (StatementFactoryException sfe) {
468             fail("Failed due to "+sfe);
469         } catch (SQLException JavaDoc se) {
470             fail("Failed due to "+se);
471         } finally {
472             try {
473                 if (preparedStatement!=null) {
474                     preparedStatement.close();
475                 }
476             } catch (SQLException JavaDoc se) {
477                     // Eat Exception
478
}
479         }
480
481     }
482
483     /**
484      * Method testMaxRows.
485      */

486     public void testMaxRows() {
487
488         PreparedStatement JavaDoc preparedStatement=null;
489         ResultSet JavaDoc resultSet;
490
491         try {
492             StatementFactory sf = (StatementFactory)
493                 Lookup.getInstance().fetchComponent(STATEMENT_FACTORY);
494
495             preparedStatement =
496                 sf.createPreparedStatement(MAX_ROWS_QUERY);
497
498             resultSet = preparedStatement.executeQuery();
499
500             int numberofRows = 0;
501             while (resultSet.next()){
502                 numberofRows ++;
503             }
504
505             if (numberofRows!=MR_ROWS_EXPECTED) {
506                 fail("Result Set not limited");
507             }
508
509         } catch (StatementFactoryException sfe) {
510             fail("Failed due to "+sfe);
511         } catch (SQLException JavaDoc se) {
512             fail("Failed due to "+se);
513         } finally {
514             try {
515                 if (preparedStatement!=null) {
516                     preparedStatement.close();
517                 }
518             } catch (SQLException JavaDoc se) { // Eat Exception
519
}
520         }
521
522     }
523
524     /**
525      * Method testFieldSize.
526      */

527     public void testFieldSize() {
528         PreparedStatement JavaDoc preparedStatement=null;
529         ResultSet JavaDoc resultSet;
530
531         try {
532             StatementFactory sf = (StatementFactory)
533                 Lookup.getInstance().fetchComponent(STATEMENT_FACTORY);
534
535             preparedStatement =
536                 sf.createPreparedStatement(FIELD_SIZE_QUERY);
537
538             resultSet = preparedStatement.executeQuery();
539
540             while (resultSet.next()) {
541                 String JavaDoc data = (String JavaDoc) resultSet.getObject(1);
542                 if (data.length()>FS_EXPECTED) {
543                     fail("Field size limit not respected.");
544                 }
545             }
546
547         } catch (StatementFactoryException sfe) {
548             fail("Failed due to "+sfe);
549         } catch (SQLException JavaDoc se) {
550             fail("Failed due to "+se);
551         } finally {
552             try {
553                 if (preparedStatement!=null) {
554                     preparedStatement.close();
555                 }
556             } catch (SQLException JavaDoc se) { // Eat Exception
557
}
558         }
559
560     }
561
562     /**
563      * Method testScrollInsensitive.
564      */

565     public void testScrollInsensitive() {
566         PreparedStatement JavaDoc preparedStatement=null;
567         ResultSet JavaDoc resultSet;
568
569         try {
570             StatementFactory sf = (StatementFactory)
571                 Lookup.getInstance().fetchComponent(STATEMENT_FACTORY);
572
573             preparedStatement =
574                 sf.createPreparedStatement(SCROLL_INSENSITIVE_QUERY);
575
576             resultSet = preparedStatement.executeQuery();
577
578             if (!resultSet.next()) {
579                 fail("Error reading data from scroll insensitive result set.");
580             }
581
582         } catch (StatementFactoryException sfe) {
583             fail("Failed due to "+sfe);
584         } catch (SQLException JavaDoc se) {
585             fail("Failed due to "+se);
586         } finally {
587             try {
588                 if (preparedStatement!=null) {
589                     preparedStatement.close();
590                 }
591             } catch (SQLException JavaDoc se) { // Eat Exception
592
}
593         }
594
595     }
596
597     /**
598      * Method testScrollSensitive.
599      */

600     public void testScrollSensitive() {
601         PreparedStatement JavaDoc preparedStatement=null;
602         ResultSet JavaDoc resultSet;
603
604         try {
605             StatementFactory sf = (StatementFactory)
606                 Lookup.getInstance().fetchComponent(STATEMENT_FACTORY);
607
608             preparedStatement =
609                 sf.createPreparedStatement(SCROLL_SENSITIVE_QUERY);
610
611             resultSet = preparedStatement.executeQuery();
612
613             if (!resultSet.next()) {
614                 fail("Error reading data from scroll sensitive result set.");
615             } else {
616                 int totalRecords = resultSet.getFetchSize();
617                 boolean isScrollable = resultSet.absolute((int)(totalRecords/2));
618                 assertTrue("Cannot scroll a scrollable result set", isScrollable);
619                 if (!resultSet.previous()) {
620                     fail("Error scrolling backward");
621                 }
622                 if (!resultSet.next()) {
623                     fail("Error scrolling forward");
624                 }
625             }
626
627         } catch (StatementFactoryException sfe) {
628             fail("Failed due to "+sfe);
629         } catch (SQLException JavaDoc se) {
630             fail("Failed due to "+se);
631         } finally {
632             try {
633                 if (preparedStatement!=null) {
634                     preparedStatement.close();
635                 }
636             } catch (SQLException JavaDoc se) { // Eat Exception
637
}
638         }
639
640     }
641
642     /**
643      * Method testConcurUpdatable.
644      */

645     public void testConcurUpdatable() {
646         PreparedStatement JavaDoc preparedStatement=null;
647         ResultSet JavaDoc resultSet;
648
649         try {
650             StatementFactory sf = (StatementFactory)
651                 Lookup.getInstance().fetchComponent(STATEMENT_FACTORY);
652
653             preparedStatement =
654                 sf.createPreparedStatement(CONCUR_UPDATABLE_QUERY);
655
656             resultSet = preparedStatement.executeQuery();
657
658             if (!resultSet.next()) {
659                 fail("Error reading data from concur_updatable result set.");
660             }
661
662         } catch (StatementFactoryException sfe) {
663             fail("Failed due to "+sfe);
664         } catch (SQLException JavaDoc se) {
665             fail("Failed due to "+se);
666         } finally {
667             try {
668                 if (preparedStatement!=null) {
669                     preparedStatement.close();
670                 }
671             } catch (SQLException JavaDoc se) { // Eat Exception
672
}
673         }
674
675     }
676
677     /**
678      * Method testConcurReadOnly.
679      */

680     public void testConcurReadOnly() {
681         PreparedStatement JavaDoc preparedStatement=null;
682         ResultSet JavaDoc resultSet;
683
684         try {
685             StatementFactory sf = (StatementFactory)
686                 Lookup.getInstance().fetchComponent(STATEMENT_FACTORY);
687
688             preparedStatement =
689                 sf.createPreparedStatement(CONCUR_READONLY_QUERY);
690
691             resultSet = preparedStatement.executeQuery();
692
693             if (!resultSet.next()) {
694                 fail("Error reading data from concur_readonly result set.");
695             }
696
697         } catch (StatementFactoryException sfe) {
698             fail("Failed due to "+sfe);
699         } catch (SQLException JavaDoc se) {
700             fail("Failed due to "+se);
701         } finally {
702             try {
703                 if (preparedStatement!=null) {
704                     preparedStatement.close();
705                 }
706             } catch (SQLException JavaDoc se) { // Eat Exception
707
}
708         }
709
710     }
711
712     /**
713      * Method called by jUnit to get all the tests in this test case.
714      * @return Test the suite of tests in this test case
715      */

716     public static Test suite() {
717         TestSuite test = new TestSuite();
718         test.addTest(new StatementFactoryTest("getDriverInfo"));
719         test.addTest(new StatementFactoryTest("cleanUpBeforeStart"));
720         test.addTest(new StatementFactoryTest("createTestTables"));
721         test.addTest(new StatementFactoryTest("createTestData"));
722         test.addTest(new StatementFactoryTest("testPreparedStatementOneRow"));
723         test.addTest(new StatementFactoryTest("testPreparedStatementMultiRow"));
724         test.addTest(new StatementFactoryTest("createTestPackage"));
725         test.addTest(new StatementFactoryTest("testFunctionCallableStatement"));
726         test.addTest(new StatementFactoryTest("testProcedureCallableStatement"));
727         test.addTest(new StatementFactoryTest("testNullReads"));
728         test.addTest(new StatementFactoryTest("testMaxRows"));
729         test.addTest(new StatementFactoryTest("testFieldSize"));
730         test.addTest(new StatementFactoryTest("testScrollInsensitive"));
731         test.addTest(new StatementFactoryTest("testScrollSensitive"));
732         test.addTest(new StatementFactoryTest("testConcurUpdatable"));
733         test.addTest(new StatementFactoryTest("testConcurReadOnly"));
734         test.addTest(new StatementFactoryTest("cleanUp"));
735         return test;
736
737     }
738
739
740 }
741
742
Popular Tags