1 /* 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /** 25 * @test 26 * @modules java.sql.rowset/com.sun.rowset 27 * java.sql.rowset/com.sun.rowset.internal 28 * java.sql.rowset/com.sun.rowset.providers 29 */ 30 31 package test.rowset; 32 33 import java.sql.SQLException; 34 import javax.sql.rowset.RowSetFactory; 35 import javax.sql.rowset.RowSetProvider; 36 import static org.testng.Assert.*; 37 import org.testng.annotations.DataProvider; 38 import org.testng.annotations.Test; 39 import util.BaseTest; 40 41 public class RowSetFactoryTests extends BaseTest { 42 43 // RowSet implementations that we are testing for 44 private final String DEFAULT_CACHEDROWSET_CLASSNAME = "com.sun.rowset.CachedRowSetImpl"; 45 private final String DEFAULT_FILTEREDROWSET_CLASSNAME = "com.sun.rowset.FileteredRowSetImpl"; 46 private final String DEFAULT_JDBCROWSET_CLASSNAME = "com.sun.rowset.JdbcRowSetImpl"; 47 private final String DEFAULT_JOINROWSET_CLASSNAME = "com.sun.rowset.JoinRowSetImpl"; 48 private final String DEFAULT_WEBROWSET_CLASSNAME = "com.sun.rowset.WebRowSetImpl"; 49 private final String STUB_FACTORY_CLASSNAME = "util.StubRowSetFactory"; 50 private final String STUB_CACHEDROWSET_CLASSNAME = "util.StubCachedRowSetImpl"; 51 private final String STUB_FILTEREDROWSET_CLASSNAME = "util.StubFilteredRowSetImpl"; 52 private final String STUB_JDBCROWSET_CLASSNAME = "util.StubJdbcRowSetImpl"; 53 private final String STUB_JOINROWSET_CLASSNAME = "util.StubJoinRowSetImpl"; 54 private final String STUB_WEBROWSET_CLASSNAME = "util.StubWebRowSetImpl"; 55 56 57 /* 58 * Validate that the RowSetFactory returned by RowSetProvider.newFactory() 59 * returns the correct RowSet implementations 60 */ 61 @Test(dataProvider = "RowSetValues", enabled = true) 62 public void test(RowSetFactory rsf, String impl) throws SQLException { 63 validateRowSetImpl(rsf, impl); 64 } 65 66 /* 67 * Utility Method to validate the RowsetFactory returns the correct 68 * RowSet implementation 69 */ 70 private void validateRowSetImpl(RowSetFactory rsf, String implName) 71 throws SQLException { 72 assertNotNull(rsf, "RowSetFactory should not be null"); 73 switch (implName) { 74 case DEFAULT_CACHEDROWSET_CLASSNAME: 75 assertTrue(rsf.createCachedRowSet() instanceof com.sun.rowset.CachedRowSetImpl); 76 break; 77 case DEFAULT_FILTEREDROWSET_CLASSNAME: 78 assertTrue(rsf.createFilteredRowSet() instanceof com.sun.rowset.FilteredRowSetImpl); 79 break; 80 case DEFAULT_JDBCROWSET_CLASSNAME: 81 assertTrue(rsf.createJdbcRowSet() instanceof com.sun.rowset.JdbcRowSetImpl); 82 break; 83 case DEFAULT_JOINROWSET_CLASSNAME: 84 assertTrue(rsf.createJoinRowSet() instanceof com.sun.rowset.JoinRowSetImpl); 85 break; 86 case DEFAULT_WEBROWSET_CLASSNAME: 87 assertTrue(rsf.createWebRowSet() instanceof com.sun.rowset.WebRowSetImpl); 88 break; 89 case STUB_CACHEDROWSET_CLASSNAME: 90 assertTrue(rsf.createCachedRowSet() instanceof util.StubCachedRowSetImpl); 91 break; 92 case STUB_FILTEREDROWSET_CLASSNAME: 93 assertTrue(rsf.createFilteredRowSet() instanceof util.StubFilteredRowSetImpl); 94 break; 95 case STUB_JDBCROWSET_CLASSNAME: 96 assertTrue(rsf.createJdbcRowSet() instanceof util.StubJdbcRowSetImpl); 97 break; 98 case STUB_WEBROWSET_CLASSNAME: 99 assertTrue(rsf.createWebRowSet() instanceof util.StubWebRowSetImpl); 100 break; 101 } 102 103 } 104 105 /* 106 * DataProvider used to provide the RowSetFactory and the RowSet 107 * implementation that should be returned 108 */ 109 @DataProvider(name = "RowSetValues") 110 private Object[][] RowSetValues() throws SQLException { 111 RowSetFactory rsf = RowSetProvider.newFactory(); 112 RowSetFactory rsf1 = RowSetProvider.newFactory(STUB_FACTORY_CLASSNAME, null); 113 return new Object[][]{ 114 {rsf, DEFAULT_CACHEDROWSET_CLASSNAME}, 115 {rsf, DEFAULT_FILTEREDROWSET_CLASSNAME}, 116 {rsf, DEFAULT_JDBCROWSET_CLASSNAME}, 117 {rsf, DEFAULT_JOINROWSET_CLASSNAME}, 118 {rsf, DEFAULT_WEBROWSET_CLASSNAME}, 119 {rsf1, STUB_CACHEDROWSET_CLASSNAME}, 120 {rsf1, STUB_FILTEREDROWSET_CLASSNAME}, 121 {rsf1, STUB_JDBCROWSET_CLASSNAME}, 122 {rsf1, STUB_JOINROWSET_CLASSNAME}, 123 {rsf1, STUB_WEBROWSET_CLASSNAME} 124 125 }; 126 } 127 }