use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.
the class UnitTestBuildHelper method getDB2DataManager.
/**
* getDataManager of DB2
*
* @return
*/
public Connection getDB2DataManager() {
// TypedProperties connectionParams = PropertiesLoader.getProperties(IndicatorEvaluator.class, "db.properties"); //$NON-NLS-1$
// $NON-NLS-1$
String driverClassName = "com.ibm.db2.jcc.DB2Driver";
// $NON-NLS-1$
String dbUrl = "jdbc:db2://192.168.31.135:50000/sample";
// $NON-NLS-1$
String sqlTypeName = "IBM DB2";
DBConnectionParameter params = new DBConnectionParameter();
// $NON-NLS-1$
params.setName("DB2_Connection");
params.setDriverClassName(driverClassName);
params.setJdbcUrl(dbUrl);
params.setSqlTypeName(sqlTypeName);
Properties properties = new Properties();
properties.setProperty(TaggedValueHelper.UNIVERSE, "");
properties.setProperty(TaggedValueHelper.DATA_FILTER, "");
properties.setProperty(TaggedValueHelper.USER, "db2inst1");
properties.setProperty(TaggedValueHelper.PASSWORD, "db2inst1");
params.setParameters(properties);
// create connection
ConnectionUtils.setTimeout(false);
MetadataFillFactory instance = MetadataFillFactory.getDBInstance();
IMetadataConnection metaConnection = instance.fillUIParams(ParameterUtil.toMap(params));
ReturnCode rc = null;
try {
rc = instance.checkConnection(metaConnection);
} catch (java.lang.RuntimeException e) {
Assert.fail("connect to " + dbUrl + "failed," + e.getMessage());
}
Connection dataProvider = null;
if (rc.isOk()) {
dataProvider = instance.fillUIConnParams(metaConnection, null);
dataProvider.setName("DB2_Connection");
// because the DI side code is changed, modify the following code.
metaConnection.setCurrentConnection(dataProvider);
try {
ProjectNodeHelper.fillCatalogAndSchemas(metaConnection, (DatabaseConnection) dataProvider);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Assert.assertNotNull("Can not connect to Database: " + dbUrl, dataProvider);
return dataProvider;
}
use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.
the class AnalysisExecutorHelperTest method testCheckIndicatorWithOutDependencyFiles.
@Test
public void testCheckIndicatorWithOutDependencyFiles() {
// Load analysis item/property model from test file.
// $NON-NLS-1$
String anaPropertyFile = "/data/builtin/indicator_without_dep/TDQ_Data_Profiling/Analyses/patternMatchAna_0.1.properties";
Resource anaPropertyResource = getPlatformResource(anaPropertyFile);
Analysis ana = null;
Property anaProperty = null;
while (anaPropertyResource.getAllContents().hasNext()) {
EObject eobj = anaPropertyResource.getAllContents().next();
if (eobj instanceof Property) {
anaProperty = (Property) eobj;
ana = ((TDQAnalysisItem) anaProperty.getItem()).getAnalysis();
break;
}
}
if (ana == null) {
Assert.fail("The analysis is null!");
}
if (ana.getResults() == null) {
Assert.fail("The result of analysis is null!");
}
if (ana.getResults().getIndicators() == null) {
Assert.fail("The indicators of analysis is null!");
}
for (Indicator indicator : ana.getResults().getIndicators()) {
if (!(indicator instanceof PatternMatchingIndicator)) {
// Check system indicator and UDI
assertTrue(indicator.getIndicatorDefinition().getName() != null);
assertTrue(indicator.getBuiltInIndicatorDefinition() != null);
assertTrue(indicator.getBuiltInIndicatorDefinition() == indicator.getIndicatorDefinition());
}
}
ReturnCode rc = AnalysisExecutorHelper.check(ana);
assertTrue(rc.isOk());
for (Indicator indicator : ana.getResults().getIndicators()) {
if (!(indicator instanceof PatternMatchingIndicator)) {
// Check system indicator and UDI
assertTrue(indicator.getIndicatorDefinition().getName() != null);
assertTrue(indicator.getBuiltInIndicatorDefinition() != null);
assertTrue(indicator.getBuiltInIndicatorDefinition() == indicator.getIndicatorDefinition());
}
}
}
use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.
the class AnalysisExecutorHelperTest method testCheckIndicatorWithOutDependencyFilesAndBuiltIn.
@Test
public void testCheckIndicatorWithOutDependencyFilesAndBuiltIn() {
// Load analysis item/property model from test file.
// $NON-NLS-1$
String anaPropertyFile = "/data/builtin/indicator_without_dep_builtin/TDQ_Data_Profiling/Analyses/patternMatchAna_0.1.properties";
Resource anaPropertyResource = getPlatformResource(anaPropertyFile);
Analysis ana = null;
Property anaProperty = null;
while (anaPropertyResource.getAllContents().hasNext()) {
EObject eobj = anaPropertyResource.getAllContents().next();
if (eobj instanceof Property) {
anaProperty = (Property) eobj;
ana = ((TDQAnalysisItem) anaProperty.getItem()).getAnalysis();
break;
}
}
if (ana == null) {
Assert.fail("The analysis is null!");
}
if (ana.getResults() == null) {
Assert.fail("The result of analysis is null!");
}
if (ana.getResults().getIndicators() == null) {
Assert.fail("The indicators of analysis is null!");
}
for (Indicator indicator : ana.getResults().getIndicators()) {
if (!(indicator instanceof PatternMatchingIndicator)) {
// Check system indicator and UDI
assertTrue(indicator.getIndicatorDefinition().getName() == null);
assertTrue(indicator.getBuiltInIndicatorDefinition() == null);
}
}
ReturnCode rc = AnalysisExecutorHelper.check(ana);
assertFalse(rc.isOk());
}
use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.
the class UnitTestBuildHelper method getRealOracleDatabase.
/**
* get a real database connection,the connection parameters load from a propery file.
*
* @return
*/
public static Connection getRealOracleDatabase() {
Properties connectionParams = DBPropertiesUtils.getDefault().getProperties();
// $NON-NLS-1$
String driverClassName = connectionParams.getProperty("driver_oracle");
// $NON-NLS-1$
String dbUrl = connectionParams.getProperty("url_oracle");
// $NON-NLS-1$
String sqlTypeName = connectionParams.getProperty("sqlTypeName_oracle");
// $NON-NLS-1$
String dbVersion = connectionParams.getProperty("dbVersion_oracle");
// $NON-NLS-1$
String userName = connectionParams.getProperty("user_oracle");
// $NON-NLS-1$
String password = connectionParams.getProperty("password_oracle");
DBConnectionParameter params = new DBConnectionParameter();
// $NON-NLS-1$
params.setName("My connection");
params.setDriverClassName(driverClassName);
params.setJdbcUrl(dbUrl);
params.setSqlTypeName(sqlTypeName);
params.setParameters(connectionParams);
params.getParameters();
Properties properties = new Properties();
properties.setProperty(TaggedValueHelper.USER, userName);
properties.setProperty(TaggedValueHelper.PASSWORD, password);
properties.setProperty(TaggedValueHelper.DB_PRODUCT_VERSION, dbVersion);
params.setParameters(properties);
// create connection
ConnectionUtils.setTimeout(false);
MetadataFillFactory instance = MetadataFillFactory.getDBInstance();
IMetadataConnection metaConnection = instance.fillUIParams(ParameterUtil.toMap(params));
metaConnection.setDbVersionString(dbVersion);
ReturnCode rc = null;
try {
rc = instance.checkConnection(metaConnection);
} catch (java.lang.RuntimeException e) {
// $NON-NLS-1$ //$NON-NLS-2$
Assert.fail("connect to " + dbUrl + "failed," + e.getMessage());
}
Connection dataProvider = null;
if (rc.isOk()) {
dataProvider = instance.fillUIConnParams(metaConnection, null);
dataProvider.setName(DATA_PROVIDER_NAME);
// because the DI side code is changed, modify the following code.
metaConnection.setCurrentConnection(dataProvider);
try {
ProjectNodeHelper.fillCatalogAndSchemas(metaConnection, (DatabaseConnection) dataProvider);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Assert.assertNotNull(dataProvider);
return dataProvider;
}
use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.
the class WorkspaceResourceHelperTest method testCheckSourceFileNodeOpening.
/**
* Test method for
* {@link org.talend.dataprofiler.core.helper.WorkspaceResourceHelper#checkSourceFileNodeOpening(org.talend.dq.nodes.SourceFileRepNode)}
* .
*/
@Test
public void testCheckSourceFileNodeOpening() {
SourceFileRepNode fileNodeMock = mock(SourceFileRepNode.class);
// $NON-NLS-1$
String nodeLabel = "nodeLabel";
when(fileNodeMock.getLabel()).thenReturn(nodeLabel);
// $NON-NLS-1$
stub(method(WorkspaceResourceHelper.class, "sourceFileHasBeenOpened", SourceFileRepNode.class)).toReturn(Boolean.TRUE);
ReturnCode rc = WorkspaceResourceHelper.checkSourceFileNodeOpening(fileNodeMock);
assertTrue(rc.isOk());
assertTrue(rc.getMessage().startsWith(nodeLabel));
}
Aggregations