db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bpendle...@apache.org
Subject svn commit: r1095247 - /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlClientCommandTest.java
Date Wed, 20 Apr 2011 00:58:32 GMT
Author: bpendleton
Date: Wed Apr 20 00:58:32 2011
New Revision: 1095247

URL: http://svn.apache.org/viewvc?rev=1095247&view=rev
Log:
DERBY-4260: Make derbynet/NetworkServerControlClientCommandTest run regardless of the locale

This patch was contributed by Houx Zhang (houxzhang @ gmail dot com).

This patch modifies the NetworkServerControlClientCommandTest to pass

	-Dderby.ui.locale=en_US

when running the sub-commands of the test, to ensure that the test assertions,
which look for specific English language strings, find the expected values.
That way, the test will pass, even if run in a shell environment where the
locale is set to a non-English value.


Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NetworkServerControlClientCommandTest.java

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=1095247&r1=1095246&r2=1095247&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
Wed Apr 20 00:58:32 2011
@@ -22,8 +22,6 @@ limitations under the License.
 package org.apache.derbyTesting.functionTests.tests.derbynet;
 
 import java.io.IOException;
-import java.util.Locale;
-
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
@@ -38,50 +36,95 @@ public class NetworkServerControlClientC
 
     public NetworkServerControlClientCommandTest(String name) {
         super(name);
-
+    }
+    
+    public void testPingWithoutArgs() throws InterruptedException, IOException {
+        if (!hasDefaultDerbyPortUsing()) {
+            /* If the port isn't the default one, we make sure that the test passes.
+             * The -p parameter isn't specified here.
+             * Changed to accomodate DERBY-4217
+             */
+            return;
+        }        
+        
+        String[] pingWithoutArgsCmd = new String[] {
+                "org.apache.derby.drda.NetworkServerControl", "ping" };
+        
+        pingWithoutArgsCmd = decorateCmdWithEnglishLocale(pingWithoutArgsCmd); 
+        
+        assertSuccessfulPing(pingWithoutArgsCmd);                
+    }
+    
+    private boolean hasDefaultDerbyPortUsing() {
+        return TestConfiguration.getCurrent().getPort() ==
+                DerbyConstants.DEFAULT_DERBY_PORT;
     }
 
-    /**
-     * Test various ping commands from the command line
-     * 
-     * @throws Exception
+    /*
+     * English locale is neccessary for running on non-English Locale.
+     * See #Derby-4260
      */
-    public void testPing() throws Exception {
-        String currentHost = TestConfiguration.getCurrent().getHostName();
-        String currentPort = Integer.toString(TestConfiguration.getCurrent().getPort());
-        String bogusPort = Integer.toString(
-                TestConfiguration.getCurrent().getBogusPort());
+    private String[] decorateCmdWithEnglishLocale(String[] cmd) {
+        String[] newCmd = new String[cmd.length + 1];
+        newCmd[0] = "-Dderby.ui.locale=en_US";
         
-        String[] pingCmd1 = new String[] {
-                "org.apache.derby.drda.NetworkServerControl", "ping" };
-        String[] pingCmd3 = new String[] {"org.apache.derby.drda.NetworkServerControl",
-                "ping", "-h", currentHost};
+        System.arraycopy(cmd, 0, newCmd, 1, cmd.length);
         
-        /* If the port isn't the default one, we make sure that these two tests pass.
-         * The -p parameter isn't specified here.
-         * Changed to accomodate DERBY-4217
-         */
-        if (TestConfiguration.getCurrent().getPort() ==
-                DerbyConstants.DEFAULT_DERBY_PORT) {
-	        assertSuccessfulPing(pingCmd1);
-            assertSuccessfulPing(pingCmd3);
-        }
+        return newCmd;
+    }
+    
+    public void testPingWithDefinedHost() throws InterruptedException, IOException {
+        if (!hasDefaultDerbyPortUsing()) {
+            /* If the port isn't the default one, we make sure that the test passes.
+             * The -p parameter isn't specified here.
+             * Changed to accomodate DERBY-4217
+             */
+            return;
+        }        
         
-        String[] pingCmd2 = new String[] {
+        String currentHost = TestConfiguration.getCurrent().getHostName();
+        String[] pingWithoutArgsCmd = new String[] {
+                "org.apache.derby.drda.NetworkServerControl", "ping", "-h", currentHost};
+                
+        pingWithoutArgsCmd = decorateCmdWithEnglishLocale(pingWithoutArgsCmd);
+                
+        assertSuccessfulPing(pingWithoutArgsCmd);
+    }
+    
+    public void testPingWithDefinedHostAndPort() throws InterruptedException, IOException
{
+        String currentPort = Integer.toString(TestConfiguration.getCurrent().getPort());
+        String currentHost = TestConfiguration.getCurrent().getHostName();
+        String[] pingWithoutArgsCmd = new String[] {
                 "org.apache.derby.drda.NetworkServerControl", "ping", "-h",
                 currentHost, "-p", currentPort};
-        assertSuccessfulPing(pingCmd2);
         
-        String[] pingCmd4 = new String[] {
-                "org.apache.derby.drda.NetworkServerControl", "ping", "-h",
-                "nothere" };
-        assertFailedPing(pingCmd4,"Unable to find host");
-        String[] pingCmd5= new String[] {"org.apache.derby.drda.NetworkServerControl",
-        "ping", "-h", currentHost, "-p", bogusPort};
-        assertFailedPing(pingCmd5,"Could not connect to Derby Network Server");
-
+        pingWithoutArgsCmd = decorateCmdWithEnglishLocale(pingWithoutArgsCmd);
+        
+        assertSuccessfulPing(pingWithoutArgsCmd);
     }
-
+    
+    public void testPingWithWrongHost() throws InterruptedException, IOException {
+        String[] pingWithoutArgsCmd = new String[] {
+                "org.apache.derby.drda.NetworkServerControl", "ping", "-h", "nothere"};
+                
+        pingWithoutArgsCmd = decorateCmdWithEnglishLocale(pingWithoutArgsCmd);
+                
+        assertFailedPing(pingWithoutArgsCmd, "Unable to find host");
+    }
+    
+    public void testPingWithBogusPort() throws InterruptedException, IOException {
+        String currentHost = TestConfiguration.getCurrent().getHostName();
+        String bogusPort = Integer.toString(
+                TestConfiguration.getCurrent().getBogusPort());
+        String[] pingWithoutArgsCmd = new String[] {
+                "org.apache.derby.drda.NetworkServerControl",
+                "ping", "-h", currentHost, "-p", bogusPort};
+                
+        pingWithoutArgsCmd = decorateCmdWithEnglishLocale(pingWithoutArgsCmd);
+                
+        assertFailedPing(pingWithoutArgsCmd, "Could not connect to Derby Network Server");
+    }
+    
     /**
      * Execute ping command and verify that it completes successfully
      * @param pingCmd array of java arguments for ping command
@@ -89,15 +132,9 @@ public class NetworkServerControlClientC
      * @throws IOException
      */
     private void  assertSuccessfulPing(String[] pingCmd) throws InterruptedException, IOException
{
-        
-/*        InputStream is = Utilities.execJavaCmd(pingCmd, 0);
-        byte[] b = new byte[80];
-        is.read(b, 0, 80);
-        String output = new String(b);
-        assertTrue(output.startsWith("Connection obtained"));
-*/
         assertExecJavaCmdAsExpected(new String[] {"Connection obtained"}, pingCmd, 0);
     }
+    
     /**
      * Execute ping command and verify that it fails with the expected message
      * 
@@ -107,32 +144,27 @@ public class NetworkServerControlClientC
      * @throws IOException
      */
     private void assertFailedPing(String[] pingCmd,String expectedMessage) throws InterruptedException,
IOException {
-        
-        /*InputStream is = Utilities.execJavaCmd(pingCmd, 1);
-        byte[] b = new byte[80];
-        is.read(b, 0, 80);
-        String output = new String(b);
-        assertTrue(output.startsWith(expectedMessage));*/
         assertExecJavaCmdAsExpected(new String[] {expectedMessage}, pingCmd, 1);
     }
     
 
     public static Test suite() {
 
-        TestSuite suite = new TestSuite("NetworkServerControlClientCommandTest");
-        
+        TestSuite suite = new TestSuite("NetworkServerControlClientCommandTest");       

 
-        // need network server, english locale so we can compare command output 
+        // need network server so we can compare command output 
         // and we don't run on J2ME because java command is different.
-        if (!Derby.hasServer() || !Locale.getDefault().getLanguage().equals("en") ||
+        if (!Derby.hasServer() ||
                 JDBC.vmSupportsJSR169())
             return suite;
+        
         Test test = TestConfiguration
                 .clientServerSuite(NetworkServerControlClientCommandTest.class);
         
         // no security manager because we exec a process and don't have permission for that.
         test = SecurityManagerSetup.noSecurityManager(test);
         suite.addTest(test);
+        
         return suite;
     }
 



Mime
View raw message