Search in sources :

Example 1 with JDBCDatastoreProperties

use of org.talend.components.jdbc.datastore.JDBCDatastoreProperties in project components by Talend.

the class JdbcComponentTestIT method initializeJDBCDatastoreProperties.

@Test
public void initializeJDBCDatastoreProperties() throws java.io.IOException {
    // given
    SerPropertiesDto propDto = new SerPropertiesDto();
    propDto.setProperties(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());
    // should resemble jdbc_data_store_form.json
    assertNotNull(jdbcProperties.get("jsonSchema"));
    assertNotNull(jdbcProperties.get("properties"));
    assertNotNull(jdbcProperties.get("uiSchema"));
    assertEquals("JDBCDatastore", jdbcProperties.get("properties").get("@definitionName").textValue());
}
Also used : Response(com.jayway.restassured.response.Response) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) 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)

Example 2 with JDBCDatastoreProperties

use of org.talend.components.jdbc.datastore.JDBCDatastoreProperties in project components by Talend.

the class JDBCDatasetTestIT method createDatasetProperties.

private JDBCDatasetProperties createDatasetProperties(boolean updateSchema) {
    JDBCDatastoreDefinition def = new JDBCDatastoreDefinition();
    JDBCDatastoreProperties datastore = new JDBCDatastoreProperties("datastore");
    datastore.dbTypes.setValue("DERBY");
    datastore.afterDbTypes();
    datastore.jdbcUrl.setValue(allSetting.getJdbcUrl());
    datastore.userId.setValue(allSetting.getUsername());
    datastore.password.setValue(allSetting.getPassword());
    JDBCDatasetProperties dataset = (JDBCDatasetProperties) def.createDatasetProperties(datastore);
    dataset.sql.setValue(DBTestUtils.getSQL(tablename));
    if (updateSchema) {
        updateSchema(dataset);
    }
    return dataset;
}
Also used : JDBCDatastoreDefinition(org.talend.components.jdbc.datastore.JDBCDatastoreDefinition) JDBCDatasetProperties(org.talend.components.jdbc.dataset.JDBCDatasetProperties) JDBCDatastoreProperties(org.talend.components.jdbc.datastore.JDBCDatastoreProperties)

Example 3 with JDBCDatastoreProperties

use of org.talend.components.jdbc.datastore.JDBCDatastoreProperties in project components by Talend.

the class JDBCDatasetOracleTestIT method createDatasetProperties.

private JDBCDatasetProperties createDatasetProperties() {
    JDBCDatastoreDefinition def = new JDBCDatastoreDefinition();
    JDBCDatastoreProperties datastore = new JDBCDatastoreProperties("datastore");
    datastore.dbTypes.setValue("ORACLE");
    datastore.jdbcUrl.setValue(allSetting.getJdbcUrl());
    datastore.userId.setValue(allSetting.getUsername());
    datastore.password.setValue(allSetting.getPassword());
    JDBCDatasetProperties dataset = (JDBCDatasetProperties) def.createDatasetProperties(datastore);
    dataset.sql.setValue(DBTestUtils.getSQL(tablename));
    return dataset;
}
Also used : JDBCDatastoreDefinition(org.talend.components.jdbc.datastore.JDBCDatastoreDefinition) JDBCDatasetProperties(org.talend.components.jdbc.dataset.JDBCDatasetProperties) JDBCDatastoreProperties(org.talend.components.jdbc.datastore.JDBCDatastoreProperties)

Example 4 with JDBCDatastoreProperties

use of org.talend.components.jdbc.datastore.JDBCDatastoreProperties in project components by Talend.

the class JDBCBeamRuntimeTest method testPipeline.

@Test
public void testPipeline() throws Exception {
    JDBCDatastoreProperties jdbcDatastoreProperties;
    jdbcDatastoreProperties = new JDBCDatastoreProperties("datastore");
    jdbcDatastoreProperties.init();
    jdbcDatastoreProperties.dbTypes.setValue("DERBY");
    jdbcDatastoreProperties.jdbcUrl.setValue(JDBC_URL);
    JDBCDatasetProperties inputDatasetProperties = new JDBCDatasetProperties("inputDataset");
    inputDatasetProperties.init();
    inputDatasetProperties.setDatastoreProperties(jdbcDatastoreProperties);
    inputDatasetProperties.sql.setValue("select * from " + TABLE_IN);
    // Schema inputSchema =
    // SchemaBuilder.record("DYNAMIC").fields().name("ID").type(SchemaBuilder.builder().stringType())
    // .noDefault().name("NAME").type(SchemaBuilder.builder().stringType()).noDefault().endRecord();
    // inputDatasetProperties.main.schema.setValue(inputSchema);
    JDBCInputProperties inputProperties = new JDBCInputProperties("input");
    inputProperties.init();
    inputProperties.setDatasetProperties(inputDatasetProperties);
    JDBCDatasetProperties outputDatasetProperties = new JDBCDatasetProperties("outputDataset");
    outputDatasetProperties.init();
    outputDatasetProperties.setDatastoreProperties(jdbcDatastoreProperties);
    outputDatasetProperties.sourceType.setValue(JDBCDatasetProperties.SourceType.TABLE_NAME);
    outputDatasetProperties.tableName.setValue(TABLE_OUT);
    Schema outputSchema = SchemaBuilder.record("DYNAMIC").fields().name("ID").prop(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, "ID").type(SchemaBuilder.builder().intType()).noDefault().name("NAME").prop(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, "NAME").type(SchemaBuilder.builder().stringType()).noDefault().endRecord();
    outputDatasetProperties.main.schema.setValue(outputSchema);
    JDBCOutputProperties outputProperties = new JDBCOutputProperties("output");
    outputProperties.init();
    outputProperties.setDatasetProperties(outputDatasetProperties);
    outputProperties.dataAction.setValue(JDBCOutputProperties.DataAction.INSERT);
    JDBCInputPTransformRuntime inputRuntime = new JDBCInputPTransformRuntime();
    inputRuntime.initialize(null, inputProperties);
    JDBCOutputPTransformRuntime outputRuntime = new JDBCOutputPTransformRuntime();
    outputRuntime.initialize(null, outputProperties);
    pipeline.apply(inputRuntime).apply(outputRuntime);
    PipelineResult pipelineResult = pipeline.run();
    Map<Integer, String> results = new HashMap<>();
    try (Connection connection = dataSource.getConnection()) {
        try (Statement statement = connection.createStatement()) {
            try (ResultSet resultSet = statement.executeQuery("select * from " + TABLE_OUT)) {
                while (resultSet.next()) {
                    results.put(resultSet.getInt(1), resultSet.getString(2));
                }
            }
        }
    }
    assertEquals(assertRows, results);
}
Also used : HashMap(java.util.HashMap) JDBCOutputProperties(org.talend.components.jdbc.datastream.JDBCOutputProperties) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Schema(org.apache.avro.Schema) Connection(java.sql.Connection) PipelineResult(org.apache.beam.sdk.PipelineResult) JDBCDatasetProperties(org.talend.components.jdbc.dataset.JDBCDatasetProperties) JDBCDatastoreProperties(org.talend.components.jdbc.datastore.JDBCDatastoreProperties) JDBCInputProperties(org.talend.components.jdbc.dataprep.JDBCInputProperties) ResultSet(java.sql.ResultSet) Test(org.junit.Test)

Example 5 with JDBCDatastoreProperties

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

Aggregations

JDBCDatastoreProperties (org.talend.components.jdbc.datastore.JDBCDatastoreProperties)16 JDBCDatasetProperties (org.talend.components.jdbc.dataset.JDBCDatasetProperties)12 Test (org.junit.Test)7 AllSetting (org.talend.components.jdbc.runtime.setting.AllSetting)6 JDBCDatastoreDefinition (org.talend.components.jdbc.datastore.JDBCDatastoreDefinition)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Response (com.jayway.restassured.response.Response)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 SerPropertiesDto (org.talend.components.service.rest.dto.SerPropertiesDto)2 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 HashMap (java.util.HashMap)1 Schema (org.apache.avro.Schema)1 PipelineResult (org.apache.beam.sdk.PipelineResult)1 JDBCInputProperties (org.talend.components.jdbc.dataprep.JDBCInputProperties)1 JDBCOutputProperties (org.talend.components.jdbc.datastream.JDBCOutputProperties)1