Author: shawkins
Date: 2010-06-17 14:35:22 -0400 (Thu, 17 Jun 2010)
New Revision: 2240
Added:
trunk/client/src/test/java/org/teiid/jdbc/TestCallableStatement.java
trunk/client/src/test/java/org/teiid/jdbc/TestConnection.java
trunk/client/src/test/java/org/teiid/jdbc/TestJDBCURL.java
trunk/client/src/test/java/org/teiid/jdbc/TestPreparedStatement.java
trunk/client/src/test/java/org/teiid/jdbc/TestResultSet.java
trunk/client/src/test/java/org/teiid/jdbc/TestSQLException.java
trunk/client/src/test/java/org/teiid/jdbc/TestStatement.java
trunk/client/src/test/java/org/teiid/jdbc/TestXAConnection.java
Removed:
trunk/client/src/test/java/org/teiid/jdbc/TestMMCallableStatement.java
trunk/client/src/test/java/org/teiid/jdbc/TestMMConnection.java
trunk/client/src/test/java/org/teiid/jdbc/TestMMJDBCURL.java
trunk/client/src/test/java/org/teiid/jdbc/TestMMPreparedStatement.java
trunk/client/src/test/java/org/teiid/jdbc/TestMMResultSet.java
trunk/client/src/test/java/org/teiid/jdbc/TestMMSQLException.java
trunk/client/src/test/java/org/teiid/jdbc/TestMMStatement.java
trunk/client/src/test/java/org/teiid/jdbc/TestMMXAConnection.java
trunk/common-core/src/test/java/org/teiid/api/
trunk/common-core/src/test/java/org/teiid/common/
Modified:
trunk/build/kits/jboss-container/teiid-examples/portfolio/customer-schema.sql
trunk/build/kits/jboss-container/teiid-examples/portfolio/data/marketdata-price.txt
trunk/client/src/main/java/org/teiid/jdbc/ResultSetImpl.java
trunk/client/src/test/java/org/teiid/jdbc/TestAllResultsImpl.java
trunk/common-core/src/main/java/org/teiid/core/types/BlobImpl.java
trunk/common-core/src/main/java/org/teiid/core/types/ClobImpl.java
trunk/common-core/src/test/java/org/teiid/core/types/TestBlobValue.java
trunk/common-core/src/test/java/org/teiid/core/types/TestClobValue.java
Log:
TEIID-1021 fix for resultsetimpl regression with the xmltype. fixing an issue with
substream reading with blobs/clobs. Also updating the text example.
Modified: trunk/build/kits/jboss-container/teiid-examples/portfolio/customer-schema.sql
===================================================================
---
trunk/build/kits/jboss-container/teiid-examples/portfolio/customer-schema.sql 2010-06-17
16:09:26 UTC (rev 2239)
+++
trunk/build/kits/jboss-container/teiid-examples/portfolio/customer-schema.sql 2010-06-17
18:35:22 UTC (rev 2240)
@@ -88,9 +88,9 @@
INSERT INTO PRODUCT (ID,SYMBOL,COMPANY_NAME) VALUES(1002,'BA','The Boeing
Company');
INSERT INTO PRODUCT (ID,SYMBOL,COMPANY_NAME) VALUES(1003,'MON','Monsanto
Company');
-INSERT INTO PRODUCT (ID,SYMBOL,COMPANY_NAME) VALUES(1004,'ORCL','Oracle
Corporation');
+INSERT INTO PRODUCT (ID,SYMBOL,COMPANY_NAME) VALUES(1004,'PNRA','Panera Bread
Company');
INSERT INTO PRODUCT (ID,SYMBOL,COMPANY_NAME) VALUES(1005,'SY','Sybase
Incorporated');
-INSERT INTO PRODUCT (ID,SYMBOL,COMPANY_NAME) VALUES(1006,'MSFT','Microsoft
Corporation');
+INSERT INTO PRODUCT (ID,SYMBOL,COMPANY_NAME) VALUES(1006,'BTU','Peabody
Energy');
INSERT INTO PRODUCT (ID,SYMBOL,COMPANY_NAME) VALUES(1007,'IBM','International
Business Machines Corporation');
INSERT INTO PRODUCT (ID,SYMBOL,COMPANY_NAME) VALUES(1008,'DELL','Dell
Computer Corporation');
INSERT INTO PRODUCT (ID,SYMBOL,COMPANY_NAME)
VALUES(1010,'HPQ','Hewlett-Packard Company');
@@ -101,7 +101,6 @@
INSERT INTO PRODUCT (ID,SYMBOL,COMPANY_NAME) VALUES(1015,'MCD','McDonalds
Corporation');
INSERT INTO PRODUCT (ID,SYMBOL,COMPANY_NAME) VALUES(1016,'DOW','Dow Chemical
Company');
INSERT INTO PRODUCT (ID,SYMBOL,COMPANY_NAME) VALUES(1018,'GM','General Motors
Corporation');
-INSERT INTO PRODUCT (ID,SYMBOL,COMPANY_NAME) VALUES(1022,'JAVA','Sun
Microsystems Incorporated');
INSERT INTO PRODUCT (ID,SYMBOL,COMPANY_NAME) VALUES(1024,'SBGI','Sinclair
Broadcast Group Incorporated');
INSERT INTO PRODUCT (ID,SYMBOL,COMPANY_NAME) VALUES(1025,'COLM','Columbia
Sportsware Company');
INSERT INTO PRODUCT (ID,SYMBOL,COMPANY_NAME) VALUES(1026,'COLB','Columbia
Banking System Incorporated');
Modified:
trunk/build/kits/jboss-container/teiid-examples/portfolio/data/marketdata-price.txt
===================================================================
---
trunk/build/kits/jboss-container/teiid-examples/portfolio/data/marketdata-price.txt 2010-06-17
16:09:26 UTC (rev 2239)
+++
trunk/build/kits/jboss-container/teiid-examples/portfolio/data/marketdata-price.txt 2010-06-17
18:35:22 UTC (rev 2240)
@@ -2,9 +2,9 @@
RHT,30.00
BA,42.75
MON,78.75
-ORCL,16.54
+PNRA,84.97
SY,24.30
-MSFT,20.60
+BTU,41.25
IBM,80.89
DELL,10.75
HPQ,31.52
Modified: trunk/client/src/main/java/org/teiid/jdbc/ResultSetImpl.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/ResultSetImpl.java 2010-06-17 16:09:26 UTC
(rev 2239)
+++ trunk/client/src/main/java/org/teiid/jdbc/ResultSetImpl.java 2010-06-17 18:35:22 UTC
(rev 2240)
@@ -286,9 +286,9 @@
// defect 13539 - set the currentValue (defined in MMResultSet) so that wasNull()
accurately returns whether this value was null
currentValue = cursorRow.get(column-1);
- if (currentValue instanceof Streamable) {
+ if (currentValue instanceof Streamable<?>) {
if (Boolean.getBoolean(Streamable.FORCE_STREAMING)) {
- Object reference = ((Streamable)currentValue).getReference();
+ Object reference = ((Streamable<?>)currentValue).getReference();
if (reference != null) {
currentValue = reference;
return currentValue;
@@ -303,8 +303,9 @@
currentValue = new BlobImpl(isf);
}
else if (currentValue instanceof XMLType) {
- currentValue = new
SQLXMLImpl(createInputStreamFactory((XMLType)currentValue));
-
((SQLXMLImpl)currentValue).setEncoding(((XMLType)currentValue).getEncoding());
+ XMLType val = (XMLType)currentValue;
+ currentValue = new SQLXMLImpl(createInputStreamFactory(val));
+ ((SQLXMLImpl)currentValue).setEncoding(val.getEncoding());
}
}
else if (currentValue instanceof java.util.Date) {
Modified: trunk/client/src/test/java/org/teiid/jdbc/TestAllResultsImpl.java
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/TestAllResultsImpl.java 2010-06-17 16:09:26
UTC (rev 2239)
+++ trunk/client/src/test/java/org/teiid/jdbc/TestAllResultsImpl.java 2010-06-17 18:35:22
UTC (rev 2240)
@@ -62,7 +62,7 @@
private StatementImpl statement;
@Before public void setUp() throws Exception {
- statement = TestMMResultSet.createMockStatement(TYPE_SCROLL_SENSITIVE);
+ statement = TestResultSet.createMockStatement(TYPE_SCROLL_SENSITIVE);
}
/** test hasNext(), actual result set should return FALSE. */
@@ -766,14 +766,14 @@
private ResultSetImpl helpGetResultSetImpl(int type)
throws SQLException {
ResultsMessage rsMsg = exampleResultsMsg2();
- statement = TestMMResultSet.createMockStatement(type);
+ statement = TestResultSet.createMockStatement(type);
ResultSetImpl rs = new ResultSetImpl(rsMsg, statement);
return rs;
}
private ResultSetImpl helpGetNoResults(int type) throws SQLException {
ResultsMessage rsMsg = exampleResultsMsg3();
- statement = TestMMResultSet.createMockStatement(type);
+ statement = TestResultSet.createMockStatement(type);
ResultSetImpl rs = new ResultSetImpl(rsMsg, statement);
return rs;
}
Copied: trunk/client/src/test/java/org/teiid/jdbc/TestCallableStatement.java (from rev
2238, trunk/client/src/test/java/org/teiid/jdbc/TestMMCallableStatement.java)
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/TestCallableStatement.java
(rev 0)
+++ trunk/client/src/test/java/org/teiid/jdbc/TestCallableStatement.java 2010-06-17
18:35:22 UTC (rev 2240)
@@ -0,0 +1,109 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright (C) 2008 Red Hat, Inc.
+ * Licensed to Red Hat, Inc. under one or more contributor
+ * license agreements. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.jdbc;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.mockito.Mockito;
+import org.teiid.client.RequestMessage;
+import org.teiid.client.ResultsMessage;
+import org.teiid.client.metadata.ParameterInfo;
+import org.teiid.client.security.LogonResult;
+import org.teiid.core.types.JDBCSQLTypeInfo;
+import org.teiid.jdbc.CallableStatementImpl;
+import org.teiid.jdbc.ConnectionImpl;
+import org.teiid.jdbc.ResultSetImpl;
+import org.teiid.net.ServerConnection;
+
+
+public class TestCallableStatement extends TestCase {
+
+ public void testWasNull() throws Exception {
+ CallableStatementImpl mmcs = getCallableStatement();
+
+ Map<Integer, Integer> params = new HashMap<Integer, Integer>();
+ mmcs.outParamIndexMap = params;
+ params.put(Integer.valueOf(1), Integer.valueOf(1));
+ params.put(Integer.valueOf(2), Integer.valueOf(2));
+ ResultSetImpl rs = Mockito.mock(ResultSetImpl.class);
+ mmcs.resultSet = rs;
+ Mockito.stub(rs.getOutputParamValue(1)).toReturn(null);
+ Mockito.stub(rs.getOutputParamValue(2)).toReturn(Boolean.TRUE);
+ mmcs.getBoolean(1);
+ assertTrue(mmcs.wasNull());
+ assertTrue(mmcs.getBoolean(2));
+ assertFalse(mmcs.wasNull());
+ }
+
+ public void testGetOutputParameter() throws Exception {
+ CallableStatementImpl mmcs = getCallableStatement();
+
+ RequestMessage request = new RequestMessage();
+ request.setExecutionId(1);
+ ResultsMessage resultsMsg = new ResultsMessage(request);
+ List[] results = new List[] {Arrays.asList(null, null, null), Arrays.asList(null, 1,
2)};
+ resultsMsg.setResults(results);
+ resultsMsg.setColumnNames(new String[] { "IntNum", "Out1",
"Out2" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ resultsMsg.setDataTypes(new String[] { JDBCSQLTypeInfo.INTEGER,
JDBCSQLTypeInfo.INTEGER, JDBCSQLTypeInfo.INTEGER });
+ resultsMsg.setFinalRow(results.length);
+ resultsMsg.setLastRow(results.length);
+ resultsMsg.setFirstRow(1);
+ resultsMsg.setParameters(Arrays.asList(new ParameterInfo(ParameterInfo.RESULT_SET, 1),
new ParameterInfo(ParameterInfo.OUT, 1), new ParameterInfo(ParameterInfo.OUT, 1)));
+ mmcs.createResultSet(resultsMsg);
+ assertEquals(1, mmcs.getInt(1));
+ assertEquals(2, mmcs.getInt(2));
+ }
+
+ public void testUnknownIndex() throws Exception {
+ CallableStatementImpl mmcs = getCallableStatement();
+
+ mmcs.outParamIndexMap = new HashMap<Integer, Integer>();
+
+ try {
+ mmcs.getBoolean(0);
+ fail("expected exception"); //$NON-NLS-1$
+ } catch (IllegalArgumentException e) {
+ assertEquals("Parameter is not found at index 0.", e.getMessage());
+ }
+ }
+
+ private CallableStatementImpl getCallableStatement() throws SQLException {
+ ConnectionImpl conn = Mockito.mock(ConnectionImpl.class);
+ ServerConnection sc = Mockito.mock(ServerConnection.class);
+
+ Mockito.stub(sc.getLogonResult()).toReturn(new LogonResult());
+ Mockito.stub(conn.getServerConnection()).toReturn(sc);
+
+ CallableStatementImpl mmcs = new CallableStatementImpl(conn, "{?=call x(?)}",
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
+ return mmcs;
+ }
+
+}
Property changes on: trunk/client/src/test/java/org/teiid/jdbc/TestCallableStatement.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied: trunk/client/src/test/java/org/teiid/jdbc/TestConnection.java (from rev 2238,
trunk/client/src/test/java/org/teiid/jdbc/TestMMConnection.java)
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/TestConnection.java
(rev 0)
+++ trunk/client/src/test/java/org/teiid/jdbc/TestConnection.java 2010-06-17 18:35:22 UTC
(rev 2240)
@@ -0,0 +1,132 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.jdbc;
+
+import static org.mockito.Mockito.*;
+
+import java.sql.SQLException;
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.teiid.client.DQP;
+import org.teiid.client.security.LogonResult;
+import org.teiid.client.security.SessionToken;
+import org.teiid.client.util.ResultsFuture;
+import org.teiid.client.xa.XATransactionException;
+import org.teiid.client.xa.XidImpl;
+import org.teiid.jdbc.BaseDataSource;
+import org.teiid.jdbc.ConnectionImpl;
+import org.teiid.net.ServerConnection;
+
+
+public class TestConnection extends TestCase {
+
+ protected static final String STD_DATABASE_NAME = "QT_Ora9DS";
//$NON-NLS-1$
+ protected static final int STD_DATABASE_VERSION = 1;
+
+ static String serverUrl =
"jdbc:metamatrix:QT_Ora9DS@mm://localhost:7001;version=1;user=metamatrixadmin;password=mm";
//$NON-NLS-1$
+
+ public TestConnection(String name) {
+ super(name);
+ }
+
+ public static ConnectionImpl getMMConnection() {
+ ServerConnection mock = mock(ServerConnection.class);
+ DQP dqp = mock(DQP.class);
+ try {
+ stub(dqp.start((XidImpl)Mockito.anyObject(), Mockito.anyInt(),
Mockito.anyInt())).toAnswer(new Answer() {
+ @Override
+ public Object answer(InvocationOnMock invocation) throws Throwable {
+ return ResultsFuture.NULL_FUTURE;
+ }
+ });
+ stub(dqp.rollback((XidImpl)Mockito.anyObject())).toAnswer(new Answer() {
+ @Override
+ public Object answer(InvocationOnMock invocation) throws Throwable {
+ return ResultsFuture.NULL_FUTURE;
+ }
+ });
+ stub(dqp.rollback()).toAnswer(new Answer() {
+ @Override
+ public Object answer(InvocationOnMock invocation) throws Throwable {
+ return ResultsFuture.NULL_FUTURE;
+ }
+ });
+ } catch (XATransactionException e) {
+ throw new RuntimeException(e);
+ }
+ stub(mock.getService(DQP.class)).toReturn(dqp);
+ Properties props = new Properties();
+ props.setProperty(BaseDataSource.VDB_NAME, STD_DATABASE_NAME);
+ props.setProperty(BaseDataSource.VDB_VERSION,
String.valueOf(STD_DATABASE_VERSION));
+ props.setProperty(BaseDataSource.USER_NAME, "metamatrixadmin");
//$NON-NLS-1$
+ stub(mock.getLogonResult()).toReturn(new LogonResult(new SessionToken(1,
"metamatrixadmin"), STD_DATABASE_NAME,STD_DATABASE_VERSION , "fake"));
//$NON-NLS-1$
+ return new ConnectionImpl(mock, props, serverUrl);
+ }
+
+ public void testGetMetaData() throws Exception {
+ assertNotNull(getMMConnection().getMetaData());
+ }
+
+ public void testGetSchema() throws Exception {
+ assertEquals("Actual schema is not equql to the expected one. ",
STD_DATABASE_NAME, getMMConnection().getVDBName()); //$NON-NLS-1$
+ }
+
+ public void testNativeSql() throws Exception {
+ String sql = "SELECT * FROM BQT1.SmallA"; //$NON-NLS-1$
+ assertEquals("Actual schema is not equql to the expected one. ", sql,
getMMConnection().nativeSQL(sql)); //$NON-NLS-1$
+ }
+
+ /** test getUserName() through DriverManager */
+ public void testGetUserName2() throws Exception {
+ assertEquals("Actual userName is not equal to the expected one. ",
"metamatrixadmin", getMMConnection().getUserName()); //$NON-NLS-1$
//$NON-NLS-2$
+ }
+
+ /** test isReadOnly default value on Connection */
+ public void testIsReadOnly() throws Exception {
+ assertEquals(false, getMMConnection().isReadOnly());
+ }
+
+ /** test setReadOnly on Connection */
+ public void testSetReadOnly1() throws Exception {
+ ConnectionImpl conn = getMMConnection();
+ conn.setReadOnly(true);
+ assertEquals(true, conn.isReadOnly());
+ }
+
+ /** test setReadOnly on Connection during a transaction */
+ public void testSetReadOnly2() throws Exception {
+ ConnectionImpl conn = getMMConnection();
+ conn.setAutoCommit(false);
+ try {
+ conn.setReadOnly(true);
+ fail("Error Expected"); //$NON-NLS-1$
+ } catch (SQLException e) {
+ // error expected
+ }
+ }
+}
Copied: trunk/client/src/test/java/org/teiid/jdbc/TestJDBCURL.java (from rev 2238,
trunk/client/src/test/java/org/teiid/jdbc/TestMMJDBCURL.java)
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/TestJDBCURL.java
(rev 0)
+++ trunk/client/src/test/java/org/teiid/jdbc/TestJDBCURL.java 2010-06-17 18:35:22 UTC
(rev 2240)
@@ -0,0 +1,342 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.jdbc;
+
+import java.net.URLEncoder;
+import java.util.Properties;
+
+import org.teiid.jdbc.BaseDataSource;
+import org.teiid.jdbc.ExecutionProperties;
+import org.teiid.jdbc.JDBCURL;
+import org.teiid.net.TeiidURL;
+
+import junit.framework.TestCase;
+
+
+
+/**
+ * @since 4.3
+ */
+public class TestJDBCURL extends TestCase {
+
+ // Need to allow embedded spaces and ='s within optional properties
+ public final void testCredentials() throws Exception {
+ String credentials = URLEncoder.encode("defaultToLogon,(system=BQT1 SQL
Server 2000 Simple Cap,user=xyz,password=xyz)", "UTF-8"); //$NON-NLS-1$
//$NON-NLS-2$
+ JDBCURL url = new
JDBCURL("jdbc:metamatrix:QT_sqls2kds@mm://slwxp136:43100;credentials="+credentials);
//$NON-NLS-1$
+ Properties p = url.getProperties();
+ assertEquals("defaultToLogon,(system=BQT1 SQL Server 2000 Simple
Cap,user=xyz,password=xyz)", p.getProperty("credentials"));
//$NON-NLS-1$//$NON-NLS-2$
+ }
+
+ public void testJDBCURLWithProperties() {
+ String URL =
"jdbc:metamatrix:bqt@mm://localhost:12345;version=1;user=xyz;password=***;logLevel=1;configFile=testdata/bqt/dqp_stmt_e2e.xmi;disableLocalTxn=true;autoFailover=false";
//$NON-NLS-1$
+
+ Properties expectedProperties = new Properties();
+ expectedProperties.setProperty("version", "1"); //$NON-NLS-1$
//$NON-NLS-2$
+ expectedProperties.setProperty("user", "xyz"); //$NON-NLS-1$
//$NON-NLS-2$
+ expectedProperties.setProperty("password", "***");
//$NON-NLS-1$ //$NON-NLS-2$
+ expectedProperties.setProperty("logLevel", "1");
//$NON-NLS-1$ //$NON-NLS-2$
+ expectedProperties.setProperty("configFile",
"testdata/bqt/dqp_stmt_e2e.xmi"); //$NON-NLS-1$ //$NON-NLS-2$
+ expectedProperties.setProperty(ExecutionProperties.DISABLE_LOCAL_TRANSACTIONS,
"true"); //$NON-NLS-1$
+ expectedProperties.setProperty(TeiidURL.CONNECTION.AUTO_FAILOVER,
"false"); //$NON-NLS-1$
+ JDBCURL url = new JDBCURL(URL);
+ assertEquals("bqt", url.getVDBName()); //$NON-NLS-1$
+ assertEquals("mm://localhost:12345", url.getConnectionURL());
//$NON-NLS-1$
+ assertEquals(expectedProperties, url.getProperties());
+ }
+
+ public void testJDBCURLWithoutProperties() {
+ String URL = "jdbc:metamatrix:bqt@mm://localhost:12345"; //$NON-NLS-1$
+
+ JDBCURL url = new JDBCURL(URL);
+ assertEquals("bqt", url.getVDBName()); //$NON-NLS-1$
+ assertEquals("mm://localhost:12345", url.getConnectionURL());
//$NON-NLS-1$
+ assertEquals(new Properties(), url.getProperties());
+ }
+
+ public void testCaseConversion() {
+ // Different case ------------------------------------HERE -v
----------------and HERE -v
+ String URL =
"jdbc:metamatrix:bqt@mm://localhost:12345;VERSION=1;user=xyz;password=***;configFile=testdata/bqt/dqp_stmt_e2e.xmi";
//$NON-NLS-1$
+
+ Properties expectedProperties = new Properties();
+ expectedProperties.setProperty("version", "1"); //$NON-NLS-1$
//$NON-NLS-2$
+ expectedProperties.setProperty("user", "xyz"); //$NON-NLS-1$
//$NON-NLS-2$
+ expectedProperties.setProperty("password", "***");
//$NON-NLS-1$ //$NON-NLS-2$
+ expectedProperties.setProperty("configFile",
"testdata/bqt/dqp_stmt_e2e.xmi"); //$NON-NLS-1$ //$NON-NLS-2$
+ JDBCURL url = new JDBCURL(URL);
+ assertEquals("bqt", url.getVDBName()); //$NON-NLS-1$
+ assertEquals("mm://localhost:12345", url.getConnectionURL());
//$NON-NLS-1$
+ assertEquals(expectedProperties, url.getProperties());
+ }
+
+ public void testWithExtraSemicolons() {
+ String URL =
"jdbc:metamatrix:bqt@mm://localhost:12345;version=1;user=xyz;password=***;logLevel=1;;;configFile=testdata/bqt/dqp_stmt_e2e.xmi;;";
//$NON-NLS-1$
+
+ Properties expectedProperties = new Properties();
+ expectedProperties.setProperty("version", "1"); //$NON-NLS-1$
//$NON-NLS-2$
+ expectedProperties.setProperty("user", "xyz"); //$NON-NLS-1$
//$NON-NLS-2$
+ expectedProperties.setProperty("password", "***");
//$NON-NLS-1$ //$NON-NLS-2$
+ expectedProperties.setProperty("logLevel", "1");
//$NON-NLS-1$ //$NON-NLS-2$
+ expectedProperties.setProperty("configFile",
"testdata/bqt/dqp_stmt_e2e.xmi"); //$NON-NLS-1$ //$NON-NLS-2$
+ JDBCURL url = new JDBCURL(URL);
+ assertEquals("bqt", url.getVDBName()); //$NON-NLS-1$
+ assertEquals("mm://localhost:12345", url.getConnectionURL());
//$NON-NLS-1$
+ assertEquals(expectedProperties, url.getProperties());
+ }
+
+ public void testWithWhitespace() {
+ String URL = "jdbc:metamatrix:bqt@mm://localhost:12345; version =1;user= xyz
;password=***; logLevel = 1 ; configFile=testdata/bqt/dqp_stmt_e2e.xmi ;";
//$NON-NLS-1$
+
+ Properties expectedProperties = new Properties();
+ expectedProperties.setProperty("version", "1"); //$NON-NLS-1$
//$NON-NLS-2$
+ expectedProperties.setProperty("user", "xyz"); //$NON-NLS-1$
//$NON-NLS-2$
+ expectedProperties.setProperty("password", "***");
//$NON-NLS-1$ //$NON-NLS-2$
+ expectedProperties.setProperty("logLevel", "1");
//$NON-NLS-1$ //$NON-NLS-2$
+ expectedProperties.setProperty("configFile",
"testdata/bqt/dqp_stmt_e2e.xmi"); //$NON-NLS-1$ //$NON-NLS-2$
+ JDBCURL url = new JDBCURL(URL);
+ assertEquals("bqt", url.getVDBName()); //$NON-NLS-1$
+ assertEquals("mm://localhost:12345", url.getConnectionURL());
//$NON-NLS-1$
+ assertEquals(expectedProperties, url.getProperties());
+ }
+
+ public void testNoPropertyValue() {
+ String URL =
"jdbc:metamatrix:bqt@mm://localhost:12345;version=1;user=xyz;password=***;logLevel=;configFile=";
//$NON-NLS-1$
+
+ Properties expectedProperties = new Properties();
+ expectedProperties.setProperty("version", "1"); //$NON-NLS-1$
//$NON-NLS-2$
+ expectedProperties.setProperty("user", "xyz"); //$NON-NLS-1$
//$NON-NLS-2$
+ expectedProperties.setProperty("password", "***");
//$NON-NLS-1$ //$NON-NLS-2$
+ expectedProperties.setProperty("logLevel", ""); //$NON-NLS-1$
//$NON-NLS-2$
+ expectedProperties.setProperty("configFile", "");
//$NON-NLS-1$ //$NON-NLS-2$
+ JDBCURL url = new JDBCURL(URL);
+ assertEquals("bqt", url.getVDBName()); //$NON-NLS-1$
+ assertEquals("mm://localhost:12345", url.getConnectionURL());
//$NON-NLS-1$
+ assertEquals(expectedProperties, url.getProperties());
+ }
+
+ public void testInvalidProtocol() {
+ String URL =
"jdbc:monkeymatrix:bqt@mm://localhost:12345;version=1;user=xyz;password=***;logLevel=1";
//$NON-NLS-1$
+ try {
+ new JDBCURL(URL);
+ fail("Illegal argument should have failed."); //$NON-NLS-1$
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ public void testNoVDBName() {
+ String URL =
"jdbc:metamatrix:@mm://localhost:12345;version=1;user=xyz;password=***;logLevel=1";
//$NON-NLS-1$
+ try {
+ new JDBCURL(URL);
+ fail("Illegal argument should have failed."); //$NON-NLS-1$
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ public void testNoAtSignInURL() {
+ String URL =
"jdbc:metamatrix:bqt!mm://localhost:12345;version=1;user=xyz;password=***;logLevel=1";
//$NON-NLS-1$
+ try {
+ new JDBCURL(URL);
+ // No @ sign is llowed as part of embedded driver now,
+ // but this form of URL rejected in the acceptURL
+ //fail("Illegal argument should have failed.");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ public void testMoreThanOneAtSign() {
+ String URL =
"jdbc:metamatrix:bqt@mm://localhost:12345;version=1;user=xy@;password=***;logLevel=1";
//$NON-NLS-1$
+ try {
+ // this allowed as customer properties can have @ in their properties
+ new JDBCURL(URL);
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ public void testNoEqualsInProperty() {
+ String URL =
"jdbc:metamatrix:bqt@mm://localhost:12345;version=1;user=xyz;password***;logLevel=1";
//$NON-NLS-1$
+ try {
+ new JDBCURL(URL);
+ fail("Illegal argument should have failed."); //$NON-NLS-1$
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ public void testMoreThanOneEqualsInProperty() {
+ String URL =
"jdbc:metamatrix:bqt@mm://localhost:12345;version=1;user=xyz;password==***;logLevel=1";
//$NON-NLS-1$
+ try {
+ new JDBCURL(URL);
+ fail("Illegal argument should have failed."); //$NON-NLS-1$
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ URL =
"jdbc:metamatrix:bqt@mm://localhost:12345;version=1;user=xyz;password=***=;logLevel=1";
//$NON-NLS-1$
+ try {
+ new JDBCURL(URL);
+ fail("Illegal argument should have failed."); //$NON-NLS-1$
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ URL =
"jdbc:metamatrix:bqt@mm://localhost:12345;version=1;user=xyz;=password=***;logLevel=1";
//$NON-NLS-1$
+ try {
+ new JDBCURL(URL);
+ fail("Illegal argument should have failed."); //$NON-NLS-1$
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ public void testNoKeyInProperty() {
+ String URL =
"jdbc:metamatrix:bqt@mm://localhost:12345;version=1;user=xyz;=***;logLevel=1";
//$NON-NLS-1$
+ try {
+ new JDBCURL(URL);
+ fail("Illegal argument should have failed."); //$NON-NLS-1$
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ public void testConstructor() {
+ JDBCURL url = new JDBCURL("myVDB", "mm://myhost:12345",null);
//$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("jdbc:teiid:myVDB@mm://myhost:12345", url.getJDBCURL());
//$NON-NLS-1$
+
+ Properties props = new Properties();
+ props.setProperty(BaseDataSource.USER_NAME, "myuser"); //$NON-NLS-1$
+ props.setProperty(BaseDataSource.PASSWORD, "mypassword");
//$NON-NLS-1$
+ props.put("ClieNTtOKeN", new Integer(1)); //$NON-NLS-1$
+ url = new JDBCURL("myVDB", "mm://myhost:12345", props);
//$NON-NLS-1$ //$NON-NLS-2$
+
assertEquals("jdbc:teiid:myVDB@mm://myhost:12345;user=myuser;password=mypassword",
url.getJDBCURL()); //$NON-NLS-1$
+ }
+
+ public void testConstructor_Exception() {
+ try {
+ new JDBCURL(null, "myhost", null); //$NON-NLS-1$
+ fail("Should have failed."); //$NON-NLS-1$
+ } catch (Exception e) {
+
+ }
+ try {
+ new JDBCURL(" ", "myhost", null); //$NON-NLS-1$
//$NON-NLS-2$
+ fail("Should have failed."); //$NON-NLS-1$
+ } catch (Exception e) {
+
+ }
+
+ try {
+ // in embedded situation there is no connection url
+ new JDBCURL("myVDB", " ", null); //$NON-NLS-1$
//$NON-NLS-2$
+ } catch (Exception e) {
+
+ }
+ }
+
+ public void testNormalize() {
+ Properties props = new Properties();
+ props.setProperty("UsEr", "myuser"); //$NON-NLS-1$
//$NON-NLS-2$
+ props.setProperty("pAssWOrD", "mypassword"); //$NON-NLS-1$
//$NON-NLS-2$
+ props.put("ClieNTtOKeN", new Integer(1)); //$NON-NLS-1$
+ JDBCURL.normalizeProperties(props);
+ assertEquals("myuser", props.getProperty(BaseDataSource.USER_NAME));
//$NON-NLS-1$
+ assertEquals("mypassword", props.getProperty(BaseDataSource.PASSWORD));
//$NON-NLS-1$
+ }
+
+ public final void testEncodedPropertyProperties() throws Exception {
+ String password =
"=@#^&*()+!%$^%@#_-)_~{}||\\`':;,./<>?password has = & %";
//$NON-NLS-1$
+ Properties props = new Properties();
+ props.setProperty("UsEr", "foo"); //$NON-NLS-1$
//$NON-NLS-2$
+ props.setProperty("PASswoRd", password); //$NON-NLS-1$
+ JDBCURL.normalizeProperties(props);
+
+ assertEquals(password, props.getProperty("password")); //$NON-NLS-1$
+ assertEquals("foo", props.getProperty("user"));
//$NON-NLS-1$//$NON-NLS-2$
+ }
+
+ public final void testEncodedPropertyInURL() throws Exception {
+ String password =
"=@#^&*()+!%$^%@#_-)_~{}||\\`':;,./<>?password has = & %";
//$NON-NLS-1$
+ String encPassword = URLEncoder.encode(password, "UTF-8");
//$NON-NLS-1$
+ JDBCURL url = new
JDBCURL("jdbc:metamatrix:QT_sqls2kds@mm://slwxp136:43100;PASswoRd="+encPassword);
//$NON-NLS-1$
+ Properties p = url.getProperties();
+ assertEquals(password, p.getProperty("password")); //$NON-NLS-1$
+ }
+
+
+ public void testGetServerURL_NoProperties() {
+ String result = new
JDBCURL("jdbc:metamatrix:designtimecatalog@mm://slwxp172:44401;user=ddifranco;password=mm").getConnectionURL();
//$NON-NLS-1$
+ assertEquals("mm://slwxp172:44401", result); //$NON-NLS-1$
+ }
+
+ public void testGetServerURL_Properties() {
+ String result = new
JDBCURL("jdbc:metamatrix:designtimecatalog@mm://slwxp172:44401;user=ddifranco;password=mm").getConnectionURL();
//$NON-NLS-1$
+ assertEquals("mm://slwxp172:44401", result); //$NON-NLS-1$
+ }
+
+ /**
+ * Test getServerURL with a valid URL and password that contains at least
+ * one ASCII character in the range of 32 to 126 excluding the ; and = sign.
+ *
+ * @since 5.0.2
+ */
+ public void testGetServerURL_PasswordProperties() throws Exception {
+ String result = null;
+ String srcURL =
"jdbc:metamatrix:designtimecatalog@mm://slwxp172:44401;user=ddifranco;password=";
//$NON-NLS-1$
+ String password = null;
+ String tgtURL = "mm://slwxp172:44401"; //$NON-NLS-1$
+
+
+ for ( char ch = 32; ch <= 126; ch++ ) {
+ //exclude URL reserved characters
+ if ( ch != ';' && ch != '=' && ch !=
'%') {
+ password = ch+"mm"; //$NON-NLS-1$
+ result = new JDBCURL(srcURL+URLEncoder.encode(password,
"UTF-8")).getConnectionURL(); //$NON-NLS-1$
+ assertEquals("Failed to obtain correct ServerURL when using password
"+password,tgtURL, result); //$NON-NLS-1$
+ }
+ }
+
+ }
+
+ public void testGetServerURL_2Servers() {
+ String result = new
JDBCURL("jdbc:metamatrix:designtimecatalog@mm://slwxp172:44401,slabc123:12345;user=ddifranco;password=mm").getConnectionURL();
//$NON-NLS-1$
+ assertEquals("mm://slwxp172:44401,slabc123:12345", result);
//$NON-NLS-1$
+ }
+
+ public void testBuildEmbeedURL() {
+ JDBCURL url = new JDBCURL("vdb", "/home/foo/deploy.properties",
new Properties()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("jdbc:teiid:vdb@/home/foo/deploy.properties",
url.getJDBCURL()); //$NON-NLS-1$
+
+ Properties p = new Properties();
+ p.setProperty("user", "test"); //$NON-NLS-1$ //$NON-NLS-2$
+ p.setProperty("password", "pass"); //$NON-NLS-1$ //$NON-NLS-2$
+ p.setProperty("autoFailover", "true"); //$NON-NLS-1$
//$NON-NLS-2$
+ p.setProperty("any", "thing"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ url = new JDBCURL("vdb", "/home/foo/deploy.properties", p);
//$NON-NLS-1$ //$NON-NLS-2$
+
assertTrue(url.getJDBCURL().startsWith("jdbc:teiid:vdb@/home/foo/deploy.properties;user=test;"));
//$NON-NLS-1$
+ assertTrue(url.getJDBCURL().indexOf("any=thing")!=-1); //$NON-NLS-1$
+ assertTrue(url.getJDBCURL().indexOf("password=pass")!=-1); //$NON-NLS-1$
+ assertTrue(url.getJDBCURL().indexOf("autoFailover=true")!=-1);
//$NON-NLS-1$
+
+ }
+}
Deleted: trunk/client/src/test/java/org/teiid/jdbc/TestMMCallableStatement.java
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/TestMMCallableStatement.java 2010-06-17
16:09:26 UTC (rev 2239)
+++ trunk/client/src/test/java/org/teiid/jdbc/TestMMCallableStatement.java 2010-06-17
18:35:22 UTC (rev 2240)
@@ -1,109 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright (C) 2008 Red Hat, Inc.
- * Licensed to Red Hat, Inc. under one or more contributor
- * license agreements. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.jdbc;
-
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-import org.mockito.Mockito;
-import org.teiid.client.RequestMessage;
-import org.teiid.client.ResultsMessage;
-import org.teiid.client.metadata.ParameterInfo;
-import org.teiid.client.security.LogonResult;
-import org.teiid.core.types.JDBCSQLTypeInfo;
-import org.teiid.jdbc.CallableStatementImpl;
-import org.teiid.jdbc.ConnectionImpl;
-import org.teiid.jdbc.ResultSetImpl;
-import org.teiid.net.ServerConnection;
-
-
-public class TestMMCallableStatement extends TestCase {
-
- public void testWasNull() throws Exception {
- CallableStatementImpl mmcs = getCallableStatement();
-
- Map<Integer, Integer> params = new HashMap<Integer, Integer>();
- mmcs.outParamIndexMap = params;
- params.put(Integer.valueOf(1), Integer.valueOf(1));
- params.put(Integer.valueOf(2), Integer.valueOf(2));
- ResultSetImpl rs = Mockito.mock(ResultSetImpl.class);
- mmcs.resultSet = rs;
- Mockito.stub(rs.getOutputParamValue(1)).toReturn(null);
- Mockito.stub(rs.getOutputParamValue(2)).toReturn(Boolean.TRUE);
- mmcs.getBoolean(1);
- assertTrue(mmcs.wasNull());
- assertTrue(mmcs.getBoolean(2));
- assertFalse(mmcs.wasNull());
- }
-
- public void testGetOutputParameter() throws Exception {
- CallableStatementImpl mmcs = getCallableStatement();
-
- RequestMessage request = new RequestMessage();
- request.setExecutionId(1);
- ResultsMessage resultsMsg = new ResultsMessage(request);
- List[] results = new List[] {Arrays.asList(null, null, null), Arrays.asList(null, 1,
2)};
- resultsMsg.setResults(results);
- resultsMsg.setColumnNames(new String[] { "IntNum", "Out1",
"Out2" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- resultsMsg.setDataTypes(new String[] { JDBCSQLTypeInfo.INTEGER,
JDBCSQLTypeInfo.INTEGER, JDBCSQLTypeInfo.INTEGER });
- resultsMsg.setFinalRow(results.length);
- resultsMsg.setLastRow(results.length);
- resultsMsg.setFirstRow(1);
- resultsMsg.setParameters(Arrays.asList(new ParameterInfo(ParameterInfo.RESULT_SET, 1),
new ParameterInfo(ParameterInfo.OUT, 1), new ParameterInfo(ParameterInfo.OUT, 1)));
- mmcs.createResultSet(resultsMsg);
- assertEquals(1, mmcs.getInt(1));
- assertEquals(2, mmcs.getInt(2));
- }
-
- public void testUnknownIndex() throws Exception {
- CallableStatementImpl mmcs = getCallableStatement();
-
- mmcs.outParamIndexMap = new HashMap<Integer, Integer>();
-
- try {
- mmcs.getBoolean(0);
- fail("expected exception"); //$NON-NLS-1$
- } catch (IllegalArgumentException e) {
- assertEquals("Parameter is not found at index 0.", e.getMessage());
- }
- }
-
- private CallableStatementImpl getCallableStatement() throws SQLException {
- ConnectionImpl conn = Mockito.mock(ConnectionImpl.class);
- ServerConnection sc = Mockito.mock(ServerConnection.class);
-
- Mockito.stub(sc.getLogonResult()).toReturn(new LogonResult());
- Mockito.stub(conn.getServerConnection()).toReturn(sc);
-
- CallableStatementImpl mmcs = new CallableStatementImpl(conn, "{?=call x(?)}",
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
- return mmcs;
- }
-
-}
Deleted: trunk/client/src/test/java/org/teiid/jdbc/TestMMConnection.java
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/TestMMConnection.java 2010-06-17 16:09:26
UTC (rev 2239)
+++ trunk/client/src/test/java/org/teiid/jdbc/TestMMConnection.java 2010-06-17 18:35:22
UTC (rev 2240)
@@ -1,132 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.jdbc;
-
-import static org.mockito.Mockito.*;
-
-import java.sql.SQLException;
-import java.util.Properties;
-
-import junit.framework.TestCase;
-
-import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-import org.teiid.client.DQP;
-import org.teiid.client.security.LogonResult;
-import org.teiid.client.security.SessionToken;
-import org.teiid.client.util.ResultsFuture;
-import org.teiid.client.xa.XATransactionException;
-import org.teiid.client.xa.XidImpl;
-import org.teiid.jdbc.BaseDataSource;
-import org.teiid.jdbc.ConnectionImpl;
-import org.teiid.net.ServerConnection;
-
-
-public class TestMMConnection extends TestCase {
-
- protected static final String STD_DATABASE_NAME = "QT_Ora9DS";
//$NON-NLS-1$
- protected static final int STD_DATABASE_VERSION = 1;
-
- static String serverUrl =
"jdbc:metamatrix:QT_Ora9DS@mm://localhost:7001;version=1;user=metamatrixadmin;password=mm";
//$NON-NLS-1$
-
- public TestMMConnection(String name) {
- super(name);
- }
-
- public static ConnectionImpl getMMConnection() {
- ServerConnection mock = mock(ServerConnection.class);
- DQP dqp = mock(DQP.class);
- try {
- stub(dqp.start((XidImpl)Mockito.anyObject(), Mockito.anyInt(),
Mockito.anyInt())).toAnswer(new Answer() {
- @Override
- public Object answer(InvocationOnMock invocation) throws Throwable {
- return ResultsFuture.NULL_FUTURE;
- }
- });
- stub(dqp.rollback((XidImpl)Mockito.anyObject())).toAnswer(new Answer() {
- @Override
- public Object answer(InvocationOnMock invocation) throws Throwable {
- return ResultsFuture.NULL_FUTURE;
- }
- });
- stub(dqp.rollback()).toAnswer(new Answer() {
- @Override
- public Object answer(InvocationOnMock invocation) throws Throwable {
- return ResultsFuture.NULL_FUTURE;
- }
- });
- } catch (XATransactionException e) {
- throw new RuntimeException(e);
- }
- stub(mock.getService(DQP.class)).toReturn(dqp);
- Properties props = new Properties();
- props.setProperty(BaseDataSource.VDB_NAME, STD_DATABASE_NAME);
- props.setProperty(BaseDataSource.VDB_VERSION,
String.valueOf(STD_DATABASE_VERSION));
- props.setProperty(BaseDataSource.USER_NAME, "metamatrixadmin");
//$NON-NLS-1$
- stub(mock.getLogonResult()).toReturn(new LogonResult(new SessionToken(1,
"metamatrixadmin"), STD_DATABASE_NAME,STD_DATABASE_VERSION , "fake"));
//$NON-NLS-1$
- return new ConnectionImpl(mock, props, serverUrl);
- }
-
- public void testGetMetaData() throws Exception {
- assertNotNull(getMMConnection().getMetaData());
- }
-
- public void testGetSchema() throws Exception {
- assertEquals("Actual schema is not equql to the expected one. ",
STD_DATABASE_NAME, getMMConnection().getVDBName()); //$NON-NLS-1$
- }
-
- public void testNativeSql() throws Exception {
- String sql = "SELECT * FROM BQT1.SmallA"; //$NON-NLS-1$
- assertEquals("Actual schema is not equql to the expected one. ", sql,
getMMConnection().nativeSQL(sql)); //$NON-NLS-1$
- }
-
- /** test getUserName() through DriverManager */
- public void testGetUserName2() throws Exception {
- assertEquals("Actual userName is not equal to the expected one. ",
"metamatrixadmin", getMMConnection().getUserName()); //$NON-NLS-1$
//$NON-NLS-2$
- }
-
- /** test isReadOnly default value on Connection */
- public void testIsReadOnly() throws Exception {
- assertEquals(false, getMMConnection().isReadOnly());
- }
-
- /** test setReadOnly on Connection */
- public void testSetReadOnly1() throws Exception {
- ConnectionImpl conn = getMMConnection();
- conn.setReadOnly(true);
- assertEquals(true, conn.isReadOnly());
- }
-
- /** test setReadOnly on Connection during a transaction */
- public void testSetReadOnly2() throws Exception {
- ConnectionImpl conn = getMMConnection();
- conn.setAutoCommit(false);
- try {
- conn.setReadOnly(true);
- fail("Error Expected"); //$NON-NLS-1$
- } catch (SQLException e) {
- // error expected
- }
- }
-}
Deleted: trunk/client/src/test/java/org/teiid/jdbc/TestMMJDBCURL.java
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/TestMMJDBCURL.java 2010-06-17 16:09:26 UTC
(rev 2239)
+++ trunk/client/src/test/java/org/teiid/jdbc/TestMMJDBCURL.java 2010-06-17 18:35:22 UTC
(rev 2240)
@@ -1,342 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.jdbc;
-
-import java.net.URLEncoder;
-import java.util.Properties;
-
-import org.teiid.jdbc.BaseDataSource;
-import org.teiid.jdbc.ExecutionProperties;
-import org.teiid.jdbc.JDBCURL;
-import org.teiid.net.TeiidURL;
-
-import junit.framework.TestCase;
-
-
-
-/**
- * @since 4.3
- */
-public class TestMMJDBCURL extends TestCase {
-
- // Need to allow embedded spaces and ='s within optional properties
- public final void testCredentials() throws Exception {
- String credentials = URLEncoder.encode("defaultToLogon,(system=BQT1 SQL
Server 2000 Simple Cap,user=xyz,password=xyz)", "UTF-8"); //$NON-NLS-1$
//$NON-NLS-2$
- JDBCURL url = new
JDBCURL("jdbc:metamatrix:QT_sqls2kds@mm://slwxp136:43100;credentials="+credentials);
//$NON-NLS-1$
- Properties p = url.getProperties();
- assertEquals("defaultToLogon,(system=BQT1 SQL Server 2000 Simple
Cap,user=xyz,password=xyz)", p.getProperty("credentials"));
//$NON-NLS-1$//$NON-NLS-2$
- }
-
- public void testJDBCURLWithProperties() {
- String URL =
"jdbc:metamatrix:bqt@mm://localhost:12345;version=1;user=xyz;password=***;logLevel=1;configFile=testdata/bqt/dqp_stmt_e2e.xmi;disableLocalTxn=true;autoFailover=false";
//$NON-NLS-1$
-
- Properties expectedProperties = new Properties();
- expectedProperties.setProperty("version", "1"); //$NON-NLS-1$
//$NON-NLS-2$
- expectedProperties.setProperty("user", "xyz"); //$NON-NLS-1$
//$NON-NLS-2$
- expectedProperties.setProperty("password", "***");
//$NON-NLS-1$ //$NON-NLS-2$
- expectedProperties.setProperty("logLevel", "1");
//$NON-NLS-1$ //$NON-NLS-2$
- expectedProperties.setProperty("configFile",
"testdata/bqt/dqp_stmt_e2e.xmi"); //$NON-NLS-1$ //$NON-NLS-2$
- expectedProperties.setProperty(ExecutionProperties.DISABLE_LOCAL_TRANSACTIONS,
"true"); //$NON-NLS-1$
- expectedProperties.setProperty(TeiidURL.CONNECTION.AUTO_FAILOVER,
"false"); //$NON-NLS-1$
- JDBCURL url = new JDBCURL(URL);
- assertEquals("bqt", url.getVDBName()); //$NON-NLS-1$
- assertEquals("mm://localhost:12345", url.getConnectionURL());
//$NON-NLS-1$
- assertEquals(expectedProperties, url.getProperties());
- }
-
- public void testJDBCURLWithoutProperties() {
- String URL = "jdbc:metamatrix:bqt@mm://localhost:12345"; //$NON-NLS-1$
-
- JDBCURL url = new JDBCURL(URL);
- assertEquals("bqt", url.getVDBName()); //$NON-NLS-1$
- assertEquals("mm://localhost:12345", url.getConnectionURL());
//$NON-NLS-1$
- assertEquals(new Properties(), url.getProperties());
- }
-
- public void testCaseConversion() {
- // Different case ------------------------------------HERE -v
----------------and HERE -v
- String URL =
"jdbc:metamatrix:bqt@mm://localhost:12345;VERSION=1;user=xyz;password=***;configFile=testdata/bqt/dqp_stmt_e2e.xmi";
//$NON-NLS-1$
-
- Properties expectedProperties = new Properties();
- expectedProperties.setProperty("version", "1"); //$NON-NLS-1$
//$NON-NLS-2$
- expectedProperties.setProperty("user", "xyz"); //$NON-NLS-1$
//$NON-NLS-2$
- expectedProperties.setProperty("password", "***");
//$NON-NLS-1$ //$NON-NLS-2$
- expectedProperties.setProperty("configFile",
"testdata/bqt/dqp_stmt_e2e.xmi"); //$NON-NLS-1$ //$NON-NLS-2$
- JDBCURL url = new JDBCURL(URL);
- assertEquals("bqt", url.getVDBName()); //$NON-NLS-1$
- assertEquals("mm://localhost:12345", url.getConnectionURL());
//$NON-NLS-1$
- assertEquals(expectedProperties, url.getProperties());
- }
-
- public void testWithExtraSemicolons() {
- String URL =
"jdbc:metamatrix:bqt@mm://localhost:12345;version=1;user=xyz;password=***;logLevel=1;;;configFile=testdata/bqt/dqp_stmt_e2e.xmi;;";
//$NON-NLS-1$
-
- Properties expectedProperties = new Properties();
- expectedProperties.setProperty("version", "1"); //$NON-NLS-1$
//$NON-NLS-2$
- expectedProperties.setProperty("user", "xyz"); //$NON-NLS-1$
//$NON-NLS-2$
- expectedProperties.setProperty("password", "***");
//$NON-NLS-1$ //$NON-NLS-2$
- expectedProperties.setProperty("logLevel", "1");
//$NON-NLS-1$ //$NON-NLS-2$
- expectedProperties.setProperty("configFile",
"testdata/bqt/dqp_stmt_e2e.xmi"); //$NON-NLS-1$ //$NON-NLS-2$
- JDBCURL url = new JDBCURL(URL);
- assertEquals("bqt", url.getVDBName()); //$NON-NLS-1$
- assertEquals("mm://localhost:12345", url.getConnectionURL());
//$NON-NLS-1$
- assertEquals(expectedProperties, url.getProperties());
- }
-
- public void testWithWhitespace() {
- String URL = "jdbc:metamatrix:bqt@mm://localhost:12345; version =1;user= xyz
;password=***; logLevel = 1 ; configFile=testdata/bqt/dqp_stmt_e2e.xmi ;";
//$NON-NLS-1$
-
- Properties expectedProperties = new Properties();
- expectedProperties.setProperty("version", "1"); //$NON-NLS-1$
//$NON-NLS-2$
- expectedProperties.setProperty("user", "xyz"); //$NON-NLS-1$
//$NON-NLS-2$
- expectedProperties.setProperty("password", "***");
//$NON-NLS-1$ //$NON-NLS-2$
- expectedProperties.setProperty("logLevel", "1");
//$NON-NLS-1$ //$NON-NLS-2$
- expectedProperties.setProperty("configFile",
"testdata/bqt/dqp_stmt_e2e.xmi"); //$NON-NLS-1$ //$NON-NLS-2$
- JDBCURL url = new JDBCURL(URL);
- assertEquals("bqt", url.getVDBName()); //$NON-NLS-1$
- assertEquals("mm://localhost:12345", url.getConnectionURL());
//$NON-NLS-1$
- assertEquals(expectedProperties, url.getProperties());
- }
-
- public void testNoPropertyValue() {
- String URL =
"jdbc:metamatrix:bqt@mm://localhost:12345;version=1;user=xyz;password=***;logLevel=;configFile=";
//$NON-NLS-1$
-
- Properties expectedProperties = new Properties();
- expectedProperties.setProperty("version", "1"); //$NON-NLS-1$
//$NON-NLS-2$
- expectedProperties.setProperty("user", "xyz"); //$NON-NLS-1$
//$NON-NLS-2$
- expectedProperties.setProperty("password", "***");
//$NON-NLS-1$ //$NON-NLS-2$
- expectedProperties.setProperty("logLevel", ""); //$NON-NLS-1$
//$NON-NLS-2$
- expectedProperties.setProperty("configFile", "");
//$NON-NLS-1$ //$NON-NLS-2$
- JDBCURL url = new JDBCURL(URL);
- assertEquals("bqt", url.getVDBName()); //$NON-NLS-1$
- assertEquals("mm://localhost:12345", url.getConnectionURL());
//$NON-NLS-1$
- assertEquals(expectedProperties, url.getProperties());
- }
-
- public void testInvalidProtocol() {
- String URL =
"jdbc:monkeymatrix:bqt@mm://localhost:12345;version=1;user=xyz;password=***;logLevel=1";
//$NON-NLS-1$
- try {
- new JDBCURL(URL);
- fail("Illegal argument should have failed."); //$NON-NLS-1$
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-
- public void testNoVDBName() {
- String URL =
"jdbc:metamatrix:@mm://localhost:12345;version=1;user=xyz;password=***;logLevel=1";
//$NON-NLS-1$
- try {
- new JDBCURL(URL);
- fail("Illegal argument should have failed."); //$NON-NLS-1$
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-
- public void testNoAtSignInURL() {
- String URL =
"jdbc:metamatrix:bqt!mm://localhost:12345;version=1;user=xyz;password=***;logLevel=1";
//$NON-NLS-1$
- try {
- new JDBCURL(URL);
- // No @ sign is llowed as part of embedded driver now,
- // but this form of URL rejected in the acceptURL
- //fail("Illegal argument should have failed.");
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-
- public void testMoreThanOneAtSign() {
- String URL =
"jdbc:metamatrix:bqt@mm://localhost:12345;version=1;user=xy@;password=***;logLevel=1";
//$NON-NLS-1$
- try {
- // this allowed as customer properties can have @ in their properties
- new JDBCURL(URL);
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-
- public void testNoEqualsInProperty() {
- String URL =
"jdbc:metamatrix:bqt@mm://localhost:12345;version=1;user=xyz;password***;logLevel=1";
//$NON-NLS-1$
- try {
- new JDBCURL(URL);
- fail("Illegal argument should have failed."); //$NON-NLS-1$
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-
- public void testMoreThanOneEqualsInProperty() {
- String URL =
"jdbc:metamatrix:bqt@mm://localhost:12345;version=1;user=xyz;password==***;logLevel=1";
//$NON-NLS-1$
- try {
- new JDBCURL(URL);
- fail("Illegal argument should have failed."); //$NON-NLS-1$
- } catch (IllegalArgumentException e) {
- // expected
- }
- URL =
"jdbc:metamatrix:bqt@mm://localhost:12345;version=1;user=xyz;password=***=;logLevel=1";
//$NON-NLS-1$
- try {
- new JDBCURL(URL);
- fail("Illegal argument should have failed."); //$NON-NLS-1$
- } catch (IllegalArgumentException e) {
- // expected
- }
- URL =
"jdbc:metamatrix:bqt@mm://localhost:12345;version=1;user=xyz;=password=***;logLevel=1";
//$NON-NLS-1$
- try {
- new JDBCURL(URL);
- fail("Illegal argument should have failed."); //$NON-NLS-1$
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-
- public void testNoKeyInProperty() {
- String URL =
"jdbc:metamatrix:bqt@mm://localhost:12345;version=1;user=xyz;=***;logLevel=1";
//$NON-NLS-1$
- try {
- new JDBCURL(URL);
- fail("Illegal argument should have failed."); //$NON-NLS-1$
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-
- public void testConstructor() {
- JDBCURL url = new JDBCURL("myVDB", "mm://myhost:12345",null);
//$NON-NLS-1$ //$NON-NLS-2$
- assertEquals("jdbc:teiid:myVDB@mm://myhost:12345", url.getJDBCURL());
//$NON-NLS-1$
-
- Properties props = new Properties();
- props.setProperty(BaseDataSource.USER_NAME, "myuser"); //$NON-NLS-1$
- props.setProperty(BaseDataSource.PASSWORD, "mypassword");
//$NON-NLS-1$
- props.put("ClieNTtOKeN", new Integer(1)); //$NON-NLS-1$
- url = new JDBCURL("myVDB", "mm://myhost:12345", props);
//$NON-NLS-1$ //$NON-NLS-2$
-
assertEquals("jdbc:teiid:myVDB@mm://myhost:12345;user=myuser;password=mypassword",
url.getJDBCURL()); //$NON-NLS-1$
- }
-
- public void testConstructor_Exception() {
- try {
- new JDBCURL(null, "myhost", null); //$NON-NLS-1$
- fail("Should have failed."); //$NON-NLS-1$
- } catch (Exception e) {
-
- }
- try {
- new JDBCURL(" ", "myhost", null); //$NON-NLS-1$
//$NON-NLS-2$
- fail("Should have failed."); //$NON-NLS-1$
- } catch (Exception e) {
-
- }
-
- try {
- // in embedded situation there is no connection url
- new JDBCURL("myVDB", " ", null); //$NON-NLS-1$
//$NON-NLS-2$
- } catch (Exception e) {
-
- }
- }
-
- public void testNormalize() {
- Properties props = new Properties();
- props.setProperty("UsEr", "myuser"); //$NON-NLS-1$
//$NON-NLS-2$
- props.setProperty("pAssWOrD", "mypassword"); //$NON-NLS-1$
//$NON-NLS-2$
- props.put("ClieNTtOKeN", new Integer(1)); //$NON-NLS-1$
- JDBCURL.normalizeProperties(props);
- assertEquals("myuser", props.getProperty(BaseDataSource.USER_NAME));
//$NON-NLS-1$
- assertEquals("mypassword", props.getProperty(BaseDataSource.PASSWORD));
//$NON-NLS-1$
- }
-
- public final void testEncodedPropertyProperties() throws Exception {
- String password =
"=@#^&*()+!%$^%@#_-)_~{}||\\`':;,./<>?password has = & %";
//$NON-NLS-1$
- Properties props = new Properties();
- props.setProperty("UsEr", "foo"); //$NON-NLS-1$
//$NON-NLS-2$
- props.setProperty("PASswoRd", password); //$NON-NLS-1$
- JDBCURL.normalizeProperties(props);
-
- assertEquals(password, props.getProperty("password")); //$NON-NLS-1$
- assertEquals("foo", props.getProperty("user"));
//$NON-NLS-1$//$NON-NLS-2$
- }
-
- public final void testEncodedPropertyInURL() throws Exception {
- String password =
"=@#^&*()+!%$^%@#_-)_~{}||\\`':;,./<>?password has = & %";
//$NON-NLS-1$
- String encPassword = URLEncoder.encode(password, "UTF-8");
//$NON-NLS-1$
- JDBCURL url = new
JDBCURL("jdbc:metamatrix:QT_sqls2kds@mm://slwxp136:43100;PASswoRd="+encPassword);
//$NON-NLS-1$
- Properties p = url.getProperties();
- assertEquals(password, p.getProperty("password")); //$NON-NLS-1$
- }
-
-
- public void testGetServerURL_NoProperties() {
- String result = new
JDBCURL("jdbc:metamatrix:designtimecatalog@mm://slwxp172:44401;user=ddifranco;password=mm").getConnectionURL();
//$NON-NLS-1$
- assertEquals("mm://slwxp172:44401", result); //$NON-NLS-1$
- }
-
- public void testGetServerURL_Properties() {
- String result = new
JDBCURL("jdbc:metamatrix:designtimecatalog@mm://slwxp172:44401;user=ddifranco;password=mm").getConnectionURL();
//$NON-NLS-1$
- assertEquals("mm://slwxp172:44401", result); //$NON-NLS-1$
- }
-
- /**
- * Test getServerURL with a valid URL and password that contains at least
- * one ASCII character in the range of 32 to 126 excluding the ; and = sign.
- *
- * @since 5.0.2
- */
- public void testGetServerURL_PasswordProperties() throws Exception {
- String result = null;
- String srcURL =
"jdbc:metamatrix:designtimecatalog@mm://slwxp172:44401;user=ddifranco;password=";
//$NON-NLS-1$
- String password = null;
- String tgtURL = "mm://slwxp172:44401"; //$NON-NLS-1$
-
-
- for ( char ch = 32; ch <= 126; ch++ ) {
- //exclude URL reserved characters
- if ( ch != ';' && ch != '=' && ch !=
'%') {
- password = ch+"mm"; //$NON-NLS-1$
- result = new JDBCURL(srcURL+URLEncoder.encode(password,
"UTF-8")).getConnectionURL(); //$NON-NLS-1$
- assertEquals("Failed to obtain correct ServerURL when using password
"+password,tgtURL, result); //$NON-NLS-1$
- }
- }
-
- }
-
- public void testGetServerURL_2Servers() {
- String result = new
JDBCURL("jdbc:metamatrix:designtimecatalog@mm://slwxp172:44401,slabc123:12345;user=ddifranco;password=mm").getConnectionURL();
//$NON-NLS-1$
- assertEquals("mm://slwxp172:44401,slabc123:12345", result);
//$NON-NLS-1$
- }
-
- public void testBuildEmbeedURL() {
- JDBCURL url = new JDBCURL("vdb", "/home/foo/deploy.properties",
new Properties()); //$NON-NLS-1$ //$NON-NLS-2$
- assertEquals("jdbc:teiid:vdb@/home/foo/deploy.properties",
url.getJDBCURL()); //$NON-NLS-1$
-
- Properties p = new Properties();
- p.setProperty("user", "test"); //$NON-NLS-1$ //$NON-NLS-2$
- p.setProperty("password", "pass"); //$NON-NLS-1$ //$NON-NLS-2$
- p.setProperty("autoFailover", "true"); //$NON-NLS-1$
//$NON-NLS-2$
- p.setProperty("any", "thing"); //$NON-NLS-1$ //$NON-NLS-2$
-
- url = new JDBCURL("vdb", "/home/foo/deploy.properties", p);
//$NON-NLS-1$ //$NON-NLS-2$
-
assertTrue(url.getJDBCURL().startsWith("jdbc:teiid:vdb@/home/foo/deploy.properties;user=test;"));
//$NON-NLS-1$
- assertTrue(url.getJDBCURL().indexOf("any=thing")!=-1); //$NON-NLS-1$
- assertTrue(url.getJDBCURL().indexOf("password=pass")!=-1); //$NON-NLS-1$
- assertTrue(url.getJDBCURL().indexOf("autoFailover=true")!=-1);
//$NON-NLS-1$
-
- }
-}
Deleted: trunk/client/src/test/java/org/teiid/jdbc/TestMMPreparedStatement.java
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/TestMMPreparedStatement.java 2010-06-17
16:09:26 UTC (rev 2239)
+++ trunk/client/src/test/java/org/teiid/jdbc/TestMMPreparedStatement.java 2010-06-17
18:35:22 UTC (rev 2240)
@@ -1,343 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.jdbc;
-
-import static org.junit.Assert.*;
-
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.TimeZone;
-
-import org.junit.Test;
-import org.mockito.Matchers;
-import org.mockito.Mockito;
-import org.teiid.client.DQP;
-import org.teiid.client.RequestMessage;
-import org.teiid.client.ResultsMessage;
-import org.teiid.client.RequestMessage.ResultsMode;
-import org.teiid.client.security.LogonResult;
-import org.teiid.client.util.ResultsFuture;
-import org.teiid.jdbc.ConnectionImpl;
-import org.teiid.jdbc.PreparedStatementImpl;
-import org.teiid.jdbc.TeiidSQLException;
-import org.teiid.net.ServerConnection;
-
-
-/**
- * Test case to validate general operations on an <code>MMPreparedStatement
- * </code>
- */
-public class TestMMPreparedStatement {
-
- /**
- * Test that <code>MMPreparedStatement</code>'s
<code>execute()</code> method
- * will throw a <code>MMSQLException</code> if a connection does not exist.
- *
- * @throws Exception
- */
- @Test(expected=TeiidSQLException.class) public void testUpdateException() throws
Exception {
- PreparedStatementImpl statement = getMMPreparedStatement("delete from
table"); //$NON-NLS-1$
- statement.execute();
- }
-
- /**
- * Verify that the <code>executeBatch()</code> method of <code>
- * MMPreparedStatement</code> is resulting in the correct command,
- * parameter values for each command of the batch, and the request type
- * are being set in the request message that would normally be sent to the
- * server.
- *
- * @throws Exception
- */
- @Test public void testBatchedUpdateExecution() throws Exception {
- // Build up a fake connection instance for use with the prepared statement
- ConnectionImpl conn = Mockito.mock(ConnectionImpl.class);
- DQP dqp = Mockito.mock(DQP.class);
- ServerConnection serverConn = Mockito.mock(ServerConnection.class);
- LogonResult logonResult = Mockito.mock(LogonResult.class);
-
- // stub methods
- Mockito.stub(conn.getServerConnection()).toReturn(serverConn);
- Mockito.stub(serverConn.getLogonResult()).toReturn(logonResult);
- Mockito.stub(logonResult.getTimeZone()).toReturn(TimeZone.getDefault());
-
- // a dummy result message that is specific to this test case
- ResultsFuture<ResultsMessage> results = new
ResultsFuture<ResultsMessage>();
- Mockito.stub(dqp.executeRequest(Matchers.anyLong(),
(RequestMessage)Matchers.anyObject())).toReturn(results);
- ResultsMessage rm = new ResultsMessage();
- rm.setResults(new List<?>[] {Arrays.asList(0), Arrays.asList(0),
Arrays.asList(0)});
- rm.setUpdateResult(true);
- results.getResultsReceiver().receiveResults(rm);
- Mockito.stub(conn.getDQP()).toReturn(dqp);
-
- // some update SQL
- String sqlCommand = "delete from table where col=?"; //$NON-NLS-1$
- TestableMMPreparedStatement statement = (TestableMMPreparedStatement)
getMMPreparedStatement(conn, sqlCommand);
-
- ArrayList<ArrayList<Object>> expectedParameterValues = new
ArrayList<ArrayList<Object>>(3);
- // Add some batches and their parameter values
- expectedParameterValues.add( new ArrayList<Object>( Arrays.asList( new Object[] {
new Integer(1) } ) ) );
- statement.setInt(1, new Integer(1));
- statement.addBatch();
- expectedParameterValues.add( new ArrayList<Object>( Arrays.asList( new Object[] {
new Integer(2) } ) ) );
- statement.setInt(1, new Integer(2));
- statement.addBatch();
- expectedParameterValues.add( new ArrayList<Object>( Arrays.asList( new Object[] {
new Integer(3) } ) ) );
- statement.setInt(1, new Integer(3));
- statement.addBatch();
-
- // execute the batch and verify that it matches our dummy results
- // message set earlier
- assertTrue(Arrays.equals(new int[] {0, 0, 0}, statement.executeBatch()));
-
- // Now verify the statement's RequestMessage is what we expect
- assertEquals("Command does not match", sqlCommand,
statement.requestMessage.getCommandString()); //$NON-NLS-1$
- assertEquals("Parameter values do not match", expectedParameterValues,
statement.requestMessage.getParameterValues()); //$NON-NLS-1$
- assertTrue("RequestMessage.isBatchedUpdate should be true",
statement.requestMessage.isBatchedUpdate()); //$NON-NLS-1$
- assertFalse("RequestMessage.isCallableStatement should be false",
statement.requestMessage.isCallableStatement()); //$NON-NLS-1$
- assertTrue("RequestMessage.isPreparedStatement should be true",
statement.requestMessage.isPreparedStatement()); //$NON-NLS-1$
- }
-
- /**
- * Verify that the <code>clearBatch()</code> method of
- * <code>MMPreparedStatement</code> is clearing the list of batched
- * commands.
- * <p>
- * This is done by first adding command parameter values to the batch and
- * then invoking the <code>clearBatch()</code> method.
- *
- * @throws Exception
- */
- @Test public void testClearBatch() throws Exception {
- PreparedStatementImpl statement = getMMPreparedStatement("delete from table where
col=?"); //$NON-NLS-1$
- // Add some stuff
- statement.setInt(1, new Integer(1));
- statement.addBatch();
- statement.setInt(1, new Integer(2));
- statement.addBatch();
- // Make sure something is really there
- assertTrue("MMPreparedStatement.ParameterValuesList should not be empty",
statement.getParameterValuesList().size() > 0); //$NON-NLS-1$
- // Now clear it
- statement.clearBatch();
- assertTrue("MMPreparedStatement.ParameterValuesList should be empty",
statement.getParameterValuesList().size() == 0); //$NON-NLS-1$
- }
-
- /**
- * Adds additional batches of command parameter values to a prepared
- * statement after a previous list has been cleared.
- * <p>
- * This is done by first adding command parameter values to the batch and
- * then invoking the <code>clearBatch()</code> method. Then a different
- * set of command parameter values are added to the existing batch command.
- * <p>
- * The expected result is the command parameter list for the batches will
- * only reflect what was added after <code>clearBatch()</code> was invoked.
- *
- * @throws Exception
- */
- @Test public void testClearBatchAddBatch() throws Exception {
- PreparedStatementImpl statement = getMMPreparedStatement("delete from table where
col=?"); //$NON-NLS-1$
-
- statement.setInt(1, new Integer(1));
- statement.addBatch();
- statement.setInt(1, new Integer(2));
- statement.addBatch();
- // Make sure something is really there
- assertTrue("MMPreparedStatement.ParameterValuesList should not be empty",
statement.getParameterValuesList().size() > 0); //$NON-NLS-1$
- // Now clear it
- statement.clearBatch();
- // Make sure it is empty now
- assertTrue("MMPreparedStatement.ParameterValuesList should be empty",
statement.getParameterValuesList().size() == 0); //$NON-NLS-1$
-
- ArrayList<ArrayList<Object>> expectedParameterValues = new
ArrayList<ArrayList<Object>>(1);
-
- // Now add something for validation
- expectedParameterValues.add( new ArrayList<Object>( Arrays.asList( new Object[] {
new Integer(5) } ) ) );
- statement.setInt(1, new Integer(5));
- statement.addBatch();
- assertEquals("MMPreparedStatement.ParameterValuesList does not match",
expectedParameterValues, statement.getParameterValuesList()); //$NON-NLS-1$
- }
-
- /**
- * Test the <code>addBatch()</code> method of
<code>MMPreparedStatement</code>
- * to verify that the command parameter values of the batch are added to the
- * command parameter values list.
- *
- * @throws Exception
- */
- @Test public void testAddBatch() throws Exception {
- PreparedStatementImpl statement = getMMPreparedStatement("delete from table where
col=?"); //$NON-NLS-1$
-
- ArrayList<ArrayList<Object>> expectedParameterValues = new
ArrayList<ArrayList<Object>>(1);
-
- // First we add a single batch
- expectedParameterValues.add( new ArrayList<Object>( Arrays.asList( new Object[] {
new Integer(1) } ) ) );
- statement.setInt(1, new Integer(1));
- statement.addBatch();
- assertEquals("MMPreparedStatement.ParameterValuesList does not match",
expectedParameterValues, statement.getParameterValuesList()); //$NON-NLS-1$
-
- // Now add some more batches just for sanity sake
- expectedParameterValues.add( new ArrayList<Object>( Arrays.asList( new Object[] {
new Integer(3) } ) ) );
- expectedParameterValues.add( new ArrayList<Object>( Arrays.asList( new Object[] {
new Integer(5) } ) ) );
- statement.setInt(1, new Integer(3));
- statement.addBatch();
- statement.setInt(1, new Integer(5));
- statement.addBatch();
- assertEquals("MMPreparedStatement.ParameterValuesList does not match",
expectedParameterValues, statement.getParameterValuesList()); //$NON-NLS-1$
- }
-
- /**
- * Test the <code>addBatch()</code> method of
<code>MMPreparedStatement</code>
- * using a batch with an empty parameter value list. The test will verify
- * no failures occur when there are no command parameter values defined
- * when the <code>addBatch()</code> method is invoked.
- * <p>
- * It is valid to add an empty parameter value list to a batch list.
- * <p>
- * For example:
- * <p>
- * <code>PreparedStatement stmt = conn.prepareStatement(sql);<br \>
- * stmt.addBatch();<br \>
- * stmt.addBatch();<br \>
- * stmt.executeBatch();</code>
- *
- * @throws Exception
- */
- @Test public void testAddBatchNoParameterValues() throws Exception {
- PreparedStatementImpl statement = getMMPreparedStatement("delete from table where
col=?"); //$NON-NLS-1$
-
- // This will hold our expected values list
- ArrayList<ArrayList<Object>> expectedParameterValues = new
ArrayList<ArrayList<Object>>(1);
-
- // First batch has an empty parameter value list
- expectedParameterValues.add( new ArrayList<Object>(Collections.emptyList()) );
-
- // No values have been set so we are adding a batch with an empty
- // parameter value list
- statement.addBatch();
-
- // Second batch contains a parameter value list
- expectedParameterValues.add( new ArrayList<Object>( Arrays.asList( new Object[] {
new Integer(1) } ) ) );
-
- // We now are adding a batch that does have parameter values
- statement.setInt(1, new Integer(1));
- statement.addBatch();
-
- // Check to see if our statement contains our expected parameter value list
- assertEquals("MMPreparedStatement.ParameterValuesList does not match",
expectedParameterValues, statement.getParameterValuesList()); //$NON-NLS-1$
- }
-
- /**
- * A helper method to get an <code>MMPreparedStatement</code> that can be
- * used for simple test cases.
- * <p>
- * The returned value is an instance of
<code>TestableMMPreparedStatement</code>
- * <p>
- * This method invokes <code>getMMPreparedStatement(final MMConnection conn,
- * final String sql)</code> with a fake connection object constructed by
- * <code>Mockito</code>.
- *
- * @param sql the query for the prepared statement
- * @return an instance of TestableMMPreparedStatement
- * @throws SQLException
- */
- protected PreparedStatementImpl getMMPreparedStatement(final String sql) throws
SQLException {
- ConnectionImpl conn = Mockito.mock(ConnectionImpl.class);
- ServerConnection serverConn = Mockito.mock(ServerConnection.class);
- LogonResult logonResult = Mockito.mock(LogonResult.class);
-
- Mockito.stub(conn.getServerConnection()).toReturn(serverConn);
- Mockito.stub(serverConn.getLogonResult()).toReturn(logonResult);
- Mockito.stub(logonResult.getTimeZone()).toReturn(TimeZone.getDefault());
-
- return getMMPreparedStatement(conn, sql);
- }
-
- /**
- * A helper method to get an <code>MMPreparedStatement</code> that can be
- * used for simple test cases.
- * <p>
- * The returned value is an instance of
<code>TestableMMPreparedStatement</code>
- * <p>
- * <code>conn</code> should be a valid instance of
<code>MMConnection</code>
- * or this method will fail.
- *
- * @param conn an instance of <code>MMConnection</code>
- * @param sql the query for the prepared statement
- * @return an instance of TestableMMPreparedStatement
- * @throws SQLException
- */
- protected PreparedStatementImpl getMMPreparedStatement(final ConnectionImpl conn, final
String sql) throws SQLException {
- TestableMMPreparedStatement statement = new TestableMMPreparedStatement(conn, sql,
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
-
- // Make sure everything is empty on start
- assertTrue("MMPreparedStatement.ParameterValuesList should be empty",
statement.getParameterValuesList().size() == 0); //$NON-NLS-1$
- assertTrue("MMPreparedStatement.ParameterValues should be empty",
statement.getParameterValues().size() == 0); //$NON-NLS-1$
-
- return statement;
- }
-
- /**
- * Represents an extension to <code>MMPreparedStatement</code> that
- * gives access to the <code>RequestMessage</code> that is passed
- * around inside <code>MMPreparedStatement</code>.
- * <p>
- * This extension simply adds a field named <code>requestMessage</code>
- * which is <code>public</code>. This field gets set when the
<code>protected</code>
- * method <code>createRequestMessage()</code> is called.
- * <p>
- * This extension also overrides <code>RequestMessage
createRequestMessage(String[] commands,
- * boolean isBatchedCommand, Boolean requiresResultSet)</code> so that
- * reference to the created <code>RequestMessage</code> can be retained in
- * the field <code>requestMessage</code>.
- */
- class TestableMMPreparedStatement extends PreparedStatementImpl {
- /**
- * Contains a reference to the <code>RequestMessage</code> created by
- * a call to <code>createRequestMessage(String[] commands,
- * boolean isBatchedCommand, Boolean requiresResultSet)</code>. This
- * will allow easy access to the prepared statement's request message
- * generated by a call to one of the statement's execute methods.
- */
- public RequestMessage requestMessage;
- @Override
- protected RequestMessage createRequestMessage(String[] commands,
- boolean isBatchedCommand, ResultsMode resultsMode) {
- this.requestMessage = super
- .createRequestMessage(commands, isBatchedCommand, resultsMode);
- return this.requestMessage;
- }
-
- public TestableMMPreparedStatement(ConnectionImpl connection,
- String sql, int resultSetType, int resultSetConcurrency)
- throws SQLException {
- super(connection, sql, resultSetType, resultSetConcurrency);
- }
-
- }
-
-}
Deleted: trunk/client/src/test/java/org/teiid/jdbc/TestMMResultSet.java
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/TestMMResultSet.java 2010-06-17 16:09:26 UTC
(rev 2239)
+++ trunk/client/src/test/java/org/teiid/jdbc/TestMMResultSet.java 2010-06-17 18:35:22 UTC
(rev 2240)
@@ -1,753 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.jdbc;
-
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.*;
-
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.SQLException;
-import java.sql.Types;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.List;
-import java.util.TimeZone;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeoutException;
-
-import org.junit.Test;
-import org.teiid.client.DQP;
-import org.teiid.client.ResultsMessage;
-import org.teiid.core.TeiidProcessingException;
-
-
-public class TestMMResultSet {
-
- /** test next() without walking through */
- @Test public void testNext1() throws SQLException {
- ResultSet cs = helpExecuteQuery();
- assertEquals(" Actual doesn't match with expected. ", new
Integer(0), new Integer(cs.getRow())); //$NON-NLS-1$
- cs.close();
- }
-
- /** test next() with walking through all the rows and compare records */
- @Test public void testNext2() throws SQLException {
- List[] expected = TestAllResultsImpl.exampleResults1(1000);
- ResultSetImpl cs = helpExecuteQuery();
-
- int i=0;
- while(cs.next()) {
- assertEquals(" Actual doesn't match with expected. ",
expected[i], cs.getCurrentRecord()); //$NON-NLS-1$
- i++;
- }
-
- cs.close();
- }
-
- /** test with LargeA -- only work with real model rather than fake metadata*/
-
- // Note for all the following: processor batch size is 100,
- // so some of these tests check what happens when the client
- // fetch size is above, the same, or below it
- public static final int PROC_BATCH_SIZE = 100;
-
- /** Test stability when next() is called beyond the rowcount. */
- @Test public void testNextBeyondEnd_fetchEqualsCount() throws Exception {
- helpTestNextBeyondResultSet(1000, 1000);
- }
-
- /** Test stability when next() is called beyond the rowcount. */
- @Test public void testNextBeyondEnd_fetchLessThanCount() throws Exception {
- helpTestNextBeyondResultSet(100, 1000);
- }
-
- /** Test stability when next() is called beyond the rowcount with one more row. */
- @Test public void testNextBeyondEnd_fetchLessThanCount1() throws Exception {
- helpTestNextBeyondResultSet(100, 101);
- }
-
- /** Test stability when next() is called beyond the rowcount. */
- @Test public void testNextBeyondEnd_fetchLessThanCountNonMultiple() throws Exception
{
- helpTestNextBeyondResultSet(120, 1000);
- }
-
- /** Test stability when next() is called beyond the rowcount. */
- @Test public void testNextBeyondEnd_fetchGreaterThanCount() throws Exception {
- helpTestNextBeyondResultSet(300, PROC_BATCH_SIZE);
- }
-
- /** Test stability when next() is called beyond the rowcount. */
- @Test public void testNextBeyondEnd_fetchGreaterThanCountNonMultiple() throws
Exception {
- helpTestNextBeyondResultSet(310, PROC_BATCH_SIZE-50);
- }
-
- /** Test stability when next() is called beyond the rowcount. */
- @Test public void testNextBeyondEnd_fetchGreaterThanCountNonMultiple2() throws
Exception {
- helpTestNextBeyondResultSet(300, PROC_BATCH_SIZE+10);
- }
-
- /** Test that the returned results walks through all results if
- * fetchSize < rows < proc batch size.
- * Test for defect 11356
- */
- @Test public void
testNextBeyondEnd_fetchLessThanCount_ResultsBetweenFetchAndProcBatch() throws Exception {
- helpTestNextBeyondResultSet(30, PROC_BATCH_SIZE-25);
- }
-
- public void helpTestNextBeyondResultSet(int fetchSize, int numRows) throws Exception
{
- ResultSet cs = helpExecuteQuery(fetchSize, numRows,
ResultSet.TYPE_SCROLL_INSENSITIVE);
- try {
- Object lastRowValue = null;
- for (int rowNum = 1; rowNum <= numRows; rowNum++) {
- assertEquals("Should return true before end cs.next()", true,
cs.next()); //$NON-NLS-1$
- }
-
- lastRowValue = cs.getObject(1);
-
- // Should just return false and leave cursor where it is
- for(int i=numRows+1; i<numRows+4; i++) {
- assertEquals("Should return false when going past the end: " +
i, false, cs.next()); //$NON-NLS-1$
- assertEquals("Is after last should be true: " + i, true,
cs.isAfterLast()); //$NON-NLS-1$
- }
-
- // Should still be just after last row
- cs.previous();
- assertEquals("Is last should be true", true, cs.isLast());
//$NON-NLS-1$
- assertEquals("Not on last row", lastRowValue, cs.getObject(1));
//$NON-NLS-1$
-
- } finally {
- cs.close();
- }
- }
-
- /** test both next() and previous() -- when result set scroll in bidirection */
- @Test public void testBidirection() throws SQLException {
- ResultSetImpl cs = helpExecuteQuery();
- assertNotNull(cs);
- cs.absolute(290);
- assertEquals(" Actual value doesn't match with expected one.", new
Integer(290), cs.getCurrentRecord().get(0)); //$NON-NLS-1$
- cs.next();
- assertEquals(" Actual value doesn't match with expected one.", new
Integer(291), cs.getCurrentRecord().get(0)); //$NON-NLS-1$
- cs.next();
- assertEquals(" Actual value doesn't match with expected one.", new
Integer(292), cs.getCurrentRecord().get(0)); //$NON-NLS-1$
- cs.previous();
- assertEquals(" Actual value doesn't match with expected one.", new
Integer(291), cs.getCurrentRecord().get(0)); //$NON-NLS-1$
- cs.next();
- assertEquals(" Actual value doesn't match with expected one.", new
Integer(292), cs.getCurrentRecord().get(0)); //$NON-NLS-1$
- cs.close();
- }
-
- /** test hasNext() without walking through any row */
- @Test public void testHasNext1() throws SQLException {
- ResultSetImpl cs = helpExecuteQuery();
- assertEquals(" hasNext() doesn't match expected value. ", true,
cs.hasNext()); //$NON-NLS-1$
- cs.close();
- }
-
- /** test hasNext() with blocking for the Next batch -- triggering point */
- @Test public void testHasNext2() throws SQLException {
- ResultSetImpl cs = helpExecuteQuery();
- cs.absolute(100);
- assertEquals(" hasNext() doesn't match expected value. ", true,
cs.hasNext()); //$NON-NLS-1$
- cs.close();
- }
-
- /** test hasNext() with nextBatch!=null -- short response */
- @Test public void testHasNext3() throws SQLException {
- ResultSetImpl cs = helpExecuteQuery();
- int i = 0;
- while (cs.next()) {
- if (i == 289) {
- break;
- }
- i++;
- }
- assertEquals(" hasNext() doesn't match expected value. ", true,
cs.hasNext()); //$NON-NLS-1$
- cs.close();
- }
-
- /** at the end of all batches */
- @Test public void testHasNext4() throws SQLException {
- ResultSetImpl cs = helpExecuteQuery();
- cs.absolute(1000);
- assertTrue(!cs.hasNext());
- cs.close();
- }
-
- /** walk all way through from the end back to first row */
- @Test public void testPrevious1() throws SQLException {
- ResultSetImpl cs = helpExecuteQuery();
- List[] expected = TestAllResultsImpl.exampleResults1(1000);
- while(cs.next()) {
- //System.out.println(" rs.next == " + cs.getCurrentRecord());
- }
- // cursor is after the last row. getRow() should return 0 when not on a valid
row
- assertEquals(" current row doesn't match expected value. ", 0,
cs.getRow()); //$NON-NLS-1$
-
- int i= 1000;
- while (cs.previous()) {
- //System.out.println(" rs.previous == " + cs.getCurrentRecord());
- assertEquals(" Actual doesn't match with expected. ",
expected[i-1], cs.getCurrentRecord()); //$NON-NLS-1$
- i--;
- }
- assertEquals(" current row doesn't match expected value. ", 0,
cs.getRow()); //$NON-NLS-1$
- cs.close();
- }
-
- /** test the previous in the middle of a batch */
- @Test public void testPrevious2() throws SQLException {
- ResultSetImpl cs = helpExecuteQuery();
- cs.absolute(290);
-
- // cursor is at the row of 289 now
- assertTrue(cs.previous());
- assertEquals(" current row doesn't match expected value. ", 289,
cs.getRow()); //$NON-NLS-1$
- cs.close();
- }
-
- /** walk all way through from the end back to first row */
- @Test public void testPrevious3() throws Exception {
- //large batch size
- ResultSetImpl cs = helpExecuteQuery(600, 10000,
ResultSet.TYPE_SCROLL_INSENSITIVE);
- List[] expected = TestAllResultsImpl.exampleResults1(10000);
- while(cs.next()) {
- }
- // cursor is after the last row. getRow() should return 0 when not on a valid
row
- assertEquals(" current row doesn't match expected value. ", 0,
cs.getRow()); //$NON-NLS-1$
-
- int i= 10000;
- while (cs.previous()) {
- //System.out.println(" rs.previous == " + cs.getCurrentRecord());
- assertEquals(" Actual doesn't match with expected. ",
expected[i-1], cs.getCurrentRecord()); //$NON-NLS-1$
- i--;
- }
- assertEquals(" current row doesn't match expected value. ", 0,
cs.getRow()); //$NON-NLS-1$
- cs.close();
- }
-
- /** walk all way through from the end back to first row */
- @Test public void testPrevious4() throws Exception {
- //small batch size
- ResultSetImpl cs = helpExecuteQuery(50, 1000,
ResultSet.TYPE_SCROLL_INSENSITIVE);
- List[] expected = TestAllResultsImpl.exampleResults1(1000);
- while(cs.next()) {
- //System.out.println(" rs.next == " + cs.getCurrentRecord());
- }
- // cursor is after the last row. getRow() should return 0 when not on a valid
row
- assertEquals(" current row doesn't match expected value. ", 0,
cs.getRow()); //$NON-NLS-1$
-
- int i= 1000;
- while (cs.previous()) {
- //System.out.println(" rs.previous == " + cs.getCurrentRecord());
- assertEquals(" Actual doesn't match with expected. ",
expected[i-1], cs.getCurrentRecord()); //$NON-NLS-1$
- i--;
- }
- assertEquals(" current row doesn't match expected value. ", 0,
cs.getRow()); //$NON-NLS-1$
- cs.close();
- }
-
- /** test rare case that cursor change direction */
- @Test public void testChangeDirection() throws SQLException {
- ResultSetImpl cs = helpExecuteQuery();
- cs.absolute(291);
- cs.previous();
-
- assertEquals(" current row doesn't match expected value. ", 290,
cs.getRow()); //$NON-NLS-1$
- cs.close();
- }
-
- @Test public void testIsFirst() throws SQLException {
- ResultSetImpl cs = helpExecuteQuery();
- cs.next();
- assertTrue(cs.isFirst());
- cs.close();
- }
-
- /** test cursor is in the middle of all batches */
- @Test public void testIsLast1() throws SQLException {
- ResultSetImpl cs = helpExecuteQuery();
- cs.next();
- assertTrue(!cs.isLast());
- cs.close();
- }
-
- /** test cursor at the triggering point -- blocking case*/
- @Test public void testIsLast2() throws SQLException {
- ResultSetImpl cs = helpExecuteQuery();
-
- int i = 0;
- while (cs.next()) {
- if (i == 99) {
- break;
- }
- i++;
- }
-
- assertTrue(!cs.isLast());
- cs.close();
- }
-
- /** test cursor at the last row of all batches */
- @Test public void testIsLast3() throws SQLException {
- ResultSetImpl cs = helpExecuteQuery();
- cs.absolute(1000);
- assertTrue(cs.isLast());
- cs.close();
- }
-
- @Test public void testIsBeforeFirst() throws SQLException {
- ResultSetImpl cs = helpExecuteQuery();
- assertTrue(cs.isBeforeFirst());
- cs.close();
- }
-
- @Test public void testBeforeFirst() throws SQLException {
- ResultSetImpl cs = helpExecuteQuery();
-
- // move to row 1
- cs.next();
- assertEquals(" Current row number doesn't match with expected
one.", 1, cs.getRow()); //$NON-NLS-1$
-
- // move back to before first row
- cs.beforeFirst();
- assertTrue(cs.isBeforeFirst());
- cs.close();
- }
-
- @Test public void testFirst() throws SQLException {
- ResultSetImpl cs = helpExecuteQuery();
-
- // move to row #2
- cs.next();
- cs.next();
- assertEquals(" Current row number doesn't match with expected
one.", 2, cs.getRow()); //$NON-NLS-1$
-
- // move back to the 1st row
- cs.first();
- assertEquals(" Current row number doesn't match with expected
one.", 1, cs.getRow()); //$NON-NLS-1$
- cs.close();
- }
-
- @Test public void testAfterLast() throws SQLException {
- ResultSetImpl cs = helpExecuteQuery();
- cs.afterLast();
- assertTrue(cs.isAfterLast());
- cs.close();
- }
-
- /** right after the last row */
- @Test public void testIsAfterLast1() throws SQLException {
- ResultSetImpl cs = helpExecuteQuery();
- cs.absolute(1000);
- cs.next();
- assertTrue(cs.isAfterLast());
- cs.close();
- }
-
- /** right before the first */
- @Test public void testIsAfterLast2() throws Exception {
- ResultSetImpl cs = helpExecuteQuery();
- assertTrue(!cs.isAfterLast());
- cs.close();
- }
-
- /** absolute with cursor movement backward in the same batch -- absolute(positive)
*/
- @Test public void testAbsolute1() throws SQLException {
- ResultSetImpl cs = helpExecuteQuery();
-
- // move to row #2
- cs.next();
- cs.next();
- assertEquals(" Current row number doesn't match with expected
one.", 2, cs.getRow()); //$NON-NLS-1$
-
- // move back to the 1st row
- cs.absolute(1);
- assertEquals(" Current row number doesn't match with expected
one.", 1, cs.getRow()); //$NON-NLS-1$
- cs.close();
- }
-
- /** absolute with cursor movement forward in the same batch -- absolute(positive) */
- @Test public void testAbsolute2() throws SQLException {
- ResultSetImpl cs = helpExecuteQuery();
-
- // move to row #2
- cs.next();
- cs.next();
- assertEquals(" Current row number doesn't match with expected
one.", 2, cs.getRow()); //$NON-NLS-1$
-
- // move back to the 1st row
- cs.absolute(3);
- assertEquals(" Current row number doesn't match with expected
one.", 3, cs.getRow()); //$NON-NLS-1$
- cs.close();
- }
-
- /** absolute with cursor movement forward -- absolute(positive) -- blocking */
- @Test public void testAbsolute3() throws SQLException {
- ResultSetImpl cs = helpExecuteQuery();
-
- // move to row #2
- cs.next();
- cs.next();
- assertEquals(" Current row number doesn't match with expected
one.", 2, cs.getRow()); //$NON-NLS-1$
-
- // move to row #100 -- blocking
- cs.absolute(100);
- assertEquals(" Current row number doesn't match with expected
one.", 100, cs.getRow()); //$NON-NLS-1$
- cs.close();
- }
-
- /** absolute with cursor movement forward -- absolute(positive) -- triggering point
*/
- @Test public void testAbsolute4() throws SQLException {
- ResultSetImpl cs = helpExecuteQuery();
-
- // move to row #2
- cs.next();
- cs.next();
- assertEquals(" Current row number doesn't match with expected
one.", 2, cs.getRow()); //$NON-NLS-1$
-
- // move to row #200 -- new batch
- cs.absolute(200);
- assertEquals(" Current row number doesn't match with expected
one.", 200, cs.getRow()); //$NON-NLS-1$
- cs.close();
- }
-
- /** absolute with cursor movement back in the same batch -- absolute(negative) */
- @Test public void testAbsolute5() throws SQLException {
- ResultSetImpl cs = helpExecuteQuery();
-
- // move to row #2
- cs.next();
- cs.next();
- assertEquals(" Current row number doesn't match with expected
one.", 2, cs.getRow()); //$NON-NLS-1$
-
- // move back to the 1st row
- cs.absolute(-1);
- assertEquals(" Current row number doesn't match with expected
one.", 1000, cs.getRow()); //$NON-NLS-1$
- cs.close();
- }
-
- /** absolute after last row */
- @Test public void testAbsolute6() throws SQLException {
- ResultSetImpl cs = helpExecuteQuery();
- cs.absolute(1005);
- // Cursor should be after last row. getRow() should return 0 because
- // cursor is not on a valid row
- assertEquals(" Current row number doesn't match with expected
one.", 0, cs.getRow()); //$NON-NLS-1$
- cs.close();
- }
-
- /** relative(positive) -- forward to another batch */
- @Test public void testRelative1() throws SQLException {
- ResultSetImpl cs = helpExecuteQuery();
-
- // move to the row #3
- cs.absolute(3);
- assertEquals(" Current row number doesn't match with expected
one.", 3, cs.getRow()); //$NON-NLS-1$
-
- // move to the row #140
- cs.relative(137);
- assertEquals(" Current row number doesn't match with expected
one.", 140, cs.getRow()); //$NON-NLS-1$
- cs.close();
- }
-
- /** relative(negative) -- backward to another batch */
- @Test public void testRelative2() throws SQLException {
- ResultSetImpl cs = helpExecuteQuery();
-
- // move to the row #137
- cs.absolute(137);
- assertEquals(" Current row number doesn't match with expected
one.", 137, cs.getRow()); //$NON-NLS-1$
-
- // move to the row #4
- cs.relative(-133);
- assertEquals(" Current row number doesn't match with expected
one.", 4, cs.getRow()); //$NON-NLS-1$
- cs.close();
- }
-
- /** relative(negative) -- backward to triggering point or blocking batch */
- @Test public void testRelative3() throws SQLException {
- ResultSetImpl cs = helpExecuteQuery();
-
- // move to the row #137
- cs.absolute(137);
- assertEquals(" Current row number doesn't match with expected
one.", 137, cs.getRow()); //$NON-NLS-1$
-
- // move to the row #100
- cs.relative(-37);
- assertEquals(" Current row number doesn't match with expected
one.", 100, cs.getRow()); //$NON-NLS-1$
- cs.close();
- }
-
- /** relative(negative) -- backward to triggering point or blocking batch */
- @Test public void testRelative4() throws SQLException {
- ResultSetImpl cs = helpExecuteQuery();
-
- // move to the row #237 in the third batch, so that the fourth batch has been
requested when we switch direction
- cs.absolute(237);
- assertEquals(" Current row number doesn't match with expected
one.", 237, cs.getRow()); //$NON-NLS-1$
-
- // move to the row #37
- cs.relative(-200);
- assertEquals(" Current row number doesn't match with expected
one.", 37, cs.getRow()); //$NON-NLS-1$
- cs.close();
- }
-
- /** in the first fetched batch */
- @Test public void testGetRow1() throws SQLException {
- ResultSet cs = helpExecuteQuery();
-
- int i = 0;
- while (cs.next()) {
- if (i == 102) {
- break;
- }
- i++;
- }
-
- assertEquals(" Current row number doesn't match with expected
one.", i+1, cs.getRow()); //$NON-NLS-1$
- cs.close();
- }
-
- /** in the first batch */
- @Test public void testGetRow2() throws SQLException {
- ResultSet cs = helpExecuteQuery();
-
- cs.next();
- assertEquals(" Current row number doesn't match with expected
one.", 1, cs.getRow()); //$NON-NLS-1$
- cs.close();
- }
-
- /** in the triggering point -- blocking */
- @Test public void testGetRow3() throws SQLException {
- ResultSet cs = helpExecuteQuery();
- int i = 0;
- while (cs.next()) {
- if (i == 99) {
- break;
- }
- i++;
- }
- assertEquals(" Current row number doesn't match with expected
one.", 100, cs.getRow()); //$NON-NLS-1$
- cs.close();
- }
-
- @Test public void testGetCurrentRecord() throws SQLException {
- ResultSet cs = helpExecuteQuery();
- cs.absolute(103);
- assertEquals(" Current record doesn't match with expected one.",
new Integer(103), ((ResultSetImpl)cs).getCurrentRecord().get(0));
//$NON-NLS-1$
- cs.close();
- }
-
- /** test close() without walking through any of the record*/
- @Test public void testClose() throws SQLException {
- ResultSetImpl cs = helpExecuteQuery();
- assertEquals(" Actual doesn't match with expected. ", new
Integer(0), new Integer(cs.getRow())); //$NON-NLS-1$
- cs.close();
- }
-
- /** test basic results-related metadata */
- @Test public void testGetMetaData() throws SQLException {
- ResultSetImpl cs = helpExecuteQuery();
-
- // check result set metadata
- // expected column info.
- List columnName = getBQTRSMetaData1a();
- List columnType = getBQTRSMetaData1b();
- List columnTypeName = getBQTRSMetaData1c();
-
- ResultSetMetaData rm = cs.getMetaData();
- assertNotNull(rm);
-
- for (int j = 1; j <= rm.getColumnCount(); j++) {
- assertEquals(" Actual doesn't match with expected. ",
columnName.get(j-1), rm.getColumnName(j)); //$NON-NLS-1$
- assertEquals(" Actual doesn't match with expected. ",
columnType.get(j-1), new Integer(rm.getColumnType(j))); //$NON-NLS-1$
- assertEquals(" Actual doesn't match with expected. ",
columnTypeName.get(j-1), rm.getColumnTypeName(j)); //$NON-NLS-1$
- }
-
- cs.close();
- }
-
- @Test public void testFindColumn() throws SQLException {
- ResultSetImpl cs = helpExecuteQuery();
- ResultSetMetaData rm = cs.getMetaData();
- assertNotNull(rm);
- //assertEquals(" Actual columnName doesn't match with expected. ",
1, cs.findColumn("BQT1.MediumA.IntKey"));
- assertEquals(" Actual columnName doesn't match with expected. ", 1,
cs.findColumn("IntKey")); //$NON-NLS-1$ //$NON-NLS-2$
- cs.close();
- }
-
- @Test public void testFindNonExistentColumn() throws SQLException {
- ResultSet rs = helpExecuteQuery();
- rs.next();
- try {
- rs.findColumn("BOGUS"); //$NON-NLS-1$
- } catch(SQLException e) {
- }
-
- try {
- rs.getObject("BOGUS"); //$NON-NLS-1$
- } catch(SQLException e) {
- }
- rs.close();
- }
-
- @Test public void testGetStatement() throws SQLException {
- ResultSetImpl cs = helpExecuteQuery();
- assertNotNull(cs.getStatement());
- cs.close();
- }
-
- @Test public void testGetPlanDescription() throws SQLException {
- ResultSetImpl cs = helpExecuteQuery();
- assertNotNull(cs);
-
- assertNull((cs.getStatement()).getPlanDescription());
- cs.close();
- }
-
- /** getObject(String) */
- @Test public void testGetObject2() throws SQLException {
- ResultSet cs = helpExecuteQuery();
-
- // move to the 1st row
- cs.next();
- assertEquals(" Actual value doesn't match with expected. ", new
Integer(1), cs.getObject("IntKey")); //$NON-NLS-1$ //$NON-NLS-2$
- cs.close();
- }
-
- @Test public void testGetWarnings() throws SQLException {
- ResultSet cs = helpExecuteQuery();
- assertNull(cs.getWarnings());
- cs.close();
- }
-
- @Test public void testGetCursorName() throws SQLException {
- ResultSetImpl cs = helpExecuteQuery();
- assertNull(cs.getCursorName());
- cs.close();
- }
-
- @Test public void testAllGetters() throws SQLException {
- ResultSetImpl cs = helpExecuteQuery();
- cs.next();
- assertEquals(" Actual value of getInt() doesn't match with expected one.
", 1, cs.getInt("IntKey")); //$NON-NLS-1$ //$NON-NLS-2$
- assertEquals(" Actual value of getString() doesn't match with expected
one. ", "1", cs.getString("IntKey")); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
-
- // Add these back when the MediumA has all those columns
- assertEquals(" Actual value of getFloat() doesn't match with expected
one. ", new Float(1), new Float(cs.getFloat("IntKey"))); //$NON-NLS-1$
//$NON-NLS-2$
- assertEquals(" Actual value of getLong() doesn't match with expected
one. ", 1, cs.getLong("IntKey")); //$NON-NLS-1$ //$NON-NLS-2$
- assertEquals(" Actual value of getDouble() doesn't match with expected
one. ", new Double(1), new Double(cs.getDouble("IntKey"))); //$NON-NLS-1$
//$NON-NLS-2$
- assertEquals(" Actual value of getByte() doesn't match with expected
one. ", (byte)1, cs.getByte("IntKey")); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /** test wasNull() for ResultSet, this result actually is not a cursor result, but
AllResults here. */
- @Test public void testWasNull() throws SQLException {
- ResultSet cs = helpExecuteQuery();
- cs.next();
- assertNotNull(cs.getObject("IntKey")); //$NON-NLS-1$
- assertFalse(cs.wasNull());
- }
-
- @Test public void testForwardOnly() throws Exception {
- ResultSetImpl cs = helpExecuteQuery(400, 1000, ResultSet.TYPE_FORWARD_ONLY);
-
- while (cs.next()) {
- cs.getObject(1);
- }
-
- assertTrue(cs.isAfterLast());
- cs.close();
- }
-
- @Test public void testOutputParameter() throws Exception {
- StatementImpl statement = createMockStatement(ResultSet.TYPE_FORWARD_ONLY);
- ResultsMessage resultsMsg = new ResultsMessage();
- resultsMsg.setResults(new List<?>[] {Arrays.asList(1, null, null),
Arrays.asList(null, 2, 3)});
- resultsMsg.setLastRow(2);
- resultsMsg.setFirstRow(1);
- resultsMsg.setFinalRow(2);
- resultsMsg.setColumnNames(new String[] {"x", "out1",
"out2"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- resultsMsg.setDataTypes(new String[] {"integer", "integer",
"integer"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- ResultSetImpl cs = new ResultSetImpl(resultsMsg, statement, null, 2);
-
- int count = 0;
- while (cs.next()) {
- cs.getObject(1);
- count++;
- }
- assertEquals(1, count);
- assertTrue(cs.isAfterLast());
- assertEquals(2, cs.getOutputParamValue(2));
- assertEquals(3, cs.getOutputParamValue(3));
- }
-
- /////////////////////// Helper Method ///////////////////
-
- private ResultSetImpl helpExecuteQuery() {
- try {
- return helpExecuteQuery(400, 1000, ResultSet.TYPE_SCROLL_INSENSITIVE);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- private ResultSetImpl helpExecuteQuery(int fetchSize, int totalResults, int
cursorType) throws SQLException, TeiidProcessingException, InterruptedException,
ExecutionException, TimeoutException {
- StatementImpl statement = createMockStatement(cursorType);
- return TestAllResultsImpl.helpTestBatching(statement, fetchSize, Math.min(fetchSize,
totalResults), totalResults);
- }
-
- static StatementImpl createMockStatement(int cursorType) throws SQLException {
- StatementImpl statement = mock(StatementImpl.class);
- stub(statement.getDQP()).toReturn(mock(DQP.class));
- stub(statement.getResultSetType()).toReturn(cursorType);
- TimeZone tz = TimeZone.getTimeZone("GMT-06:00"); //$NON-NLS-1$
- TimeZone serverTz = TimeZone.getTimeZone("GMT-05:00"); //$NON-NLS-1$
- stub(statement.getDefaultCalendar()).toReturn(Calendar.getInstance(tz));
- stub(statement.getServerTimeZone()).toReturn(serverTz);
- return statement;
- }
-
- ////////////////////////Expected Results////////////////
- /** column name */
- private List getBQTRSMetaData1a() {
- List results = new ArrayList();
- results.add("IntKey"); //$NON-NLS-1$
- return results;
- }
-
- /** column type */
- private List getBQTRSMetaData1b() {
- List results = new ArrayList();
- results.add(new Integer(Types.INTEGER));
- return results;
- }
-
- /** column type name*/
- private List getBQTRSMetaData1c() {
- List results = new ArrayList();
- results.add("integer"); //$NON-NLS-1$
- return results;
- }
-}
Deleted: trunk/client/src/test/java/org/teiid/jdbc/TestMMSQLException.java
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/TestMMSQLException.java 2010-06-17 16:09:26
UTC (rev 2239)
+++ trunk/client/src/test/java/org/teiid/jdbc/TestMMSQLException.java 2010-06-17 18:35:22
UTC (rev 2240)
@@ -1,234 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.jdbc;
-
-import java.io.IOException;
-import java.net.ConnectException;
-import java.net.MalformedURLException;
-import java.net.NoRouteToHostException;
-import java.net.SocketException;
-import java.net.SocketTimeoutException;
-import java.net.UnknownHostException;
-import java.sql.SQLException;
-
-import junit.framework.TestCase;
-
-import org.teiid.client.ProcedureErrorInstructionException;
-import org.teiid.core.TeiidProcessingException;
-import org.teiid.core.TeiidException;
-import org.teiid.core.TeiidException;
-import org.teiid.core.TeiidRuntimeException;
-import org.teiid.net.CommunicationException;
-import org.teiid.net.ConnectionException;
-
-
-public class TestMMSQLException extends TestCase {
-
- /*
- * Test method for 'com.metamatrix.jdbc.MMSQLException.MMSQLException()'
- */
- public void testMMSQLException() {
- TeiidSQLException e = new TeiidSQLException();
- String sqlState = e.getSQLState();
- Throwable cause = e.getCause();
- int errorCode = e.getErrorCode();
- Throwable nestedException = e.getCause();
- SQLException nextException = e.getNextException();
-
- assertTrue(
- "Expected MMSQLException.getSQLState() to return <null> but got
\"" //$NON-NLS-1$
- + sqlState + "\" instead.", sqlState == null); //$NON-NLS-1$
- assertTrue(
- "Expected MMSQLException.getCause() to return <null> but got ["
//$NON-NLS-1$
- + (cause != null ? cause.getClass().getName()
- : "<unknown>") + "] instead.", cause == null);
//$NON-NLS-1$ //$NON-NLS-2$
- assertTrue(
- "Expected MMSQLException.getErrorCode() to return [0] but got ["
//$NON-NLS-1$
- + errorCode + "] instead.", errorCode == 0); //$NON-NLS-1$
- assertTrue(
- "Expected MMSQLException.getNestedException() to return <null> but got
[" //$NON-NLS-1$
- + (nestedException != null ? nestedException.getClass()
- .getName() : "<unknown>") + "] instead.", //$NON-NLS-1$
//$NON-NLS-2$
- nestedException == null);
- assertTrue(
- "Expected MMSQLException.getNextException() to return <null> but got a
SQLException with message \"" //$NON-NLS-1$
- + (nextException != null ? nextException.getMessage()
- : "") + "\" instead.", nextException == null);
//$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /*
- * Test method for 'com.metamatrix.jdbc.MMSQLException.create(Throwable)'
- *
- * Tests various simple exceptions to see if the expected SQLState is
- * returend.
- */
- public void testCreateThrowable_01() {
- testCreateThrowable(new CommunicationException(
- "A test MM Communication Exception"), //$NON-NLS-1$
- SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
- testCreateThrowable(
- new ConnectException("A test connection attempt exception"), //$NON-NLS-1$
- SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
- testCreateThrowable(
- new ConnectionException("A test MM Connection Exception"), //$NON-NLS-1$
- SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
- testCreateThrowable(new IOException(
- "A test Generic java.io.IOException"), //$NON-NLS-1$
- SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
- testCreateThrowable(
- new MalformedURLException(
- "A test java.net.MalformedURLException"), //$NON-NLS-1$
- SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
- testCreateThrowable(new TeiidException(
- "A test Generic MM Core Exception"), SQLStates.DEFAULT); //$NON-NLS-1$
- testCreateThrowable(new TeiidException("A test MM Exception"), //$NON-NLS-1$
- SQLStates.DEFAULT);
- testCreateThrowable(new TeiidProcessingException(
- "A test Generic MM Query Processing Exception"), //$NON-NLS-1$
- SQLStates.USAGE_ERROR);
- testCreateThrowable(new TeiidRuntimeException(
- "A test MM Runtime Exception"), SQLStates.DEFAULT); //$NON-NLS-1$
- testCreateThrowable(new TeiidSQLException(
- "A test Generic MM SQL Exception"), SQLStates.DEFAULT); //$NON-NLS-1$
- testCreateThrowable(
- new NoRouteToHostException(
- "A test java.net.NoRouteToHostException"), //$NON-NLS-1$
- SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
- testCreateThrowable(new NullPointerException("A test NPE"), //$NON-NLS-1$
- SQLStates.DEFAULT);
- testCreateThrowable(new ProcedureErrorInstructionException(
- "A test SQL Procedure Error exception"), //$NON-NLS-1$
- SQLStates.VIRTUAL_PROCEDURE_ERROR);
- testCreateThrowable(new SocketTimeoutException(
- "A test socket timeout exception"), //$NON-NLS-1$
- SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
- testCreateThrowable(
- new UnknownHostException("A test connection attempt exception"),
//$NON-NLS-1$
- SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
- }
-
- /*
- * Test method for 'com.metamatrix.jdbc.MMSQLException.create(Throwable)'
- *
- * Tests various nested exceptions to see if the expected SQLState is
- * returend.
- */
- public void testCreateThrowable_02() {
- testCreateThrowable(
- new CommunicationException(new ConnectException(
- "A test java.net.ConnectException"), //$NON-NLS-1$
- "Test Communication Exception with a ConnectException in it"),
//$NON-NLS-1$
- SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
- testCreateThrowable(new CommunicationException(new SocketException(
- "A test java.net.SocketException"), //$NON-NLS-1$
- "Test Communication Exception with a SocketException in it"),
//$NON-NLS-1$
- SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
- testCreateThrowable(
- new TeiidException(new SocketTimeoutException(
- "A test java.net.SocketTimeoutException"), //$NON-NLS-1$
- "Test MetaMatrixException with a SocketTimeoutException in it"),
//$NON-NLS-1$
- SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
- }
-
- public void testCreateThrowable3() {
- TeiidSQLException e = testCreateThrowable(
- new TeiidException(
- new TeiidRuntimeException(
- new SocketTimeoutException(
- "A test MM Invalid Session
Exception"), //$NON-NLS-1$
- "Test MetaMatrixRuntimeException with a
InvalidSessionException in it"), //$NON-NLS-1$
- "Test MM Core Exception with an MM Runtime
Exception in it and an InvalidSessionException nested within"), //$NON-NLS-1$
- SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
-
- //test to ensure that wrapping mmsqlexceptions works
- TeiidSQLException e1 = TeiidSQLException.create(e, "new message");
//$NON-NLS-1$
- assertEquals("new message", e1.getMessage()); //$NON-NLS-1$
- testCreateThrowable(((TeiidSQLException)e1.getCause()).getCause(),
SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
- }
-
- /*
- * Helper method to test SQLState and general MMSQLException validation
- */
- private TeiidSQLException testCreateThrowable(Throwable ecause, String esqlState) {
- TeiidSQLException e = TeiidSQLException.create(ecause);
- if (ecause.getClass() == TeiidSQLException.class) {
- ecause = null;
- }
- String sqlState = e.getSQLState();
- Throwable cause = e.getCause();
- int errorCode = e.getErrorCode();
- Throwable nestedException = e.getCause();
- SQLException nextException = e.getNextException();
-
- assertTrue("Expected MMSQLException.getSQLState() to return \""
//$NON-NLS-1$
- + esqlState + "\" but got \"" + sqlState + "\"
instead.", //$NON-NLS-1$ //$NON-NLS-2$
- sqlState.compareTo(esqlState) == 0);
- assertTrue("Expected MMSQLException.getCause() to return [" //$NON-NLS-1$
- + (ecause != null ? ecause.getClass().getName() : "<null>")
//$NON-NLS-1$
- + "] but got [" //$NON-NLS-1$
- + (cause != null ? cause.getClass().getName() : "<unknown>")
//$NON-NLS-1$
- + "] instead.", cause == ecause); //$NON-NLS-1$
- assertTrue(
- "Expected MMSQLException.getErrorCode() to return [0] but got ["
//$NON-NLS-1$
- + errorCode + "] instead.", errorCode == 0); //$NON-NLS-1$
- assertTrue("Expected MMSQLException.getNestedException() to return ["
//$NON-NLS-1$
- + (ecause != null ? ecause.getClass().getName() : "<null>")
//$NON-NLS-1$
- + "] but got [" //$NON-NLS-1$
- + (nestedException != null ? nestedException.getClass()
- .getName() : "<unknown>") + "] instead.", //$NON-NLS-1$
//$NON-NLS-2$
- nestedException == ecause);
- assertTrue(
- "Expected MMSQLException.getNextException() to return <null> but got a
SQLException with message \"" //$NON-NLS-1$
- + (nextException != null ? nextException.getMessage()
- : "") + "\" instead.", nextException == null);
//$NON-NLS-1$ //$NON-NLS-2$
- return e;
- }
-
- public void testCreate() {
- TeiidSQLException exception = TeiidSQLException.create(new Exception());
-
- assertEquals(exception.getMessage(), Exception.class.getName());
- assertNotNull(exception.getSQLState());
- assertEquals(exception.getSQLState(), "38000"); //$NON-NLS-1$
-
- assertEquals(exception, TeiidSQLException.create(exception));
- }
-
- public void testCreateFromSQLException() {
- SQLException sqlexception = new SQLException("foo", "21");
//$NON-NLS-1$ //$NON-NLS-2$
-
- SQLException nested = new SQLException("bar"); //$NON-NLS-1$
-
- sqlexception.setNextException(nested);
-
- String message = "top level message"; //$NON-NLS-1$
-
- TeiidSQLException exception = TeiidSQLException.create(sqlexception, message);
-
- assertEquals(exception.getMessage(), message);
- assertEquals(exception.getSQLState(), sqlexception.getSQLState());
- assertEquals(exception.getNextException().getMessage(),
sqlexception.getMessage());
- assertEquals(exception.getNextException().getNextException().getMessage(),
nested.getMessage());
- }
-
-}
Deleted: trunk/client/src/test/java/org/teiid/jdbc/TestMMStatement.java
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/TestMMStatement.java 2010-06-17 16:09:26 UTC
(rev 2239)
+++ trunk/client/src/test/java/org/teiid/jdbc/TestMMStatement.java 2010-06-17 18:35:22 UTC
(rev 2240)
@@ -1,88 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.jdbc;
-
-import static org.junit.Assert.*;
-
-import java.sql.ResultSet;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Properties;
-
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.teiid.client.DQP;
-import org.teiid.client.RequestMessage;
-import org.teiid.client.ResultsMessage;
-import org.teiid.client.util.ResultsFuture;
-import org.teiid.jdbc.ConnectionImpl;
-import org.teiid.jdbc.TeiidSQLException;
-import org.teiid.jdbc.StatementImpl;
-
-
-public class TestMMStatement {
-
- @Test(expected=TeiidSQLException.class) public void testUpdateException() throws
Exception {
- StatementImpl statement = new StatementImpl(Mockito.mock(ConnectionImpl.class),
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
- statement.executeQuery("delete from table"); //$NON-NLS-1$
- }
-
- @Test public void testBatchExecution() throws Exception {
- ConnectionImpl conn = Mockito.mock(ConnectionImpl.class);
- DQP dqp = Mockito.mock(DQP.class);
- ResultsFuture<ResultsMessage> results = new
ResultsFuture<ResultsMessage>();
- Mockito.stub(dqp.executeRequest(Mockito.anyLong(),
(RequestMessage)Mockito.anyObject())).toReturn(results);
- ResultsMessage rm = new ResultsMessage();
- rm.setResults(new List<?>[] {Arrays.asList(1), Arrays.asList(2)});
- rm.setUpdateResult(true);
- results.getResultsReceiver().receiveResults(rm);
- Mockito.stub(conn.getDQP()).toReturn(dqp);
- StatementImpl statement = new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY);
- statement.addBatch("delete from table"); //$NON-NLS-1$
- statement.addBatch("delete from table1"); //$NON-NLS-1$
- assertTrue(Arrays.equals(new int[] {1, 2}, statement.executeBatch()));
- }
-
- @Test public void testSetStatement() throws Exception {
- ConnectionImpl conn = Mockito.mock(ConnectionImpl.class);
- Properties p = new Properties();
- Mockito.stub(conn.getConnectionProperties()).toReturn(p);
- StatementImpl statement = new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY);
- assertFalse(statement.execute("set foo bar")); //$NON-NLS-1$
- assertEquals("bar", p.get("foo")); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- @Test public void testPropertiesOverride() throws Exception {
- ConnectionImpl conn = Mockito.mock(ConnectionImpl.class);
- Properties p = new Properties();
- p.setProperty(ExecutionProperties.ANSI_QUOTED_IDENTIFIERS, Boolean.TRUE.toString());
- Mockito.stub(conn.getConnectionProperties()).toReturn(p);
- StatementImpl statement = new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY);
- assertEquals(Boolean.TRUE.toString(),
statement.getExecutionProperty(ExecutionProperties.ANSI_QUOTED_IDENTIFIERS));
- statement.setExecutionProperty(ExecutionProperties.ANSI_QUOTED_IDENTIFIERS,
Boolean.FALSE.toString());
- assertEquals(Boolean.FALSE.toString(),
statement.getExecutionProperty(ExecutionProperties.ANSI_QUOTED_IDENTIFIERS));
- assertEquals(Boolean.TRUE.toString(),
p.getProperty(ExecutionProperties.ANSI_QUOTED_IDENTIFIERS));
- }
-
-
-}
Deleted: trunk/client/src/test/java/org/teiid/jdbc/TestMMXAConnection.java
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/TestMMXAConnection.java 2010-06-17 16:09:26
UTC (rev 2239)
+++ trunk/client/src/test/java/org/teiid/jdbc/TestMMXAConnection.java 2010-06-17 18:35:22
UTC (rev 2240)
@@ -1,72 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.jdbc;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-
-import javax.transaction.xa.XAResource;
-
-import org.teiid.client.xa.XidImpl;
-import org.teiid.jdbc.ConnectionImpl;
-import org.teiid.jdbc.StatementImpl;
-import org.teiid.jdbc.XAConnectionImpl;
-
-import junit.framework.TestCase;
-
-
-
-public class TestMMXAConnection extends TestCase {
-
- public void testConnectionClose() throws Exception {
-
- final ConnectionImpl mmConn = TestMMConnection.getMMConnection();
-
- XAConnectionImpl xaConn = new XAConnectionImpl(new XAConnectionImpl.ConnectionSource()
{
- //## JDBC4.0-begin ##
- @Override
- //## JDBC4.0-end ##
- public ConnectionImpl createConnection() throws SQLException {
- return mmConn;
- }
- });
-
- Connection conn = xaConn.getConnection();
- StatementImpl stmt = (StatementImpl)conn.createStatement();
- conn.setAutoCommit(false);
- conn.close();
-
- assertTrue(stmt.isClosed());
- assertTrue(conn.getAutoCommit());
-
- conn = xaConn.getConnection();
- stmt = (StatementImpl)conn.createStatement();
- XAResource resource = xaConn.getXAResource();
- resource.start(new XidImpl(1, new byte[0], new byte[0]), XAResource.TMNOFLAGS);
- conn.close();
-
- assertTrue(stmt.isClosed());
- assertTrue(conn.getAutoCommit());
- }
-
-}
Copied: trunk/client/src/test/java/org/teiid/jdbc/TestPreparedStatement.java (from rev
2238, trunk/client/src/test/java/org/teiid/jdbc/TestMMPreparedStatement.java)
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/TestPreparedStatement.java
(rev 0)
+++ trunk/client/src/test/java/org/teiid/jdbc/TestPreparedStatement.java 2010-06-17
18:35:22 UTC (rev 2240)
@@ -0,0 +1,343 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.jdbc;
+
+import static org.junit.Assert.*;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.TimeZone;
+
+import org.junit.Test;
+import org.mockito.Matchers;
+import org.mockito.Mockito;
+import org.teiid.client.DQP;
+import org.teiid.client.RequestMessage;
+import org.teiid.client.ResultsMessage;
+import org.teiid.client.RequestMessage.ResultsMode;
+import org.teiid.client.security.LogonResult;
+import org.teiid.client.util.ResultsFuture;
+import org.teiid.jdbc.ConnectionImpl;
+import org.teiid.jdbc.PreparedStatementImpl;
+import org.teiid.jdbc.TeiidSQLException;
+import org.teiid.net.ServerConnection;
+
+
+/**
+ * Test case to validate general operations on an <code>MMPreparedStatement
+ * </code>
+ */
+public class TestPreparedStatement {
+
+ /**
+ * Test that <code>MMPreparedStatement</code>'s
<code>execute()</code> method
+ * will throw a <code>MMSQLException</code> if a connection does not exist.
+ *
+ * @throws Exception
+ */
+ @Test(expected=TeiidSQLException.class) public void testUpdateException() throws
Exception {
+ PreparedStatementImpl statement = getMMPreparedStatement("delete from
table"); //$NON-NLS-1$
+ statement.execute();
+ }
+
+ /**
+ * Verify that the <code>executeBatch()</code> method of <code>
+ * MMPreparedStatement</code> is resulting in the correct command,
+ * parameter values for each command of the batch, and the request type
+ * are being set in the request message that would normally be sent to the
+ * server.
+ *
+ * @throws Exception
+ */
+ @Test public void testBatchedUpdateExecution() throws Exception {
+ // Build up a fake connection instance for use with the prepared statement
+ ConnectionImpl conn = Mockito.mock(ConnectionImpl.class);
+ DQP dqp = Mockito.mock(DQP.class);
+ ServerConnection serverConn = Mockito.mock(ServerConnection.class);
+ LogonResult logonResult = Mockito.mock(LogonResult.class);
+
+ // stub methods
+ Mockito.stub(conn.getServerConnection()).toReturn(serverConn);
+ Mockito.stub(serverConn.getLogonResult()).toReturn(logonResult);
+ Mockito.stub(logonResult.getTimeZone()).toReturn(TimeZone.getDefault());
+
+ // a dummy result message that is specific to this test case
+ ResultsFuture<ResultsMessage> results = new
ResultsFuture<ResultsMessage>();
+ Mockito.stub(dqp.executeRequest(Matchers.anyLong(),
(RequestMessage)Matchers.anyObject())).toReturn(results);
+ ResultsMessage rm = new ResultsMessage();
+ rm.setResults(new List<?>[] {Arrays.asList(0), Arrays.asList(0),
Arrays.asList(0)});
+ rm.setUpdateResult(true);
+ results.getResultsReceiver().receiveResults(rm);
+ Mockito.stub(conn.getDQP()).toReturn(dqp);
+
+ // some update SQL
+ String sqlCommand = "delete from table where col=?"; //$NON-NLS-1$
+ TestableMMPreparedStatement statement = (TestableMMPreparedStatement)
getMMPreparedStatement(conn, sqlCommand);
+
+ ArrayList<ArrayList<Object>> expectedParameterValues = new
ArrayList<ArrayList<Object>>(3);
+ // Add some batches and their parameter values
+ expectedParameterValues.add( new ArrayList<Object>( Arrays.asList( new Object[] {
new Integer(1) } ) ) );
+ statement.setInt(1, new Integer(1));
+ statement.addBatch();
+ expectedParameterValues.add( new ArrayList<Object>( Arrays.asList( new Object[] {
new Integer(2) } ) ) );
+ statement.setInt(1, new Integer(2));
+ statement.addBatch();
+ expectedParameterValues.add( new ArrayList<Object>( Arrays.asList( new Object[] {
new Integer(3) } ) ) );
+ statement.setInt(1, new Integer(3));
+ statement.addBatch();
+
+ // execute the batch and verify that it matches our dummy results
+ // message set earlier
+ assertTrue(Arrays.equals(new int[] {0, 0, 0}, statement.executeBatch()));
+
+ // Now verify the statement's RequestMessage is what we expect
+ assertEquals("Command does not match", sqlCommand,
statement.requestMessage.getCommandString()); //$NON-NLS-1$
+ assertEquals("Parameter values do not match", expectedParameterValues,
statement.requestMessage.getParameterValues()); //$NON-NLS-1$
+ assertTrue("RequestMessage.isBatchedUpdate should be true",
statement.requestMessage.isBatchedUpdate()); //$NON-NLS-1$
+ assertFalse("RequestMessage.isCallableStatement should be false",
statement.requestMessage.isCallableStatement()); //$NON-NLS-1$
+ assertTrue("RequestMessage.isPreparedStatement should be true",
statement.requestMessage.isPreparedStatement()); //$NON-NLS-1$
+ }
+
+ /**
+ * Verify that the <code>clearBatch()</code> method of
+ * <code>MMPreparedStatement</code> is clearing the list of batched
+ * commands.
+ * <p>
+ * This is done by first adding command parameter values to the batch and
+ * then invoking the <code>clearBatch()</code> method.
+ *
+ * @throws Exception
+ */
+ @Test public void testClearBatch() throws Exception {
+ PreparedStatementImpl statement = getMMPreparedStatement("delete from table where
col=?"); //$NON-NLS-1$
+ // Add some stuff
+ statement.setInt(1, new Integer(1));
+ statement.addBatch();
+ statement.setInt(1, new Integer(2));
+ statement.addBatch();
+ // Make sure something is really there
+ assertTrue("MMPreparedStatement.ParameterValuesList should not be empty",
statement.getParameterValuesList().size() > 0); //$NON-NLS-1$
+ // Now clear it
+ statement.clearBatch();
+ assertTrue("MMPreparedStatement.ParameterValuesList should be empty",
statement.getParameterValuesList().size() == 0); //$NON-NLS-1$
+ }
+
+ /**
+ * Adds additional batches of command parameter values to a prepared
+ * statement after a previous list has been cleared.
+ * <p>
+ * This is done by first adding command parameter values to the batch and
+ * then invoking the <code>clearBatch()</code> method. Then a different
+ * set of command parameter values are added to the existing batch command.
+ * <p>
+ * The expected result is the command parameter list for the batches will
+ * only reflect what was added after <code>clearBatch()</code> was invoked.
+ *
+ * @throws Exception
+ */
+ @Test public void testClearBatchAddBatch() throws Exception {
+ PreparedStatementImpl statement = getMMPreparedStatement("delete from table where
col=?"); //$NON-NLS-1$
+
+ statement.setInt(1, new Integer(1));
+ statement.addBatch();
+ statement.setInt(1, new Integer(2));
+ statement.addBatch();
+ // Make sure something is really there
+ assertTrue("MMPreparedStatement.ParameterValuesList should not be empty",
statement.getParameterValuesList().size() > 0); //$NON-NLS-1$
+ // Now clear it
+ statement.clearBatch();
+ // Make sure it is empty now
+ assertTrue("MMPreparedStatement.ParameterValuesList should be empty",
statement.getParameterValuesList().size() == 0); //$NON-NLS-1$
+
+ ArrayList<ArrayList<Object>> expectedParameterValues = new
ArrayList<ArrayList<Object>>(1);
+
+ // Now add something for validation
+ expectedParameterValues.add( new ArrayList<Object>( Arrays.asList( new Object[] {
new Integer(5) } ) ) );
+ statement.setInt(1, new Integer(5));
+ statement.addBatch();
+ assertEquals("MMPreparedStatement.ParameterValuesList does not match",
expectedParameterValues, statement.getParameterValuesList()); //$NON-NLS-1$
+ }
+
+ /**
+ * Test the <code>addBatch()</code> method of
<code>MMPreparedStatement</code>
+ * to verify that the command parameter values of the batch are added to the
+ * command parameter values list.
+ *
+ * @throws Exception
+ */
+ @Test public void testAddBatch() throws Exception {
+ PreparedStatementImpl statement = getMMPreparedStatement("delete from table where
col=?"); //$NON-NLS-1$
+
+ ArrayList<ArrayList<Object>> expectedParameterValues = new
ArrayList<ArrayList<Object>>(1);
+
+ // First we add a single batch
+ expectedParameterValues.add( new ArrayList<Object>( Arrays.asList( new Object[] {
new Integer(1) } ) ) );
+ statement.setInt(1, new Integer(1));
+ statement.addBatch();
+ assertEquals("MMPreparedStatement.ParameterValuesList does not match",
expectedParameterValues, statement.getParameterValuesList()); //$NON-NLS-1$
+
+ // Now add some more batches just for sanity sake
+ expectedParameterValues.add( new ArrayList<Object>( Arrays.asList( new Object[] {
new Integer(3) } ) ) );
+ expectedParameterValues.add( new ArrayList<Object>( Arrays.asList( new Object[] {
new Integer(5) } ) ) );
+ statement.setInt(1, new Integer(3));
+ statement.addBatch();
+ statement.setInt(1, new Integer(5));
+ statement.addBatch();
+ assertEquals("MMPreparedStatement.ParameterValuesList does not match",
expectedParameterValues, statement.getParameterValuesList()); //$NON-NLS-1$
+ }
+
+ /**
+ * Test the <code>addBatch()</code> method of
<code>MMPreparedStatement</code>
+ * using a batch with an empty parameter value list. The test will verify
+ * no failures occur when there are no command parameter values defined
+ * when the <code>addBatch()</code> method is invoked.
+ * <p>
+ * It is valid to add an empty parameter value list to a batch list.
+ * <p>
+ * For example:
+ * <p>
+ * <code>PreparedStatement stmt = conn.prepareStatement(sql);<br \>
+ * stmt.addBatch();<br \>
+ * stmt.addBatch();<br \>
+ * stmt.executeBatch();</code>
+ *
+ * @throws Exception
+ */
+ @Test public void testAddBatchNoParameterValues() throws Exception {
+ PreparedStatementImpl statement = getMMPreparedStatement("delete from table where
col=?"); //$NON-NLS-1$
+
+ // This will hold our expected values list
+ ArrayList<ArrayList<Object>> expectedParameterValues = new
ArrayList<ArrayList<Object>>(1);
+
+ // First batch has an empty parameter value list
+ expectedParameterValues.add( new ArrayList<Object>(Collections.emptyList()) );
+
+ // No values have been set so we are adding a batch with an empty
+ // parameter value list
+ statement.addBatch();
+
+ // Second batch contains a parameter value list
+ expectedParameterValues.add( new ArrayList<Object>( Arrays.asList( new Object[] {
new Integer(1) } ) ) );
+
+ // We now are adding a batch that does have parameter values
+ statement.setInt(1, new Integer(1));
+ statement.addBatch();
+
+ // Check to see if our statement contains our expected parameter value list
+ assertEquals("MMPreparedStatement.ParameterValuesList does not match",
expectedParameterValues, statement.getParameterValuesList()); //$NON-NLS-1$
+ }
+
+ /**
+ * A helper method to get an <code>MMPreparedStatement</code> that can be
+ * used for simple test cases.
+ * <p>
+ * The returned value is an instance of
<code>TestableMMPreparedStatement</code>
+ * <p>
+ * This method invokes <code>getMMPreparedStatement(final MMConnection conn,
+ * final String sql)</code> with a fake connection object constructed by
+ * <code>Mockito</code>.
+ *
+ * @param sql the query for the prepared statement
+ * @return an instance of TestableMMPreparedStatement
+ * @throws SQLException
+ */
+ protected PreparedStatementImpl getMMPreparedStatement(final String sql) throws
SQLException {
+ ConnectionImpl conn = Mockito.mock(ConnectionImpl.class);
+ ServerConnection serverConn = Mockito.mock(ServerConnection.class);
+ LogonResult logonResult = Mockito.mock(LogonResult.class);
+
+ Mockito.stub(conn.getServerConnection()).toReturn(serverConn);
+ Mockito.stub(serverConn.getLogonResult()).toReturn(logonResult);
+ Mockito.stub(logonResult.getTimeZone()).toReturn(TimeZone.getDefault());
+
+ return getMMPreparedStatement(conn, sql);
+ }
+
+ /**
+ * A helper method to get an <code>MMPreparedStatement</code> that can be
+ * used for simple test cases.
+ * <p>
+ * The returned value is an instance of
<code>TestableMMPreparedStatement</code>
+ * <p>
+ * <code>conn</code> should be a valid instance of
<code>MMConnection</code>
+ * or this method will fail.
+ *
+ * @param conn an instance of <code>MMConnection</code>
+ * @param sql the query for the prepared statement
+ * @return an instance of TestableMMPreparedStatement
+ * @throws SQLException
+ */
+ protected PreparedStatementImpl getMMPreparedStatement(final ConnectionImpl conn, final
String sql) throws SQLException {
+ TestableMMPreparedStatement statement = new TestableMMPreparedStatement(conn, sql,
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
+
+ // Make sure everything is empty on start
+ assertTrue("MMPreparedStatement.ParameterValuesList should be empty",
statement.getParameterValuesList().size() == 0); //$NON-NLS-1$
+ assertTrue("MMPreparedStatement.ParameterValues should be empty",
statement.getParameterValues().size() == 0); //$NON-NLS-1$
+
+ return statement;
+ }
+
+ /**
+ * Represents an extension to <code>MMPreparedStatement</code> that
+ * gives access to the <code>RequestMessage</code> that is passed
+ * around inside <code>MMPreparedStatement</code>.
+ * <p>
+ * This extension simply adds a field named <code>requestMessage</code>
+ * which is <code>public</code>. This field gets set when the
<code>protected</code>
+ * method <code>createRequestMessage()</code> is called.
+ * <p>
+ * This extension also overrides <code>RequestMessage
createRequestMessage(String[] commands,
+ * boolean isBatchedCommand, Boolean requiresResultSet)</code> so that
+ * reference to the created <code>RequestMessage</code> can be retained in
+ * the field <code>requestMessage</code>.
+ */
+ class TestableMMPreparedStatement extends PreparedStatementImpl {
+ /**
+ * Contains a reference to the <code>RequestMessage</code> created by
+ * a call to <code>createRequestMessage(String[] commands,
+ * boolean isBatchedCommand, Boolean requiresResultSet)</code>. This
+ * will allow easy access to the prepared statement's request message
+ * generated by a call to one of the statement's execute methods.
+ */
+ public RequestMessage requestMessage;
+ @Override
+ protected RequestMessage createRequestMessage(String[] commands,
+ boolean isBatchedCommand, ResultsMode resultsMode) {
+ this.requestMessage = super
+ .createRequestMessage(commands, isBatchedCommand, resultsMode);
+ return this.requestMessage;
+ }
+
+ public TestableMMPreparedStatement(ConnectionImpl connection,
+ String sql, int resultSetType, int resultSetConcurrency)
+ throws SQLException {
+ super(connection, sql, resultSetType, resultSetConcurrency);
+ }
+
+ }
+
+}
Property changes on: trunk/client/src/test/java/org/teiid/jdbc/TestPreparedStatement.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied: trunk/client/src/test/java/org/teiid/jdbc/TestResultSet.java (from rev 2238,
trunk/client/src/test/java/org/teiid/jdbc/TestMMResultSet.java)
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/TestResultSet.java
(rev 0)
+++ trunk/client/src/test/java/org/teiid/jdbc/TestResultSet.java 2010-06-17 18:35:22 UTC
(rev 2240)
@@ -0,0 +1,777 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.jdbc;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+
+import java.nio.charset.Charset;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.List;
+import java.util.TimeZone;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeoutException;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.teiid.client.DQP;
+import org.teiid.client.ResultsMessage;
+import org.teiid.client.lob.LobChunk;
+import org.teiid.client.util.ResultsFuture;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.core.types.XMLType;
+
+@SuppressWarnings("nls")
+public class TestResultSet {
+
+ /** test next() without walking through */
+ @Test public void testNext1() throws SQLException {
+ ResultSet cs = helpExecuteQuery();
+ assertEquals(" Actual doesn't match with expected. ", new
Integer(0), new Integer(cs.getRow())); //$NON-NLS-1$
+ cs.close();
+ }
+
+ /** test next() with walking through all the rows and compare records */
+ @Test public void testNext2() throws SQLException {
+ List[] expected = TestAllResultsImpl.exampleResults1(1000);
+ ResultSetImpl cs = helpExecuteQuery();
+
+ int i=0;
+ while(cs.next()) {
+ assertEquals(" Actual doesn't match with expected. ",
expected[i], cs.getCurrentRecord()); //$NON-NLS-1$
+ i++;
+ }
+
+ cs.close();
+ }
+
+ /** test with LargeA -- only work with real model rather than fake metadata*/
+
+ // Note for all the following: processor batch size is 100,
+ // so some of these tests check what happens when the client
+ // fetch size is above, the same, or below it
+ public static final int PROC_BATCH_SIZE = 100;
+
+ /** Test stability when next() is called beyond the rowcount. */
+ @Test public void testNextBeyondEnd_fetchEqualsCount() throws Exception {
+ helpTestNextBeyondResultSet(1000, 1000);
+ }
+
+ /** Test stability when next() is called beyond the rowcount. */
+ @Test public void testNextBeyondEnd_fetchLessThanCount() throws Exception {
+ helpTestNextBeyondResultSet(100, 1000);
+ }
+
+ /** Test stability when next() is called beyond the rowcount with one more row. */
+ @Test public void testNextBeyondEnd_fetchLessThanCount1() throws Exception {
+ helpTestNextBeyondResultSet(100, 101);
+ }
+
+ /** Test stability when next() is called beyond the rowcount. */
+ @Test public void testNextBeyondEnd_fetchLessThanCountNonMultiple() throws Exception
{
+ helpTestNextBeyondResultSet(120, 1000);
+ }
+
+ /** Test stability when next() is called beyond the rowcount. */
+ @Test public void testNextBeyondEnd_fetchGreaterThanCount() throws Exception {
+ helpTestNextBeyondResultSet(300, PROC_BATCH_SIZE);
+ }
+
+ /** Test stability when next() is called beyond the rowcount. */
+ @Test public void testNextBeyondEnd_fetchGreaterThanCountNonMultiple() throws
Exception {
+ helpTestNextBeyondResultSet(310, PROC_BATCH_SIZE-50);
+ }
+
+ /** Test stability when next() is called beyond the rowcount. */
+ @Test public void testNextBeyondEnd_fetchGreaterThanCountNonMultiple2() throws
Exception {
+ helpTestNextBeyondResultSet(300, PROC_BATCH_SIZE+10);
+ }
+
+ /** Test that the returned results walks through all results if
+ * fetchSize < rows < proc batch size.
+ * Test for defect 11356
+ */
+ @Test public void
testNextBeyondEnd_fetchLessThanCount_ResultsBetweenFetchAndProcBatch() throws Exception {
+ helpTestNextBeyondResultSet(30, PROC_BATCH_SIZE-25);
+ }
+
+ public void helpTestNextBeyondResultSet(int fetchSize, int numRows) throws Exception
{
+ ResultSet cs = helpExecuteQuery(fetchSize, numRows,
ResultSet.TYPE_SCROLL_INSENSITIVE);
+ try {
+ Object lastRowValue = null;
+ for (int rowNum = 1; rowNum <= numRows; rowNum++) {
+ assertEquals("Should return true before end cs.next()", true,
cs.next()); //$NON-NLS-1$
+ }
+
+ lastRowValue = cs.getObject(1);
+
+ // Should just return false and leave cursor where it is
+ for(int i=numRows+1; i<numRows+4; i++) {
+ assertEquals("Should return false when going past the end: " +
i, false, cs.next()); //$NON-NLS-1$
+ assertEquals("Is after last should be true: " + i, true,
cs.isAfterLast()); //$NON-NLS-1$
+ }
+
+ // Should still be just after last row
+ cs.previous();
+ assertEquals("Is last should be true", true, cs.isLast());
//$NON-NLS-1$
+ assertEquals("Not on last row", lastRowValue, cs.getObject(1));
//$NON-NLS-1$
+
+ } finally {
+ cs.close();
+ }
+ }
+
+ /** test both next() and previous() -- when result set scroll in bidirection */
+ @Test public void testBidirection() throws SQLException {
+ ResultSetImpl cs = helpExecuteQuery();
+ assertNotNull(cs);
+ cs.absolute(290);
+ assertEquals(" Actual value doesn't match with expected one.", new
Integer(290), cs.getCurrentRecord().get(0)); //$NON-NLS-1$
+ cs.next();
+ assertEquals(" Actual value doesn't match with expected one.", new
Integer(291), cs.getCurrentRecord().get(0)); //$NON-NLS-1$
+ cs.next();
+ assertEquals(" Actual value doesn't match with expected one.", new
Integer(292), cs.getCurrentRecord().get(0)); //$NON-NLS-1$
+ cs.previous();
+ assertEquals(" Actual value doesn't match with expected one.", new
Integer(291), cs.getCurrentRecord().get(0)); //$NON-NLS-1$
+ cs.next();
+ assertEquals(" Actual value doesn't match with expected one.", new
Integer(292), cs.getCurrentRecord().get(0)); //$NON-NLS-1$
+ cs.close();
+ }
+
+ /** test hasNext() without walking through any row */
+ @Test public void testHasNext1() throws SQLException {
+ ResultSetImpl cs = helpExecuteQuery();
+ assertEquals(" hasNext() doesn't match expected value. ", true,
cs.hasNext()); //$NON-NLS-1$
+ cs.close();
+ }
+
+ /** test hasNext() with blocking for the Next batch -- triggering point */
+ @Test public void testHasNext2() throws SQLException {
+ ResultSetImpl cs = helpExecuteQuery();
+ cs.absolute(100);
+ assertEquals(" hasNext() doesn't match expected value. ", true,
cs.hasNext()); //$NON-NLS-1$
+ cs.close();
+ }
+
+ /** test hasNext() with nextBatch!=null -- short response */
+ @Test public void testHasNext3() throws SQLException {
+ ResultSetImpl cs = helpExecuteQuery();
+ int i = 0;
+ while (cs.next()) {
+ if (i == 289) {
+ break;
+ }
+ i++;
+ }
+ assertEquals(" hasNext() doesn't match expected value. ", true,
cs.hasNext()); //$NON-NLS-1$
+ cs.close();
+ }
+
+ /** at the end of all batches */
+ @Test public void testHasNext4() throws SQLException {
+ ResultSetImpl cs = helpExecuteQuery();
+ cs.absolute(1000);
+ assertTrue(!cs.hasNext());
+ cs.close();
+ }
+
+ /** walk all way through from the end back to first row */
+ @Test public void testPrevious1() throws SQLException {
+ ResultSetImpl cs = helpExecuteQuery();
+ List[] expected = TestAllResultsImpl.exampleResults1(1000);
+ while(cs.next()) {
+ //System.out.println(" rs.next == " + cs.getCurrentRecord());
+ }
+ // cursor is after the last row. getRow() should return 0 when not on a valid
row
+ assertEquals(" current row doesn't match expected value. ", 0,
cs.getRow()); //$NON-NLS-1$
+
+ int i= 1000;
+ while (cs.previous()) {
+ //System.out.println(" rs.previous == " + cs.getCurrentRecord());
+ assertEquals(" Actual doesn't match with expected. ",
expected[i-1], cs.getCurrentRecord()); //$NON-NLS-1$
+ i--;
+ }
+ assertEquals(" current row doesn't match expected value. ", 0,
cs.getRow()); //$NON-NLS-1$
+ cs.close();
+ }
+
+ /** test the previous in the middle of a batch */
+ @Test public void testPrevious2() throws SQLException {
+ ResultSetImpl cs = helpExecuteQuery();
+ cs.absolute(290);
+
+ // cursor is at the row of 289 now
+ assertTrue(cs.previous());
+ assertEquals(" current row doesn't match expected value. ", 289,
cs.getRow()); //$NON-NLS-1$
+ cs.close();
+ }
+
+ /** walk all way through from the end back to first row */
+ @Test public void testPrevious3() throws Exception {
+ //large batch size
+ ResultSetImpl cs = helpExecuteQuery(600, 10000,
ResultSet.TYPE_SCROLL_INSENSITIVE);
+ List[] expected = TestAllResultsImpl.exampleResults1(10000);
+ while(cs.next()) {
+ }
+ // cursor is after the last row. getRow() should return 0 when not on a valid
row
+ assertEquals(" current row doesn't match expected value. ", 0,
cs.getRow()); //$NON-NLS-1$
+
+ int i= 10000;
+ while (cs.previous()) {
+ //System.out.println(" rs.previous == " + cs.getCurrentRecord());
+ assertEquals(" Actual doesn't match with expected. ",
expected[i-1], cs.getCurrentRecord()); //$NON-NLS-1$
+ i--;
+ }
+ assertEquals(" current row doesn't match expected value. ", 0,
cs.getRow()); //$NON-NLS-1$
+ cs.close();
+ }
+
+ /** walk all way through from the end back to first row */
+ @Test public void testPrevious4() throws Exception {
+ //small batch size
+ ResultSetImpl cs = helpExecuteQuery(50, 1000,
ResultSet.TYPE_SCROLL_INSENSITIVE);
+ List[] expected = TestAllResultsImpl.exampleResults1(1000);
+ while(cs.next()) {
+ //System.out.println(" rs.next == " + cs.getCurrentRecord());
+ }
+ // cursor is after the last row. getRow() should return 0 when not on a valid
row
+ assertEquals(" current row doesn't match expected value. ", 0,
cs.getRow()); //$NON-NLS-1$
+
+ int i= 1000;
+ while (cs.previous()) {
+ //System.out.println(" rs.previous == " + cs.getCurrentRecord());
+ assertEquals(" Actual doesn't match with expected. ",
expected[i-1], cs.getCurrentRecord()); //$NON-NLS-1$
+ i--;
+ }
+ assertEquals(" current row doesn't match expected value. ", 0,
cs.getRow()); //$NON-NLS-1$
+ cs.close();
+ }
+
+ /** test rare case that cursor change direction */
+ @Test public void testChangeDirection() throws SQLException {
+ ResultSetImpl cs = helpExecuteQuery();
+ cs.absolute(291);
+ cs.previous();
+
+ assertEquals(" current row doesn't match expected value. ", 290,
cs.getRow()); //$NON-NLS-1$
+ cs.close();
+ }
+
+ @Test public void testIsFirst() throws SQLException {
+ ResultSetImpl cs = helpExecuteQuery();
+ cs.next();
+ assertTrue(cs.isFirst());
+ cs.close();
+ }
+
+ /** test cursor is in the middle of all batches */
+ @Test public void testIsLast1() throws SQLException {
+ ResultSetImpl cs = helpExecuteQuery();
+ cs.next();
+ assertTrue(!cs.isLast());
+ cs.close();
+ }
+
+ /** test cursor at the triggering point -- blocking case*/
+ @Test public void testIsLast2() throws SQLException {
+ ResultSetImpl cs = helpExecuteQuery();
+
+ int i = 0;
+ while (cs.next()) {
+ if (i == 99) {
+ break;
+ }
+ i++;
+ }
+
+ assertTrue(!cs.isLast());
+ cs.close();
+ }
+
+ /** test cursor at the last row of all batches */
+ @Test public void testIsLast3() throws SQLException {
+ ResultSetImpl cs = helpExecuteQuery();
+ cs.absolute(1000);
+ assertTrue(cs.isLast());
+ cs.close();
+ }
+
+ @Test public void testIsBeforeFirst() throws SQLException {
+ ResultSetImpl cs = helpExecuteQuery();
+ assertTrue(cs.isBeforeFirst());
+ cs.close();
+ }
+
+ @Test public void testBeforeFirst() throws SQLException {
+ ResultSetImpl cs = helpExecuteQuery();
+
+ // move to row 1
+ cs.next();
+ assertEquals(" Current row number doesn't match with expected
one.", 1, cs.getRow()); //$NON-NLS-1$
+
+ // move back to before first row
+ cs.beforeFirst();
+ assertTrue(cs.isBeforeFirst());
+ cs.close();
+ }
+
+ @Test public void testFirst() throws SQLException {
+ ResultSetImpl cs = helpExecuteQuery();
+
+ // move to row #2
+ cs.next();
+ cs.next();
+ assertEquals(" Current row number doesn't match with expected
one.", 2, cs.getRow()); //$NON-NLS-1$
+
+ // move back to the 1st row
+ cs.first();
+ assertEquals(" Current row number doesn't match with expected
one.", 1, cs.getRow()); //$NON-NLS-1$
+ cs.close();
+ }
+
+ @Test public void testAfterLast() throws SQLException {
+ ResultSetImpl cs = helpExecuteQuery();
+ cs.afterLast();
+ assertTrue(cs.isAfterLast());
+ cs.close();
+ }
+
+ /** right after the last row */
+ @Test public void testIsAfterLast1() throws SQLException {
+ ResultSetImpl cs = helpExecuteQuery();
+ cs.absolute(1000);
+ cs.next();
+ assertTrue(cs.isAfterLast());
+ cs.close();
+ }
+
+ /** right before the first */
+ @Test public void testIsAfterLast2() throws Exception {
+ ResultSetImpl cs = helpExecuteQuery();
+ assertTrue(!cs.isAfterLast());
+ cs.close();
+ }
+
+ /** absolute with cursor movement backward in the same batch -- absolute(positive)
*/
+ @Test public void testAbsolute1() throws SQLException {
+ ResultSetImpl cs = helpExecuteQuery();
+
+ // move to row #2
+ cs.next();
+ cs.next();
+ assertEquals(" Current row number doesn't match with expected
one.", 2, cs.getRow()); //$NON-NLS-1$
+
+ // move back to the 1st row
+ cs.absolute(1);
+ assertEquals(" Current row number doesn't match with expected
one.", 1, cs.getRow()); //$NON-NLS-1$
+ cs.close();
+ }
+
+ /** absolute with cursor movement forward in the same batch -- absolute(positive) */
+ @Test public void testAbsolute2() throws SQLException {
+ ResultSetImpl cs = helpExecuteQuery();
+
+ // move to row #2
+ cs.next();
+ cs.next();
+ assertEquals(" Current row number doesn't match with expected
one.", 2, cs.getRow()); //$NON-NLS-1$
+
+ // move back to the 1st row
+ cs.absolute(3);
+ assertEquals(" Current row number doesn't match with expected
one.", 3, cs.getRow()); //$NON-NLS-1$
+ cs.close();
+ }
+
+ /** absolute with cursor movement forward -- absolute(positive) -- blocking */
+ @Test public void testAbsolute3() throws SQLException {
+ ResultSetImpl cs = helpExecuteQuery();
+
+ // move to row #2
+ cs.next();
+ cs.next();
+ assertEquals(" Current row number doesn't match with expected
one.", 2, cs.getRow()); //$NON-NLS-1$
+
+ // move to row #100 -- blocking
+ cs.absolute(100);
+ assertEquals(" Current row number doesn't match with expected
one.", 100, cs.getRow()); //$NON-NLS-1$
+ cs.close();
+ }
+
+ /** absolute with cursor movement forward -- absolute(positive) -- triggering point
*/
+ @Test public void testAbsolute4() throws SQLException {
+ ResultSetImpl cs = helpExecuteQuery();
+
+ // move to row #2
+ cs.next();
+ cs.next();
+ assertEquals(" Current row number doesn't match with expected
one.", 2, cs.getRow()); //$NON-NLS-1$
+
+ // move to row #200 -- new batch
+ cs.absolute(200);
+ assertEquals(" Current row number doesn't match with expected
one.", 200, cs.getRow()); //$NON-NLS-1$
+ cs.close();
+ }
+
+ /** absolute with cursor movement back in the same batch -- absolute(negative) */
+ @Test public void testAbsolute5() throws SQLException {
+ ResultSetImpl cs = helpExecuteQuery();
+
+ // move to row #2
+ cs.next();
+ cs.next();
+ assertEquals(" Current row number doesn't match with expected
one.", 2, cs.getRow()); //$NON-NLS-1$
+
+ // move back to the 1st row
+ cs.absolute(-1);
+ assertEquals(" Current row number doesn't match with expected
one.", 1000, cs.getRow()); //$NON-NLS-1$
+ cs.close();
+ }
+
+ /** absolute after last row */
+ @Test public void testAbsolute6() throws SQLException {
+ ResultSetImpl cs = helpExecuteQuery();
+ cs.absolute(1005);
+ // Cursor should be after last row. getRow() should return 0 because
+ // cursor is not on a valid row
+ assertEquals(" Current row number doesn't match with expected
one.", 0, cs.getRow()); //$NON-NLS-1$
+ cs.close();
+ }
+
+ /** relative(positive) -- forward to another batch */
+ @Test public void testRelative1() throws SQLException {
+ ResultSetImpl cs = helpExecuteQuery();
+
+ // move to the row #3
+ cs.absolute(3);
+ assertEquals(" Current row number doesn't match with expected
one.", 3, cs.getRow()); //$NON-NLS-1$
+
+ // move to the row #140
+ cs.relative(137);
+ assertEquals(" Current row number doesn't match with expected
one.", 140, cs.getRow()); //$NON-NLS-1$
+ cs.close();
+ }
+
+ /** relative(negative) -- backward to another batch */
+ @Test public void testRelative2() throws SQLException {
+ ResultSetImpl cs = helpExecuteQuery();
+
+ // move to the row #137
+ cs.absolute(137);
+ assertEquals(" Current row number doesn't match with expected
one.", 137, cs.getRow()); //$NON-NLS-1$
+
+ // move to the row #4
+ cs.relative(-133);
+ assertEquals(" Current row number doesn't match with expected
one.", 4, cs.getRow()); //$NON-NLS-1$
+ cs.close();
+ }
+
+ /** relative(negative) -- backward to triggering point or blocking batch */
+ @Test public void testRelative3() throws SQLException {
+ ResultSetImpl cs = helpExecuteQuery();
+
+ // move to the row #137
+ cs.absolute(137);
+ assertEquals(" Current row number doesn't match with expected
one.", 137, cs.getRow()); //$NON-NLS-1$
+
+ // move to the row #100
+ cs.relative(-37);
+ assertEquals(" Current row number doesn't match with expected
one.", 100, cs.getRow()); //$NON-NLS-1$
+ cs.close();
+ }
+
+ /** relative(negative) -- backward to triggering point or blocking batch */
+ @Test public void testRelative4() throws SQLException {
+ ResultSetImpl cs = helpExecuteQuery();
+
+ // move to the row #237 in the third batch, so that the fourth batch has been
requested when we switch direction
+ cs.absolute(237);
+ assertEquals(" Current row number doesn't match with expected
one.", 237, cs.getRow()); //$NON-NLS-1$
+
+ // move to the row #37
+ cs.relative(-200);
+ assertEquals(" Current row number doesn't match with expected
one.", 37, cs.getRow()); //$NON-NLS-1$
+ cs.close();
+ }
+
+ /** in the first fetched batch */
+ @Test public void testGetRow1() throws SQLException {
+ ResultSet cs = helpExecuteQuery();
+
+ int i = 0;
+ while (cs.next()) {
+ if (i == 102) {
+ break;
+ }
+ i++;
+ }
+
+ assertEquals(" Current row number doesn't match with expected
one.", i+1, cs.getRow()); //$NON-NLS-1$
+ cs.close();
+ }
+
+ /** in the first batch */
+ @Test public void testGetRow2() throws SQLException {
+ ResultSet cs = helpExecuteQuery();
+
+ cs.next();
+ assertEquals(" Current row number doesn't match with expected
one.", 1, cs.getRow()); //$NON-NLS-1$
+ cs.close();
+ }
+
+ /** in the triggering point -- blocking */
+ @Test public void testGetRow3() throws SQLException {
+ ResultSet cs = helpExecuteQuery();
+ int i = 0;
+ while (cs.next()) {
+ if (i == 99) {
+ break;
+ }
+ i++;
+ }
+ assertEquals(" Current row number doesn't match with expected
one.", 100, cs.getRow()); //$NON-NLS-1$
+ cs.close();
+ }
+
+ @Test public void testGetCurrentRecord() throws SQLException {
+ ResultSet cs = helpExecuteQuery();
+ cs.absolute(103);
+ assertEquals(" Current record doesn't match with expected one.",
new Integer(103), ((ResultSetImpl)cs).getCurrentRecord().get(0));
//$NON-NLS-1$
+ cs.close();
+ }
+
+ /** test close() without walking through any of the record*/
+ @Test public void testClose() throws SQLException {
+ ResultSetImpl cs = helpExecuteQuery();
+ assertEquals(" Actual doesn't match with expected. ", new
Integer(0), new Integer(cs.getRow())); //$NON-NLS-1$
+ cs.close();
+ }
+
+ /** test basic results-related metadata */
+ @Test public void testGetMetaData() throws SQLException {
+ ResultSetImpl cs = helpExecuteQuery();
+
+ // check result set metadata
+ // expected column info.
+ List columnName = getBQTRSMetaData1a();
+ List columnType = getBQTRSMetaData1b();
+ List columnTypeName = getBQTRSMetaData1c();
+
+ ResultSetMetaData rm = cs.getMetaData();
+ assertNotNull(rm);
+
+ for (int j = 1; j <= rm.getColumnCount(); j++) {
+ assertEquals(" Actual doesn't match with expected. ",
columnName.get(j-1), rm.getColumnName(j)); //$NON-NLS-1$
+ assertEquals(" Actual doesn't match with expected. ",
columnType.get(j-1), new Integer(rm.getColumnType(j))); //$NON-NLS-1$
+ assertEquals(" Actual doesn't match with expected. ",
columnTypeName.get(j-1), rm.getColumnTypeName(j)); //$NON-NLS-1$
+ }
+
+ cs.close();
+ }
+
+ @Test public void testFindColumn() throws SQLException {
+ ResultSetImpl cs = helpExecuteQuery();
+ ResultSetMetaData rm = cs.getMetaData();
+ assertNotNull(rm);
+ //assertEquals(" Actual columnName doesn't match with expected. ",
1, cs.findColumn("BQT1.MediumA.IntKey"));
+ assertEquals(" Actual columnName doesn't match with expected. ", 1,
cs.findColumn("IntKey")); //$NON-NLS-1$ //$NON-NLS-2$
+ cs.close();
+ }
+
+ @Test public void testFindNonExistentColumn() throws SQLException {
+ ResultSet rs = helpExecuteQuery();
+ rs.next();
+ try {
+ rs.findColumn("BOGUS"); //$NON-NLS-1$
+ } catch(SQLException e) {
+ }
+
+ try {
+ rs.getObject("BOGUS"); //$NON-NLS-1$
+ } catch(SQLException e) {
+ }
+ rs.close();
+ }
+
+ @Test public void testGetStatement() throws SQLException {
+ ResultSetImpl cs = helpExecuteQuery();
+ assertNotNull(cs.getStatement());
+ cs.close();
+ }
+
+ @Test public void testGetPlanDescription() throws SQLException {
+ ResultSetImpl cs = helpExecuteQuery();
+ assertNotNull(cs);
+
+ assertNull((cs.getStatement()).getPlanDescription());
+ cs.close();
+ }
+
+ /** getObject(String) */
+ @Test public void testGetObject2() throws SQLException {
+ ResultSet cs = helpExecuteQuery();
+
+ // move to the 1st row
+ cs.next();
+ assertEquals(" Actual value doesn't match with expected. ", new
Integer(1), cs.getObject("IntKey")); //$NON-NLS-1$ //$NON-NLS-2$
+ cs.close();
+ }
+
+ @Test public void testGetWarnings() throws SQLException {
+ ResultSet cs = helpExecuteQuery();
+ assertNull(cs.getWarnings());
+ cs.close();
+ }
+
+ @Test public void testGetCursorName() throws SQLException {
+ ResultSetImpl cs = helpExecuteQuery();
+ assertNull(cs.getCursorName());
+ cs.close();
+ }
+
+ @Test public void testAllGetters() throws SQLException {
+ ResultSetImpl cs = helpExecuteQuery();
+ cs.next();
+ assertEquals(" Actual value of getInt() doesn't match with expected one.
", 1, cs.getInt("IntKey")); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals(" Actual value of getString() doesn't match with expected
one. ", "1", cs.getString("IntKey")); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
+
+ // Add these back when the MediumA has all those columns
+ assertEquals(" Actual value of getFloat() doesn't match with expected
one. ", new Float(1), new Float(cs.getFloat("IntKey"))); //$NON-NLS-1$
//$NON-NLS-2$
+ assertEquals(" Actual value of getLong() doesn't match with expected
one. ", 1, cs.getLong("IntKey")); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals(" Actual value of getDouble() doesn't match with expected
one. ", new Double(1), new Double(cs.getDouble("IntKey"))); //$NON-NLS-1$
//$NON-NLS-2$
+ assertEquals(" Actual value of getByte() doesn't match with expected
one. ", (byte)1, cs.getByte("IntKey")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /** test wasNull() for ResultSet, this result actually is not a cursor result, but
AllResults here. */
+ @Test public void testWasNull() throws SQLException {
+ ResultSet cs = helpExecuteQuery();
+ cs.next();
+ assertNotNull(cs.getObject("IntKey")); //$NON-NLS-1$
+ assertFalse(cs.wasNull());
+ }
+
+ @Test public void testForwardOnly() throws Exception {
+ ResultSetImpl cs = helpExecuteQuery(400, 1000, ResultSet.TYPE_FORWARD_ONLY);
+
+ while (cs.next()) {
+ cs.getObject(1);
+ }
+
+ assertTrue(cs.isAfterLast());
+ cs.close();
+ }
+
+ @Test public void testOutputParameter() throws Exception {
+ StatementImpl statement = createMockStatement(ResultSet.TYPE_FORWARD_ONLY);
+ ResultsMessage resultsMsg = new ResultsMessage();
+ resultsMsg.setResults(new List<?>[] {Arrays.asList(1, null, null),
Arrays.asList(null, 2, 3)});
+ resultsMsg.setLastRow(2);
+ resultsMsg.setFirstRow(1);
+ resultsMsg.setFinalRow(2);
+ resultsMsg.setColumnNames(new String[] {"x", "out1",
"out2"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ resultsMsg.setDataTypes(new String[] {"integer", "integer",
"integer"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ ResultSetImpl cs = new ResultSetImpl(resultsMsg, statement, null, 2);
+
+ int count = 0;
+ while (cs.next()) {
+ cs.getObject(1);
+ count++;
+ }
+ assertEquals(1, count);
+ assertTrue(cs.isAfterLast());
+ assertEquals(2, cs.getOutputParamValue(2));
+ assertEquals(3, cs.getOutputParamValue(3));
+ }
+
+ @Test public void testXML() throws Exception {
+ StatementImpl statement = createMockStatement(ResultSet.TYPE_FORWARD_ONLY);
+ ResultsFuture<LobChunk> future = new ResultsFuture<LobChunk>();
+ future.getResultsReceiver().receiveResults(new
LobChunk("<a/>".getBytes(Charset.forName("UTF-8")), true));
+ Mockito.stub(statement.getDQP().requestNextLobChunk(0, 0, null)).toReturn(future);
+ ResultsMessage resultsMsg = new ResultsMessage();
+ XMLType result = new XMLType();
+ result.setEncoding("UTF-8");
+ resultsMsg.setResults(new List<?>[] {Arrays.asList(result)});
+ resultsMsg.setLastRow(1);
+ resultsMsg.setFirstRow(1);
+ resultsMsg.setFinalRow(1);
+ resultsMsg.setColumnNames(new String[] {"x"}); //$NON-NLS-1$
+ resultsMsg.setDataTypes(new String[] {"xml"}); //$NON-NLS-1$
+ ResultSetImpl cs = new ResultSetImpl(resultsMsg, statement);
+ cs.next();
+ assertEquals("<a/>", cs.getString(1));
+ }
+
+ /////////////////////// Helper Method ///////////////////
+
+ private ResultSetImpl helpExecuteQuery() {
+ try {
+ return helpExecuteQuery(400, 1000, ResultSet.TYPE_SCROLL_INSENSITIVE);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private ResultSetImpl helpExecuteQuery(int fetchSize, int totalResults, int
cursorType) throws SQLException, TeiidProcessingException, InterruptedException,
ExecutionException, TimeoutException {
+ StatementImpl statement = createMockStatement(cursorType);
+ return TestAllResultsImpl.helpTestBatching(statement, fetchSize, Math.min(fetchSize,
totalResults), totalResults);
+ }
+
+ static StatementImpl createMockStatement(int cursorType) throws SQLException {
+ StatementImpl statement = mock(StatementImpl.class);
+ stub(statement.getDQP()).toReturn(mock(DQP.class));
+ stub(statement.getResultSetType()).toReturn(cursorType);
+ TimeZone tz = TimeZone.getTimeZone("GMT-06:00"); //$NON-NLS-1$
+ TimeZone serverTz = TimeZone.getTimeZone("GMT-05:00"); //$NON-NLS-1$
+ stub(statement.getDefaultCalendar()).toReturn(Calendar.getInstance(tz));
+ stub(statement.getServerTimeZone()).toReturn(serverTz);
+ return statement;
+ }
+
+ ////////////////////////Expected Results////////////////
+ /** column name */
+ private List getBQTRSMetaData1a() {
+ List results = new ArrayList();
+ results.add("IntKey"); //$NON-NLS-1$
+ return results;
+ }
+
+ /** column type */
+ private List getBQTRSMetaData1b() {
+ List results = new ArrayList();
+ results.add(new Integer(Types.INTEGER));
+ return results;
+ }
+
+ /** column type name*/
+ private List getBQTRSMetaData1c() {
+ List results = new ArrayList();
+ results.add("integer"); //$NON-NLS-1$
+ return results;
+ }
+}
Copied: trunk/client/src/test/java/org/teiid/jdbc/TestSQLException.java (from rev 2238,
trunk/client/src/test/java/org/teiid/jdbc/TestMMSQLException.java)
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/TestSQLException.java
(rev 0)
+++ trunk/client/src/test/java/org/teiid/jdbc/TestSQLException.java 2010-06-17 18:35:22
UTC (rev 2240)
@@ -0,0 +1,234 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.jdbc;
+
+import java.io.IOException;
+import java.net.ConnectException;
+import java.net.MalformedURLException;
+import java.net.NoRouteToHostException;
+import java.net.SocketException;
+import java.net.SocketTimeoutException;
+import java.net.UnknownHostException;
+import java.sql.SQLException;
+
+import junit.framework.TestCase;
+
+import org.teiid.client.ProcedureErrorInstructionException;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.core.TeiidException;
+import org.teiid.core.TeiidException;
+import org.teiid.core.TeiidRuntimeException;
+import org.teiid.net.CommunicationException;
+import org.teiid.net.ConnectionException;
+
+
+public class TestSQLException extends TestCase {
+
+ /*
+ * Test method for 'com.metamatrix.jdbc.MMSQLException.MMSQLException()'
+ */
+ public void testMMSQLException() {
+ TeiidSQLException e = new TeiidSQLException();
+ String sqlState = e.getSQLState();
+ Throwable cause = e.getCause();
+ int errorCode = e.getErrorCode();
+ Throwable nestedException = e.getCause();
+ SQLException nextException = e.getNextException();
+
+ assertTrue(
+ "Expected MMSQLException.getSQLState() to return <null> but got
\"" //$NON-NLS-1$
+ + sqlState + "\" instead.", sqlState == null); //$NON-NLS-1$
+ assertTrue(
+ "Expected MMSQLException.getCause() to return <null> but got ["
//$NON-NLS-1$
+ + (cause != null ? cause.getClass().getName()
+ : "<unknown>") + "] instead.", cause == null);
//$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue(
+ "Expected MMSQLException.getErrorCode() to return [0] but got ["
//$NON-NLS-1$
+ + errorCode + "] instead.", errorCode == 0); //$NON-NLS-1$
+ assertTrue(
+ "Expected MMSQLException.getNestedException() to return <null> but got
[" //$NON-NLS-1$
+ + (nestedException != null ? nestedException.getClass()
+ .getName() : "<unknown>") + "] instead.", //$NON-NLS-1$
//$NON-NLS-2$
+ nestedException == null);
+ assertTrue(
+ "Expected MMSQLException.getNextException() to return <null> but got a
SQLException with message \"" //$NON-NLS-1$
+ + (nextException != null ? nextException.getMessage()
+ : "") + "\" instead.", nextException == null);
//$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /*
+ * Test method for 'com.metamatrix.jdbc.MMSQLException.create(Throwable)'
+ *
+ * Tests various simple exceptions to see if the expected SQLState is
+ * returend.
+ */
+ public void testCreateThrowable_01() {
+ testCreateThrowable(new CommunicationException(
+ "A test MM Communication Exception"), //$NON-NLS-1$
+ SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
+ testCreateThrowable(
+ new ConnectException("A test connection attempt exception"), //$NON-NLS-1$
+ SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
+ testCreateThrowable(
+ new ConnectionException("A test MM Connection Exception"), //$NON-NLS-1$
+ SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
+ testCreateThrowable(new IOException(
+ "A test Generic java.io.IOException"), //$NON-NLS-1$
+ SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
+ testCreateThrowable(
+ new MalformedURLException(
+ "A test java.net.MalformedURLException"), //$NON-NLS-1$
+ SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
+ testCreateThrowable(new TeiidException(
+ "A test Generic MM Core Exception"), SQLStates.DEFAULT); //$NON-NLS-1$
+ testCreateThrowable(new TeiidException("A test MM Exception"), //$NON-NLS-1$
+ SQLStates.DEFAULT);
+ testCreateThrowable(new TeiidProcessingException(
+ "A test Generic MM Query Processing Exception"), //$NON-NLS-1$
+ SQLStates.USAGE_ERROR);
+ testCreateThrowable(new TeiidRuntimeException(
+ "A test MM Runtime Exception"), SQLStates.DEFAULT); //$NON-NLS-1$
+ testCreateThrowable(new TeiidSQLException(
+ "A test Generic MM SQL Exception"), SQLStates.DEFAULT); //$NON-NLS-1$
+ testCreateThrowable(
+ new NoRouteToHostException(
+ "A test java.net.NoRouteToHostException"), //$NON-NLS-1$
+ SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
+ testCreateThrowable(new NullPointerException("A test NPE"), //$NON-NLS-1$
+ SQLStates.DEFAULT);
+ testCreateThrowable(new ProcedureErrorInstructionException(
+ "A test SQL Procedure Error exception"), //$NON-NLS-1$
+ SQLStates.VIRTUAL_PROCEDURE_ERROR);
+ testCreateThrowable(new SocketTimeoutException(
+ "A test socket timeout exception"), //$NON-NLS-1$
+ SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
+ testCreateThrowable(
+ new UnknownHostException("A test connection attempt exception"),
//$NON-NLS-1$
+ SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
+ }
+
+ /*
+ * Test method for 'com.metamatrix.jdbc.MMSQLException.create(Throwable)'
+ *
+ * Tests various nested exceptions to see if the expected SQLState is
+ * returend.
+ */
+ public void testCreateThrowable_02() {
+ testCreateThrowable(
+ new CommunicationException(new ConnectException(
+ "A test java.net.ConnectException"), //$NON-NLS-1$
+ "Test Communication Exception with a ConnectException in it"),
//$NON-NLS-1$
+ SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
+ testCreateThrowable(new CommunicationException(new SocketException(
+ "A test java.net.SocketException"), //$NON-NLS-1$
+ "Test Communication Exception with a SocketException in it"),
//$NON-NLS-1$
+ SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
+ testCreateThrowable(
+ new TeiidException(new SocketTimeoutException(
+ "A test java.net.SocketTimeoutException"), //$NON-NLS-1$
+ "Test MetaMatrixException with a SocketTimeoutException in it"),
//$NON-NLS-1$
+ SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
+ }
+
+ public void testCreateThrowable3() {
+ TeiidSQLException e = testCreateThrowable(
+ new TeiidException(
+ new TeiidRuntimeException(
+ new SocketTimeoutException(
+ "A test MM Invalid Session
Exception"), //$NON-NLS-1$
+ "Test MetaMatrixRuntimeException with a
InvalidSessionException in it"), //$NON-NLS-1$
+ "Test MM Core Exception with an MM Runtime
Exception in it and an InvalidSessionException nested within"), //$NON-NLS-1$
+ SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
+
+ //test to ensure that wrapping mmsqlexceptions works
+ TeiidSQLException e1 = TeiidSQLException.create(e, "new message");
//$NON-NLS-1$
+ assertEquals("new message", e1.getMessage()); //$NON-NLS-1$
+ testCreateThrowable(((TeiidSQLException)e1.getCause()).getCause(),
SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
+ }
+
+ /*
+ * Helper method to test SQLState and general MMSQLException validation
+ */
+ private TeiidSQLException testCreateThrowable(Throwable ecause, String esqlState) {
+ TeiidSQLException e = TeiidSQLException.create(ecause);
+ if (ecause.getClass() == TeiidSQLException.class) {
+ ecause = null;
+ }
+ String sqlState = e.getSQLState();
+ Throwable cause = e.getCause();
+ int errorCode = e.getErrorCode();
+ Throwable nestedException = e.getCause();
+ SQLException nextException = e.getNextException();
+
+ assertTrue("Expected MMSQLException.getSQLState() to return \""
//$NON-NLS-1$
+ + esqlState + "\" but got \"" + sqlState + "\"
instead.", //$NON-NLS-1$ //$NON-NLS-2$
+ sqlState.compareTo(esqlState) == 0);
+ assertTrue("Expected MMSQLException.getCause() to return [" //$NON-NLS-1$
+ + (ecause != null ? ecause.getClass().getName() : "<null>")
//$NON-NLS-1$
+ + "] but got [" //$NON-NLS-1$
+ + (cause != null ? cause.getClass().getName() : "<unknown>")
//$NON-NLS-1$
+ + "] instead.", cause == ecause); //$NON-NLS-1$
+ assertTrue(
+ "Expected MMSQLException.getErrorCode() to return [0] but got ["
//$NON-NLS-1$
+ + errorCode + "] instead.", errorCode == 0); //$NON-NLS-1$
+ assertTrue("Expected MMSQLException.getNestedException() to return ["
//$NON-NLS-1$
+ + (ecause != null ? ecause.getClass().getName() : "<null>")
//$NON-NLS-1$
+ + "] but got [" //$NON-NLS-1$
+ + (nestedException != null ? nestedException.getClass()
+ .getName() : "<unknown>") + "] instead.", //$NON-NLS-1$
//$NON-NLS-2$
+ nestedException == ecause);
+ assertTrue(
+ "Expected MMSQLException.getNextException() to return <null> but got a
SQLException with message \"" //$NON-NLS-1$
+ + (nextException != null ? nextException.getMessage()
+ : "") + "\" instead.", nextException == null);
//$NON-NLS-1$ //$NON-NLS-2$
+ return e;
+ }
+
+ public void testCreate() {
+ TeiidSQLException exception = TeiidSQLException.create(new Exception());
+
+ assertEquals(exception.getMessage(), Exception.class.getName());
+ assertNotNull(exception.getSQLState());
+ assertEquals(exception.getSQLState(), "38000"); //$NON-NLS-1$
+
+ assertEquals(exception, TeiidSQLException.create(exception));
+ }
+
+ public void testCreateFromSQLException() {
+ SQLException sqlexception = new SQLException("foo", "21");
//$NON-NLS-1$ //$NON-NLS-2$
+
+ SQLException nested = new SQLException("bar"); //$NON-NLS-1$
+
+ sqlexception.setNextException(nested);
+
+ String message = "top level message"; //$NON-NLS-1$
+
+ TeiidSQLException exception = TeiidSQLException.create(sqlexception, message);
+
+ assertEquals(exception.getMessage(), message);
+ assertEquals(exception.getSQLState(), sqlexception.getSQLState());
+ assertEquals(exception.getNextException().getMessage(),
sqlexception.getMessage());
+ assertEquals(exception.getNextException().getNextException().getMessage(),
nested.getMessage());
+ }
+
+}
Copied: trunk/client/src/test/java/org/teiid/jdbc/TestStatement.java (from rev 2238,
trunk/client/src/test/java/org/teiid/jdbc/TestMMStatement.java)
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/TestStatement.java
(rev 0)
+++ trunk/client/src/test/java/org/teiid/jdbc/TestStatement.java 2010-06-17 18:35:22 UTC
(rev 2240)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.jdbc;
+
+import static org.junit.Assert.*;
+
+import java.sql.ResultSet;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.teiid.client.DQP;
+import org.teiid.client.RequestMessage;
+import org.teiid.client.ResultsMessage;
+import org.teiid.client.util.ResultsFuture;
+import org.teiid.jdbc.ConnectionImpl;
+import org.teiid.jdbc.TeiidSQLException;
+import org.teiid.jdbc.StatementImpl;
+
+
+public class TestStatement {
+
+ @Test(expected=TeiidSQLException.class) public void testUpdateException() throws
Exception {
+ StatementImpl statement = new StatementImpl(Mockito.mock(ConnectionImpl.class),
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
+ statement.executeQuery("delete from table"); //$NON-NLS-1$
+ }
+
+ @Test public void testBatchExecution() throws Exception {
+ ConnectionImpl conn = Mockito.mock(ConnectionImpl.class);
+ DQP dqp = Mockito.mock(DQP.class);
+ ResultsFuture<ResultsMessage> results = new
ResultsFuture<ResultsMessage>();
+ Mockito.stub(dqp.executeRequest(Mockito.anyLong(),
(RequestMessage)Mockito.anyObject())).toReturn(results);
+ ResultsMessage rm = new ResultsMessage();
+ rm.setResults(new List<?>[] {Arrays.asList(1), Arrays.asList(2)});
+ rm.setUpdateResult(true);
+ results.getResultsReceiver().receiveResults(rm);
+ Mockito.stub(conn.getDQP()).toReturn(dqp);
+ StatementImpl statement = new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY);
+ statement.addBatch("delete from table"); //$NON-NLS-1$
+ statement.addBatch("delete from table1"); //$NON-NLS-1$
+ assertTrue(Arrays.equals(new int[] {1, 2}, statement.executeBatch()));
+ }
+
+ @Test public void testSetStatement() throws Exception {
+ ConnectionImpl conn = Mockito.mock(ConnectionImpl.class);
+ Properties p = new Properties();
+ Mockito.stub(conn.getConnectionProperties()).toReturn(p);
+ StatementImpl statement = new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY);
+ assertFalse(statement.execute("set foo bar")); //$NON-NLS-1$
+ assertEquals("bar", p.get("foo")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ @Test public void testPropertiesOverride() throws Exception {
+ ConnectionImpl conn = Mockito.mock(ConnectionImpl.class);
+ Properties p = new Properties();
+ p.setProperty(ExecutionProperties.ANSI_QUOTED_IDENTIFIERS, Boolean.TRUE.toString());
+ Mockito.stub(conn.getConnectionProperties()).toReturn(p);
+ StatementImpl statement = new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY);
+ assertEquals(Boolean.TRUE.toString(),
statement.getExecutionProperty(ExecutionProperties.ANSI_QUOTED_IDENTIFIERS));
+ statement.setExecutionProperty(ExecutionProperties.ANSI_QUOTED_IDENTIFIERS,
Boolean.FALSE.toString());
+ assertEquals(Boolean.FALSE.toString(),
statement.getExecutionProperty(ExecutionProperties.ANSI_QUOTED_IDENTIFIERS));
+ assertEquals(Boolean.TRUE.toString(),
p.getProperty(ExecutionProperties.ANSI_QUOTED_IDENTIFIERS));
+ }
+
+
+}
Property changes on: trunk/client/src/test/java/org/teiid/jdbc/TestStatement.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied: trunk/client/src/test/java/org/teiid/jdbc/TestXAConnection.java (from rev 2238,
trunk/client/src/test/java/org/teiid/jdbc/TestMMXAConnection.java)
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/TestXAConnection.java
(rev 0)
+++ trunk/client/src/test/java/org/teiid/jdbc/TestXAConnection.java 2010-06-17 18:35:22
UTC (rev 2240)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.jdbc;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import javax.transaction.xa.XAResource;
+
+import org.teiid.client.xa.XidImpl;
+import org.teiid.jdbc.ConnectionImpl;
+import org.teiid.jdbc.StatementImpl;
+import org.teiid.jdbc.XAConnectionImpl;
+
+import junit.framework.TestCase;
+
+
+
+public class TestXAConnection extends TestCase {
+
+ public void testConnectionClose() throws Exception {
+
+ final ConnectionImpl mmConn = TestConnection.getMMConnection();
+
+ XAConnectionImpl xaConn = new XAConnectionImpl(new XAConnectionImpl.ConnectionSource()
{
+ //## JDBC4.0-begin ##
+ @Override
+ //## JDBC4.0-end ##
+ public ConnectionImpl createConnection() throws SQLException {
+ return mmConn;
+ }
+ });
+
+ Connection conn = xaConn.getConnection();
+ StatementImpl stmt = (StatementImpl)conn.createStatement();
+ conn.setAutoCommit(false);
+ conn.close();
+
+ assertTrue(stmt.isClosed());
+ assertTrue(conn.getAutoCommit());
+
+ conn = xaConn.getConnection();
+ stmt = (StatementImpl)conn.createStatement();
+ XAResource resource = xaConn.getXAResource();
+ resource.start(new XidImpl(1, new byte[0], new byte[0]), XAResource.TMNOFLAGS);
+ conn.close();
+
+ assertTrue(stmt.isClosed());
+ assertTrue(conn.getAutoCommit());
+ }
+
+}
Property changes on: trunk/client/src/test/java/org/teiid/jdbc/TestXAConnection.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/common-core/src/main/java/org/teiid/core/types/BlobImpl.java
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/types/BlobImpl.java 2010-06-17 16:09:26
UTC (rev 2239)
+++ trunk/common-core/src/main/java/org/teiid/core/types/BlobImpl.java 2010-06-17 18:35:22
UTC (rev 2240)
@@ -33,6 +33,7 @@
import org.teiid.core.CorePlugin;
import org.teiid.core.types.LobSearchUtil.StreamProvider;
+import org.teiid.core.util.ObjectConverterUtil;
import org.teiid.core.util.SqlUtil;
@@ -89,19 +90,22 @@
else if (pos + length > length()) {
length = (int)(length() - pos);
}
- byte[] dataCopy = new byte[length];
InputStream in = getBinaryStream();
try {
- try {
- in.skip(pos);
- in.read(dataCopy);
- } finally {
- in.close();
- }
+ long skipped = 0;
+ while (pos > 0) {
+ skipped = in.skip(pos);
+ pos -= skipped;
+ }
+ return ObjectConverterUtil.convertToByteArray(in, length);
} catch (IOException e) {
throw new SQLException(e);
+ } finally {
+ try {
+ in.close();
+ } catch (IOException e) {
+ }
}
- return dataCopy;
}
/**
Modified: trunk/common-core/src/main/java/org/teiid/core/types/ClobImpl.java
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/types/ClobImpl.java 2010-06-17 16:09:26
UTC (rev 2239)
+++ trunk/common-core/src/main/java/org/teiid/core/types/ClobImpl.java 2010-06-17 18:35:22
UTC (rev 2240)
@@ -35,6 +35,7 @@
import javax.sql.rowset.serial.SerialClob;
import org.teiid.core.CorePlugin;
+import org.teiid.core.util.ObjectConverterUtil;
import org.teiid.core.util.ReaderInputStream;
import org.teiid.core.util.SqlUtil;
@@ -122,19 +123,21 @@
} else if ((pos+length) > length()) {
length = (int)(length()-pos);
}
- char[] dataCopy = new char[length];
Reader in = getCharacterStream();
try {
try {
- in.skip(pos);
- in.read(dataCopy);
+ long skipped = 0;
+ while (pos > 0) {
+ skipped = in.skip(pos);
+ pos -= skipped;
+ }
+ return new String(ObjectConverterUtil.convertToCharArray(in, length));
} finally {
in.close();
}
} catch (IOException e) {
throw new SQLException(e);
}
- return new String(dataCopy);
}
/**
Modified: trunk/common-core/src/test/java/org/teiid/core/types/TestBlobValue.java
===================================================================
--- trunk/common-core/src/test/java/org/teiid/core/types/TestBlobValue.java 2010-06-17
16:09:26 UTC (rev 2239)
+++ trunk/common-core/src/test/java/org/teiid/core/types/TestBlobValue.java 2010-06-17
18:35:22 UTC (rev 2240)
@@ -47,7 +47,6 @@
assertEquals(testString, new String(bv.getBytes(1L, (int)bv.length())));
}
-
public void testBlobValuePersistence() throws Exception {
String testString = "this is test clob"; //$NON-NLS-1$
SerialBlob blob = new SerialBlob(testString.getBytes());
Modified: trunk/common-core/src/test/java/org/teiid/core/types/TestClobValue.java
===================================================================
--- trunk/common-core/src/test/java/org/teiid/core/types/TestClobValue.java 2010-06-17
16:09:26 UTC (rev 2239)
+++ trunk/common-core/src/test/java/org/teiid/core/types/TestClobValue.java 2010-06-17
18:35:22 UTC (rev 2240)
@@ -22,33 +22,32 @@
package org.teiid.core.types;
+import static org.junit.Assert.*;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
+import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import java.io.Reader;
import javax.sql.rowset.serial.SerialClob;
-import org.teiid.core.types.ClobType;
+import org.junit.Test;
import org.teiid.core.util.UnitTestUtil;
+public class TestClobValue {
-import junit.framework.TestCase;
-
-
-public class TestClobValue extends TestCase {
-
- public void testClobValue() throws Exception {
+ @Test public void testClobValue() throws Exception {
String testString = "this is test clob"; //$NON-NLS-1$
SerialClob clob = new SerialClob(testString.toCharArray());
ClobType cv = new ClobType(clob);
assertEquals(testString, cv.getSubString(1L, (int)cv.length()));
}
-
- public void testClobValuePersistence() throws Exception {
+ @Test public void testClobValuePersistence() throws Exception {
String testString = "this is test clob"; //$NON-NLS-1$
SerialClob clob = new SerialClob(testString.toCharArray());
@@ -77,4 +76,32 @@
saved.delete();
}
+ @Test public void testClobSubstring() throws Exception {
+ ClobImpl clob = new ClobImpl() {
+ public java.io.Reader getCharacterStream() throws java.sql.SQLException {
+ return new Reader() {
+
+ int pos = 0;
+
+ @Override
+ public void close() throws IOException {
+
+ }
+
+ @Override
+ public int read(char[] cbuf, int off, int len)
+ throws IOException {
+ if (pos < 2) {
+ cbuf[off] = 'a';
+ pos++;
+ return 1;
+ }
+ return -1;
+ }
+ };
+ }
+ };
+ assertEquals("aa", clob.getSubString(1, 3));
+ }
+
}