Search in sources :

Example 21 with TJDBCInputDefinition

use of org.talend.components.jdbc.tjdbcinput.TJDBCInputDefinition 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 22 with TJDBCInputDefinition

use of org.talend.components.jdbc.tjdbcinput.TJDBCInputDefinition 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)

Example 23 with TJDBCInputDefinition

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

the class JDBCInputTestIT method testGetSchemaNames.

@Test
public void testGetSchemaNames() 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));
    JDBCSource source = DBTestUtils.createCommonJDBCSource(properties);
    List<NamedThing> schemaNames = source.getSchemaNames(null);
    assertTrue(schemaNames != null);
    assertTrue(!schemaNames.isEmpty());
    boolean exists = false;
    for (NamedThing name : schemaNames) {
        if (tablename.equals(name.getName().toUpperCase())) {
            exists = true;
            break;
        }
    }
    assertTrue(exists);
}
Also used : TJDBCInputProperties(org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties) JDBCSource(org.talend.components.jdbc.runtime.JDBCSource) NamedThing(org.talend.daikon.NamedThing) TJDBCInputDefinition(org.talend.components.jdbc.tjdbcinput.TJDBCInputDefinition) Test(org.junit.Test)

Example 24 with TJDBCInputDefinition

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

the class JDBCInputTestIT method testGetSchemaFromQueryWithException2.

@Test(expected = ComponentException.class)
public void testGetSchemaFromQueryWithException2() throws Exception {
    TJDBCInputDefinition definition = new TJDBCInputDefinition();
    TJDBCInputProperties properties = DBTestUtils.createCommonJDBCInputProperties(allSetting, definition);
    properties.connection.driverClass.setValue("notexist");
    JDBCSource source = DBTestUtils.createCommonJDBCSource(properties);
    try {
        source.getSchemaFromQuery(null, "select * from " + tablename);
    } catch (ComponentException e) {
        String message = CommonUtils.getClearExceptionInfo(e);
        assertTrue(message.contains("notexist"));
        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)

Example 25 with TJDBCInputDefinition

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

the class JDBCInputTestIT method testGetSchemaWithException.

@Test(expected = ComponentException.class)
public void testGetSchemaWithException() throws Exception {
    TJDBCInputDefinition definition = new TJDBCInputDefinition();
    TJDBCInputProperties properties = DBTestUtils.createCommonJDBCInputProperties(allSetting, definition);
    properties.connection.driverClass.setValue("notexist");
    JDBCSource source = DBTestUtils.createCommonJDBCSource(properties);
    try {
        source.getEndpointSchema(null, tablename);
    } catch (ComponentException e) {
        String message = CommonUtils.getClearExceptionInfo(e);
        assertTrue(message.contains("notexist"));
        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

TJDBCInputDefinition (org.talend.components.jdbc.tjdbcinput.TJDBCInputDefinition)32 TJDBCInputProperties (org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties)32 Test (org.junit.Test)28 IndexedRecord (org.apache.avro.generic.IndexedRecord)23 Schema (org.apache.avro.Schema)17 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