Author: shawkins
Date: 2009-02-25 14:09:43 -0500 (Wed, 25 Feb 2009)
New Revision: 501
Modified:
trunk/common-core/src/test/java/com/metamatrix/common/util/TestPropertiesUtils.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/TestJDBCConnector.java
Log:
TEIID-164 fixes from rewiring integration tests
Modified:
trunk/common-core/src/test/java/com/metamatrix/common/util/TestPropertiesUtils.java
===================================================================
---
trunk/common-core/src/test/java/com/metamatrix/common/util/TestPropertiesUtils.java 2009-02-25
18:27:26 UTC (rev 500)
+++
trunk/common-core/src/test/java/com/metamatrix/common/util/TestPropertiesUtils.java 2009-02-25
19:09:43 UTC (rev 501)
@@ -24,6 +24,7 @@
import java.io.File;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
@@ -670,4 +671,61 @@
assertEquals("Property 'x' with value 'y' is not a valid
Integer.", e.getMessage());
}
}
+
+ static class Bean {
+ private int prop;
+ private String prop1;
+ private double prop2;
+ private List<String> prop3;
+
+ public int getProp() {
+ return prop;
+ }
+ public void setProp(int prop) {
+ this.prop = prop;
+ }
+ public String getProp1() {
+ return prop1;
+ }
+ public void setProp1(String prop1) {
+ this.prop1 = prop1;
+ }
+ public double getProp2() {
+ return prop2;
+ }
+ public void setProp2(double prop2) {
+ this.prop2 = prop2;
+ }
+ public List<String> getProp3() {
+ return prop3;
+ }
+ public void setProp3(List<String> prop3) {
+ this.prop3 = prop3;
+ }
+ }
+
+ public void testSetBeanProperties() {
+ Bean bean = new Bean();
+ Properties p = new Properties();
+ p.setProperty("prop", "0");
+ p.setProperty("prop1", "1");
+ p.setProperty("prop2", "2");
+ p.setProperty("prop3", "3");
+
+ PropertiesUtils.setBeanProperties(bean, p, null);
+
+ assertEquals(0, bean.getProp());
+ assertEquals("1", bean.getProp1());
+ assertEquals(2d, bean.getProp2());
+ assertEquals(Arrays.asList("3"), bean.getProp3());
+
+ p.setProperty("prop", "?");
+
+ try {
+ PropertiesUtils.setBeanProperties(bean, p, null);
+ fail("expected exception");
+ } catch (InvalidPropertyException e) {
+
+ }
+ }
}
Modified:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java 2009-02-25
18:27:26 UTC (rev 500)
+++
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java 2009-02-25
19:09:43 UTC (rev 501)
@@ -200,8 +200,13 @@
} catch (SQLException e) {
throw new ConnectorException(e);
}
- return new JDBCSourceConnection(conn, this.environment, sqlTranslator);
+ return createJDBCSourceConnection(conn, this.environment, this.sqlTranslator);
}
+
+ public Connection createJDBCSourceConnection(java.sql.Connection conn,
ConnectorEnvironment env, Translator trans)
+ throws ConnectorException {
+ return new JDBCSourceConnection(conn, env, trans);
+ }
@Override
public XAConnection getXAConnection(
@@ -221,12 +226,18 @@
}
java.sql.Connection c = conn.getConnection();
setDefaultTransactionIsolationLevel(c);
- return new JDBCSourceXAConnection(c, conn, this.environment, sqlTranslator);
+ return createJDBCSourceXAConnection(conn, c, this.environment, this.sqlTranslator);
} catch (SQLException e) {
throw new ConnectorException(e);
}
}
+ public XAConnection createJDBCSourceXAConnection(
+ javax.sql.XAConnection conn, java.sql.Connection c, ConnectorEnvironment env,
Translator trans)
+ throws ConnectorException, SQLException {
+ return new JDBCSourceXAConnection(c, conn, env, trans);
+ }
+
@Override
public ConnectorCapabilities getCapabilities() {
return capabilities;
Modified:
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/TestJDBCConnector.java
===================================================================
---
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/TestJDBCConnector.java 2009-02-25
18:27:26 UTC (rev 500)
+++
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/TestJDBCConnector.java 2009-02-25
19:09:43 UTC (rev 501)
@@ -24,10 +24,12 @@
import java.util.Properties;
-import org.junit.Assert;
+import static org.junit.Assert.*;
import org.junit.Test;
+import org.teiid.connector.jdbc.xa.XAJDBCPropertyNames;
import com.metamatrix.connector.api.ConnectorCapabilities;
+import com.metamatrix.connector.api.ConnectorException;
public class TestJDBCConnector {
@@ -37,7 +39,7 @@
connProps.setProperty(JDBCPropertyNames.EXT_CAPABILITY_CLASS,
SimpleCapabilities.class.getName());
ConnectorCapabilities caps = JDBCConnector.createCapabilities(connProps,
this.getClass().getClassLoader());
int maxIn = caps.getMaxInCriteriaSize();
- Assert.assertEquals(expected, maxIn);
+ assertEquals(expected, maxIn);
}
@Test
@@ -54,4 +56,18 @@
public void test3() throws Exception {
helpTestMaxIn(1, 1);
}
+
+ @Test
+ public void testParseUrl() throws ConnectorException {
+ String urlWithEmptyProp =
"jdbc:mmx:db2://aHost:aPort;DatabaseName=DB2_DataBase;CollectionID=aCollectionID;PackageName=aPackageName;BogusProp=aBogusProp;UnEmptyProp=;";
//$NON-NLS-1$
+ Properties props = new Properties();
+ JDBCConnector.parseURL(urlWithEmptyProp, props);
+
+ assertEquals("aPort",
props.getProperty(XAJDBCPropertyNames.PORT_NUMBER));
+ assertEquals("aHost",
props.getProperty(XAJDBCPropertyNames.SERVER_NAME));
+ assertEquals("XADS_aHost_null",
props.getProperty(XAJDBCPropertyNames.DATASOURCE_NAME));
+ assertEquals("aBogusProp", props.getProperty("bogusprop"));
+ assertNull(props.getProperty("unemptyprop"));
+ }
+
}