Search in sources :

Example 11 with DescribeSObjectResult

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"));
}
Also used : Field(com.sforce.soap.partner.Field) DescribeSObjectResult(com.sforce.soap.partner.DescribeSObjectResult) Schema(org.apache.avro.Schema) Test(org.junit.Test)

Example 12 with DescribeSObjectResult

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()));
}
Also used : Field(com.sforce.soap.partner.Field) DescribeSObjectResult(com.sforce.soap.partner.DescribeSObjectResult) Schema(org.apache.avro.Schema) Test(org.junit.Test)

Example 13 with DescribeSObjectResult

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()));
}
Also used : Field(com.sforce.soap.partner.Field) DescribeSObjectResult(com.sforce.soap.partner.DescribeSObjectResult) Schema(org.apache.avro.Schema) Test(org.junit.Test)

Example 14 with DescribeSObjectResult

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));
}
Also used : Field(com.sforce.soap.partner.Field) PartnerConnection(com.sforce.soap.partner.PartnerConnection) DescribeSObjectResult(com.sforce.soap.partner.DescribeSObjectResult) Schema(org.apache.avro.Schema) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) ConnectionHolder(org.talend.components.salesforce.runtime.common.ConnectionHolder) Test(org.junit.Test)

Aggregations

DescribeSObjectResult (com.sforce.soap.partner.DescribeSObjectResult)14 Schema (org.apache.avro.Schema)10 Field (com.sforce.soap.partner.Field)8 Test (org.junit.Test)8 ConnectionException (com.sforce.ws.ConnectionException)5 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 FieldDescription (org.talend.components.salesforce.soql.FieldDescription)2 SoqlQuery (org.talend.components.salesforce.soql.SoqlQuery)2 DeletedRecord (com.sforce.soap.partner.DeletedRecord)1 GetDeletedResult (com.sforce.soap.partner.GetDeletedResult)1 GetUpdatedResult (com.sforce.soap.partner.GetUpdatedResult)1 PartnerConnection (com.sforce.soap.partner.PartnerConnection)1 SObject (com.sforce.soap.partner.sobject.SObject)1 Date (java.util.Date)1 ResourceException (javax.resource.ResourceException)1 SOAPException (javax.xml.soap.SOAPException)1 SchemaBuilder (org.apache.avro.SchemaBuilder)1 KettleException (org.pentaho.di.core.exception.KettleException)1