1/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package tests.sql;
18
19import dalvik.annotation.KnownFailure;
20import dalvik.annotation.TestTargetClass;
21import dalvik.annotation.TestTargets;
22import dalvik.annotation.TestLevel;
23import dalvik.annotation.TestTargetNew;
24
25import java.io.IOException;
26import java.sql.ResultSet;
27import java.sql.ResultSetMetaData;
28import java.sql.SQLException;
29import java.sql.Statement;
30import java.sql.Types;
31
32@TestTargetClass(ResultSetMetaData.class)
33public class ResultSetMetaDataTest extends SQLTest {
34
35    ResultSetMetaData rsmd = null;
36    Statement st = null;
37    ResultSet rs = null;
38
39    @Override
40    public void setUp() throws Exception {
41        super.setUp();
42        try {
43            conn.setAutoCommit(false);
44            assertFalse(conn.getAutoCommit());
45            String query = "select * from zoo";
46            st = conn.createStatement();
47            st.execute(query);
48            rs = st.getResultSet();
49            rsmd = rs.getMetaData();
50        } catch (SQLException e) {
51            fail("Couldn't get ResultSetMetaData object");
52        }
53    }
54
55    @Override
56    public void tearDown() {
57        try {
58            rs.close();
59            st.close();
60        } catch (SQLException e) {
61            fail("Couldn't close Statement object");
62        }
63        super.tearDown();
64    }
65
66    /**
67     * @test java.sql.ResultSetMetaData#getCatalogName(int column)
68     */
69    @TestTargetNew(
70        level = TestLevel.COMPLETE,
71        notes = "Catalog not supported.",
72        method = "getCatalogName",
73        args = {int.class}
74    )
75    @KnownFailure("not supported")
76    public void testGetCatalogName() throws SQLException {
77        try {
78            assertNotNull(rsmd.getCatalogName(1));
79        } catch (SQLException e) {
80            fail("SQLException is thrown: " + e.getMessage());
81        }
82
83        try {
84            conn.close();
85            rsmd.getCatalogName(0);
86            fail("Exception expected");
87        } catch (SQLException e) {
88            //ok
89        }
90    }
91
92    /**
93     * @test java.sql.ResultSetMetaData#getColumnClassName(int column)
94     */
95    @TestTargetNew(
96        level = TestLevel.COMPLETE,
97        notes = "",
98        method = "getColumnClassName",
99        args = {int.class}
100    )
101    public void testGetColumnClassName() {
102        try {
103            assertNotNull(rsmd);
104            assertEquals(Short.class.getName(), rsmd.getColumnClassName(1));
105            assertEquals(String.class.getName(), rsmd.getColumnClassName(2));
106            assertEquals(String.class.getName(), rsmd.getColumnClassName(3));
107        } catch (SQLException e) {
108            fail("SQLException is thrown: " + e.getMessage());
109        }
110
111        try {
112            String name  = rsmd.getColumnClassName(0);
113            assertNull(name);
114        } catch (SQLException e) {
115            fail("SQLException is thrown");
116        }
117
118        try {
119            String name  = rsmd.getColumnClassName(4);
120            assertNull(name);
121        } catch (SQLException e) {
122            fail("SQLException is thrown");
123        }
124    }
125
126    /**
127     * @test java.sql.ResultSetMetaData#getColumnCount()
128     */
129    @TestTargetNew(
130        level = TestLevel.COMPLETE,
131        notes = "SQLException checking test fails",
132        method = "getColumnCount",
133        args = {}
134    )
135    @KnownFailure("SQLException checking test fails")
136    public void testGetColumnCount() {
137        try {
138            assertEquals(3, rsmd.getColumnCount());
139        } catch (SQLException e) {
140            fail("SQLException is thrown: " + e.getMessage());
141        }
142
143        try {
144            rs.close();
145            rsmd.getColumnCount();
146            fail("Exception expected");
147        } catch (SQLException e) {
148            //ok
149        }
150
151    }
152
153    /**
154     * @test java.sql.ResultSetMetaData#getColumnLabel(int column)
155     */
156    @TestTargetNew(
157        level = TestLevel.COMPLETE,
158        notes = "",
159        method = "getColumnLabel",
160        args = {int.class}
161    )
162    @KnownFailure("Column label has format TABLE.COLUMN expected: COLUMN")
163    public void testGetColumnLabel() {
164        String[] labels = { "id", "name", "family" };
165        try {
166            for (int i = 0; i < rsmd.getColumnCount(); i++) {
167                String label = rsmd.getColumnLabel(i + 1);
168                assertTrue("expected "+labels[i] + "got "+label,labels[i].contains(label));
169            }
170        } catch (SQLException e) {
171            fail("SQLException is thrown: " + e.getMessage());
172        }
173
174        try {
175            String label = rsmd.getColumnLabel(0);
176            fail("SQLException expected");
177        } catch (SQLException e) {
178            //ok
179        }
180
181        try {
182            String label = rsmd.getColumnLabel(5);
183            fail("SQLException expected");
184        } catch (SQLException e) {
185            //ok
186        }
187    }
188
189    /**
190     * @test java.sql.ResultSetMetaData#getColumnName(int column)
191     */
192    @TestTargetNew(
193        level = TestLevel.COMPLETE,
194        notes = "",
195        method = "getColumnName",
196        args = {int.class}
197    )
198    @KnownFailure("Column label has format TABLE.COLUMN expected: COLUMN")
199    public void testGetColumnName() {
200        String[] labels = { "id", "name", "family" };
201        try {
202            for (int i = 0; i < rsmd.getColumnCount(); i++) {
203                String name = rsmd.getColumnName(i + 1);
204                assertEquals(labels[i], name);
205            }
206        } catch (SQLException e) {
207            fail("SQLException is thrown: " + e.getMessage());
208        }
209
210        try {
211            String label = rsmd.getColumnName(0);
212            fail("SQLException is not thrown");
213        } catch (SQLException e) {
214            //ok
215        }
216
217        try {
218            String label = rsmd.getColumnName(5);
219            fail("SQLException is not thrown");
220        } catch (SQLException e) {
221            //ok
222        }
223    }
224
225    /**
226     * @test java.sql.ResultSetMetaData#getColumnType(int column)
227     *
228     * for extensive tests see: ResultSetGetterTest.testGetMetaData
229     */
230    @TestTargetNew(
231        level = TestLevel.SUFFICIENT,
232        notes = "Not all types supported. More type checking done in ResultSetGetterTest.testGetMetaData",
233        method = "getColumnType",
234        args = {int.class}
235    )
236    public void testGetColumnType() {
237        int[] types = { Types.SMALLINT, Types.VARCHAR, Types.VARCHAR};
238        try {
239            for (int i = 0; i < rsmd.getColumnCount(); i++) {
240                int type = rsmd.getColumnType(i + 1);
241                assertEquals(types[i], type);
242            }
243        } catch (SQLException e) {
244            fail("SQLException is thrown: " + e.getMessage());
245        }
246
247        try {
248            rsmd.getColumnType(0);
249            fail("SQLException is not thrown");
250        } catch (SQLException e) {
251            // expected
252        }
253        try {
254            rsmd.getColumnType(5);
255            fail("SQLException is not thrown");
256        } catch (SQLException e) {
257            // expected
258        }
259    }
260
261    /**
262     * @test java.sql.ResultSetMetaData#getColumnTypeName(int column)
263     *
264     * for extensive tests see: ResultSetGetterTest.testGetMetaData
265     */
266    @TestTargetNew(
267        level = TestLevel.SUFFICIENT,
268        notes = "not all types supported: see ResultSetGetterTests.",
269        method = "getColumnTypeName",
270        args = {int.class}
271    )
272    public void testGetColumnTypeName() {
273        try {
274            assertTrue("smallint".equalsIgnoreCase(rsmd.getColumnTypeName(1)));
275            assertTrue("varchar".equalsIgnoreCase(rsmd.getColumnTypeName(2)));
276            assertTrue("varchar".equalsIgnoreCase(rsmd.getColumnTypeName(3)));
277        } catch (SQLException e) {
278            fail("SQLException is thrown: " + e.getMessage());
279        }
280
281        try {
282            rsmd.getColumnTypeName(0);
283            fail("SQLException is not thrown");
284        } catch (SQLException e) {
285            // expected
286        }
287        try {
288            rsmd.getColumnTypeName(5);
289            fail("SQLException is not thrown");
290        } catch (SQLException e) {
291            // expected
292        }
293    }
294
295    /**
296     * @throws SQLException
297     * @test java.sql.ResultSetMetaData#getTableName(int column)
298     */
299    @TestTargetNew(
300        level = TestLevel.COMPLETE,
301        notes = "",
302        method = "getTableName",
303        args = {int.class}
304    )
305    @KnownFailure("For int = 0, exception expected")
306    public void testGetTableName() throws SQLException {
307        try {
308            assertEquals("zoo", rsmd.getTableName(1));
309        } catch (SQLException e) {
310            fail("SQLException is thrown: " + e.getMessage());
311        }
312        Statement st1 = null;
313        ResultSet rs1 = null;
314        try {
315
316            String create = "create table hutch (id integer not null, animal_id integer, address char(20), primary key (id));";
317            String insert1 = "insert into hutch (id, animal_id, address) values (1, 2, 'Birds-house, 1');";
318            String insert2 = "insert into hutch (id, animal_id, address) values (2, 1, 'Horse-house, 5');";
319            String query = "select name, animal_id from hutch, zoo where zoo.id = 1" ;
320            st1 = conn.createStatement();
321            st1.executeUpdate(create);
322            st1.executeUpdate(insert1);
323            st1.executeUpdate(insert2);
324
325            rs1 = st1.executeQuery(query);
326            assertNotNull(rs1);
327            ResultSetMetaData rsmd1 = rs1.getMetaData();
328            assertEquals("zoo", rsmd1.getTableName(1));
329            assertEquals("hutch", rsmd1.getTableName(2));
330        } catch (SQLException e) {
331            fail("SQLException is thrown: " + e.getMessage());
332        } finally {
333            try {
334                if (rs1 != null) rs1.close();
335                if (st1 != null) {
336                    st1.executeUpdate("drop table if exists hutch");
337                    st1.close();
338                }
339            } catch (SQLException sqle) {
340            }
341        }
342        //Exception Text
343        try {
344            String name = rsmd.getTableName(0);
345            fail("SQLException Expected");
346        } catch (SQLException e) {
347            // ok
348        }
349    }
350
351    /**
352     * @test {@link java.sql.ResultSetMetaData#getPrecision(int column)}
353     */
354    @TestTargetNew(
355        level = TestLevel.SUFFICIENT,
356        notes = "Tests fails: always returns 0, exception tests fail ,failing statements commented out",
357        method = "getPrecision",
358        args = {int.class}
359    )
360    @KnownFailure("not supported")
361    public void testGetPrecision() throws SQLException {
362        Statement st2 = null;
363        Statement st3 = null;
364        ResultSetMetaData rsmd2 = null;
365        try {
366        int precisionNum = 10;
367        int scale = 3;
368        int precicisionReal = 10;
369        String createTable = "create table DecimalNumbers ( valueDouble DOUBLE,"+
370        "valueFloat FLOAT , scaleTest NUMERIC("+precisionNum+","+scale+"),"+
371        " valueReal REAL("+precicisionReal+")  );";
372        String insert = "insert into DecimalNumbers values (1.5, 20.55, 30.666, 100000);";
373        String select = "select * from DecimalNumbers;";
374        st2 = conn.createStatement();
375        st2.executeUpdate(createTable);
376        st2.executeUpdate(insert);
377
378        st2.close();
379
380        st3 = conn.createStatement();
381        rs = st3.executeQuery(select);
382        assertTrue(rs.next());
383        rsmd2 = rs.getMetaData();
384
385        assertNotNull(rsmd2);
386        assertEquals(precicisionReal, rsmd2.getPrecision(4));
387        assertEquals(precisionNum,rsmd2.getPrecision(3));
388        assertTrue(rsmd2.getPrecision(2) > 0);
389        assertTrue(rsmd2.getPrecision(1) > 0);
390
391        // non numeric field
392        try {
393            rsmd.getPrecision(3);
394        } catch (SQLException e1) {
395            System.out.println("ResultSetMetaDataTest.testGetPrecision()"+e1.getMessage());
396            e1.printStackTrace();
397        }
398
399
400        try {
401            rsmd.getPrecision(0);
402            fail("SQLException is not thrown");
403        } catch (SQLException e) {
404            // expected
405        }
406        try {
407            rsmd.getPrecision(5);
408            fail("SQLException is not thrown");
409        } catch (SQLException e) {
410            // expected
411        }
412
413        try {
414            rs.close();
415            rsmd.getPrecision(1);
416            fail("Exception expected");
417        } catch (SQLException e) {
418            //ok
419        }
420        } finally  {
421            if (st2 != null) st2.close();
422            if (st3 != null) st3.close();
423        }
424    }
425
426    /**
427     * @test {@link java.sql.ResultSetMetaData#getScale(int column)}
428     */
429    @TestTargetNew(
430        level = TestLevel.SUFFICIENT,
431        notes = "Tests fail: always returns 0, exception tests fail"+
432        " no positive test case for black-box test possible: no default"+
433        " value indicated",
434        method = "getScale",
435        args = {int.class}
436    )
437    @KnownFailure("Not supported")
438    public void testGetScale() throws SQLException {
439        try {
440        int scale = 3;
441        String createTable = "create table DecimalNumbers ( valueDouble DOUBLE,"+
442        "valueFloat FLOAT , scaleTest NUMERIC(10,"+scale+")  );";
443        String insert = "insert into DecimalNumbers values (1.5, 20.55, 30.666);";
444        String select = "select * from DecimalNumbers;";
445
446        Statement st = conn.createStatement();
447        st.executeUpdate(createTable);
448        st.executeUpdate(insert);
449
450        rs = st.executeQuery(select);
451        ResultSetMetaData rsmd2 = rs.getMetaData();
452
453        assertNotNull(rsmd2);
454        assertEquals(scale,rsmd2.getScale(3));
455        assertTrue(rsmd2.getScale(1) > 0);
456        assertTrue(rsmd2.getScale(2) > 0);
457
458        try {
459            rsmd.getScale(0);
460            fail("SQLException is not thrown");
461        } catch (SQLException e) {
462            // expected
463        }
464        try {
465            rsmd.getScale(5);
466            fail("SQLException is not thrown");
467        } catch (SQLException e) {
468            // expected
469        }
470
471
472        try {
473            conn.close();
474            rsmd.getScale(1);
475            fail("Exception expected");
476        } catch (SQLException e) {
477            //ok
478        }
479        } finally  {
480            st.cancel();
481        }
482    }
483
484    /**
485     * @test {@link java.sql.ResultSetMetaData#getSchemaName(int column)}
486     */
487    @TestTargetNew(
488        level = TestLevel.COMPLETE,
489        notes = "Tests fail: always returns null. Feature only partially implemented. Missing: positive test.",
490        method = "getSchemaName",
491        args = {int.class}
492    )
493    @KnownFailure("not supported")
494    public void testGetSchema() {
495
496        try {
497            assertNull("Functionality is now supported. Change test",rsmd.getSchemaName(2));
498        } catch (SQLException e1) {
499            fail("ResultSetMetaDataTest.testGetScale()"+e1.getMessage());
500            e1.printStackTrace();
501        }
502
503
504
505        try {
506            rsmd.getSchemaName(0);
507            fail("SQLException is not thrown");
508        } catch (SQLException e) {
509            // expected
510        }
511        try {
512            rsmd.getSchemaName(5);
513            fail("SQLException is not thrown");
514        } catch (SQLException e) {
515            // expected
516        }
517
518
519        try {
520            conn.close();
521            rsmd.getSchemaName(2);
522            fail("Exception expected");
523        } catch (SQLException e) {
524            //ok
525        }
526
527    }
528
529    /**
530     * @test {@link java.sql.ResultSetMetaData#isAutoIncrement(int column)}
531     */
532    @TestTargetNew(
533        level = TestLevel.COMPLETE,
534        notes = "Tests fail: always returns false, failing statements commented out. Feature only partially implemented.Missing: Test positive case",
535        method = "isAutoIncrement",
536        args = {int.class}
537    )
538    @KnownFailure("not supported")
539    public void testisAutoIncrement() {
540
541        try {
542            assertFalse(rsmd.isAutoIncrement(1));
543        } catch (SQLException e1) {
544            fail("ResultSetMetaDataTest.testGetScale()"+e1.getMessage());
545            e1.printStackTrace();
546        }
547
548        /*
549        // Exception testing
550
551        try {
552            rsmd.isAutoIncrement(0);
553            fail("SQLException is not thrown");
554        } catch (SQLException e) {
555            // expected
556        }
557        try {
558            rsmd.isAutoIncrement(5);
559            fail("SQLException is not thrown");
560        } catch (SQLException e) {
561            // expected
562        }
563        */
564
565        try {
566            conn.close();
567            rsmd.getSchemaName(2);
568            fail("Exception expected");
569        } catch (SQLException e) {
570            //ok
571        }
572
573    }
574
575    /**
576     * @test {@link java.sql.ResultSetMetaData#isCaseSensitive(int column)}
577     */
578    @TestTargetNew(
579        level = TestLevel.SUFFICIENT,
580        notes = "Tests fail: always returns false. Exception tests fail, failing statements commented out. Feature only partially implemented.",
581        method = "isCaseSensitive",
582        args = {int.class}
583    )
584    @KnownFailure("not supported")
585    public void testIsCaseSensitive() {
586
587        try {
588            assertFalse(rsmd.isCaseSensitive(1));
589            assertFalse(rsmd.isCaseSensitive(2));
590            assertFalse(rsmd.isCaseSensitive(3));
591        } catch (SQLException e1) {
592            fail("ResultSetMetaDataTest.testGetScale()"+e1.getMessage());
593            e1.printStackTrace();
594        }
595
596        /*
597        // Exception testing
598
599        try {
600            rsmd.isCaseSensitive(0);
601            fail("SQLException is not thrown");
602        } catch (SQLException e) {
603            // expected
604        }
605        try {
606            rsmd.isCaseSensitive(5);
607            fail("SQLException is not thrown");
608        } catch (SQLException e) {
609            // expected
610        }
611        */
612
613        try {
614            conn.close();
615            rsmd.isCaseSensitive(1);
616            fail("Exception expected");
617        } catch (SQLException e) {
618            //ok
619        }
620    }
621
622    /**
623     * @test {@link java.sql.ResultSetMetaData#isCurrency(int column)}
624     */
625    @TestTargetNew(
626        level = TestLevel.COMPLETE,
627        notes = "Tests fail: always returns false. Exceptions and tests non Numeric fields fail, failing statements commented out. Feature only partially implemented. May be an optional feature.",
628        method = "isCurrency",
629        args = {int.class}
630    )
631    @KnownFailure("not supported")
632    public void testIsCurrency() {
633
634        try {
635            assertFalse(rsmd.isCurrency(1));
636        } catch (SQLException e1) {
637            fail("ResultSetMetaDataTest.testGetScale()"+e1.getMessage());
638            e1.printStackTrace();
639        }
640
641
642        // Exception testing
643
644        try {
645            rsmd.isCurrency(0);
646            fail("SQLException is not thrown");
647        } catch (SQLException e) {
648            // expected
649        }
650        try {
651            rsmd.isCurrency(5);
652            fail("SQLException is not thrown");
653        } catch (SQLException e) {
654            // expected
655        }
656
657
658        try {
659            rs.close();
660            rsmd.isCurrency(1);
661            fail("Exception expected");
662        } catch (SQLException e) {
663            //ok
664        }
665    }
666
667    /**
668     * @test {@link java.sql.ResultSetMetaData#isDefinitelyWritable(int column)}
669     */
670    @TestTargetNew(
671        level = TestLevel.SUFFICIENT,
672        notes = "Tests fail: always returns true. Exceptions fail, Feature only partially implemented.",
673        method = "isDefinitelyWritable",
674        args = {int.class}
675    )
676    @KnownFailure("not supported")
677    public void testIsDefinitlyWritable() {
678
679        try {
680            assertTrue(rsmd.isDefinitelyWritable(1));
681        } catch (SQLException e1) {
682            fail("ResultSetMetaDataTest.testisDefinitelyWritable()"
683                    + e1.getMessage());
684            e1.printStackTrace();
685        }
686
687        // Exception testing
688
689        try {
690            rsmd.isDefinitelyWritable(0);
691            fail("SQLException is not thrown");
692        } catch (SQLException e) {
693            // expected
694        }
695        try {
696            rsmd.isDefinitelyWritable(5);
697            fail("SQLException is not thrown");
698        } catch (SQLException e) {
699            // expected
700        }
701    }
702
703    /**
704     * @test {@link java.sql.ResultSetMetaData#isNullable(int column)}
705     */
706    @TestTargetNew(
707        level = TestLevel.SUFFICIENT,
708        notes = "Tests fail: always returns ResultSetMetaData.columnNullableUnknown. Exceptions fail, failing statements commented out. Feature only partially implemented. May be an optional feature.",
709        method = "isNullable",
710        args = {int.class}
711    )
712    @KnownFailure("not supported")
713    public void testIsNullable() {
714
715        try {
716            assertEquals(ResultSetMetaData.columnNullable, rsmd
717                    .isNullable(1));
718            assertEquals(ResultSetMetaData.columnNullable, rsmd
719                    .isNullable(2));
720            assertEquals(ResultSetMetaData.columnNullable, rsmd
721                    .isNullable(3));
722        } catch (SQLException e1) {
723            fail("ResultSetMetaDataTest.isNullable()" + e1.getMessage());
724            e1.printStackTrace();
725        }
726
727        /*
728        // Exception testing
729
730        try {
731            rsmd.isNullable(0);
732            fail("SQLException is not thrown");
733        } catch (SQLException e) {
734            // expected
735        }
736        try {
737            rsmd.isNullable(5);
738            fail("SQLException is not thrown");
739        } catch (SQLException e) {
740            // expected
741        }
742        */
743
744    }
745
746    /**
747     * @test {@link java.sql.ResultSetMetaData#isReadOnly(int column)}
748     */
749    @TestTargetNew(
750        level = TestLevel.NOT_FEASIBLE,
751        notes = "Cannot know from blackbox test if readonly or writable. Exceptions fail, Feature only partially implemented.",
752        method = "isReadOnly",
753        args = {int.class}
754    )
755    @KnownFailure("not supported")
756    public void testIsReadOnly() {
757
758        try {
759            assertFalse(rsmd.isReadOnly(1));
760        } catch (SQLException e1) {
761            fail("ResultSetMetaDataTest.isReadOnly" + e1.getMessage());
762            e1.printStackTrace();
763        }
764
765        // Exception testing
766
767        try {
768            rsmd.isReadOnly(0);
769            fail("SQLException is not thrown");
770        } catch (SQLException e) {
771            // expected
772        }
773    }
774
775    /**
776     * @test {@link java.sql.ResultSetMetaData#isSearchable(int column)}
777     */
778    @TestTargetNew(
779        level = TestLevel.SUFFICIENT,
780        notes = "Tests fail: always returns false. Exceptions fail, Feature only partially implemented. Missing: test for searchable field.",
781        method = "isSearchable",
782        args = {int.class}
783    )
784    @KnownFailure("not supported")
785    public void testIsSearchable() {
786
787        try {
788            assertTrue(rsmd.isSearchable(1));
789            assertTrue(rsmd.isSearchable(2));
790            assertTrue(rsmd.isSearchable(3));
791        } catch (SQLException e1) {
792            fail("ResultSetMetaDataTest.isReadOnly" + e1.getMessage());
793            e1.printStackTrace();
794        }
795
796        // Exception testing
797
798        try {
799            rsmd.isSearchable(0);
800            fail("SQLException is not thrown");
801        } catch (SQLException e) {
802            // expected
803        }
804    }
805
806    /**
807     * @test {@link java.sql.ResultSetMetaData#isSigned(int column)}
808     */
809    @TestTargetNew(
810        level = TestLevel.SUFFICIENT,
811        notes = "Tests fail: always returns false. Exceptions and tests on non numeric fields fail, Feature only partially implemented. Missing: test positive result.",
812        method = "isSigned",
813        args = {int.class}
814    )
815    @KnownFailure("not supported")
816    public void testIsSigned() {
817
818        try {
819            assertFalse(rsmd.isSigned(1));
820        } catch (SQLException e1) {
821            fail("ResultSetMetaDataTest.isSigned" + e1.getMessage());
822            e1.printStackTrace();
823        }
824
825        // Exception testing
826
827        try {
828            rsmd.isSigned(0);
829            fail("SQLException is not thrown");
830        } catch (SQLException e) {
831            // expected
832        }
833    }
834
835    /**
836     * @test {@link java.sql.ResultSetMetaData#isWritable(int column)}
837     */
838    @TestTargetNew(
839        level = TestLevel.NOT_FEASIBLE,
840        notes = "Analaguous to is Readonly.  Exceptions and tests on non numeric fields fail, failing statements commented out. Feature only partially implemented.",
841        method = "isWritable",
842        args = {int.class}
843    )
844    @KnownFailure("not supported")
845    public void testIsWritable() {
846
847        try {
848            assertTrue(rsmd.isWritable(1));
849            assertTrue(rsmd.isWritable(2));
850            assertTrue(rsmd.isWritable(3));
851        } catch (SQLException e1) {
852            fail("ResultSetMetaDataTest.isWritable" + e1.getMessage());
853            e1.printStackTrace();
854        }
855
856        // Exception testing
857
858        try {
859            rsmd.isWritable(0);
860            fail("SQLException is not thrown");
861        } catch (SQLException e) {
862            // expected
863        }
864    }
865
866
867    /**
868     * @test {@link java.sql.ResultSetMetaData#getColumnDisplaySize(int Column)}
869     */
870    @TestTargetNew(
871        level = TestLevel.SUFFICIENT,
872        notes = "Tests fail. always returns 0. Missing case where display"+
873        " size greater than 0",
874        method = "getColumnDisplaySize",
875        args = {int.class}
876    )
877    @KnownFailure("not supported")
878    public void testGetColumnDisplaySize() {
879        try {
880            for (int i = 0; i < rsmd.getColumnCount(); i++) {
881                int size = rsmd.getColumnDisplaySize(i + 1);
882                assertTrue(size > 0);
883            }
884        } catch (SQLException e) {
885            fail("SQLException is thrown: " + e.getMessage());
886        }
887
888        // Exception testing
889
890        try {
891            rsmd.getColumnDisplaySize(0);
892            fail("SQLException is not thrown");
893        } catch (SQLException e) {
894            // expected
895        }
896        try {
897            rsmd.getColumnDisplaySize(5);
898            fail("SQLException is not thrown");
899        } catch (SQLException e) {
900            // expected
901        }
902    }
903
904}
905