Search in sources :

Example 21 with ReturnCode

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;
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) SQLException(java.sql.SQLException) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) Properties(java.util.Properties) DBConnectionParameter(org.talend.dq.analysis.parameters.DBConnectionParameter) MetadataFillFactory(org.talend.metadata.managment.model.MetadataFillFactory)

Example 22 with ReturnCode

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());
        }
    }
}
Also used : PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) ReturnCode(org.talend.utils.sugars.ReturnCode) Analysis(org.talend.dataquality.analysis.Analysis) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) Property(org.talend.core.model.properties.Property) PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) Indicator(org.talend.dataquality.indicators.Indicator) Test(org.junit.Test)

Example 23 with ReturnCode

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());
}
Also used : PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) ReturnCode(org.talend.utils.sugars.ReturnCode) Analysis(org.talend.dataquality.analysis.Analysis) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) Property(org.talend.core.model.properties.Property) PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) Indicator(org.talend.dataquality.indicators.Indicator) Test(org.junit.Test)

Example 24 with ReturnCode

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;
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) SQLException(java.sql.SQLException) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) Properties(java.util.Properties) EProperties(org.talend.repository.model.IRepositoryNode.EProperties) DBConnectionParameter(org.talend.dq.analysis.parameters.DBConnectionParameter) MetadataFillFactory(org.talend.metadata.managment.model.MetadataFillFactory)

Example 25 with ReturnCode

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));
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) SourceFileRepNode(org.talend.dq.nodes.SourceFileRepNode) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

ReturnCode (org.talend.utils.sugars.ReturnCode)175 ArrayList (java.util.ArrayList)42 TypedReturnCode (org.talend.utils.sugars.TypedReturnCode)42 Test (org.junit.Test)29 File (java.io.File)26 Connection (org.talend.core.model.metadata.builder.connection.Connection)26 Indicator (org.talend.dataquality.indicators.Indicator)25 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)20 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)18 Analysis (org.talend.dataquality.analysis.Analysis)18 Property (org.talend.core.model.properties.Property)17 IFile (org.eclipse.core.resources.IFile)16 IRepositoryNode (org.talend.repository.model.IRepositoryNode)16 IFolder (org.eclipse.core.resources.IFolder)15 SQLException (java.sql.SQLException)14 PersistenceException (org.talend.commons.exception.PersistenceException)11 TdColumn (org.talend.cwm.relational.TdColumn)11 IOException (java.io.IOException)10 EObject (org.eclipse.emf.ecore.EObject)10 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)10