Search in sources :

Example 1 with JDBCSPSource

use of org.talend.components.jdbc.runtime.JDBCSPSource in project components by Talend.

the class JDBCSPTestIT method test_basic_as_input.

@SuppressWarnings("rawtypes")
@Test
public void test_basic_as_input() throws Exception {
    TJDBCSPDefinition definition = new TJDBCSPDefinition();
    TJDBCSPProperties properties = DBTestUtils.createCommonJDBCSPProperties(allSetting, definition);
    properties.isFunction.setValue(true);
    properties.returnResultIn.setValue("PARAMETER");
    properties.spName.setValue("SYSCS_UTIL.SYSCS_GET_DATABASE_NAME");
    Schema schema = DBTestUtils.createSPSchema2(tablename);
    properties.main.schema.setValue(schema);
    properties.schemaFlow.schema.setValue(schema);
    JDBCSPSource source = new JDBCSPSource();
    source.initialize(null, properties);
    ValidationResult result = source.validate(null);
    Assert.assertTrue(result.getStatus() == ValidationResult.Result.OK);
    Reader reader = source.createReader(null);
    try {
        reader.start();
        IndexedRecord row = (IndexedRecord) reader.getCurrent();
        String v1 = (String) row.get(0);
        Assert.assertEquals("memory:myDB", v1);
        // only output one row when it works as a input component
        Assert.assertFalse(reader.advance());
        reader.close();
    } finally {
        reader.close();
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) TJDBCSPProperties(org.talend.components.jdbc.tjdbcsp.TJDBCSPProperties) JDBCSPSource(org.talend.components.jdbc.runtime.JDBCSPSource) Reader(org.talend.components.api.component.runtime.Reader) TJDBCSPDefinition(org.talend.components.jdbc.tjdbcsp.TJDBCSPDefinition) ValidationResult(org.talend.daikon.properties.ValidationResult) Test(org.junit.Test)

Aggregations

Schema (org.apache.avro.Schema)1 IndexedRecord (org.apache.avro.generic.IndexedRecord)1 Test (org.junit.Test)1 Reader (org.talend.components.api.component.runtime.Reader)1 JDBCSPSource (org.talend.components.jdbc.runtime.JDBCSPSource)1 TJDBCSPDefinition (org.talend.components.jdbc.tjdbcsp.TJDBCSPDefinition)1 TJDBCSPProperties (org.talend.components.jdbc.tjdbcsp.TJDBCSPProperties)1 ValidationResult (org.talend.daikon.properties.ValidationResult)1