Search in sources :

Example 6 with ConnectionIndicator

use of org.talend.dataquality.indicators.schema.ConnectionIndicator in project tdq-studio-se by Talend.

the class AbstractSchemaEvaluatorTest method testAddToConnectionIndicator2Parameters.

@Test
public /**
 * No mock. using  java reflect mechanism to set private variable.
 * @throws SQLException
 * @throws InstantiationException
 * @throws IllegalAccessException
 * @throws NoSuchFieldException
 * @throws SecurityException
 * @throws NoSuchMethodException
 * @throws IllegalArgumentException
 * @throws InvocationTargetException
 */
void testAddToConnectionIndicator2Parameters() throws SQLException, InstantiationException, IllegalAccessException, NoSuchFieldException, SecurityException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException {
    // 
    Connection dataProvider = ConnectionFactory.eINSTANCE.createConnection();
    ConnectionIndicator connectionIndicator = SchemaFactory.eINSTANCE.createConnectionIndicator();
    List<Indicator> indicators = new ArrayList<Indicator>();
    indicators.add(connectionIndicator);
    Class<ConnectionEvaluator> connEval = ConnectionEvaluator.class;
    ConnectionEvaluator instance = connEval.newInstance();
    // $NON-NLS-1$
    Field field = connEval.getDeclaredField("dataProvider");
    field.setAccessible(true);
    field.set(instance, dataProvider);
    // $NON-NLS-1$
    Field field2 = connEval.getDeclaredField("elementIndics");
    field2.setAccessible(true);
    field2.set(instance, indicators);
    SchemaIndicator schemaIndic1 = SchemaFactory.eINSTANCE.createSchemaIndicator();
    schemaIndic1.setTableCount(3);
    schemaIndic1.setViewCount(1);
    schemaIndic1.setTableRowCount(100L);
    SchemaIndicator schemaIndic2 = SchemaFactory.eINSTANCE.createSchemaIndicator();
    schemaIndic2.setTableCount(2);
    schemaIndic2.setViewCount(2);
    schemaIndic2.setTableRowCount(95L);
    CatalogIndicator catalogIndic = SchemaFactory.eINSTANCE.createCatalogIndicator();
    catalogIndic.setSchemaCount(2);
    for (int i = 0; i < 2; i++) {
        if (i == 0) {
            instance.addToConnectionIndicator(catalogIndic, schemaIndic1);
        } else {
            instance.addToConnectionIndicator(catalogIndic, schemaIndic2);
        }
    }
    assertEquals(connectionIndicator.getCatalogCount(), 1);
    assertEquals(connectionIndicator.getSchemaCount(), 2);
    assertEquals(connectionIndicator.getTableCount(), 5);
    assertEquals(connectionIndicator.getViewCount(), 3);
    assertEquals(connectionIndicator.getTableRowCount(), 195);
}
Also used : Field(java.lang.reflect.Field) SchemaIndicator(org.talend.dataquality.indicators.schema.SchemaIndicator) Connection(org.talend.core.model.metadata.builder.connection.Connection) ArrayList(java.util.ArrayList) CatalogIndicator(org.talend.dataquality.indicators.schema.CatalogIndicator) ConnectionIndicator(org.talend.dataquality.indicators.schema.ConnectionIndicator) CatalogIndicator(org.talend.dataquality.indicators.schema.CatalogIndicator) ConnectionIndicator(org.talend.dataquality.indicators.schema.ConnectionIndicator) SchemaIndicator(org.talend.dataquality.indicators.schema.SchemaIndicator) Indicator(org.talend.dataquality.indicators.Indicator) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with ConnectionIndicator

use of org.talend.dataquality.indicators.schema.ConnectionIndicator in project tdq-studio-se by Talend.

the class ConnectionAnalysisWizard method initCWMResourceBuilder.

@Override
public ModelElement initCWMResourceBuilder() {
    Analysis analysis = (Analysis) super.initCWMResourceBuilder();
    if (getAnalysisBuilder() != null) {
        IRepositoryNode connectionRepNode = getParameter().getConnectionRepNode();
        ConnectionItem item = (ConnectionItem) connectionRepNode.getObject().getProperty().getItem();
        Connection tdProvider = item.getConnection();
        getAnalysisBuilder().setAnalysisConnection(tdProvider);
        ConnectionIndicator indicator = SchemaFactory.eINSTANCE.createConnectionIndicator();
        // MOD xqliu 2009-1-21 feature 4715
        DefinitionHandler.getInstance().setDefaultIndicatorDefinition(indicator);
        indicator.setAnalyzedElement(tdProvider);
        List<Schema> tdSchemas = ConnectionHelper.getSchema(tdProvider);
        if (tdSchemas.size() != 0) {
            addSchemaIndicator(tdSchemas, indicator);
        }
        List<Catalog> tdCatalogs = ConnectionHelper.getCatalogs(tdProvider);
        for (Catalog tdCatalog : tdCatalogs) {
            CatalogIndicator createCatalogIndicator = SchemaFactory.eINSTANCE.createCatalogIndicator();
            // MOD xqliu 2009-1-21 feature 4715
            DefinitionHandler.getInstance().setDefaultIndicatorDefinition(createCatalogIndicator);
            createCatalogIndicator.setAnalyzedElement(tdCatalog);
            // MOD xqliu 2009-11-30 bug 9114
            indicator.addCatalogIndicator(createCatalogIndicator);
            // ~
            addSchemaIndicator(CatalogHelper.getSchemas(tdCatalog), indicator);
        }
        getAnalysisBuilder().addElementToAnalyze(tdProvider, indicator);
    }
    return analysis;
}
Also used : IRepositoryNode(org.talend.repository.model.IRepositoryNode) Analysis(org.talend.dataquality.analysis.Analysis) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Schema(orgomg.cwm.resource.relational.Schema) Connection(org.talend.core.model.metadata.builder.connection.Connection) CatalogIndicator(org.talend.dataquality.indicators.schema.CatalogIndicator) ConnectionIndicator(org.talend.dataquality.indicators.schema.ConnectionIndicator) Catalog(orgomg.cwm.resource.relational.Catalog)

Aggregations

ConnectionIndicator (org.talend.dataquality.indicators.schema.ConnectionIndicator)7 CatalogIndicator (org.talend.dataquality.indicators.schema.CatalogIndicator)6 SchemaIndicator (org.talend.dataquality.indicators.schema.SchemaIndicator)5 Connection (org.talend.core.model.metadata.builder.connection.Connection)4 ArrayList (java.util.ArrayList)3 Indicator (org.talend.dataquality.indicators.Indicator)3 IRepositoryNode (org.talend.repository.model.IRepositoryNode)3 Catalog (orgomg.cwm.resource.relational.Catalog)3 OverviewIndUIElement (org.talend.dataprofiler.core.model.OverviewIndUIElement)2 RepositoryNode (org.talend.repository.model.RepositoryNode)2 Schema (orgomg.cwm.resource.relational.Schema)2 Field (java.lang.reflect.Field)1 SQLException (java.sql.SQLException)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 ConnectionItem (org.talend.core.model.properties.ConnectionItem)1 MetadataCatalogRepositoryObject (org.talend.core.repository.model.repositoryObject.MetadataCatalogRepositoryObject)1 Analysis (org.talend.dataquality.analysis.Analysis)1 SchemaSwitch (org.talend.dataquality.indicators.schema.util.SchemaSwitch)1 ReturnCode (org.talend.utils.sugars.ReturnCode)1