db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r1490716 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests: master/ suites/ tests/i18n/ tests/jdbcapi/
Date Fri, 07 Jun 2013 16:43:16 GMT
Author: kmarsden
Date: Fri Jun  7 16:43:15 2013
New Revision: 1490716

URL: http://svn.apache.org/r1490716
Log:
DERBY-6246 convert i18n/urlLocale.sql to JUnit 


Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/i18n/UrlLocaleTest.java
  (with props)
Removed:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/urlLocale.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/i18n/urlLocale.sql
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/i18n/urlLocale_app.properties
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/i18nTest.runall
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/i18n/_Suite.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DriverTest.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/i18nTest.runall
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/i18nTest.runall?rev=1490716&r1=1490715&r2=1490716&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/i18nTest.runall
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/i18nTest.runall
Fri Jun  7 16:43:15 2013
@@ -1,4 +1,3 @@
 i18n/I18NImportExport.sql
-i18n/urlLocale.sql
 i18n/messageLocale.sql
 i18n/iepnegativetests_ES.sql

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/i18n/UrlLocaleTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/i18n/UrlLocaleTest.java?rev=1490716&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/i18n/UrlLocaleTest.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/i18n/UrlLocaleTest.java
Fri Jun  7 16:43:15 2013
@@ -0,0 +1,190 @@
+/*
+ *
+ * Derby - Class org.apache.derbyTesting.functionTests.tests.lang.UrlLocaleTest
+ *
+ * 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 
+ * i18n governing permissions and limitations under the License.
+ */
+
+package org.apache.derbyTesting.functionTests.tests.i18n;
+
+import java.net.MalformedURLException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.junit.SupportFilesSetup;
+import org.apache.derbyTesting.junit.TestConfiguration;
+
+
+
+public class UrlLocaleTest extends BaseJDBCTestCase {
+    
+    public UrlLocaleTest(String name) {
+        super(name);
+    }
+
+
+    
+    /**
+     * Shutdown on tearDown to make sure all databases can be removed.
+     * @throws Exception 
+     * @see org.apache.derbyTesting.junit.BaseJDBCTestCase#tearDown()
+     */
+    public void tearDown() throws Exception {
+        super.tearDown();
+        TestConfiguration.getCurrent().shutdownEngine();
+        // Reregister driver for any subsequent tests
+        String driverClass =
+                TestConfiguration.getCurrent().getJDBCClient().getJDBCDriverName();
+        Class.forName(driverClass).newInstance();
+    }
+    
+    /**
+     * Test valid territory settings on URL
+     * 
+     */
+    public void testURLLocale()  throws SQLException, MalformedURLException {
+        // check this current database was created with the default locale
+        Statement s = createStatement();
+        s.executeUpdate("call checkRDefaultLoc()");
+        
+            // create a swiss database
+        String url = TestConfiguration.getCurrent().
+                getJDBCUrl(SupportFilesSetup.getReadWrite("swissdb").getPath());
+        url += ";create=true;territory=fr_CH";
+        Connection locConn = DriverManager.getConnection(url);
+        createLocaleProcedures(locConn);
+        Statement locStatement = locConn.createStatement();
+        locStatement.executeUpdate("call checkDatabaseLoc('fr_CH')");
+        locStatement.close();
+        locConn.close();
+        
+        //-- create a Hindi in India database (hi_IN)
+        
+        url = TestConfiguration.getCurrent().getJDBCUrl(
+                SupportFilesSetup.getReadWrite("hindi").getPath());
+        url += ";create=true;territory=hi_IN";
+        locConn = DriverManager.getConnection(url);
+        createLocaleProcedures(locConn);
+        locStatement = locConn.createStatement();
+        locStatement.executeUpdate("call checkDatabaseLoc('hi_IN')");
+        locStatement.close();
+        locConn.close();
+       //- now try one with a variant
+       // -- create a English in Israel database for JavaOS en_IL_JavaOS
+        url = TestConfiguration.getCurrent().
+                getJDBCUrl(SupportFilesSetup.getReadWrite("Israel").getPath());
+        url += ";create=true;territory=en_IL_JavaOS";
+        locConn = DriverManager.getConnection(url);
+        createLocaleProcedures(locConn);
+        locStatement = locConn.createStatement();
+        locStatement.executeUpdate("call checkDatabaseLoc('en_IL_JavaOS')");
+        locStatement.close();
+        locConn.close();
+        
+        // now try with just a language - we support this
+        // as some vms do.
+        url = TestConfiguration.getCurrent().
+                getJDBCUrl(SupportFilesSetup.getReadWrite("bacon").getPath());
+        url += ";create=true;territory=da";
+        locConn = DriverManager.getConnection(url);
+        createLocaleProcedures(locConn);
+        locStatement = locConn.createStatement();
+        locStatement.executeUpdate("call checkDatabaseLoc('da')");
+        locStatement.close();
+        locConn.close();
+                
+    }
+
+    
+    
+    /**
+     * Test invalid territory settings
+     */
+    public void testUrlLocaleNegative() throws SQLException {
+        //Connection without territory specified in territory attribute        
+        String url = TestConfiguration.getCurrent().getJDBCUrl("../extinout/fail1");
+        url += ";create=true;territory=";
+        testInvalidTerritoryFormat(url);
+        //- database will not have been created so this connection will fail
+        url = TestConfiguration.getCurrent().getJDBCUrl("../extinout/fail1");
+        try {
+            Connection locConn = DriverManager.getConnection(url);
+            fail("Database connect " + url + " should fail because db does not exist");
+        }    catch (SQLException se ) {   
+            assertSQLState("XJ004", se);
+          }
+        //Invalid territory specification
+        testInvalidTerritoryFormat("en_");
+        testInvalidTerritoryFormat("en_d");
+        testInvalidTerritoryFormat("en-US");
+        
+    }
+
+    private void testInvalidTerritoryFormat(String territory) {
+        try {
+            String url = TestConfiguration.getCurrent().getJDBCUrl("../extinout/fail3");
+            url += ";create=true;territory=" + territory;
+            Connection locConn = DriverManager.getConnection(url);
+            fail("connection without territory: " + url + "should have failed");
+        } catch (SQLException se ) {
+          assertSQLState("XJ041", se);
+          assertSQLState("XBM0X", se.getNextException());
+        }
+    }
+    
+    
+    /**
+     * Create procedures to test current territory value
+     * 
+     */
+    private static void createLocaleProcedures(Connection conn) throws SQLException {
+        Statement s = conn.createStatement();
+        s.executeUpdate("create procedure checkDatabaseLoc(in locale " +
+        "char(12)) parameter style java language java external name " +
+                "'org.apache.derbyTesting.functionTests.tests.i18n." +
+                "DefaultLocale.checkDatabaseLocale'");
+        s.executeUpdate("create procedure checkRDefaultLoc() parameter " +
+                    "style java language java external name " +
+                    "'org.apache.derbyTesting.functionTests.tests.i18n." +
+                    "DefaultLocale.checkRDefaultLocale'");
+
+    }
+    
+    public static Test suite() {
+        TestSuite suite = new TestSuite();
+        suite.addTestSuite(UrlLocaleTest.class);
+        Test tsuite =  new CleanDatabaseTestSetup(suite) {
+            /**
+             * Creates the table used in the test cases.
+             *
+             */
+            protected void decorateSQL(Statement s) throws SQLException {
+                createLocaleProcedures(s.getConnection());
+            }
+        };
+        tsuite = new SupportFilesSetup(tsuite);
+        return tsuite;
+    }
+ 
+}
+

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/i18n/UrlLocaleTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/i18n/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/i18n/_Suite.java?rev=1490716&r1=1490715&r2=1490716&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/i18n/_Suite.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/i18n/_Suite.java
Fri Jun  7 16:43:15 2013
@@ -58,6 +58,7 @@ public class _Suite extends BaseTestCase
         suite.addTest(LocalizedDisplayScriptTest.suite());
         suite.addTest(JapanCodeConversionTest.suite());
         suite.addTest(CaseI_tr_TRTest.suite());
+        suite.addTest(UrlLocaleTest.suite());
 
         return suite;
 	}

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DriverTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DriverTest.java?rev=1490716&r1=1490715&r2=1490716&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DriverTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DriverTest.java
Fri Jun  7 16:43:15 2013
@@ -69,6 +69,7 @@ public class DriverTest extends BaseJDBC
         "testcreatedb1", 
         "testcreatedb2",
         "testcreatedb3",
+        "trailblank",
         "'wombat'"
     };
     
@@ -131,7 +132,7 @@ public class DriverTest extends BaseJDBC
         }
 
         TestConfiguration config = TestConfiguration.getCurrent();
-        for (String dbName : ADDITIONAL_DBS) {
+                for (String dbName : ADDITIONAL_DBS) {
             removeDirectory(config.getDatabasePath(dbName));
         }
 
@@ -472,6 +473,22 @@ public class DriverTest extends BaseJDBC
         
         assertConnect(false, url, null);
         shutdownDB(shuturl, null);
+        
+        // Test trailing spaces - Beetle 4653. Moved from urlLocale.sql
+        url = TestConfiguration.getCurrent().getJDBCUrl("trailblank");
+        url += ";create=true";
+        assertConnect(false,url,null);
+        
+        // regular connection with trailing spaces
+        url = TestConfiguration.getCurrent().
+                getJDBCUrl("trailblank     ");
+        assertConnect(true, url, null);
+        
+        // shutdown with trailing spaces
+        url = TestConfiguration.getCurrent().
+                getJDBCUrl("trailblank     ");
+        url += ";shutdown=true";
+        shutdownDB(url,null);
     }
     
     /**



Mime
View raw message