Search in sources :

Example 21 with TJDBCInputProperties

use of org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties in project components by Talend.

the class JDBCInputTestIT method testType.

@SuppressWarnings({ "rawtypes" })
@Test
public void testType() throws Exception {
    TJDBCInputDefinition definition = new TJDBCInputDefinition();
    TJDBCInputProperties properties = DBTestUtils.createCommonJDBCInputProperties(allSetting, definition);
    properties.main.schema.setValue(DBTestUtils.createTestSchema(tablename));
    properties.tableSelection.tablename.setValue(tablename);
    properties.sql.setValue(DBTestUtils.getSQL(tablename));
    Reader reader = DBTestUtils.createCommonJDBCInputReader(properties);
    try {
        IndexedRecordConverter<Object, ? extends IndexedRecord> converter = null;
        for (boolean available = reader.start(); available; available = reader.advance()) {
            converter = DBTestUtils.getIndexRecordConverter(reader, converter);
            IndexedRecord record = converter.convertToAvro(reader.getCurrent());
            assertEquals(Integer.class, record.get(0).getClass());
            assertEquals(String.class, record.get(1).getClass());
        }
        reader.close();
    } finally {
        reader.close();
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) JDBCInputReader(org.talend.components.jdbc.runtime.reader.JDBCInputReader) Reader(org.talend.components.api.component.runtime.Reader) TJDBCInputProperties(org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties) TJDBCInputDefinition(org.talend.components.jdbc.tjdbcinput.TJDBCInputDefinition) Test(org.junit.Test)

Example 22 with TJDBCInputProperties

use of org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties in project components by Talend.

the class DBTestUtils method createCommonJDBCInputProperties.

public static TJDBCInputProperties createCommonJDBCInputProperties(AllSetting allSetting, TJDBCInputDefinition definition) {
    TJDBCInputProperties properties = (TJDBCInputProperties) definition.createRuntimeProperties();
    // TODO now framework doesn't support to load the JDBC jar by the setting
    // properties.connection.driverJar.setValue(null);
    properties.connection.driverClass.setValue(allSetting.getDriverClass());
    properties.connection.jdbcUrl.setValue(allSetting.getJdbcUrl());
    properties.connection.userPassword.userId.setValue(allSetting.getUsername());
    properties.connection.userPassword.password.setValue(allSetting.getPassword());
    return properties;
}
Also used : TJDBCInputProperties(org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties)

Example 23 with TJDBCInputProperties

use of org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties in project components by Talend.

the class JDBCSchemaTestIT method testGetSchema.

@Test
public void testGetSchema() throws Exception {
    TJDBCInputDefinition definition = new TJDBCInputDefinition();
    TJDBCInputProperties properties = DBTestUtils.createCommonJDBCInputProperties(allSetting, definition);
    properties.main.schema.setValue(DBTestUtils.createTestSchema3(true, tablename));
    properties.tableSelection.tablename.setValue(tablename);
    properties.sql.setValue(DBTestUtils.getSQL(tablename));
    JDBCSource source = DBTestUtils.createCommonJDBCSource(properties);
    RuntimeContainer container = new DefaultComponentRuntimeContainerImpl() {

        @Override
        public String getCurrentComponentId() {
            return "tJDBCInput1";
        }
    };
    java.net.URL mappings_url = this.getClass().getResource("/mappings");
    mappings_url = DBTestUtils.correctURL(mappings_url);
    container.setComponentData(container.getCurrentComponentId(), ComponentConstants.MAPPING_URL_SUBFIX, mappings_url);
    Schema schema = source.getEndpointSchema(container, tablename);
    assertEquals(tablename, schema.getName().toUpperCase());
    List<Field> columns = schema.getFields();
    testMetadata(columns);
}
Also used : Field(org.apache.avro.Schema.Field) DefaultComponentRuntimeContainerImpl(org.talend.components.api.container.DefaultComponentRuntimeContainerImpl) Schema(org.apache.avro.Schema) TJDBCInputProperties(org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties) JDBCSource(org.talend.components.jdbc.runtime.JDBCSource) TJDBCInputDefinition(org.talend.components.jdbc.tjdbcinput.TJDBCInputDefinition) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) Test(org.junit.Test)

Example 24 with TJDBCInputProperties

use of org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties in project components by Talend.

the class JDBCTypeMappingTestIT method testGetSchema.

@Test
public void testGetSchema() throws Exception {
    TJDBCInputDefinition definition = new TJDBCInputDefinition();
    TJDBCInputProperties properties = DBTestUtils.createCommonJDBCInputProperties(allSetting, definition);
    properties.main.schema.setValue(DBTestUtils.createTestSchema3(true, tablename));
    properties.tableSelection.tablename.setValue(tablename);
    properties.sql.setValue(DBTestUtils.getSQL(tablename));
    JDBCSource source = DBTestUtils.createCommonJDBCSource(properties);
    RuntimeContainer container = new DefaultComponentRuntimeContainerImpl() {

        @Override
        public String getCurrentComponentId() {
            return "tJDBCInput1";
        }
    };
    java.net.URL mappings_url = this.getClass().getResource("/mappings");
    mappings_url = DBTestUtils.correctURL(mappings_url);
    container.setComponentData(container.getCurrentComponentId(), ComponentConstants.MAPPING_URL_SUBFIX, mappings_url);
    Schema schema = source.getEndpointSchema(container, tablename);
    assertEquals(tablename, schema.getName().toUpperCase());
    List<Field> columns = schema.getFields();
    testMetadata(columns);
}
Also used : Field(org.apache.avro.Schema.Field) DefaultComponentRuntimeContainerImpl(org.talend.components.api.container.DefaultComponentRuntimeContainerImpl) Schema(org.apache.avro.Schema) TJDBCInputProperties(org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties) JDBCSource(org.talend.components.jdbc.runtime.JDBCSource) TJDBCInputDefinition(org.talend.components.jdbc.tjdbcinput.TJDBCInputDefinition) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) Test(org.junit.Test)

Example 25 with TJDBCInputProperties

use of org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties in project components by Talend.

the class JDBCInputTestIT method testGetSchemaFromQueryWithException3.

@Test(expected = ComponentException.class)
public void testGetSchemaFromQueryWithException3() throws Exception {
    TJDBCInputDefinition definition = new TJDBCInputDefinition();
    TJDBCInputProperties properties = DBTestUtils.createCommonJDBCInputProperties(allSetting, definition);
    properties.connection.jdbcUrl.setValue("wrongone");
    JDBCSource source = DBTestUtils.createCommonJDBCSource(properties);
    try {
        source.getSchemaFromQuery(null, "select * from " + tablename);
    } catch (ComponentException e) {
        String message = CommonUtils.getClearExceptionInfo(e);
        assertTrue(message != null && !message.isEmpty());
        throw e;
    }
}
Also used : ComponentException(org.talend.components.api.exception.ComponentException) TJDBCInputProperties(org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties) JDBCSource(org.talend.components.jdbc.runtime.JDBCSource) TJDBCInputDefinition(org.talend.components.jdbc.tjdbcinput.TJDBCInputDefinition) Test(org.junit.Test)

Aggregations

TJDBCInputProperties (org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties)35 TJDBCInputDefinition (org.talend.components.jdbc.tjdbcinput.TJDBCInputDefinition)32 Test (org.junit.Test)30 IndexedRecord (org.apache.avro.generic.IndexedRecord)23 Schema (org.apache.avro.Schema)19 TJDBCOutputDefinition (org.talend.components.jdbc.tjdbcoutput.TJDBCOutputDefinition)12 TJDBCOutputProperties (org.talend.components.jdbc.tjdbcoutput.TJDBCOutputProperties)12 JDBCOutputWriter (org.talend.components.jdbc.runtime.writer.JDBCOutputWriter)11 JDBCSource (org.talend.components.jdbc.runtime.JDBCSource)9 Reader (org.talend.components.api.component.runtime.Reader)6 ComponentException (org.talend.components.api.exception.ComponentException)6 ValidationResult (org.talend.daikon.properties.ValidationResult)6 TJDBCRowDefinition (org.talend.components.jdbc.tjdbcrow.TJDBCRowDefinition)5 TJDBCRowProperties (org.talend.components.jdbc.tjdbcrow.TJDBCRowProperties)5 Field (org.apache.avro.Schema.Field)4 JDBCRowSourceOrSink (org.talend.components.jdbc.runtime.JDBCRowSourceOrSink)4 IOException (java.io.IOException)3 BigDecimal (java.math.BigDecimal)3 SQLException (java.sql.SQLException)3 WriteOperation (org.talend.components.api.component.runtime.WriteOperation)3