use of org.talend.components.api.component.runtime.Reader in project components by Talend.
the class SalesforceInputTestIT method testTypeForModuleWithCompoundType.
@Test(expected = ComponentException.class)
public void testTypeForModuleWithCompoundType() throws Exception {
SalesforceInputProperties properties = createCommonSalesforceInputPropertiesForModule();
SalesforceDataprepSource source = new SalesforceDataprepSource();
source.initialize(null, properties);
source.validate(null);
properties.getDatasetProperties().selectColumnIds.setValue(Arrays.asList("IsDeleted", "Id", "Name", "BillingAddress", "ShippingAddress"));
try (Reader reader = source.createReader(null)) {
reader.start();
}
}
use of org.talend.components.api.component.runtime.Reader in project components by Talend.
the class SalesforceInputTestIT method testTypeForQuery.
@Test
public void testTypeForQuery() throws Exception {
SalesforceInputProperties properties = createCommonSalesforceInputPropertiesForQuery();
SalesforceDataprepSource source = new SalesforceDataprepSource();
source.initialize(null, properties);
source.validate(null);
try (Reader reader = source.createReader(null)) {
int count = 3;
for (boolean available = reader.start(); available; available = reader.advance()) {
IndexedRecord record = (IndexedRecord) reader.getCurrent();
assertEquals(String.class, record.get(0).getClass());
assertEquals(String.class, record.get(1).getClass());
if ((count--) < 1) {
break;
}
}
}
}
use of org.talend.components.api.component.runtime.Reader in project components by Talend.
the class CouchbaseInputTestIT method testReader.
@Test
public void testReader() {
populateBucket();
Reader reader = null;
try {
CouchbaseInputDefinition definition = new CouchbaseInputDefinition();
CouchbaseInputProperties properties = (CouchbaseInputProperties) definition.createRuntimeProperties();
properties.bootstrapNodes.setValue(bootstrapNodes);
properties.bucket.setValue(bucketName);
properties.password.setValue(password);
source = new CouchbaseSource();
source.initialize(null, properties);
reader = source.createReader(null);
boolean hasRecords = reader.start();
assertTrue(hasRecords);
IndexedRecord row = (IndexedRecord) reader.getCurrent();
assertNotNull(row);
assertEquals("foo", row.get(EventSchemaField.KEY_IDX));
assertEquals("{\"bar\":42}", new String(((byte[]) row.get(EventSchemaField.CONTENT_IDX))));
reader.close();
} catch (IOException e) {
fail(e.getMessage());
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
fail(e.getMessage());
}
}
}
}
use of org.talend.components.api.component.runtime.Reader in project components by Talend.
the class JDBCTypeMappingTestIT method doReadType.
@SuppressWarnings({ "rawtypes" })
private void doReadType(boolean nullableForAnyColumn) throws IOException {
TJDBCInputDefinition definition = new TJDBCInputDefinition();
TJDBCInputProperties properties = DBTestUtils.createCommonJDBCInputProperties(allSetting, definition);
properties.main.schema.setValue(DBTestUtils.createTestSchema3(nullableForAnyColumn, tablename));
properties.tableSelection.tablename.setValue(tablename);
properties.sql.setValue(DBTestUtils.getSQL(tablename));
Reader reader = DBTestUtils.createCommonJDBCInputReader(properties);
try {
IndexedRecordConverter<Object, ? extends IndexedRecord> converter = null;
reader.start();
converter = DBTestUtils.getIndexRecordConverter(reader, converter);
IndexedRecord record = converter.convertToAvro(reader.getCurrent());
assertEquals(Integer.class, record.get(0).getClass());
assertEquals(Short.class, record.get(1).getClass());
assertEquals(Long.class, record.get(2).getClass());
assertEquals(Float.class, record.get(3).getClass());
assertEquals(Double.class, record.get(4).getClass());
assertEquals(Float.class, record.get(5).getClass());
assertEquals(BigDecimal.class, record.get(6).getClass());
assertEquals(BigDecimal.class, record.get(7).getClass());
assertEquals(Boolean.class, record.get(8).getClass());
assertEquals(String.class, record.get(9).getClass());
assertEquals(Long.class, record.get(10).getClass());
assertEquals(Long.class, record.get(11).getClass());
assertEquals(Long.class, record.get(12).getClass());
assertEquals(String.class, record.get(13).getClass());
assertEquals(String.class, record.get(14).getClass());
reader.close();
} finally {
reader.close();
}
}
use of org.talend.components.api.component.runtime.Reader in project components by Talend.
the class JDBCTypeMappingTestIT method doReadContentWithAllType.
@SuppressWarnings({ "rawtypes", "unchecked" })
private void doReadContentWithAllType(boolean nullableForAnyColumn) {
Reader reader = null;
try {
TJDBCInputDefinition definition = new TJDBCInputDefinition();
TJDBCInputProperties properties = DBTestUtils.createCommonJDBCInputProperties(allSetting, definition);
properties.main.schema.setValue(DBTestUtils.createTestSchema3(nullableForAnyColumn, tablename));
properties.tableSelection.tablename.setValue(tablename);
properties.sql.setValue(DBTestUtils.getSQL(tablename));
reader = DBTestUtils.createCommonJDBCInputReader(properties);
reader.start();
IndexedRecord row = (IndexedRecord) reader.getCurrent();
Integer c1 = (Integer) row.get(0);
Short c2 = (Short) row.get(1);
Long c3 = (Long) row.get(2);
Float c4 = (Float) row.get(3);
Double c5 = (Double) row.get(4);
Float c6 = (Float) row.get(5);
BigDecimal c7 = (BigDecimal) row.get(6);
BigDecimal c8 = (BigDecimal) row.get(7);
Boolean c9 = (Boolean) row.get(8);
String c10 = (String) row.get(9);
Long c11 = (Long) row.get(10);
Long c12 = (Long) row.get(11);
Long c13 = (Long) row.get(12);
String c14 = (String) row.get(13);
String c15 = (String) row.get(14);
assertEquals(1, c1.intValue());
assertEquals(2, c2.intValue());
assertEquals(3, c3.intValue());
Assert.assertNotNull(c4);
Assert.assertNotNull(c5);
Assert.assertNotNull(c6);
assertEquals(new BigDecimal("7.01"), c7);
assertEquals(new BigDecimal("8.01"), c8);
assertEquals(true, c9);
assertEquals("the first char value", c10.trim());
Assert.assertNotNull(c11);
Assert.assertNotNull(c12);
Assert.assertNotNull(c13);
assertEquals("wangwei", c14);
assertEquals("a long one : 1", c15);
reader.advance();
row = (IndexedRecord) reader.getCurrent();
c1 = (Integer) row.get(0);
c2 = (Short) row.get(1);
c3 = (Long) row.get(2);
c4 = (Float) row.get(3);
c5 = (Double) row.get(4);
c6 = (Float) row.get(5);
c7 = (BigDecimal) row.get(6);
c8 = (BigDecimal) row.get(7);
c9 = (Boolean) row.get(8);
c10 = (String) row.get(9);
c11 = (Long) row.get(10);
c12 = (Long) row.get(11);
c13 = (Long) row.get(12);
c14 = (String) row.get(13);
c15 = (String) row.get(14);
assertEquals(1, c1.intValue());
assertEquals(2, c2.intValue());
assertEquals(3, c3.intValue());
Assert.assertNotNull(c4);
Assert.assertNotNull(c5);
Assert.assertNotNull(c6);
assertEquals(new BigDecimal("7.01"), c7);
assertEquals(new BigDecimal("8.01"), c8);
assertEquals(true, c9);
assertEquals("the second char value", c10.trim());
Assert.assertNotNull(c11);
Assert.assertNotNull(c12);
Assert.assertNotNull(c13);
assertEquals("gaoyan", c14);
assertEquals("a long one : 2", c15);
reader.advance();
row = (IndexedRecord) reader.getCurrent();
c1 = (Integer) row.get(0);
c2 = (Short) row.get(1);
c3 = (Long) row.get(2);
c4 = (Float) row.get(3);
c5 = (Double) row.get(4);
c6 = (Float) row.get(5);
c7 = (BigDecimal) row.get(6);
c8 = (BigDecimal) row.get(7);
c9 = (Boolean) row.get(8);
c10 = (String) row.get(9);
c11 = (Long) row.get(10);
c12 = (Long) row.get(11);
c13 = (Long) row.get(12);
c14 = (String) row.get(13);
c15 = (String) row.get(14);
assertEquals(1, c1.intValue());
assertEquals(2, c2.intValue());
assertEquals(3, c3.intValue());
Assert.assertNotNull(c4);
Assert.assertNotNull(c5);
Assert.assertNotNull(c6);
assertEquals(new BigDecimal("7.01"), c7);
assertEquals(new BigDecimal("8.01"), c8);
assertEquals(true, c9);
assertEquals("the third char value", c10.trim());
Assert.assertNotNull(c11);
Assert.assertNotNull(c12);
Assert.assertNotNull(c13);
assertEquals("dabao", c14);
assertEquals("a long one : 3", c15);
reader.advance();
row = (IndexedRecord) reader.getCurrent();
c1 = (Integer) row.get(0);
c2 = (Short) row.get(1);
c3 = (Long) row.get(2);
c4 = (Float) row.get(3);
c5 = (Double) row.get(4);
c6 = (Float) row.get(5);
c7 = (BigDecimal) row.get(6);
c8 = (BigDecimal) row.get(7);
c9 = (Boolean) row.get(8);
c10 = (String) row.get(9);
c11 = (Long) row.get(10);
c12 = (Long) row.get(11);
c13 = (Long) row.get(12);
c14 = (String) row.get(13);
c15 = (String) row.get(14);
assertEquals(1, c1.intValue());
Assert.assertNull(c2);
Assert.assertNull(c3);
Assert.assertNull(c4);
Assert.assertNull(c5);
Assert.assertNull(c6);
Assert.assertNull(c7);
Assert.assertNull(c8);
Assert.assertNull(c9);
Assert.assertNull(c10);
Assert.assertNull(c11);
Assert.assertNull(c12);
// some database set default value for this column as default
// Assert.assertNull(c13);
Assert.assertNull(c14);
Assert.assertNull(c15);
reader.advance();
row = (IndexedRecord) reader.getCurrent();
c1 = (Integer) row.get(0);
c2 = (Short) row.get(1);
c3 = (Long) row.get(2);
c4 = (Float) row.get(3);
c5 = (Double) row.get(4);
c6 = (Float) row.get(5);
c7 = (BigDecimal) row.get(6);
c8 = (BigDecimal) row.get(7);
c9 = (Boolean) row.get(8);
c10 = (String) row.get(9);
c11 = (Long) row.get(10);
c12 = (Long) row.get(11);
c13 = (Long) row.get(12);
c14 = (String) row.get(13);
c15 = (String) row.get(14);
Assert.assertNull(c1);
Assert.assertNull(c2);
Assert.assertNull(c3);
Assert.assertNull(c4);
Assert.assertNull(c5);
Assert.assertNull(c6);
Assert.assertNull(c7);
Assert.assertNull(c8);
Assert.assertNull(c9);
Assert.assertNull(c10);
Assert.assertNull(c11);
Assert.assertNull(c12);
// some database set default value for this column as default
// Assert.assertNull(c13);
Assert.assertEquals("good luck", c14);
Assert.assertNull(c15);
reader.close();
Map<String, Object> returnMap = reader.getReturnValues();
Assert.assertEquals(5, returnMap.get(ComponentDefinition.RETURN_TOTAL_RECORD_COUNT));
} catch (Exception e) {
Assert.fail(e.getMessage());
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
Assert.fail(e.getMessage());
}
}
}
}
Aggregations