8062558: Add javax/sql/rowset/spi tests
Reviewed-by: joehw
This commit is contained in:
parent
b23c39c07b
commit
ff54f6ff54
jdk/test
java/sql/testng/util
javax/sql/testng
@ -35,6 +35,7 @@ import java.sql.SQLPermission;
|
||||
import java.util.Enumeration;
|
||||
import java.util.PropertyPermission;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.logging.LoggingPermission;
|
||||
|
||||
/*
|
||||
* Simple Policy class that supports the required Permissions to validate the
|
||||
@ -57,7 +58,8 @@ public class TestPolicy extends Policy {
|
||||
* Policy used by the JDBC tests Possible values are: all (ALLPermissions),
|
||||
* setLog (SQLPemission("setLog"), deregisterDriver
|
||||
* (SQLPermission("deregisterDriver") (SQLPermission("deregisterDriver"),
|
||||
* and setSyncFactory(SQLPermission(setSyncFactory),
|
||||
* setSyncFactory(SQLPermission(setSyncFactory), and also
|
||||
* LoggerPermission("control", null) when setting a Level
|
||||
*
|
||||
* @param policy Permissions to set
|
||||
*/
|
||||
@ -79,6 +81,11 @@ public class TestPolicy extends Policy {
|
||||
setMinimalPermissions();
|
||||
permissions.add(new SQLPermission("setSyncFactory"));
|
||||
break;
|
||||
case "setSyncFactoryLogger":
|
||||
setMinimalPermissions();
|
||||
permissions.add(new SQLPermission("setSyncFactory"));
|
||||
permissions.add(new LoggingPermission("control", null));
|
||||
break;
|
||||
default:
|
||||
setMinimalPermissions();
|
||||
}
|
||||
|
@ -0,0 +1,113 @@
|
||||
/*
|
||||
* 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.spi;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import javax.sql.rowset.spi.SyncFactoryException;
|
||||
import static org.testng.Assert.*;
|
||||
import org.testng.annotations.Test;
|
||||
import util.BaseTest;
|
||||
|
||||
public class SyncFactoryExceptionTests extends BaseTest {
|
||||
|
||||
/*
|
||||
* Create SyncFactoryException with no-arg constructor
|
||||
*/
|
||||
@Test
|
||||
public void test01() {
|
||||
SyncFactoryException ex = new SyncFactoryException();
|
||||
assertTrue(ex.getMessage() == null
|
||||
&& ex.getSQLState() == null
|
||||
&& ex.getCause() == null
|
||||
&& ex.getErrorCode() == 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create SyncFactoryException with message
|
||||
*/
|
||||
@Test
|
||||
public void test02() {
|
||||
SyncFactoryException ex = new SyncFactoryException(reason);
|
||||
assertTrue(ex.getMessage().equals(reason)
|
||||
&& ex.getSQLState() == null
|
||||
&& ex.getCause() == null
|
||||
&& ex.getErrorCode() == 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that the ordering of the returned Exceptions is correct using
|
||||
* for-each loop
|
||||
*/
|
||||
@Test
|
||||
public void test03() {
|
||||
SyncFactoryException ex = new SyncFactoryException("Exception 1");
|
||||
ex.initCause(t1);
|
||||
SyncFactoryException ex1 = new SyncFactoryException("Exception 2");
|
||||
SyncFactoryException ex2 = new SyncFactoryException("Exception 3");
|
||||
ex2.initCause(t2);
|
||||
ex.setNextException(ex1);
|
||||
ex.setNextException(ex2);
|
||||
int num = 0;
|
||||
for (Throwable e : ex) {
|
||||
assertTrue(msgs[num++].equals(e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that the ordering of the returned Exceptions is correct using
|
||||
* traditional while loop
|
||||
*/
|
||||
@Test
|
||||
public void test04() {
|
||||
SQLException ex = new SyncFactoryException("Exception 1");
|
||||
ex.initCause(t1);
|
||||
SyncFactoryException ex1 = new SyncFactoryException("Exception 2");
|
||||
SyncFactoryException ex2 = new SyncFactoryException("Exception 3");
|
||||
ex2.initCause(t2);
|
||||
ex.setNextException(ex1);
|
||||
ex.setNextException(ex2);
|
||||
int num = 0;
|
||||
while (ex != null) {
|
||||
assertTrue(msgs[num++].equals(ex.getMessage()));
|
||||
Throwable c = ex.getCause();
|
||||
while (c != null) {
|
||||
assertTrue(msgs[num++].equals(c.getMessage()));
|
||||
c = c.getCause();
|
||||
}
|
||||
ex = ex.getNextException();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Serialize a SyncFactoryException and make sure you can read it back properly
|
||||
*/
|
||||
@Test
|
||||
public void test05() throws Exception {
|
||||
SyncFactoryException e = new SyncFactoryException(reason);
|
||||
SyncFactoryException ex1 = createSerializedException(e);
|
||||
assertTrue(ex1.getMessage().equals(reason)
|
||||
&& ex1.getSQLState() == null
|
||||
&& ex1.getCause() == null
|
||||
&& ex1.getErrorCode() == 0);
|
||||
}
|
||||
}
|
@ -27,13 +27,13 @@ import java.security.Policy;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.NamingException;
|
||||
import javax.sql.rowset.spi.SyncFactory;
|
||||
import javax.sql.rowset.spi.SyncFactoryException;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import util.BaseTest;
|
||||
import util.StubContext;
|
||||
import util.TestPolicy;
|
||||
|
||||
public class SyncFactoryPermissionsTests extends BaseTest {
|
||||
@ -41,6 +41,7 @@ public class SyncFactoryPermissionsTests extends BaseTest {
|
||||
Context ctx;
|
||||
private static Policy policy;
|
||||
private static SecurityManager sm;
|
||||
private final Logger alogger = Logger.getLogger(this.getClass().getName());
|
||||
|
||||
/*
|
||||
* Install a SeeurityManager along with a base Policy to allow testNG to run
|
||||
@ -67,13 +68,7 @@ public class SyncFactoryPermissionsTests extends BaseTest {
|
||||
public SyncFactoryPermissionsTests() {
|
||||
policy = Policy.getPolicy();
|
||||
sm = System.getSecurityManager();
|
||||
|
||||
try {
|
||||
ctx = new InitialContext();
|
||||
} catch (NamingException ex) {
|
||||
Logger.getLogger(SyncFactoryPermissionsTests.class.getName()).
|
||||
log(Level.SEVERE, null, ex);
|
||||
}
|
||||
ctx = new StubContext();
|
||||
}
|
||||
|
||||
/*
|
||||
@ -86,13 +81,21 @@ public class SyncFactoryPermissionsTests extends BaseTest {
|
||||
SyncFactory.setJNDIContext(ctx);
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that a SyncFactoryException is thrown if the Logger is null
|
||||
*/
|
||||
@Test(expectedExceptions = SyncFactoryException.class)
|
||||
public void test00() throws SyncFactoryException {
|
||||
Logger l = SyncFactory.getLogger();
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that setJNDIContext succeeds if SQLPermission("setSyncFactory")
|
||||
* has been granted
|
||||
*/
|
||||
@Test
|
||||
public void test1() throws Exception {
|
||||
Policy.setPolicy(new TestPolicy("setSyncFactory"));
|
||||
public void test01() throws Exception {
|
||||
setPolicy(new TestPolicy("setSyncFactory"));
|
||||
SyncFactory.setJNDIContext(ctx);
|
||||
}
|
||||
|
||||
@ -100,8 +103,77 @@ public class SyncFactoryPermissionsTests extends BaseTest {
|
||||
* Validate that setJNDIContext succeeds if AllPermissions has been granted
|
||||
*/
|
||||
@Test
|
||||
public void test2() throws Exception {
|
||||
public void test02() throws Exception {
|
||||
setPolicy(new TestPolicy("all"));
|
||||
SyncFactory.setJNDIContext(ctx);
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that AccessControlException is thrown if
|
||||
* SQLPermission("setSyncFactory") has not been granted
|
||||
*/
|
||||
@Test(expectedExceptions = AccessControlException.class)
|
||||
public void test03() throws Exception {
|
||||
setPolicy(new TestPolicy());
|
||||
SyncFactory.setLogger(alogger);
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that setLogger succeeds if SQLPermission("setSyncFactory")
|
||||
* has been granted
|
||||
*/
|
||||
@Test
|
||||
public void test04() throws Exception {
|
||||
setPolicy(new TestPolicy("setSyncFactory"));
|
||||
SyncFactory.setLogger(alogger);
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that setLogger succeeds if AllPermissions has been granted
|
||||
*/
|
||||
@Test
|
||||
public void test05() throws Exception {
|
||||
setPolicy(new TestPolicy("all"));
|
||||
SyncFactory.setLogger(alogger);
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that AccessControlException is thrown if
|
||||
* SQLPermission("setSyncFactory") has not been granted
|
||||
*/
|
||||
@Test(expectedExceptions = AccessControlException.class)
|
||||
public void test06() throws Exception {
|
||||
setPolicy(new TestPolicy());
|
||||
SyncFactory.setLogger(alogger, Level.INFO);
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that AccessControlException is thrown if
|
||||
* SQLPermission("setSyncFactory") and LoggingPermission("control", null)
|
||||
* have not been granted
|
||||
*/
|
||||
@Test(expectedExceptions = AccessControlException.class)
|
||||
public void test07() throws Exception {
|
||||
setPolicy(new TestPolicy("setSyncFactory"));
|
||||
SyncFactory.setLogger(alogger, Level.INFO);
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that setLogger succeeds if SQLPermission("setSyncFactory")
|
||||
* has been granted
|
||||
*/
|
||||
@Test
|
||||
public void test08() throws Exception {
|
||||
setPolicy(new TestPolicy("setSyncFactoryLogger"));
|
||||
SyncFactory.setLogger(alogger, Level.INFO);
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that setLogger succeeds if AllPermissions has been granted
|
||||
*/
|
||||
@Test
|
||||
public void test09() throws Exception {
|
||||
setPolicy(new TestPolicy("all"));
|
||||
SyncFactory.setLogger(alogger, Level.INFO);
|
||||
}
|
||||
}
|
||||
|
220
jdk/test/javax/sql/testng/test/rowset/spi/SyncFactoryTests.java
Normal file
220
jdk/test/javax/sql/testng/test/rowset/spi/SyncFactoryTests.java
Normal file
@ -0,0 +1,220 @@
|
||||
/*
|
||||
* 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.spi;
|
||||
|
||||
import com.sun.rowset.providers.RIOptimisticProvider;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.naming.Context;
|
||||
import javax.sql.rowset.spi.SyncFactory;
|
||||
import javax.sql.rowset.spi.SyncFactoryException;
|
||||
import javax.sql.rowset.spi.SyncProvider;
|
||||
import static org.testng.Assert.*;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
import util.PropertyStubProvider;
|
||||
import util.StubSyncProvider;
|
||||
import util.StubContext;
|
||||
|
||||
//com.sun.jndi.ldap.LdapCtxFactory
|
||||
public class SyncFactoryTests {
|
||||
private static String origFactory;
|
||||
|
||||
private final String stubProvider = "util.StubSyncProvider";
|
||||
private final String propertyStubProvider = "util.PropertyStubProvider";
|
||||
private final Logger alogger = Logger.getLogger(this.getClass().getName());
|
||||
// Initial providers including those set via a property
|
||||
List<String> initialProviders;
|
||||
// All providers including those specifically registered
|
||||
List<String> allProviders;
|
||||
private Context ctx= null;
|
||||
|
||||
public SyncFactoryTests() {
|
||||
|
||||
// Add a provider via a property
|
||||
System.setProperty("rowset.provider.classname", propertyStubProvider);
|
||||
initialProviders = Arrays.asList(
|
||||
"com.sun.rowset.providers.RIOptimisticProvider",
|
||||
"com.sun.rowset.providers.RIXMLProvider",
|
||||
propertyStubProvider);
|
||||
allProviders = new ArrayList<>();
|
||||
allProviders.addAll(initialProviders);
|
||||
allProviders.add(stubProvider);
|
||||
ctx = new StubContext();
|
||||
}
|
||||
|
||||
@BeforeMethod
|
||||
public void setUpMethod() throws Exception {
|
||||
// Make sure the provider provider that is registered is removed
|
||||
// before each run
|
||||
SyncFactory.unregisterProvider(stubProvider);
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate a non-null factory is returned
|
||||
*/
|
||||
@Test
|
||||
public void test() throws SyncFactoryException {
|
||||
SyncFactory syncFactory = SyncFactory.getSyncFactory();
|
||||
assertTrue(syncFactory != null);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check that the correct SyncProvider is returned for the specified
|
||||
* providerID for the provider registered via a property
|
||||
*/
|
||||
@Test
|
||||
public void test00() throws SyncFactoryException {
|
||||
SyncProvider p = SyncFactory.getInstance(propertyStubProvider);
|
||||
assertTrue(p instanceof PropertyStubProvider);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check that the correct SyncProvider is returned for the specified
|
||||
* providerID
|
||||
*/
|
||||
@Test
|
||||
public void test01() throws SyncFactoryException {
|
||||
SyncFactory.registerProvider(stubProvider);
|
||||
SyncProvider p = SyncFactory.getInstance(stubProvider);
|
||||
assertTrue(p instanceof StubSyncProvider);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check that the Default SyncProvider is returned if an empty String is
|
||||
* passed or if an invalid providerID is specified
|
||||
*/
|
||||
@Test
|
||||
public void test02() throws SyncFactoryException {
|
||||
SyncProvider p = SyncFactory.getInstance("");
|
||||
assertTrue(p instanceof RIOptimisticProvider);
|
||||
// Attempt to get an invalid provider and get the default provider
|
||||
p = SyncFactory.getInstance("util.InvalidSyncProvider");
|
||||
assertTrue(p instanceof RIOptimisticProvider);
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that a SyncFactoryException is thrown if the ProviderID is null
|
||||
*/
|
||||
@Test(expectedExceptions = SyncFactoryException.class)
|
||||
public void test03() throws SyncFactoryException {
|
||||
SyncProvider p = SyncFactory.getInstance(null);
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that a SyncFactoryException is thrown if the Logger is null
|
||||
*/
|
||||
@Test(expectedExceptions = SyncFactoryException.class,enabled=true)
|
||||
public void test04() throws SyncFactoryException {
|
||||
Logger l = SyncFactory.getLogger();
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that the correct logger is returned by getLogger
|
||||
*/
|
||||
@Test
|
||||
public void test05() throws SyncFactoryException {
|
||||
SyncFactory.setLogger(alogger);
|
||||
Logger l = SyncFactory.getLogger();
|
||||
assertTrue(l.equals(alogger));
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that the correct logger is returned by getLogger
|
||||
*/
|
||||
@Test
|
||||
public void test06() throws SyncFactoryException {
|
||||
SyncFactory.setLogger(alogger, Level.INFO);
|
||||
Logger l = SyncFactory.getLogger();
|
||||
assertTrue(l.equals(alogger));
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that a driver that is registered is returned by
|
||||
* getRegisteredProviders and if it is unregistered, that it is
|
||||
* not returned by getRegisteredProviders
|
||||
*/
|
||||
@Test
|
||||
public void test07() throws SyncFactoryException {
|
||||
|
||||
// Validate that only the default providers and any specified via
|
||||
// a System property are available
|
||||
validateProviders(initialProviders);
|
||||
|
||||
// Register a provider and make sure it is avaiable
|
||||
SyncFactory.registerProvider(stubProvider);
|
||||
validateProviders(allProviders);
|
||||
|
||||
// Check that if a provider is unregistered, it does not show as
|
||||
// registered
|
||||
SyncFactory.unregisterProvider(stubProvider);
|
||||
validateProviders(initialProviders);
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that setJNDIContext throws a SyncFactoryException if the
|
||||
* context is null
|
||||
*/
|
||||
@Test(expectedExceptions = SyncFactoryException.class, enabled=true)
|
||||
public void test08() throws Exception {
|
||||
SyncFactory.setJNDIContext(null);
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that setJNDIContext succeeds
|
||||
*/
|
||||
@Test(enabled=true)
|
||||
public void test09() throws Exception {
|
||||
SyncFactory.setJNDIContext(ctx);
|
||||
}
|
||||
|
||||
/*
|
||||
* Utility method to validate the expected providers are regsitered
|
||||
*/
|
||||
private void validateProviders(List<String> expectedProviders)
|
||||
throws SyncFactoryException {
|
||||
List<String> results = new ArrayList<>();
|
||||
Enumeration<SyncProvider> providers = SyncFactory.getRegisteredProviders();
|
||||
|
||||
while (providers.hasMoreElements()) {
|
||||
SyncProvider p = providers.nextElement();
|
||||
results.add(p.getProviderID());
|
||||
}
|
||||
assertTrue(expectedProviders.containsAll(results)
|
||||
&& results.size() == expectedProviders.size());
|
||||
}
|
||||
|
||||
/*
|
||||
* Utility method to dump out SyncProvider info for a registered provider
|
||||
*/
|
||||
private void showImpl(SyncProvider impl) {
|
||||
System.out.println("Provider implementation:"
|
||||
+ "\nVendor: " + impl.getVendor()
|
||||
+ "\nVersion: " + impl.getVersion()
|
||||
+ "\nProviderID: " + impl.getProviderID());
|
||||
}
|
||||
}
|
@ -0,0 +1,187 @@
|
||||
/*
|
||||
* 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.spi;
|
||||
|
||||
import com.sun.rowset.internal.SyncResolverImpl;
|
||||
import java.sql.SQLException;
|
||||
import javax.sql.rowset.spi.SyncProviderException;
|
||||
import static org.testng.Assert.*;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import util.BaseTest;
|
||||
import util.StubSyncResolver;
|
||||
|
||||
public class SyncProviderExceptionTests extends BaseTest {
|
||||
@BeforeClass
|
||||
public static void setUpClass() throws Exception {
|
||||
System.out.println(System.getProperty("java.naming.factory.initial"));
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownClass() throws Exception {
|
||||
}
|
||||
/*
|
||||
* Create SyncProviderException with no-arg constructor
|
||||
*/
|
||||
@Test
|
||||
public void test() {
|
||||
SyncProviderException ex = new SyncProviderException();
|
||||
assertTrue(ex.getMessage() == null
|
||||
&& ex.getSQLState() == null
|
||||
&& ex.getCause() == null
|
||||
&& ex.getErrorCode() == 0
|
||||
&& ex.getSyncResolver() instanceof SyncResolverImpl);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create SyncProviderException with no-arg constructor and
|
||||
* call setSyncResolver to indicate the SyncResolver to use
|
||||
*/
|
||||
@Test
|
||||
public void test01() {
|
||||
SyncProviderException ex = new SyncProviderException();
|
||||
ex.setSyncResolver(new StubSyncResolver());
|
||||
assertTrue(ex.getMessage() == null
|
||||
&& ex.getSQLState() == null
|
||||
&& ex.getCause() == null
|
||||
&& ex.getErrorCode() == 0
|
||||
&& ex.getSyncResolver() instanceof StubSyncResolver);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create SyncProviderException with message
|
||||
*/
|
||||
@Test
|
||||
public void test02() {
|
||||
SyncProviderException ex = new SyncProviderException(reason);
|
||||
assertTrue(ex.getMessage().equals(reason)
|
||||
&& ex.getSQLState() == null
|
||||
&& ex.getCause() == null
|
||||
&& ex.getErrorCode() == 0
|
||||
&& ex.getSyncResolver() instanceof SyncResolverImpl);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create SyncProviderException with message and
|
||||
* call setSyncResolver to indicate the SyncResolver to use
|
||||
*/
|
||||
@Test
|
||||
public void test03() {
|
||||
SyncProviderException ex = new SyncProviderException(reason);
|
||||
ex.setSyncResolver(new StubSyncResolver());
|
||||
|
||||
assertTrue(ex.getMessage().equals(reason)
|
||||
&& ex.getSQLState() == null
|
||||
&& ex.getCause() == null
|
||||
&& ex.getErrorCode() == 0
|
||||
&& ex.getSyncResolver() instanceof StubSyncResolver);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create SyncProviderException with and specify the SyncResolver to use
|
||||
*/
|
||||
@Test
|
||||
public void test04() {
|
||||
SyncProviderException ex = new SyncProviderException(new StubSyncResolver());
|
||||
assertTrue(ex.getMessage() == null
|
||||
&& ex.getSQLState() == null
|
||||
&& ex.getCause() == null
|
||||
&& ex.getErrorCode() == 0
|
||||
&& ex.getSyncResolver() instanceof StubSyncResolver);
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that the ordering of the returned Exceptions is correct using
|
||||
* for-each loop
|
||||
*/
|
||||
@Test
|
||||
public void test05() {
|
||||
SyncProviderException ex = new SyncProviderException("Exception 1");
|
||||
ex.initCause(t1);
|
||||
SyncProviderException ex1 = new SyncProviderException("Exception 2");
|
||||
SyncProviderException ex2 = new SyncProviderException("Exception 3");
|
||||
ex2.initCause(t2);
|
||||
ex.setNextException(ex1);
|
||||
ex.setNextException(ex2);
|
||||
int num = 0;
|
||||
for (Throwable e : ex) {
|
||||
assertTrue(msgs[num++].equals(e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that the ordering of the returned Exceptions is correct using
|
||||
* traditional while loop
|
||||
*/
|
||||
@Test
|
||||
public void test06() {
|
||||
SQLException ex = new SyncProviderException("Exception 1");
|
||||
ex.initCause(t1);
|
||||
SyncProviderException ex1 = new SyncProviderException("Exception 2");
|
||||
SyncProviderException ex2 = new SyncProviderException("Exception 3");
|
||||
ex2.initCause(t2);
|
||||
ex.setNextException(ex1);
|
||||
ex.setNextException(ex2);
|
||||
int num = 0;
|
||||
while (ex != null) {
|
||||
assertTrue(msgs[num++].equals(ex.getMessage()));
|
||||
Throwable c = ex.getCause();
|
||||
while (c != null) {
|
||||
assertTrue(msgs[num++].equals(c.getMessage()));
|
||||
c = c.getCause();
|
||||
}
|
||||
ex = ex.getNextException();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Serialize a SyncProviderException and make sure you can read it back properly
|
||||
*/
|
||||
@Test
|
||||
public void test07() throws Exception {
|
||||
SyncProviderException e = new SyncProviderException(reason);
|
||||
SyncProviderException ex1 = createSerializedException(e);
|
||||
assertTrue(ex1.getMessage().equals(reason)
|
||||
&& ex1.getSQLState() == null
|
||||
&& ex1.getCause() == null
|
||||
&& ex1.getErrorCode() == 0
|
||||
&& ex1.getSyncResolver() instanceof SyncResolverImpl, ex1.getSyncResolver().getClass().getName());
|
||||
}
|
||||
|
||||
/*
|
||||
* Serialize a SyncProviderException and make sure you can read it back properly
|
||||
*/
|
||||
@Test
|
||||
public void test08() throws Exception {
|
||||
SyncProviderException e = new SyncProviderException(reason);
|
||||
e.setSyncResolver(new StubSyncResolver());
|
||||
|
||||
SyncProviderException ex1 = createSerializedException(e);
|
||||
assertTrue(ex1.getMessage().equals(reason)
|
||||
&& ex1.getSQLState() == null
|
||||
&& ex1.getCause() == null
|
||||
&& ex1.getErrorCode() == 0
|
||||
&& ex1.getSyncResolver() instanceof StubSyncResolver);
|
||||
}
|
||||
}
|
27
jdk/test/javax/sql/testng/util/PropertyStubProvider.java
Normal file
27
jdk/test/javax/sql/testng/util/PropertyStubProvider.java
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
public class PropertyStubProvider extends StubSyncProvider {
|
||||
|
||||
}
|
220
jdk/test/javax/sql/testng/util/StubContext.java
Normal file
220
jdk/test/javax/sql/testng/util/StubContext.java
Normal file
@ -0,0 +1,220 @@
|
||||
/*
|
||||
* 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.util.Hashtable;
|
||||
import javax.naming.Binding;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NameClassPair;
|
||||
import javax.naming.NameParser;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class StubContext implements Context {
|
||||
|
||||
@Override
|
||||
public Object lookup(Name name) throws NamingException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object lookup(String name) throws NamingException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(Name name, Object obj) throws NamingException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(String name, Object obj) throws NamingException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rebind(Name name, Object obj) throws NamingException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rebind(String name, Object obj) throws NamingException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unbind(Name name) throws NamingException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unbind(String name) throws NamingException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rename(Name oldName, Name newName) throws NamingException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rename(String oldName, String newName) throws NamingException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {
|
||||
return new NamingEnumerationStub();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
|
||||
return new NamingEnumerationStub();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamingEnumeration<Binding> listBindings(Name name) throws NamingException {
|
||||
return new NamingEnumerationStub();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamingEnumeration<Binding> listBindings(String name) throws NamingException {
|
||||
return new NamingEnumerationStub();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroySubcontext(Name name) throws NamingException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroySubcontext(String name) throws NamingException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context createSubcontext(Name name) throws NamingException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context createSubcontext(String name) throws NamingException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object lookupLink(Name name) throws NamingException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object lookupLink(String name) throws NamingException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NameParser getNameParser(Name name) throws NamingException {
|
||||
return new NameParserStub();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NameParser getNameParser(String name) throws NamingException {
|
||||
return new NameParserStub();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Name composeName(Name name, Name prefix) throws NamingException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String composeName(String name, String prefix) throws NamingException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object addToEnvironment(String propName, Object propVal) throws NamingException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object removeFromEnvironment(String propName) throws NamingException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hashtable<?, ?> getEnvironment() throws NamingException {
|
||||
return new Hashtable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws NamingException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNameInNamespace() throws NamingException {
|
||||
return null;
|
||||
}
|
||||
|
||||
class NamingEnumerationStub implements NamingEnumeration {
|
||||
|
||||
@Override
|
||||
public Object next() throws NamingException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMore() throws NamingException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws NamingException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMoreElements() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object nextElement() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class NameParserStub implements NameParser {
|
||||
|
||||
@Override
|
||||
public Name parse(String name) throws NamingException {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
92
jdk/test/javax/sql/testng/util/StubSyncProvider.java
Normal file
92
jdk/test/javax/sql/testng/util/StubSyncProvider.java
Normal file
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* 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 javax.sql.RowSetReader;
|
||||
import javax.sql.RowSetWriter;
|
||||
import javax.sql.rowset.spi.SyncProvider;
|
||||
import javax.sql.rowset.spi.SyncProviderException;
|
||||
|
||||
public class StubSyncProvider extends SyncProvider {
|
||||
|
||||
/**
|
||||
* The unique provider identifier.
|
||||
*/
|
||||
private String providerID = "util.StubSyncProvider";
|
||||
|
||||
/**
|
||||
* The vendor name of this SyncProvider implementation
|
||||
*/
|
||||
private String vendorName = "Oracle Corporation";
|
||||
|
||||
/**
|
||||
* The version number of this SyncProvider implementation
|
||||
*/
|
||||
private String versionNumber = "1.0";
|
||||
|
||||
@Override
|
||||
public String getProviderID() {
|
||||
return providerID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RowSetReader getRowSetReader() {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public RowSetWriter getRowSetWriter() {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getProviderGrade() {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDataSourceLock(int datasource_lock) throws SyncProviderException {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDataSourceLock() throws SyncProviderException {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int supportsUpdatableView() {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return versionNumber;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVendor() {
|
||||
return vendorName;
|
||||
}
|
||||
|
||||
}
|
1616
jdk/test/javax/sql/testng/util/StubSyncResolver.java
Normal file
1616
jdk/test/javax/sql/testng/util/StubSyncResolver.java
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user