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 kr...@apache.org on 2010/06/17 11:56:55 UTC
svn commit: r955529 - in
/db/derby/code/trunk/java/testing/org/apache/derbyTesting:
functionTests/tests/derbynet/ functionTests/tests/lang/ junit/
Author: kristwaa
Date: Thu Jun 17 09:56:54 2010
New Revision: 955529
URL: http://svn.apache.org/viewvc?rev=955529&view=rev
Log:
DERBY-2419: Tighten encapsulation of state in TestConfiguration
Made port and hostname private, and adjusted affected tests.
Introduced DerbyConstants to hold constants used by/in the JUnit tests.
Patch file: derby-2419-3a-further_encapsulation.diff
Added:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DerbyConstants.java (with props)
Modified:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NSSecurityMechanismTest.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlClientCommandTest.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AlterTableTest.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SecurityPolicyReloadingTest.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NSSecurityMechanismTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NSSecurityMechanismTest.java?rev=955529&r1=955528&r2=955529&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NSSecurityMechanismTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NSSecurityMechanismTest.java Thu Jun 17 09:56:54 2010
@@ -1250,7 +1250,7 @@ public class NSSecurityMechanismTest ext
private HashMap addRequiredAttributes(HashMap attrs)
{
- String hostName = TestConfiguration.DEFAULT_HOSTNAME;
+ String hostName = TestConfiguration.getCurrent().getHostName();
int port = TestConfiguration.getCurrent().getPort();
if (usingDB2Client())
{
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlClientCommandTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlClientCommandTest.java?rev=955529&r1=955528&r2=955529&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlClientCommandTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlClientCommandTest.java Thu Jun 17 09:56:54 2010
@@ -22,7 +22,6 @@ limitations under the License.
package org.apache.derbyTesting.functionTests.tests.derbynet;
import java.io.IOException;
-import java.io.InputStream;
import java.util.Locale;
import junit.framework.Test;
@@ -33,7 +32,7 @@ import org.apache.derbyTesting.junit.JDB
import org.apache.derbyTesting.junit.SecurityManagerSetup;
import org.apache.derbyTesting.junit.TestConfiguration;
import org.apache.derbyTesting.junit.BaseJDBCTestCase;
-import org.apache.derbyTesting.junit.Utilities;
+import org.apache.derbyTesting.junit.DerbyConstants;
public class NetworkServerControlClientCommandTest extends BaseJDBCTestCase {
@@ -61,7 +60,8 @@ public class NetworkServerControlClientC
* The -p parameter isn't specified here.
* Changed to accomodate DERBY-4217
*/
- if (TestConfiguration.getCurrent().getPort() == TestConfiguration.DEFAULT_PORT) {
+ if (TestConfiguration.getCurrent().getPort() ==
+ DerbyConstants.DEFAULT_DERBY_PORT) {
assertSuccessfulPing(pingCmd1);
assertSuccessfulPing(pingCmd3);
}
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AlterTableTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AlterTableTest.java?rev=955529&r1=955528&r2=955529&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AlterTableTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AlterTableTest.java Thu Jun 17 09:56:54 2010
@@ -40,6 +40,7 @@ import org.apache.derbyTesting.junit.JDB
import org.apache.derbyTesting.junit.BaseJDBCTestCase;
import org.apache.derbyTesting.junit.TestConfiguration;
import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.junit.DerbyConstants;
public final class AlterTableTest extends BaseJDBCTestCase {
@@ -268,7 +269,7 @@ public final class AlterTableTest extend
rs = st.executeQuery(
"select tablename, " +
- "SYSCS_UTIL.SYSCS_CHECK_TABLE('" + TestConfiguration.TEST_DBO +
+ "SYSCS_UTIL.SYSCS_CHECK_TABLE('" + DerbyConstants.TEST_DBO +
"', tablename) from " + "sys.systables where tabletype = 'T'");
expRS = new String[][]{
@@ -738,7 +739,7 @@ public final class AlterTableTest extend
rs = st.executeQuery(
"select tablename, " +
- "SYSCS_UTIL.SYSCS_CHECK_TABLE('" + TestConfiguration.TEST_DBO +
+ "SYSCS_UTIL.SYSCS_CHECK_TABLE('" + DerbyConstants.TEST_DBO +
"', tablename) from " + "sys.systables where tabletype = 'T'");
expColNames = new String[]{"TABLENAME", "2"};
@@ -803,7 +804,7 @@ public final class AlterTableTest extend
rs = st.executeQuery(
"select tablename, " + "SYSCS_UTIL.SYSCS_CHECK_TABLE('" +
- TestConfiguration.TEST_DBO + "', tablename) from " +
+ DerbyConstants.TEST_DBO + "', tablename) from " +
"sys.systables where tabletype = 'T' and tablename = 'T0_1'");
expColNames = new String[]{"TABLENAME", "2"};
@@ -870,7 +871,7 @@ public final class AlterTableTest extend
rs = st.executeQuery(
"select tablename, " +
- "SYSCS_UTIL.SYSCS_CHECK_TABLE('" + TestConfiguration.TEST_DBO +
+ "SYSCS_UTIL.SYSCS_CHECK_TABLE('" + DerbyConstants.TEST_DBO +
"', tablename) from " + "sys.systables where tabletype = 'T'");
expRS = new String[][]{
@@ -959,7 +960,7 @@ public final class AlterTableTest extend
st.executeUpdate(
"alter table x add constraint NEWCONS primary key (x)");
- // schemaname should be TestConfiguration.TEST_DBO
+ // schemaname should be DerbyConstants.TEST_DBO
rs = st.executeQuery(
"select schemaname, constraintname from " +
@@ -967,8 +968,8 @@ public final class AlterTableTest extend
"s.schemaid = c.schemaid order by 1");
JDBC.assertFullResultSet(rs, new String[][]{
- {TestConfiguration.TEST_DBO, "P1"},
- {TestConfiguration.TEST_DBO, "NEWCONS"}
+ {DerbyConstants.TEST_DBO, "P1"},
+ {DerbyConstants.TEST_DBO, "NEWCONS"}
});
//duplicating values ina priary key column
assertStatementError("23505", st,
@@ -976,20 +977,20 @@ public final class AlterTableTest extend
st.executeUpdate(
" alter table x drop constraint " +
- TestConfiguration.TEST_DBO + ".newcons");
+ DerbyConstants.TEST_DBO + ".newcons");
st.executeUpdate(
" alter table x add constraint newcons primary key (x)");
- // schemaname should be TestConfiguration.TEST_DBO
+ // schemaname should be DerbyConstants.TEST_DBO
rs = st.executeQuery(
"select schemaname, constraintname from " +
"sys.sysconstraints c, sys.sysschemas s where " +
"s.schemaid = c.schemaid order by 1");
JDBC.assertFullResultSet(rs, new String[][]{
- {TestConfiguration.TEST_DBO, "P1"},
- {TestConfiguration.TEST_DBO, "NEWCONS"}
+ {DerbyConstants.TEST_DBO, "P1"},
+ {DerbyConstants.TEST_DBO, "NEWCONS"}
});
//schema does not exist
@@ -1001,7 +1002,7 @@ public final class AlterTableTest extend
st.executeUpdate(
"alter table x drop constraint " +
- TestConfiguration.TEST_DBO + ".newcons");
+ DerbyConstants.TEST_DBO + ".newcons");
// bad schema name(table x is not in the same schema of constraint)
assertStatementError("42X85", st,
@@ -1022,15 +1023,15 @@ public final class AlterTableTest extend
"sys.sysconstraints c, sys.sysschemas s where " +
"s.schemaid = c.schemaid order by 1");
JDBC.assertFullResultSet(rs, new String[][]{
- {TestConfiguration.TEST_DBO, "P1"},
- {TestConfiguration.TEST_DBO, "CON"}
+ {DerbyConstants.TEST_DBO, "P1"},
+ {DerbyConstants.TEST_DBO, "CON"}
});
st.executeUpdate("set schema emptyschema");
// fail, cannot find emptyschema.conn
assertStatementError("42X86", st,
- "alter table " + TestConfiguration.TEST_DBO +
+ "alter table " + DerbyConstants.TEST_DBO +
".x drop constraint emptyschema.con");
rs = st.executeQuery(
@@ -1038,8 +1039,8 @@ public final class AlterTableTest extend
"sys.sysconstraints c, sys.sysschemas s where " +
"s.schemaid = c.schemaid order by 1");
JDBC.assertFullResultSet(rs, new String[][]{
- {TestConfiguration.TEST_DBO, "P1"},
- {TestConfiguration.TEST_DBO, "CON"}
+ {DerbyConstants.TEST_DBO, "P1"},
+ {DerbyConstants.TEST_DBO, "CON"}
});
st.executeUpdate(" set schema newschema");
@@ -1047,10 +1048,10 @@ public final class AlterTableTest extend
// add constraint, default to table schema
st.executeUpdate(
- "alter table " + TestConfiguration.TEST_DBO +
+ "alter table " + DerbyConstants.TEST_DBO +
".x add constraint con2 check (x > 1)");
- // added constraint in TestConfiguration.TEST_DBO
+ // added constraint in DerbyConstants.TEST_DBO
//(defaults to table's schema)
rs = st.executeQuery(
@@ -1058,12 +1059,12 @@ public final class AlterTableTest extend
"sys.sysconstraints c, sys.sysschemas s where " +
"s.schemaid = c.schemaid order by 1,2");
JDBC.assertFullResultSet(rs, new String[][]{
- {TestConfiguration.TEST_DBO, "CON"},
- {TestConfiguration.TEST_DBO, "CON2"},
- {TestConfiguration.TEST_DBO, "P1"}
+ {DerbyConstants.TEST_DBO, "CON"},
+ {DerbyConstants.TEST_DBO, "CON2"},
+ {DerbyConstants.TEST_DBO, "P1"}
});
- st.executeUpdate("drop table " + TestConfiguration.TEST_DBO + ".x");
+ st.executeUpdate("drop table " + DerbyConstants.TEST_DBO + ".x");
st.executeUpdate("drop schema newschema restrict");
}
@@ -1131,8 +1132,8 @@ public final class AlterTableTest extend
"alter table t1 drop constraint C1_PLUS_C2");
st.executeUpdate(
- " alter table " + TestConfiguration.TEST_DBO +
- ".t1 drop constraint " + TestConfiguration.TEST_DBO +
+ " alter table " + DerbyConstants.TEST_DBO +
+ ".t1 drop constraint " + DerbyConstants.TEST_DBO +
".C1_PLUS_C2");
assertStatementError("42X86", pSt);
@@ -2264,7 +2265,7 @@ public final class AlterTableTest extend
st.executeQuery(
" select GRANTEE,GRANTOR,TYPE,COLUMNS from sys.syscolperms");
JDBC.assertFullResultSet(rs, new String[][]{
- {"BRYAN", TestConfiguration.TEST_DBO, "s", "{0, 1, 2}"}
+ {"BRYAN", DerbyConstants.TEST_DBO, "s", "{0, 1, 2}"}
});
st.executeUpdate("alter table atdc_10 drop column b restrict");
@@ -2273,7 +2274,7 @@ public final class AlterTableTest extend
st.executeQuery(
" select GRANTEE,GRANTOR,TYPE,COLUMNS from sys.syscolperms");
JDBC.assertFullResultSet(rs, new String[][]{
- {"BRYAN", TestConfiguration.TEST_DBO, "s", "{0, 1}"}
+ {"BRYAN", DerbyConstants.TEST_DBO, "s", "{0, 1}"}
});
assertStatementError("42X14", st,
@@ -2283,7 +2284,7 @@ public final class AlterTableTest extend
st.executeQuery(
" select GRANTEE,GRANTOR,TYPE,COLUMNS from sys.syscolperms");
JDBC.assertFullResultSet(rs, new String[][]{
- {"BRYAN", TestConfiguration.TEST_DBO, "s", "{0, 1}"}
+ {"BRYAN", DerbyConstants.TEST_DBO, "s", "{0, 1}"}
});
// Include the test from the DERBY-1909 report:
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SecurityPolicyReloadingTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SecurityPolicyReloadingTest.java?rev=955529&r1=955528&r2=955529&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SecurityPolicyReloadingTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SecurityPolicyReloadingTest.java Thu Jun 17 09:56:54 2010
@@ -30,14 +30,12 @@ import java.sql.CallableStatement;
import java.sql.SQLException;
import junit.framework.Test;
-import junit.extensions.TestSetup;
import junit.framework.TestSuite;
import org.apache.derbyTesting.junit.BaseJDBCTestCase;
-import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.DerbyConstants;
import org.apache.derbyTesting.junit.SecurityManagerSetup;
import org.apache.derbyTesting.junit.SupportFilesSetup;
-import org.apache.derbyTesting.junit.SystemPropertyTestSetup;
import org.apache.derbyTesting.junit.TestConfiguration;
/**
@@ -224,7 +222,7 @@ public class SecurityPolicyReloadingTest
private void dbaTest()
throws Exception
{
- Connection conn = openUserConnection( TestConfiguration.TEST_DBO );
+ Connection conn = openUserConnection( DerbyConstants.TEST_DBO );
assertTrue( "Initially, should be able to read property.", canReadProperty() );
@@ -275,7 +273,7 @@ public class SecurityPolicyReloadingTest
throws Exception
{
String insufficientPrivilege = "XK000";
- Connection conn = openUserConnection( TestConfiguration.TEST_DBO );
+ Connection conn = openUserConnection( DerbyConstants.TEST_DBO );
// First change to a policy which does not permit policy reloading
changePolicyFile( conn, UNRELOADABLE_SOURCE_POLICY, true, null );
Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DerbyConstants.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DerbyConstants.java?rev=955529&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DerbyConstants.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DerbyConstants.java Thu Jun 17 09:56:54 2010
@@ -0,0 +1,38 @@
+/*
+
+Derby - Class org.apache.derbyTesting.junit.DerbyConstants
+
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+*/
+
+package org.apache.derbyTesting.junit;
+
+/**
+ * DerbyConstants used by the Derby JUnit framework, for instance when assuming
+ * something about default settings of a property.
+ */
+public interface DerbyConstants {
+
+ /**
+ * The default port used by the network server and the network tools when
+ * no port has been specified.
+ */
+ int DEFAULT_DERBY_PORT = 1527;
+
+ /** Default name for the DBO (database owner). */
+ String TEST_DBO = "TEST_DBO";
+}
Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DerbyConstants.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java?rev=955529&r1=955528&r2=955529&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java Thu Jun 17 09:56:54 2010
@@ -65,10 +65,9 @@ public class TestConfiguration {
private final static String DEFAULT_USER_NAME = "APP";
private final static String DEFAULT_USER_PASSWORD = "APP";
- public final static int DEFAULT_PORT = 1527;
+ private final static int DEFAULT_PORT = 1527;
private final static String DEFAULT_FRAMEWORK = "embedded";
- public final static String DEFAULT_HOSTNAME = "localhost";
- public final static String DEFAULT_SSL = "off";
+ private final static String DEFAULT_HOSTNAME = "localhost";
/**
* Maximum number of ports used by Suites.All
@@ -93,8 +92,6 @@ public class TestConfiguration {
basePort = lastAssignedPort;
}
private static int assignedPortCount = 1;
-
- public final static String TEST_DBO = "TEST_DBO";
private FileOutputStream serverOutput;
@@ -830,7 +827,7 @@ public class TestConfiguration {
return changeUserDecorator(
new DatabaseChangeSetup(setSQLAuthMode, DEFAULT_DBNAME_SQL, DEFAULT_DBNAME_SQL, true),
- TEST_DBO, "dummy"); // DRDA doesn't like empty pw
+ DerbyConstants.TEST_DBO, "dummy"); // DRDA doesn't like empty pw
}
@@ -866,7 +863,7 @@ public class TestConfiguration {
DEFAULT_DBNAME_SQL, DEFAULT_DBNAME_SQL, true);
return changeUserDecorator(setSQLAuthMode,
- TEST_DBO,
+ DerbyConstants.TEST_DBO,
"dummy"); // DRDA doesn't like empty pw
}
@@ -891,7 +888,7 @@ public class TestConfiguration {
String[] users, String passwordToken)
{
String[] usersWithDBO = new String[users.length + 1];
- usersWithDBO[0] = TEST_DBO;
+ usersWithDBO[0] = DerbyConstants.TEST_DBO;
System.arraycopy(users, 0, usersWithDBO, 1, users.length);
return sqlAuthorizationDecorator(
DatabasePropertyTestSetup.builtinAuthentication(test,