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 package test.rowset;
  24 
  25 import java.sql.SQLException;
  26 import javax.sql.rowset.RowSetFactory;
  27 import javax.sql.rowset.RowSetProvider;
  28 import static org.testng.Assert.*;
  29 import org.testng.annotations.DataProvider;
  30 import org.testng.annotations.Test;
  31 import util.BaseTest;
  32 
  33 public class RowSetFactoryTests extends BaseTest {
  34 
  35     // RowSet implementations that we are testing for
  36     private final String DEFAULT_CACHEDROWSET_CLASSNAME = "com.sun.rowset.CachedRowSetImpl";
  37     private final String DEFAULT_FILTEREDROWSET_CLASSNAME = "com.sun.rowset.FileteredRowSetImpl";
  38     private final String DEFAULT_JDBCROWSET_CLASSNAME = "com.sun.rowset.JdbcRowSetImpl";
  39     private final String DEFAULT_JOINROWSET_CLASSNAME = "com.sun.rowset.JoinRowSetImpl";
  40     private final String DEFAULT_WEBROWSET_CLASSNAME = "com.sun.rowset.WebRowSetImpl";
  41     private final String STUB_FACTORY_CLASSNAME = "util.StubRowSetFactory";
  42     private final String STUB_CACHEDROWSET_CLASSNAME = "util.StubCachedRowSetImpl";
  43     private final String STUB_FILTEREDROWSET_CLASSNAME = "util.StubFilteredRowSetImpl";
  44     private final String STUB_JDBCROWSET_CLASSNAME = "util.StubJdbcRowSetImpl";
  45     private final String STUB_JOINROWSET_CLASSNAME = "util.StubJoinRowSetImpl";
  46     private final String STUB_WEBROWSET_CLASSNAME = "util.StubWebRowSetImpl";
  47 
  48 
  49     /*
  50      * Validate that the RowSetFactory returned by RowSetProvider.newFactory()
  51      * returns the correct RowSet implementations
  52      */
  53     @Test(dataProvider = "RowSetValues", enabled = true)
  54     public void test(RowSetFactory rsf, String impl) throws SQLException {
  55         validateRowSetImpl(rsf, impl);
  56     }
  57 
  58     /*
  59      * Utility Method to validate the RowsetFactory returns the correct
  60      * RowSet implementation
  61      */
  62     private void validateRowSetImpl(RowSetFactory rsf, String implName)
  63             throws SQLException {
  64         assertNotNull(rsf, "RowSetFactory should not be null");
  65         switch (implName) {
  66             case DEFAULT_CACHEDROWSET_CLASSNAME:
  67                 assertTrue(rsf.createCachedRowSet() instanceof com.sun.rowset.CachedRowSetImpl);
  68                 break;
  69             case DEFAULT_FILTEREDROWSET_CLASSNAME:
  70                 assertTrue(rsf.createFilteredRowSet() instanceof com.sun.rowset.FilteredRowSetImpl);
  71                 break;
  72             case DEFAULT_JDBCROWSET_CLASSNAME:
  73                 assertTrue(rsf.createJdbcRowSet() instanceof com.sun.rowset.JdbcRowSetImpl);
  74                 break;
  75             case DEFAULT_JOINROWSET_CLASSNAME:
  76                 assertTrue(rsf.createJoinRowSet() instanceof com.sun.rowset.JoinRowSetImpl);
  77                 break;
  78             case DEFAULT_WEBROWSET_CLASSNAME:
  79                 assertTrue(rsf.createWebRowSet() instanceof com.sun.rowset.WebRowSetImpl);
  80                 break;
  81             case STUB_CACHEDROWSET_CLASSNAME:
  82                 assertTrue(rsf.createCachedRowSet() instanceof util.StubCachedRowSetImpl);
  83                 break;
  84             case STUB_FILTEREDROWSET_CLASSNAME:
  85                 assertTrue(rsf.createFilteredRowSet() instanceof util.StubFilteredRowSetImpl);
  86                 break;
  87             case STUB_JDBCROWSET_CLASSNAME:
  88                 assertTrue(rsf.createJdbcRowSet() instanceof util.StubJdbcRowSetImpl);
  89                 break;
  90             case STUB_WEBROWSET_CLASSNAME:
  91                 assertTrue(rsf.createWebRowSet() instanceof util.StubWebRowSetImpl);
  92                 break;
  93         }
  94 
  95     }
  96 
  97     /*
  98      * DataProvider used to provide the RowSetFactory and the RowSet
  99      * implementation that should be returned
 100      */
 101     @DataProvider(name = "RowSetValues")
 102     private Object[][] RowSetValues() throws SQLException {
 103         RowSetFactory rsf = RowSetProvider.newFactory();
 104         RowSetFactory rsf1 = RowSetProvider.newFactory(STUB_FACTORY_CLASSNAME, null);
 105         return new Object[][]{
 106             {rsf, DEFAULT_CACHEDROWSET_CLASSNAME},
 107             {rsf, DEFAULT_FILTEREDROWSET_CLASSNAME},
 108             {rsf, DEFAULT_JDBCROWSET_CLASSNAME},
 109             {rsf, DEFAULT_JOINROWSET_CLASSNAME},
 110             {rsf, DEFAULT_WEBROWSET_CLASSNAME},
 111             {rsf1, STUB_CACHEDROWSET_CLASSNAME},
 112             {rsf1, STUB_FILTEREDROWSET_CLASSNAME},
 113             {rsf1, STUB_JDBCROWSET_CLASSNAME},
 114             {rsf1, STUB_JOINROWSET_CLASSNAME},
 115             {rsf1, STUB_WEBROWSET_CLASSNAME}
 116 
 117         };
 118     }
 119 }