use of orgomg.cwm.resource.relational.Catalog in project tdq-studio-se by Talend.
the class PatternExplorerRealTest method testGetValidRowsStatement_5.
/**
* Test method for {@link org.talend.dq.analysis.explore.PatternExplorer#getValidRowsStatement()}. when the test for
* indicator is user define indicator
*/
@Test
public void testGetValidRowsStatement_5() {
patternExplorer = new RegexPatternExplorer();
// mock setEntity
PatternMatchingIndicator indicator = IndicatorsFactoryImpl.eINSTANCE.createRegexpMatchingIndicator();
UDIndicatorDefinition indicatorDef = UserdefineFactoryImpl.eINSTANCE.createUDIndicatorDefinition();
indicator.setIndicatorDefinition(indicatorDef);
TdExpression udiTdExpression = RelationalFactoryImpl.eINSTANCE.createTdExpression();
udiTdExpression.setLanguage(SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
udiTdExpression.setBody(ViewValidRows);
indicatorDef.getViewValidRowsExpression().add(udiTdExpression);
// create pattern parameter
IndicatorParameters createIndicatorParameters = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
indicator.setParameters(createIndicatorParameters);
Domain createDomain = DomainFactoryImpl.eINSTANCE.createDomain();
createIndicatorParameters.setDataValidDomain(createDomain);
Pattern createPattern = PatternFactoryImpl.eINSTANCE.createPattern();
createDomain.getPatterns().add(createPattern);
RegularExpression createPatternComponent = PatternFactoryImpl.eINSTANCE.createRegularExpression();
createPattern.getComponents().add(createPatternComponent);
TdExpression createTdExpression = RelationalFactoryImpl.eINSTANCE.createTdExpression();
createPatternComponent.setExpression(createTdExpression);
createTdExpression.setLanguage(SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
// $NON-NLS-1$
createTdExpression.setBody("`su.*`");
TdColumn element = RelationalFactoryImpl.eINSTANCE.createTdColumn();
// $NON-NLS-1$
element.setName("lname");
TdTable createTdTable = RelationalFactoryImpl.eINSTANCE.createTdTable();
// $NON-NLS-1$
createTdTable.setName("table1");
TableHelper.addColumn(createTdTable, element);
Catalog createCatalog = orgomg.cwm.resource.relational.impl.RelationalFactoryImpl.eINSTANCE.createCatalog();
// $NON-NLS-1$
createCatalog.setName("catalog1");
List<TdTable> tableList = new ArrayList<TdTable>();
tableList.add(createTdTable);
CatalogHelper.addTables(tableList, createCatalog);
indicator.setAnalyzedElement(element);
Expression createIndiExpression = CoreFactoryImpl.eINSTANCE.createExpression();
createIndiExpression.setLanguage(SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
// $NON-NLS-1$
createIndiExpression.setBody("SELECT * FROM `tbi`.`customer` WHERE (customer.lname = \"sunny\")");
indicator.setInstantiatedExpression(createIndiExpression);
Analysis analysis = AnalysisFactoryImpl.eINSTANCE.createAnalysis();
AnalysisContext createAnalysisContext = AnalysisFactoryImpl.eINSTANCE.createAnalysisContext();
analysis.setContext(createAnalysisContext);
DatabaseConnection createDatabaseConnection = ConnectionFactoryImpl.eINSTANCE.createDatabaseConnection();
TaggedValueHelper.setTaggedValue(createDatabaseConnection, TaggedValueHelper.DB_PRODUCT_NAME, SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
// $NON-NLS-1$
TaggedValueHelper.setTaggedValue(createDatabaseConnection, TaggedValueHelper.DB_PRODUCT_VERSION, "1.0");
// $NON-NLS-1$
TaggedValueHelper.setTaggedValue(createDatabaseConnection, TaggedValueHelper.DB_IDENTIFIER_QUOTE_STRING, "`");
createAnalysisContext.setConnection(createDatabaseConnection);
ChartDataEntity cdEntity = new ChartDataEntity();
cdEntity.setIndicator(indicator);
Assert.assertTrue(patternExplorer.setAnalysis(analysis));
patternExplorer.setEnitty(cdEntity);
String clause = patternExplorer.getValidRowsStatement();
// $NON-NLS-1$
assertEquals("SELECT * FROM `catalog1`.`table1` ", clause);
}
use of orgomg.cwm.resource.relational.Catalog in project tdq-studio-se by Talend.
the class DbmsLanguageTest method createTdTable.
private TdTable createTdTable() {
Connection conn = ConnectionFactory.eINSTANCE.createDatabaseConnection();
// $NON-NLS-1$
Catalog catalog = CatalogHelper.createCatalog("myCatalog");
ConnectionHelper.addCatalog(catalog, conn);
List<TdTable> tables = new ArrayList<TdTable>();
TdTable tdTable = RelationalFactory.eINSTANCE.createTdTable();
// $NON-NLS-1$
tdTable.setName("myTable");
tables.add(tdTable);
CatalogHelper.addTables(tables, catalog);
return tdTable;
}
use of orgomg.cwm.resource.relational.Catalog in project tdq-studio-se by Talend.
the class SwitchContextGroupNameImplTest method testUpdateContextGroupSuccessMysql.
/**
* Test method for
* {@link org.talend.repository.ui.utils.SwitchContextGroupNameImpl#updateContextGroup(org.talend.core.model.properties.ConnectionItem)}
* . mysql case
*/
@Test
public void testUpdateContextGroupSuccessMysql() {
boolean updateContextGroup = SwitchContextGroupNameImpl.getInstance().updateContextGroup(createDatabaseConnectionItem, ContextTpeyNameNew);
Connection connection = createDatabaseConnectionItem.getConnection();
List<Catalog> catalogs = ConnectionHelper.getCatalogs(connection);
assertTrue(updateContextGroup);
assertTrue(catalogs.size() == 1);
assertTrue(catalogs.get(0).getName().equalsIgnoreCase(catalogNew));
}
use of orgomg.cwm.resource.relational.Catalog in project tdq-studio-se by Talend.
the class SwitchContextGroupNameImplTest method testUpdateContextGroupfail1.
/**
* Test method for
* {@link org.talend.repository.ui.utils.SwitchContextGroupNameImpl#updateContextGroup(org.talend.core.model.properties.ConnectionItem)}
* . fail1: createDatabaseConnectionItem is null will nothing to do and return false
*/
@Test
public void testUpdateContextGroupfail1() {
boolean updateContextGroup = SwitchContextGroupNameImpl.getInstance().updateContextGroup(null, ContextTpeyNameNew);
Connection connection = createDatabaseConnectionItem.getConnection();
List<Catalog> catalogs = ConnectionHelper.getCatalogs(connection);
assertFalse(updateContextGroup);
assertTrue(catalogs.size() == 1);
assertTrue(catalogs.get(0).getName().equalsIgnoreCase(catalogOld));
}
use of orgomg.cwm.resource.relational.Catalog in project tdq-studio-se by Talend.
the class SwitchContextGroupNameImplTest method createCatalogSchema.
/**
* DOC talend Comment method "createSchema".
*
* @param schemaOld2
*/
private void createCatalogSchema(String schemaOld2) {
Connection connection = createDatabaseConnectionItem.getConnection();
((DatabaseConnection) connection).setUiSchema(this.contextSchemaName);
List<Catalog> catalogs = ConnectionHelper.getCatalogs(connection);
Catalog catalog = catalogs.get(0);
Schema createSchema = SchemaHelper.createSchema(schemaOld);
List<Schema> schemas = new ArrayList<Schema>();
schemas.add(createSchema);
CatalogHelper.addSchemas(schemas, catalog);
}
Aggregations