use of com.sforce.soap.partner.DescribeSObjectResult in project components by Talend.
the class SalesforceAvroRegistryStringTest method testInferSchemaWithReferenceField.
@Test
public void testInferSchemaWithReferenceField() {
Field referenceField = new Field();
referenceField.setName("reference");
referenceField.setType(FieldType.string);
referenceField.setReferenceTo(new String[] { "SomeRecord" });
referenceField.setRelationshipName("relationship");
DescribeSObjectResult dsor = new DescribeSObjectResult();
dsor.setName("MySObjectRecord");
dsor.setFields(new Field[] { referenceField });
Schema schema = SalesforceAvroRegistryString.get().inferSchema(dsor);
Schema.Field field = schema.getField("reference");
assertThat(field.schema().getType(), is(Schema.Type.STRING));
assertThat(field.getProp(SalesforceSchemaConstants.REF_MODULE_NAME), is("SomeRecord"));
assertThat(field.getProp(SalesforceSchemaConstants.REF_FIELD_NAME), is("relationship"));
}
use of com.sforce.soap.partner.DescribeSObjectResult in project components by Talend.
the class SalesforceAvroRegistryStringTest method testLocationTypeFilter.
@Test
public void testLocationTypeFilter() throws Exception {
DescribeSObjectResult describeSObjectResult = new DescribeSObjectResult();
Field location = new Field();
location.setName("location");
location.setType(FieldType.location);
describeSObjectResult.setFields(new Field[] { location });
Schema schema = SalesforceAvroRegistryString.get().inferSchema(describeSObjectResult);
assertThat(0, is(schema.getFields().size()));
}
use of com.sforce.soap.partner.DescribeSObjectResult in project components by Talend.
the class SalesforceAvroRegistryStringTest method testAddressTypeFilter.
@Test
public void testAddressTypeFilter() throws Exception {
DescribeSObjectResult describeSObjectResult = new DescribeSObjectResult();
Field address = new Field();
address.setName("address");
address.setType(FieldType.address);
describeSObjectResult.setFields(new Field[] { address });
Schema schema = SalesforceAvroRegistryString.get().inferSchema(describeSObjectResult);
assertThat(0, is(schema.getFields().size()));
}
use of com.sforce.soap.partner.DescribeSObjectResult in project components by Talend.
the class SalesforceSourceOrSinkTest method testGuessSchema.
/**
* Checks {@link SalesforceSourceOrSink#guessSchema(String)} returns the
* {@link org.apache.avro.Schema} with date and string type
*/
@Test
public void testGuessSchema() throws Exception {
String field0Name = "Id";
String field1Name = "LastModifiedDate";
String field2Name = "LastActivityDate";
String drivingEntity = "Account";
String soql = new StringBuilder().append("SELECT").append(" ").append(field0Name).append(",").append(SPACE).append(field1Name).append(",").append(SPACE).append(field2Name).append(SPACE).append("FROM").append(SPACE).append(drivingEntity).toString();
final PartnerConnection partnerConnectionMock = Mockito.mock(PartnerConnection.class);
class SalesforceSourceOrSinkChild extends SalesforceSourceOrSink {
@Override
protected ConnectionHolder connect(RuntimeContainer container) {
ConnectionHolder connectionHolder = new ConnectionHolder();
connectionHolder.connection = partnerConnectionMock;
return connectionHolder;
}
}
Field field0 = new Field();
field0.setName(field0Name);
field0.setType(FieldType.string);
Field field1 = new Field();
field1.setName(field1Name);
field1.setType(FieldType.date);
Field field2 = new Field();
field2.setName(field2Name);
field2.setType(FieldType.date);
Field[] fields = new Field[3];
fields[0] = field0;
fields[1] = field1;
fields[2] = field2;
DescribeSObjectResult describeSObjectResult = new DescribeSObjectResult();
describeSObjectResult.setFields(fields);
Mockito.when(partnerConnectionMock.describeSObject(drivingEntity)).thenReturn(describeSObjectResult);
SalesforceSourceOrSinkChild salesforceSourceOrSinkChild = new SalesforceSourceOrSinkChild();
salesforceSourceOrSinkChild.initialize(runtimeContainerMock, properties);
Schema resultSchema = salesforceSourceOrSinkChild.guessSchema(soql);
LOGGER.debug("result schema: " + resultSchema.toString());
Assert.assertEquals("GuessedSchema", resultSchema.getName());
Assert.assertEquals(field0Name, resultSchema.getFields().get(0).name());
Assert.assertEquals(field1Name, resultSchema.getFields().get(1).name());
Assert.assertEquals("java.util.Date", AvroUtils.unwrapIfNullable(resultSchema.getFields().get(1).schema()).getProp("java-class"));
Assert.assertEquals("yyyy-MM-dd", resultSchema.getFields().get(1).getProp(SchemaConstants.TALEND_COLUMN_PATTERN));
Assert.assertEquals(field2Name, resultSchema.getFields().get(2).name());
Assert.assertEquals("java.util.Date", AvroUtils.unwrapIfNullable(resultSchema.getFields().get(2).schema()).getProp("java-class"));
Assert.assertEquals("yyyy-MM-dd", resultSchema.getFields().get(2).getProp(SchemaConstants.TALEND_COLUMN_PATTERN));
}
Aggregations