Search in sources :

Example 11 with JDBCDatasetProperties

use of org.talend.components.jdbc.dataset.JDBCDatasetProperties in project components by Talend.

the class JdbcInputTestIT method createCommonJDBCInputProperties.

private JDBCInputProperties createCommonJDBCInputProperties(JDBCInputDefinition definition) {
    JDBCDatastoreDefinition datastore_def = new JDBCDatastoreDefinition();
    JDBCDatastoreProperties datastore_props = new JDBCDatastoreProperties("datastore");
    datastore_props.dbTypes.setValue("DERBY");
    datastore_props.afterDbTypes();
    datastore_props.jdbcUrl.setValue(allSetting.getJdbcUrl());
    datastore_props.userId.setValue(allSetting.getUsername());
    datastore_props.password.setValue(allSetting.getPassword());
    JDBCDatasetProperties dataset = (JDBCDatasetProperties) datastore_def.createDatasetProperties(datastore_props);
    dataset.sql.setValue(DBTestUtils.getSQL(tablename));
    dataset.updateSchema();
    JDBCInputProperties properties = (JDBCInputProperties) definition.createRuntimeProperties();
    properties.setDatasetProperties(dataset);
    return properties;
}
Also used : JDBCDatastoreDefinition(org.talend.components.jdbc.datastore.JDBCDatastoreDefinition) JDBCDatasetProperties(org.talend.components.jdbc.dataset.JDBCDatasetProperties) JDBCDatastoreProperties(org.talend.components.jdbc.datastore.JDBCDatastoreProperties)

Example 12 with JDBCDatasetProperties

use of org.talend.components.jdbc.dataset.JDBCDatasetProperties in project components by Talend.

the class JdbcDatasetRuntimeTest method testBasic.

@Test
public void testBasic() throws Exception {
    JDBCDatasetProperties props = createDatasetProperties();
    final List<IndexedRecord> consumed = new ArrayList<>();
    RuntimeInfo ri = def.getRuntimeInfo(props);
    try (SandboxedInstance si = RuntimeUtil.createRuntimeClass(ri, getClass().getClassLoader())) {
        DatasetRuntime runtime = (DatasetRuntime) si.getInstance();
        runtime.initialize(null, props);
        assertThat(runtime, not(nullValue()));
        Schema s = runtime.getSchema();
        assertThat(s, not(nullValue()));
        runtime.getSample(100, new Consumer<IndexedRecord>() {

            @Override
            public void accept(IndexedRecord ir) {
                consumed.add(ir);
            }
        });
    }
    assertThat(consumed, hasSize(2));
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) IndexedRecord(org.apache.avro.generic.IndexedRecord) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) DatasetRuntime(org.talend.components.common.dataset.runtime.DatasetRuntime) Schema(org.apache.avro.Schema) ArrayList(java.util.ArrayList) JDBCDatasetProperties(org.talend.components.jdbc.dataset.JDBCDatasetProperties) Test(org.junit.Test)

Example 13 with JDBCDatasetProperties

use of org.talend.components.jdbc.dataset.JDBCDatasetProperties in project components by Talend.

the class JDBCInputPropertiesTest method testGetRuntimeSetting.

/**
 * Run the AllSetting getRuntimeSetting() method test.
 *
 * @throws Exception
 *
 * @generatedBy CodePro at 17-6-23 AM11:58
 */
@Test
public void testGetRuntimeSetting() throws Exception {
    JDBCInputProperties fixture = new JDBCInputProperties("");
    JDBCDatasetProperties dataset = new JDBCDatasetProperties("dataset");
    JDBCDatastoreProperties datastore = new JDBCDatastoreProperties("datastore");
    datastore.init();
    dataset.setDatastoreProperties(datastore);
    fixture.setDatasetProperties(dataset);
    AllSetting result = fixture.getRuntimeSetting();
    assertNotNull(result);
}
Also used : AllSetting(org.talend.components.jdbc.runtime.setting.AllSetting) JDBCDatasetProperties(org.talend.components.jdbc.dataset.JDBCDatasetProperties) JDBCDatastoreProperties(org.talend.components.jdbc.datastore.JDBCDatastoreProperties) Test(org.junit.Test)

Example 14 with JDBCDatasetProperties

use of org.talend.components.jdbc.dataset.JDBCDatasetProperties in project components by Talend.

the class JDBCInputProperties method getRuntimeSetting.

@Override
public AllSetting getRuntimeSetting() {
    AllSetting setting = new AllSetting();
    JDBCDatasetProperties datasetProperties = this.getDatasetProperties();
    JDBCDatastoreProperties datastoreProperties = datasetProperties.getDatastoreProperties();
    setting.setDriverPaths(datastoreProperties.getCurrentDriverPaths());
    setting.setDriverClass(datastoreProperties.getCurrentDriverClass());
    setting.setJdbcUrl(datastoreProperties.jdbcUrl.getValue());
    setting.setUsername(datastoreProperties.userId.getValue());
    setting.setPassword(datastoreProperties.password.getValue());
    setting.setSql(datasetProperties.sql.getValue());
    setting.setSchema(datasetProperties.main.schema.getValue());
    return setting;
}
Also used : AllSetting(org.talend.components.jdbc.runtime.setting.AllSetting) JDBCDatasetProperties(org.talend.components.jdbc.dataset.JDBCDatasetProperties) JDBCDatastoreProperties(org.talend.components.jdbc.datastore.JDBCDatastoreProperties)

Example 15 with JDBCDatasetProperties

use of org.talend.components.jdbc.dataset.JDBCDatasetProperties in project components by Talend.

the class JdbcComponentTestIT method initializeJDBCDatasetProperties.

@Test
public void initializeJDBCDatasetProperties() throws java.io.IOException {
    // given
    SerPropertiesDto propDto = new SerPropertiesDto();
    propDto.setProperties(new JDBCDatasetProperties("").init().toSerialized());
    propDto.setDependencies(singletonList(new JDBCDatastoreProperties("").init().toSerialized()));
    // when
    Response response = // 
    given().content(propDto).contentType(ServiceConstants.JSONIO_CONTENT_TYPE).accept(// 
    ServiceConstants.UI_SPEC_CONTENT_TYPE).expect().statusCode(200).log().ifError().post(getVersionPrefix() + "/properties/uispec");
    // then
    ObjectNode jdbcProperties = mapper.readerFor(ObjectNode.class).readValue(response.asInputStream());
    assertNotNull(jdbcProperties.get("jsonSchema"));
    assertNotNull(jdbcProperties.get("properties"));
    assertNotNull(jdbcProperties.get("uiSchema"));
    assertEquals("JDBCDataset", jdbcProperties.get("properties").get("@definitionName").textValue());
}
Also used : Response(com.jayway.restassured.response.Response) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JDBCDatasetProperties(org.talend.components.jdbc.dataset.JDBCDatasetProperties) JDBCDatastoreProperties(org.talend.components.jdbc.datastore.JDBCDatastoreProperties) SerPropertiesDto(org.talend.components.service.rest.dto.SerPropertiesDto) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

JDBCDatasetProperties (org.talend.components.jdbc.dataset.JDBCDatasetProperties)28 Test (org.junit.Test)19 JDBCDatastoreProperties (org.talend.components.jdbc.datastore.JDBCDatastoreProperties)12 Schema (org.apache.avro.Schema)8 JDBCDatastoreDefinition (org.talend.components.jdbc.datastore.JDBCDatastoreDefinition)5 JDBCDatasetRuntime (org.talend.components.jdbc.runtime.dataprep.JDBCDatasetRuntime)4 AllSetting (org.talend.components.jdbc.runtime.setting.AllSetting)4 Ignore (org.junit.Ignore)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Response (com.jayway.restassured.response.Response)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 IndexedRecord (org.apache.avro.generic.IndexedRecord)1 PipelineResult (org.apache.beam.sdk.PipelineResult)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 DatasetRuntime (org.talend.components.common.dataset.runtime.DatasetRuntime)1