8059570: Addition of tests for RowSetFactory and RowSetProvider

Reviewed-by: dfuchs
This commit is contained in:
Lance Andersen 2014-10-06 12:56:54 -04:00
parent 3215ed2f0a
commit 9547e0ff45
10 changed files with 9621 additions and 0 deletions

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,119 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package test.rowset;
import java.sql.SQLException;
import javax.sql.rowset.RowSetFactory;
import javax.sql.rowset.RowSetProvider;
import static org.testng.Assert.*;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import util.BaseTest;
public class RowSetFactoryTests extends BaseTest {
// RowSet implementations that we are testing for
private final String DEFAULT_CACHEDROWSET_CLASSNAME = "com.sun.rowset.CachedRowSetImpl";
private final String DEFAULT_FILTEREDROWSET_CLASSNAME = "com.sun.rowset.FileteredRowSetImpl";
private final String DEFAULT_JDBCROWSET_CLASSNAME = "com.sun.rowset.JdbcRowSetImpl";
private final String DEFAULT_JOINROWSET_CLASSNAME = "com.sun.rowset.JoinRowSetImpl";
private final String DEFAULT_WEBROWSET_CLASSNAME = "com.sun.rowset.WebRowSetImpl";
private final String STUB_FACTORY_CLASSNAME = "util.StubRowSetFactory";
private final String STUB_CACHEDROWSET_CLASSNAME = "util.StubCachedRowSetImpl";
private final String STUB_FILTEREDROWSET_CLASSNAME = "util.StubFilteredRowSetImpl";
private final String STUB_JDBCROWSET_CLASSNAME = "util.StubJdbcRowSetImpl";
private final String STUB_JOINROWSET_CLASSNAME = "util.StubJoinRowSetImpl";
private final String STUB_WEBROWSET_CLASSNAME = "util.StubWebRowSetImpl";
/*
* Validate that the RowSetFactory returned by RowSetProvider.newFactory()
* returns the correct RowSet implementations
*/
@Test(dataProvider = "RowSetValues")
public void test(RowSetFactory rsf, String impl) throws SQLException {
validateRowSetImpl(rsf, impl);
}
/*
* Utility Method to validate the RowsetFactory returns the correct
* RowSet implementation
*/
private void validateRowSetImpl(RowSetFactory rsf, String implName)
throws SQLException {
assertNotNull(rsf, "RowSetFactory should not be null");
switch (implName) {
case DEFAULT_CACHEDROWSET_CLASSNAME:
assertTrue(rsf.createCachedRowSet() instanceof com.sun.rowset.CachedRowSetImpl);
break;
case DEFAULT_FILTEREDROWSET_CLASSNAME:
assertTrue(rsf.createFilteredRowSet() instanceof com.sun.rowset.FilteredRowSetImpl);
break;
case DEFAULT_JDBCROWSET_CLASSNAME:
assertTrue(rsf.createJdbcRowSet() instanceof com.sun.rowset.JdbcRowSetImpl);
break;
case DEFAULT_JOINROWSET_CLASSNAME:
assertTrue(rsf.createJoinRowSet() instanceof com.sun.rowset.JoinRowSetImpl);
break;
case DEFAULT_WEBROWSET_CLASSNAME:
assertTrue(rsf.createWebRowSet() instanceof com.sun.rowset.WebRowSetImpl);
break;
case STUB_CACHEDROWSET_CLASSNAME:
assertTrue(rsf.createCachedRowSet() instanceof util.StubCachedRowSetImpl);
break;
case STUB_FILTEREDROWSET_CLASSNAME:
assertTrue(rsf.createFilteredRowSet() instanceof util.StubFilteredRowSetImpl);
break;
case STUB_JDBCROWSET_CLASSNAME:
assertTrue(rsf.createJdbcRowSet() instanceof util.StubJdbcRowSetImpl);
break;
case STUB_WEBROWSET_CLASSNAME:
assertTrue(rsf.createWebRowSet() instanceof util.StubWebRowSetImpl);
break;
}
}
/*
* DataProvider used to provide the RowSetFactory and the RowSet
* implementation that should be returned
*/
@DataProvider(name = "RowSetValues")
private Object[][] RowSetValues() throws SQLException {
RowSetFactory rsf = RowSetProvider.newFactory();
RowSetFactory rsf1 = RowSetProvider.newFactory(STUB_FACTORY_CLASSNAME, null);
return new Object[][]{
{rsf, DEFAULT_CACHEDROWSET_CLASSNAME},
{rsf, DEFAULT_FILTEREDROWSET_CLASSNAME},
{rsf, DEFAULT_JDBCROWSET_CLASSNAME},
{rsf, DEFAULT_JOINROWSET_CLASSNAME},
{rsf, DEFAULT_WEBROWSET_CLASSNAME},
{rsf1, STUB_CACHEDROWSET_CLASSNAME},
{rsf1, STUB_FILTEREDROWSET_CLASSNAME},
{rsf1, STUB_JDBCROWSET_CLASSNAME},
{rsf1, STUB_JOINROWSET_CLASSNAME},
{rsf1, STUB_WEBROWSET_CLASSNAME}
};
}
}

View File

@ -0,0 +1,189 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package test.rowset;
import com.sun.rowset.RowSetFactoryImpl;
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.sql.SQLException;
import javax.sql.rowset.RowSetFactory;
import javax.sql.rowset.RowSetProvider;
import static org.testng.Assert.*;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import util.BaseTest;
import util.StubRowSetFactory;
public class RowSetProviderTests extends BaseTest {
// Default RowSetFactory Implementation
private final String DEFFAULT_FACTORY_CLASSNAME = "com.sun.rowset.RowSetFactoryImpl";
// Stub RowSetFactory Implementation
private final String STUB_FACTORY_CLASSNAME = "util.StubRowSetFactory";
// Indicator that the factory implementation does not need to be checked
private final String NO_VALADATE_IMPL = "";
// Original System property value for javax.sql.rowset.RowSetFactory
private static String origFactoryProperty;
// Original ClassLoader
private static ClassLoader cl;
// Path to the location of the jar files used by the ServiceLoader API
private static String jarPath;
/*
* Save off the original property value for javax.sql.rowset.RowSetFactory
*/
@BeforeClass
public static void setUpClass() throws Exception {
origFactoryProperty = System.getProperty("javax.sql.rowset.RowSetFactory");
cl = Thread.currentThread().getContextClassLoader();
jarPath = System.getProperty("test.src", ".") + File.separatorChar
+ "jars" + File.separatorChar;
}
/*
* Install the original javax.sql.rowset.RowSetFactory property value
*/
@AfterClass
public static void tearDownClass() throws Exception {
if (origFactoryProperty != null) {
System.setProperty("javax.sql.rowset.RowSetFactory",
origFactoryProperty);
}
}
/*
* Clear the javax.sql.rowset.RowSetFactory property value
*/
@AfterMethod
public void tearDownMethod() throws Exception {
System.clearProperty("javax.sql.rowset.RowSetFactory");
Thread.currentThread().setContextClassLoader(cl);
}
/*
* Validate that the correct RowSetFactory is returned by newFactory().
*/
@Test(dataProvider = "RowSetFactoryValues")
public void test(RowSetFactory rsf, String impl) throws SQLException {
validateProvider(rsf, impl);
}
/*
* Validate that the default RowSetFactory is returned by newFactory()
* when specified by the javax.sql.rowset.RowSetFactory property.
*/
@Test
public void test01() throws SQLException {
System.setProperty("javax.sql.rowset.RowSetFactory",
DEFFAULT_FACTORY_CLASSNAME);
validateProvider(RowSetProvider.newFactory(), DEFFAULT_FACTORY_CLASSNAME);
}
/*
* Validate that the correct RowSetFactory is returned by newFactory()
* when specified by the javax.sql.rowset.RowSetFactory property.
*/
@Test
public void test2() throws SQLException {
System.setProperty("javax.sql.rowset.RowSetFactory", STUB_FACTORY_CLASSNAME);
validateProvider(RowSetProvider.newFactory(), STUB_FACTORY_CLASSNAME);
}
/*
* Validate that a SQLException is thrown by newFactory()
* when specified RowSetFactory specified by the
* javax.sql.rowset.RowSetFactory property is not valid.
*/
@Test(expectedExceptions = SQLException.class)
public void test3() throws SQLException {
System.setProperty("javax.sql.rowset.RowSetFactory",
"invalid.RowSetFactoryImpl");
RowSetFactory rsf = RowSetProvider.newFactory();
}
/*
* Validate that the correct RowSetFactory is returned by newFactory()
* when specified by the ServiceLoader API.
*/
@Test
public void test4() throws Exception {
File f = new File(jarPath + "goodFactory.jar");
URLClassLoader loader = new URLClassLoader(new URL[]{
new URL(f.toURI().toString())}, getClass().getClassLoader());
Thread.currentThread().setContextClassLoader(loader);
validateProvider(RowSetProvider.newFactory(), STUB_FACTORY_CLASSNAME);
}
/*
* Validate that a SQLException is thrown by newFactory() if the default
*RowSetFactory specified by the ServlceLoader API is not valid
*/
@Test(expectedExceptions = SQLException.class)
public void test5() throws Exception {
File f = new File(jarPath + "badFactory.jar");
URLClassLoader loader = new URLClassLoader(new URL[]{
new URL(f.toURI().toString())}, getClass().getClassLoader());
Thread.currentThread().setContextClassLoader(loader);
RowSetProvider.newFactory();
}
/*
* Utility Method to validate that the RowsetFactory returned from
* RowSetProvider.newFactory() is correct
*/
private void validateProvider(RowSetFactory rsf, String implName) {
assertNotNull(rsf, "RowSetFactory should not be null");
switch (implName) {
case DEFFAULT_FACTORY_CLASSNAME:
assertTrue(rsf instanceof RowSetFactoryImpl);
break;
case STUB_FACTORY_CLASSNAME:
assertTrue(rsf instanceof StubRowSetFactory);
break;
default:
}
}
/*
* DataProvider used to provide a RowSetFactory and the expected
* RowSetFactory implementation that should be returned
*/
@DataProvider(name = "RowSetFactoryValues")
private Object[][] RowSetFactoryValues() throws SQLException {
RowSetFactory rsf = RowSetProvider.newFactory();
RowSetFactory rsf1 = RowSetProvider.newFactory(STUB_FACTORY_CLASSNAME, null);
RowSetFactory rsf2 = RowSetProvider.newFactory(DEFFAULT_FACTORY_CLASSNAME, null);
return new Object[][]{
{rsf, NO_VALADATE_IMPL},
{rsf, DEFFAULT_FACTORY_CLASSNAME},
{rsf1, STUB_FACTORY_CLASSNAME},
{rsf2, DEFFAULT_FACTORY_CLASSNAME}
};
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,60 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package util;
import java.sql.SQLException;
import javax.sql.rowset.CachedRowSet;
import javax.sql.rowset.FilteredRowSet;
import javax.sql.rowset.JdbcRowSet;
import javax.sql.rowset.JoinRowSet;
import javax.sql.rowset.RowSetFactory;
import javax.sql.rowset.WebRowSet;
public class StubRowSetFactory implements RowSetFactory {
@Override
public CachedRowSet createCachedRowSet() throws SQLException {
return new StubCachedRowSetImpl();
}
@Override
public FilteredRowSet createFilteredRowSet() throws SQLException {
return new StubFilteredRowSetImpl();
}
@Override
public JdbcRowSet createJdbcRowSet() throws SQLException {
return new StubJdbcRowSetImpl();
}
@Override
public JoinRowSet createJoinRowSet() throws SQLException {
return new StubJoinRowSetImpl();
}
@Override
public WebRowSet createWebRowSet() throws SQLException {
return new StubWebRowSetImpl();
}
}

File diff suppressed because it is too large Load Diff