db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From myrn...@apache.org
Subject svn commit: r1097460 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools: ConnectWrongSubprotocolTest.java _Suite.java
Date Thu, 28 Apr 2011 13:51:08 GMT
Author: myrnavl
Date: Thu Apr 28 13:51:08 2011
New Revision: 1097460

URL: http://svn.apache.org/viewvc?rev=1097460&view=rev
Log:
DERBY-5084; convert ijConnName.sql to a ScriptTest junit test
  creating new test for the remaining test case
  patch contributed by Houx Zhang (houxzhang at gmail dot com)

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ConnectWrongSubprotocolTest.java
  (with props)
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/_Suite.java

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ConnectWrongSubprotocolTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ConnectWrongSubprotocolTest.java?rev=1097460&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ConnectWrongSubprotocolTest.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ConnectWrongSubprotocolTest.java
Thu Apr 28 13:51:08 2011
@@ -0,0 +1,85 @@
+package org.apache.derbyTesting.functionTests.tests.tools;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.UnsupportedEncodingException;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Properties;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.Derby;
+import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.SystemPropertyTestSetup;
+import org.apache.derbyTesting.junit.TestConfiguration;
+
+
+public class ConnectWrongSubprotocolTest extends BaseJDBCTestCase {
+
+    public ConnectWrongSubprotocolTest(String name) {
+        super(name);
+    }
+    
+    public static Test suite() {
+        // Test does not run on J2ME
+        if (JDBC.vmSupportsJSR169())
+            return new TestSuite("empty: no support for Driver.sql.Manager with jsr 169");
+        
+        if (!Derby.hasTools())
+            return new TestSuite("empty: no tools support");
+        
+    	Properties props = new Properties();        
+        props.setProperty("ij.connection.wrongSubprotocol", "jdbc:noone:fruitfly;create=true");
+        
+        Test test = TestConfiguration.embeddedSuite(ConnectWrongSubprotocolTest.class);
+        
+    	return new SystemPropertyTestSetup(test, props);
+    }
+    
+    public void testConnectWrongSubprotocolWithSystemProperty()
+    		throws UnsupportedEncodingException, SQLException {
+    	String emptyIjScript = "";
+    	boolean useSystemProperties = true;
+    	
+    	checkConnectWrongSubprotocol(emptyIjScript, useSystemProperties);    	
+    }
+    
+    public void testConnectWrongSubprotoctestolWithoutSystemProperty()
+            throws UnsupportedEncodingException, SQLException {
+        String ijScriptConnectWrongSubprotocol = "connect 'jdbc:noone:fruitfly;create=true';";
+        boolean useSystemProperties = false;
+        
+        checkConnectWrongSubprotocol(ijScriptConnectWrongSubprotocol, useSystemProperties);
+    }
+    
+    private void checkConnectWrongSubprotocol(String ijScript, boolean useSystemProperties)
+            throws UnsupportedEncodingException, SQLException {
+        String ijResult = runIjScript(ijScript, useSystemProperties);       
+                assertTrue(ijResult.indexOf("08001") > -1);
+        assertTrue(ijResult.indexOf("No suitable driver") > -1);        
+    }
+
+    private String runIjScript(String ijScript, boolean useSystemProperties) 
+            throws UnsupportedEncodingException, SQLException {
+        ByteArrayInputStream bais = 
+        		new ByteArrayInputStream(ijScript.getBytes());
+        ByteArrayOutputStream baos = new ByteArrayOutputStream(10 * 1024);
+        Connection conn = getConnection();
+        
+        org.apache.derby.tools.ij.runScript(
+                conn,
+                bais,
+                "US-ASCII",
+                baos,
+                "US-ASCII",
+                useSystemProperties);
+        
+        if (!conn.isClosed() && !conn.getAutoCommit())
+            conn.commit();
+
+        return new String(baos.toByteArray());
+    }
+}

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

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/_Suite.java?rev=1097460&r1=1097459&r2=1097460&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/_Suite.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/_Suite.java
Thu Apr 28 13:51:08 2011
@@ -57,6 +57,7 @@ public class _Suite extends BaseTestCase
         suite.addTest(IjSecurityManagerTest.suite());
         suite.addTest(IjConnNameTest.suite());
         suite.addTest(RollBackWrappingWhenFailOnImportTest.suite());
+        suite.addTest(ConnectWrongSubprotocolTest.suite());
         
         // SysinfoAPITest currently fails when run against jars, so is
         // disabled. Only the first jar file on the classpath properly



Mime
View raw message