[teiid-commits] teiid SVN: r1421 - trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Fri Sep 18 22:46:39 EDT 2009


Author: vhalbert at redhat.com
Date: 2009-09-18 22:46:38 -0400 (Fri, 18 Sep 2009)
New Revision: 1421

Modified:
   trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSource.java
   trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSourceMgr.java
Log:
Teiid 773 - organize integration test - added option to specify  which datasources (narrow the available datasources) to include in the test 

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSource.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSource.java	2009-09-19 02:37:21 UTC (rev 1420)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSource.java	2009-09-19 02:46:38 UTC (rev 1421)
@@ -48,10 +48,10 @@
 		return this.props;
 	}
 	
-	public boolean isOfDBType(String type) {
-		return (this.dbtype.equalsIgnoreCase(type));
+	public String getDBType() {
+		return this.dbtype;
 	}
-	
+
 	public int getBitMask() {
 		return this.bitMask;
 	}

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSourceMgr.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSourceMgr.java	2009-09-19 02:37:21 UTC (rev 1420)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSourceMgr.java	2009-09-19 02:46:38 UTC (rev 1421)
@@ -19,6 +19,7 @@
 import org.jdom.JDOMException;
 import org.teiid.test.framework.exception.QueryTestFailedException;
 import org.teiid.test.framework.exception.TransactionRuntimeException;
+import org.teiid.test.util.StringUtil;
 
 import com.metamatrix.common.xml.XMLReaderWriter;
 import com.metamatrix.common.xml.XMLReaderWriterImpl;
@@ -35,8 +36,14 @@
  */
 public class DataSourceMgr {
 	
+	/**
+	 * The USE_DATASOURCES_PROP is a comma delimited system property that can be used to limit the
+	 * datasources that are in use for the tests.   Use the name defined in the datasource_mapping.xml.
+	 * This enables one to test between certain datasources without having to remove 
+	 * connection.properties files.
+	 */
+	static final String USE_DATASOURCES_PROP = "usedataources";
 
-
 	static final String RELATIVE_DIRECTORY = "datasources/";
 	static final String DATASOURCE_MAPPING_FILE = "datasource_mapping.xml";
 
@@ -73,6 +80,17 @@
 		return _instance;
 	}
 	
+	public static synchronized void reset() {
+		
+		_instance.dstypeMap.clear();
+		_instance.allDatasourcesMap.clear();
+		_instance.modelToDatasourceMap.clear();
+		_instance.assignedDataSources.clear();
+		
+		_instance = null;
+		
+	}
+	
 	public int numberOfAvailDataSources() {
 		return allDatasourcesMap.size();
 	}
@@ -172,7 +190,7 @@
 				
 				modelToDatasourceMap.put(key, ds);
 				
-			}
+			} 
 
 
 		} else {
@@ -200,7 +218,15 @@
 
 	private void loadDataSourceMappings()
 			throws QueryTestFailedException {
+		
+		Set<String> limitds = new HashSet<String>();
+        String limitdsprop = System.getProperty(USE_DATASOURCES_PROP);
+        if (limitdsprop != null && limitdsprop.length() > 0) { 
+        	List<String> dss = StringUtil.split(limitdsprop, ",");
+        	limitds.addAll(dss);
+        }
 
+
 		Document doc = null;
 		XMLReaderWriter readerWriter = new XMLReaderWriterImpl();
 
@@ -230,7 +256,7 @@
 
 				for (Iterator<Element> typeit = typeElements.iterator(); typeit.hasNext();) {
 					Element e = typeit.next();
-					addDataSource(e, typename, datasources);				
+					addDataSource(e, typename, datasources, limitds);				
 				}	
 				dstypeMap.put(typename, datasources);
 				allDatasourcesMap.putAll(datasources);
@@ -252,8 +278,14 @@
 
 	}
 	
-	private static void addDataSource(Element element, String type, Map<String, DataSource> datasources) {
+	private static void addDataSource(Element element, String group, Map<String, DataSource> datasources, Set<String> include) {
 			String name = element.getAttributeValue(Property.Attributes.NAME);
+			
+			if (include.size() > 0) {
+				if (!include.contains(name)) {
+					return;
+				}
+			}
 			Properties props = getProperties(element);
 			
 			String dir = props.getProperty(DataSource.DIRECTORY);
@@ -262,7 +294,7 @@
 			if (dsprops != null) {
 				props.putAll(dsprops);
 				DataSource ds = new DataSource(name,
-						type,
+						group,
 						props);
 				datasources.put(ds.getName(), ds);
 				System.out.println("Loaded datasource " + ds.getName());
@@ -350,14 +382,14 @@
 		DataSourceMgr mgr = DataSourceMgr.getInstance();
 
 		try {
-			DataSource ds1 = mgr.getDatasource("ds_mysql", "model1");
+			DataSource ds1 = mgr.getDatasource("ds_oracle", "model1");
 			
 			DataSource ds2 = mgr.getDatasource("nonxa", "model1");
 			if (ds1 != ds2) {
 				throw new RuntimeException("Datasources are not the same");
 			}
 			System.out.println("Value for ds_mysql: "
-					+ mgr.getDatasourceProperties("ds_mysql", "model1"));
+					+ mgr.getDatasourceProperties("ds_oracle", "model1"));
 			
 			boolean shouldbeavail = mgr.hasAvailableDataSource("nonxa", DataSource.ExclusionTypeBitMask.ORACLE);
 			if (!shouldbeavail) {
@@ -377,7 +409,36 @@
 		} catch (QueryTestFailedException e) {
 			e.printStackTrace();
 		}
+		
+		DataSourceMgr.reset();
+		
+		System.setProperty(DataSourceMgr.USE_DATASOURCES_PROP, "ds_sqlserver");
+		
+		mgr = DataSourceMgr.getInstance();
 
+		try {
+			
+			DataSource dsfind = mgr.getDatasource("ds_sqlserver", "model1");
+			if (dsfind == null) {
+				throw new RuntimeException("The special included datasource was not found");
+				
+			}
+			System.out.println("Datasource :" + dsfind.getName() + " was found");
+			
+			try {
+				DataSource dsnotfound = mgr.getDatasource("ds_oracle", "model1");
+				if (dsnotfound != null) {
+					throw new RuntimeException("The special excluded datasource was found");
+					
+				}
+			} catch (QueryTestFailedException qtf) {
+			
+				System.out.println("Datasource:  ds_oracle: was not found and should not have");
+			}
+
+		} catch (QueryTestFailedException e) {
+			e.printStackTrace();
+		}
 	}
 
 }



More information about the teiid-commits mailing list