use of org.teiid.test.framework.ConfigPropertyLoader in project teiid by teiid.
the class DataSourceFactory method main.
public static void main(String[] args) {
// NOTE: to run this test to validate the DataSourceMgr, do the following:
// --- need 3 datasources, Oracle, SqlServer and 1 other
ConfigPropertyLoader config = ConfigPropertyLoader.getInstance();
DataSourceFactory factory = new DataSourceFactory(config);
try {
if (factory.getDatasource("model1") == null) {
throw new TransactionRuntimeException("No datasource was not found");
}
} catch (QueryTestFailedException e) {
e.printStackTrace();
}
factory.cleanup();
ConfigPropertyLoader.reset();
// the following verifies that order of "use" datasources is applied to request for datasources.
config = ConfigPropertyLoader.getInstance();
config.setProperty(ConfigPropertyNames.USE_DATASOURCES_PROP, "oracle,sqlserver");
factory = new DataSourceFactory(config);
try {
DataSource dsfind = factory.getDatasource("model2");
if (dsfind == null) {
throw new TransactionRuntimeException("No datasource was not found as the 2nd datasource");
}
if (dsfind.getConnectorType() == null) {
throw new TransactionRuntimeException("Connector types was not defined");
}
if (!dsfind.getName().equalsIgnoreCase("sqlserver")) {
throw new TransactionRuntimeException("Sqlserver was not found as the 2nd datasource");
}
dsfind = factory.getDatasource("model1");
if (dsfind == null) {
throw new TransactionRuntimeException("No datasource was not found as the 2nd datasource");
}
if (!dsfind.getName().equalsIgnoreCase("oracle")) {
throw new TransactionRuntimeException("Oracle was not found as the 2nd datasource");
}
System.out.println("Datasource :" + dsfind.getName() + " was found");
// the following test verifies that a sqlserver datasource is not
// returned (excluded)
factory.cleanup();
ConfigPropertyLoader.reset();
config = ConfigPropertyLoader.getInstance();
config.setProperty(ConfigPropertyNames.EXCLUDE_DATASBASE_TYPES_PROP, "sqlserver");
factory = new DataSourceFactory(config);
int n = factory.getNumberAvailableDataSources();
TestLogger.log("Num avail datasources: " + n);
for (int i = 0; i < n; i++) {
String k = String.valueOf(i);
DataSource ds1 = factory.getDatasource("model" + k);
if (ds1 == null) {
throw new TransactionRuntimeException("No datasource was found for: model:" + k);
}
if (ds1.getDBType().equalsIgnoreCase(DataSourceFactory.DataBaseTypes.SQLSERVER)) {
throw new TransactionRuntimeException("sqlserver dbtype should have been excluded");
}
}
DataSource reuse = factory.getDatasource("model1");
if (reuse != null) {
} else {
throw new TransactionRuntimeException("The process was not able to reassign an already used datasource");
}
factory.cleanup();
ConfigPropertyLoader.reset();
// test required database types
// test 1 source
config = ConfigPropertyLoader.getInstance();
config.setModelAssignedToDatabaseType("pm1", DataSourceFactory.DataBaseTypes.ORACLE);
factory = new DataSourceFactory(config);
DataSource ds1 = factory.getDatasource("pm1");
if (!ds1.getDBType().equalsIgnoreCase(DataSourceFactory.DataBaseTypes.ORACLE)) {
throw new TransactionRuntimeException("Required DB Type of oracle for model pm1 is :" + ds1.getDBType());
}
TestLogger.log("Test1 Required DS1 " + ds1.getDBType());
factory.cleanup();
ConfigPropertyLoader.reset();
// test required database types
// test 2 sources, 1 required and other ANY
config = ConfigPropertyLoader.getInstance();
config.setModelAssignedToDatabaseType("pm2", DataSourceFactory.DataBaseTypes.SQLSERVER);
config.setModelAssignedToDatabaseType("pm1", DataSourceFactory.DataBaseTypes.ANY);
factory = new DataSourceFactory(config);
DataSource ds2 = factory.getDatasource("pm2");
if (!ds2.getDBType().equalsIgnoreCase(DataSourceFactory.DataBaseTypes.SQLSERVER)) {
throw new TransactionRuntimeException("Required DB Type of sqlserver for model pm2 is :" + ds2.getDBType());
}
TestLogger.log("Test2 Required DS2 " + ds2.getDBType());
factory.cleanup();
ConfigPropertyLoader.reset();
// test required database types
// test 2 sources, 2 required
config = ConfigPropertyLoader.getInstance();
config.setModelAssignedToDatabaseType("pm2", DataSourceFactory.DataBaseTypes.SQLSERVER);
config.setModelAssignedToDatabaseType("pm1", DataSourceFactory.DataBaseTypes.ORACLE);
factory = new DataSourceFactory(config);
DataSource ds3a = factory.getDatasource("pm2");
if (!ds3a.getDBType().equalsIgnoreCase(DataSourceFactory.DataBaseTypes.SQLSERVER)) {
throw new TransactionRuntimeException("Required DB Type of sqlserver for model pm12 is :" + ds3a.getDBType());
}
DataSource ds3b = factory.getDatasource("pm1");
if (!ds3b.getDBType().equalsIgnoreCase(DataSourceFactory.DataBaseTypes.ORACLE)) {
throw new TransactionRuntimeException("Required DB Type of oracle for model pm1 is :" + ds3b.getDBType());
}
TestLogger.log("Test3 Required DS3a " + ds3a.getDBType());
TestLogger.log("Test3 Required DS3b " + ds3b.getDBType());
factory.cleanup();
} catch (QueryTestFailedException e) {
e.printStackTrace();
}
}
use of org.teiid.test.framework.ConfigPropertyLoader in project teiid by teiid.
the class XMLExpectedResults method main.
public static void main(String[] args) {
System.setProperty(ConfigPropertyNames.CONFIG_FILE, "ctc-bqt-test.properties");
ConfigPropertyLoader _instance = ConfigPropertyLoader.getInstance();
Properties p = _instance.getProperties();
if (p == null || p.isEmpty()) {
throw new RuntimeException("Failed to load config properties file");
}
QueryScenario set = ClassFactory.createQueryScenario("testscenario");
_instance.setProperty(XMLQueryReader.PROP_QUERY_FILES_ROOT_DIR, new File("src/main/resources/").getAbsolutePath());
try {
Iterator<String> it = set.getQuerySetIDs().iterator();
while (it.hasNext()) {
String querySetID = it.next();
List<QueryTest> queries = set.getQueries(querySetID);
if (queries.size() == 0l) {
System.out.println("Failed, didn't load any queries ");
}
ExpectedResults er = set.getExpectedResults(querySetID);
// new XMLExpectedResults(_instance.getProperties(), querySetID);
ResultsGenerator gr = set.getResultsGenerator();
// new XMLGenerateResults(_instance.getProperties(), "testname", set.getOutputDirectory());
Iterator<QueryTest> qIt = queries.iterator();
while (qIt.hasNext()) {
QueryTest q = qIt.next();
// String qId = (String) qIt.next();
// String sql = (String) queries.get(qId);
// System.out.println("SetID #: " + cnt + " Qid: " + qId + " sql: " + sql);
File resultsFile = er.getResultsFile(q.getQueryID());
if (resultsFile == null) {
System.out.println("Failed to get results file for queryID " + q.getQueryID());
}
}
}
System.out.println("Completed Test");
} catch (QueryTestFailedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.teiid.test.framework.ConfigPropertyLoader in project teiid by teiid.
the class XMLQueryReader method main.
public static void main(String[] args) {
System.setProperty(ConfigPropertyNames.CONFIG_FILE, "ctc-bqt-test.properties");
ConfigPropertyLoader _instance = ConfigPropertyLoader.getInstance();
Properties p = _instance.getProperties();
if (p == null || p.isEmpty()) {
throw new RuntimeException("Failed to load config properties file");
}
_instance.setProperty(PROP_QUERY_FILES_ROOT_DIR, new File("src/main/resources/").getAbsolutePath());
try {
XMLQueryReader reader = new XMLQueryReader("scenario_id", _instance.getProperties());
Iterator<String> it = reader.getQuerySetIDs().iterator();
while (it.hasNext()) {
String querySetID = it.next();
List<QueryTest> queries = reader.getQueries(querySetID);
if (queries.size() == 0l) {
System.out.println("Failed, didn't load any queries ");
}
}
} catch (QueryTestFailedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.teiid.test.framework.ConfigPropertyLoader in project teiid by teiid.
the class ConnectionStrategyFactory method createConnectionStrategy.
public static ConnectionStrategy createConnectionStrategy() {
ConfigPropertyLoader configLoader = ConfigPropertyLoader.getInstance();
ConnectionStrategy strategy = null;
Properties props = configLoader.getProperties();
String type = props.getProperty(ConfigPropertyNames.CONNECTION_TYPE, ConfigPropertyNames.CONNECTION_TYPES.DRIVER_CONNECTION);
if (type == null) {
throw new TransactionRuntimeException("Property " + ConfigPropertyNames.CONNECTION_TYPE + " was specified");
}
try {
if (type.equalsIgnoreCase(ConfigPropertyNames.CONNECTION_TYPES.DRIVER_CONNECTION)) {
// pass in null to create new strategy
strategy = new DriverConnection(props);
TestLogger.logDebug("Created Driver Strategy");
} else if (type.equalsIgnoreCase(ConfigPropertyNames.CONNECTION_TYPES.DATASOURCE_CONNECTION)) {
strategy = new DataSourceConnection(props);
TestLogger.logDebug("Created DataSource Strategy");
} else if (type.equalsIgnoreCase(ConfigPropertyNames.CONNECTION_TYPES.JNDI_CONNECTION)) {
strategy = new JEEConnection(props);
TestLogger.logDebug("Created JEE Strategy");
}
if (strategy == null) {
new TransactionRuntimeException("Invalid property value for " + ConfigPropertyNames.CONNECTION_TYPE + " is " + type);
}
// call configure here because this is creating the connection to Teiid
// direct connections to the datasource use the static call directly to create strategy and don't need to configure
strategy.configure();
return strategy;
} catch (Exception e) {
throw new TransactionRuntimeException(e);
}
}
use of org.teiid.test.framework.ConfigPropertyLoader in project teiid by teiid.
the class ConnectionStrategyFactory method main.
public static void main(String[] args) {
// NOTE: to run this test to validate the DataSourceMgr, do the following:
// --- need 3 datasources, Oracle, SqlServer and 1 other
ConfigPropertyLoader config = ConfigPropertyLoader.getInstance();
new DataSourceFactory(config);
}
Aggregations