You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ka...@apache.org on 2013/04/10 17:11:11 UTC
svn commit: r1466508 - in
/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet:
NetworkServerControlApiTest.java _Suite.java build.xml
Author: kahatlen
Date: Wed Apr 10 15:11:11 2013
New Revision: 1466508
URL: http://svn.apache.org/r1466508
Log:
DERBY-6162: Simplify privileged actions in NetworkServerControlApiTest
Modified:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlApiTest.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/_Suite.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/build.xml
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlApiTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlApiTest.java?rev=1466508&r1=1466507&r2=1466508&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlApiTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlApiTest.java Wed Apr 10 15:11:11 2013
@@ -22,8 +22,7 @@
package org.apache.derbyTesting.functionTests.tests.derbynet;
import org.apache.derby.drda.NetworkServerControl;
-import org.apache.derbyTesting.functionTests.tests.lang.SecurityPolicyReloadingTest;
-import org.apache.derbyTesting.functionTests.tests.lang.SimpleTest;
+import org.apache.derbyTesting.functionTests.util.PrivilegedFileOpsForTests;
import org.apache.derbyTesting.functionTests.util.TestUtil;
import org.apache.derbyTesting.junit.BaseJDBCTestCase;
import org.apache.derbyTesting.junit.Derby;
@@ -38,12 +37,10 @@ import java.io.File;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.security.AccessController;
-import java.security.Policy;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.sql.Connection;
import java.sql.SQLException;
-import java.util.Enumeration;
import java.util.Properties;
import junit.framework.Test;
@@ -191,50 +188,28 @@ public class NetworkServerControlApiTest
}
}
- /**
- * Wraps InitAddress.getByName in privilege block.
- *
- * @param host host to resolve
- * @return InetAddress of host
- * @throws UnknownHostException
- */
- private InetAddress privInetAddressGetByName(final String host) throws UnknownHostException
- {
- InetAddress inetAddr = null;
- try {
- inetAddr = (InetAddress) AccessController
- .doPrivileged(new PrivilegedExceptionAction() {
- public Object run() throws UnknownHostException {
- return InetAddress.getByName(host);
- }
- });
- } catch (PrivilegedActionException pe) {
- Exception e = pe.getException();
- if (e instanceof UnknownHostException)
- throw (UnknownHostException) e;
- else
- throw (SecurityException) e;
- }
- return inetAddr;
-
- }
-
-
-
-
- private boolean fileExists(String filename) {
- final File file = new File(filename);
+ /**
+ * Wraps InitAddress.getByName in privilege block.
+ *
+ * @param host host to resolve
+ * @return InetAddress of host
+ */
+ private InetAddress privInetAddressGetByName(final String host)
+ throws UnknownHostException {
try {
- return ((Boolean)AccessController.doPrivileged(
- new PrivilegedExceptionAction() {
- public Object run() throws SecurityException {
- return new Boolean(file.exists());
- }
- })).booleanValue();
+ return AccessController.doPrivileged(
+ new PrivilegedExceptionAction<InetAddress>() {
+ public InetAddress run() throws UnknownHostException {
+ return InetAddress.getByName(host);
+ }
+ });
} catch (PrivilegedActionException pae) {
- throw (SecurityException)pae.getException();
+ throw (UnknownHostException) pae.getCause();
}
-
+ }
+
+ private boolean fileExists(String filename) {
+ return PrivilegedFileOpsForTests.exists(new File(filename));
}
/**
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/_Suite.java?rev=1466508&r1=1466507&r2=1466508&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/_Suite.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/_Suite.java Wed Apr 10 15:11:11 2013
@@ -46,7 +46,6 @@ public class _Suite extends BaseTestCase
TestSuite suite = new TestSuite("derbynet");
suite.addTest(PrepareStatementTest.suite());
- suite.addTest(NetworkServerControlApiTest.suite());
suite.addTest(ShutDownDBWhenNSShutsDownTest.suite());
suite.addTest(DRDAProtocolTest.suite());
suite.addTest(ClientSideSystemPropertiesTest.suite());
@@ -81,6 +80,7 @@ public class _Suite extends BaseTestCase
// Test does not run on J2ME
suite.addTest(DerbyNetNewServerTest.suite());
suite.addTest(ProtocolTest.suite());
+ suite.addTest(NetworkServerControlApiTest.suite());
}
// These tests references a client class directly
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/build.xml?rev=1466508&r1=1466507&r2=1466508&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/build.xml (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/build.xml Wed Apr 10 15:11:11 2013
@@ -87,6 +87,7 @@
<exclude name="${this.dir}/dataSourcePermissions_net.java"/>
<exclude name="${this.dir}/SqlExceptionTest.java"/>
<exclude name="${this.dir}/ProtocolTest.java"/>
+ <exclude name="${this.dir}/NetworkServerControlApiTest.java"/>
</javac>
</target>
@@ -131,7 +132,9 @@
<pathelement path="${junit}"/>
<pathelement path="${java15compile.classpath}"/>
</classpath>
+ <compilerarg value="-Xlint"/>
<include name="${this.dir}/ProtocolTest.java"/>
+ <include name="${this.dir}/NetworkServerControlApiTest.java"/>
</javac>
</target>