Search in sources :

Example 41 with ComponentDefinition

use of org.talend.components.api.component.ComponentDefinition in project components by Talend.

the class SalesforceWriterTestIT method testSinkAllWithStringValue.

/*
     * With current API like date/datetime/int/.... string value can't be write to server side So we need convert the field
     * value type.
     */
@Test
public void testSinkAllWithStringValue() throws Exception {
    // Component framework objects.
    ComponentDefinition sfDef = new TSalesforceOutputDefinition();
    TSalesforceOutputProperties sfProps = (TSalesforceOutputProperties) sfDef.createRuntimeProperties();
    SalesforceTestBase.setupProps(sfProps.connection, false);
    sfProps.module.setValue("moduleName", "Event");
    sfProps.module.main.schema.setValue(SCHEMA_INSERT_EVENT);
    sfProps.ceaseForError.setValue(true);
    // Automatically generate the out schemas.
    sfProps.module.schemaListener.afterSchema();
    DefaultComponentRuntimeContainerImpl container = new DefaultComponentRuntimeContainerImpl();
    List<IndexedRecord> records = new ArrayList<>();
    String random = createNewRandom();
    IndexedRecord r1 = new GenericData.Record(SCHEMA_INSERT_EVENT);
    r1.put(0, "2011-02-02T02:02:02");
    r1.put(1, "2011-02-02T22:02:02.000Z");
    r1.put(2, "2011-02-02");
    r1.put(3, "1200");
    r1.put(4, "true");
    r1.put(5, random);
    // Rejected and successful writes are reset on the next record.
    IndexedRecord r2 = new GenericData.Record(SCHEMA_INSERT_EVENT);
    r2.put(0, "2016-02-02T02:02:02.000Z");
    r2.put(1, "2016-02-02T12:02:02");
    r2.put(2, "2016-02-02");
    r2.put(3, "600");
    r2.put(4, "0");
    r2.put(5, random);
    records.add(r1);
    records.add(r2);
    SalesforceSink salesforceSink = new SalesforceSink();
    salesforceSink.initialize(adaptor, sfProps);
    salesforceSink.validate(adaptor);
    Writer<Result> batchWriter = salesforceSink.createWriteOperation().createWriter(adaptor);
    writeRows(batchWriter, records);
    assertEquals(2, ((SalesforceWriter) batchWriter).getSuccessfulWrites().size());
    TSalesforceInputProperties sfInputProps = getSalesforceInputProperties();
    sfInputProps.copyValuesFrom(sfProps);
    sfInputProps.condition.setValue("Subject = '" + random + "' ORDER BY DurationInMinutes ASC");
    sfInputProps.module.main.schema.setValue(SCHEMA_INPUT_AND_DELETE_EVENT);
    List<IndexedRecord> inpuRecords = readRows(sfInputProps);
    try {
        assertEquals(2, inpuRecords.size());
        IndexedRecord inputRecords_1 = inpuRecords.get(0);
        IndexedRecord inputRecords_2 = inpuRecords.get(1);
        assertEquals(random, inputRecords_1.get(6));
        assertEquals(random, inputRecords_2.get(6));
        // we use containsInAnyOrder because we are not garanteed to have the same order every run.
        assertThat(Arrays.asList("2011-02-02T02:02:02.000Z", "2016-02-02T02:02:02.000Z"), containsInAnyOrder(inputRecords_1.get(1), inputRecords_2.get(1)));
        assertThat(Arrays.asList("2011-02-02T22:02:02.000Z", "2016-02-02T12:02:02.000Z"), containsInAnyOrder(inputRecords_1.get(2), inputRecords_2.get(2)));
        assertThat(Arrays.asList("2011-02-02", "2016-02-02"), containsInAnyOrder(inputRecords_1.get(3), inputRecords_2.get(3)));
        assertThat(Arrays.asList("1200", "600"), containsInAnyOrder(inputRecords_1.get(4), inputRecords_2.get(4)));
        assertThat(Arrays.asList("true", "false"), containsInAnyOrder(inputRecords_1.get(5), inputRecords_2.get(5)));
    } finally {
        deleteRows(inpuRecords, sfInputProps);
    }
}
Also used : TSalesforceOutputProperties(org.talend.components.salesforce.tsalesforceoutput.TSalesforceOutputProperties) IndexedRecord(org.apache.avro.generic.IndexedRecord) DefaultComponentRuntimeContainerImpl(org.talend.components.api.container.DefaultComponentRuntimeContainerImpl) ArrayList(java.util.ArrayList) TSalesforceInputProperties(org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties) Result(org.talend.components.api.component.runtime.Result) TSalesforceOutputDefinition(org.talend.components.salesforce.tsalesforceoutput.TSalesforceOutputDefinition) IndexedRecord(org.apache.avro.generic.IndexedRecord) ComponentDefinition(org.talend.components.api.component.ComponentDefinition) Test(org.junit.Test)

Example 42 with ComponentDefinition

use of org.talend.components.api.component.ComponentDefinition in project components by Talend.

the class SalesforceComponentTestIT method testSchemaSerialized2.

@Test
public void testSchemaSerialized2() throws Throwable {
    ComponentDefinition definition = getComponentService().getComponentDefinition(TSalesforceOutputDefinition.COMPONENT_NAME);
    TSalesforceOutputProperties outputProps = (TSalesforceOutputProperties) getComponentService().getComponentProperties(TSalesforceOutputDefinition.COMPONENT_NAME);
    Schema reject = SchemaBuilder.record("Reject").fields().name("A").type().stringType().noDefault().name("B").type().stringType().noDefault().endRecord();
    Schema main = SchemaBuilder.record("Main").fields().name("C").type().stringType().noDefault().name("D").type().stringType().noDefault().endRecord();
    outputProps.setValue("module.main.schema", main);
    outputProps.setValue("schemaReject.schema", reject);
    Schema main2 = (Schema) outputProps.getValuedProperty("module.main.schema").getValue();
    Schema reject2 = (Schema) outputProps.getValuedProperty("schemaReject.schema").getValue();
    assertEquals(main.toString(), main2.toString());
    assertEquals(reject.toString(), reject2.toString());
    String serialized = outputProps.toSerialized();
    TSalesforceOutputProperties afterSerialized = Properties.Helper.fromSerializedPersistent(serialized, TSalesforceOutputProperties.class).object;
    main2 = (Schema) afterSerialized.getValuedProperty("module.main.schema").getValue();
    reject2 = (Schema) afterSerialized.getValuedProperty("schemaReject.schema").getValue();
    assertEquals(main.toString(), main2.toString());
    assertEquals(reject.toString(), reject2.toString());
}
Also used : TSalesforceOutputProperties(org.talend.components.salesforce.tsalesforceoutput.TSalesforceOutputProperties) Schema(org.apache.avro.Schema) ComponentDefinition(org.talend.components.api.component.ComponentDefinition) Test(org.junit.Test)

Example 43 with ComponentDefinition

use of org.talend.components.api.component.ComponentDefinition in project components by Talend.

the class SalesforceComponentTestIT method testFamily.

@Test
public void testFamily() {
    ComponentDefinition cd = getComponentService().getComponentDefinition("tSalesforceConnection");
    assertEquals(2, cd.getFamilies().length);
    assertEquals("Business/Salesforce", cd.getFamilies()[0]);
    assertEquals("Cloud/Salesforce", cd.getFamilies()[1]);
}
Also used : ComponentDefinition(org.talend.components.api.component.ComponentDefinition) Test(org.junit.Test)

Example 44 with ComponentDefinition

use of org.talend.components.api.component.ComponentDefinition in project components by Talend.

the class SalesforceComponentTestIT method testInputConnectionRef.

/*
     * If the logic changes for this test please specify appropriate timeout.
     * The average execution time for this test 1.4-1.9 sec.
     */
@Test(timeout = 30_000)
public void testInputConnectionRef() throws Throwable {
    ComponentDefinition definition = getComponentService().getComponentDefinition(TSalesforceInputDefinition.COMPONENT_NAME);
    TSalesforceInputProperties props = (TSalesforceInputProperties) getComponentService().getComponentProperties(TSalesforceInputDefinition.COMPONENT_NAME);
    setupProps(props.connection, !ADD_QUOTES);
    SalesforceSourceOrSink salesforceSourceOrSink = new SalesforceSourceOrSink();
    salesforceSourceOrSink.initialize(null, props);
    assertEquals(ValidationResult.Result.OK, salesforceSourceOrSink.validate(null).getStatus());
    // Referenced properties simulating salesforce connect component
    SalesforceConnectionProperties cProps = (SalesforceConnectionProperties) getComponentService().getComponentProperties(TSalesforceConnectionDefinition.COMPONENT_NAME);
    setupProps(cProps, !ADD_QUOTES);
    cProps.userPassword.password.setValue("xxx");
    String compId = "comp1";
    // Use the connection props of the salesforce connect component
    props.connection.referencedComponent.referenceType.setValue(ComponentReferenceProperties.ReferenceType.COMPONENT_INSTANCE);
    props.connection.referencedComponent.componentInstanceId.setValue(compId);
    props.connection.referencedComponent.setReference(cProps);
    checkAndAfter(props.connection.getForm(Form.REFERENCE), "referencedComponent", props.connection);
    salesforceSourceOrSink = new SalesforceSourceOrSink();
    salesforceSourceOrSink.initialize(null, props);
    salesforceSourceOrSink.validate(null);
    assertEquals(ValidationResult.Result.ERROR, salesforceSourceOrSink.validate(null).getStatus());
    // Back to using the connection props of the salesforce input component
    props.connection.referencedComponent.referenceType.setValue(ComponentReferenceProperties.ReferenceType.THIS_COMPONENT);
    props.connection.referencedComponent.componentInstanceId.setValue(null);
    props.connection.referencedComponent.setReference(null);
    // Check that the null referenced component works.
    checkAndAfter(props.connection.getForm(Form.REFERENCE), "referencedComponent", props.connection);
    salesforceSourceOrSink = new SalesforceSourceOrSink();
    salesforceSourceOrSink.initialize(null, props);
    salesforceSourceOrSink.validate(null);
    assertEquals(ValidationResult.Result.OK, salesforceSourceOrSink.validate(null).getStatus());
}
Also used : SalesforceSourceOrSink(org.talend.components.salesforce.runtime.SalesforceSourceOrSink) SalesforceConnectionProperties(org.talend.components.salesforce.SalesforceConnectionProperties) TSalesforceInputProperties(org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties) ComponentDefinition(org.talend.components.api.component.ComponentDefinition) Test(org.junit.Test)

Example 45 with ComponentDefinition

use of org.talend.components.api.component.ComponentDefinition in project components by Talend.

the class SalesforceComponentTestIT method testRuntimeInfo.

@Test
public void testRuntimeInfo() {
    ComponentDefinition definition = getComponentService().getComponentDefinition(TSalesforceBulkExecDefinition.COMPONENT_NAME);
    ComponentProperties properties = this.getComponentService().getComponentProperties(TSalesforceBulkExecDefinition.COMPONENT_NAME);
    assertNotNull("should not null", definition.getRuntimeInfo(ExecutionEngine.DI, properties, ConnectorTopology.NONE));
    assertNotNull("should not null", definition.getRuntimeInfo(ExecutionEngine.DI, properties, ConnectorTopology.OUTGOING));
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) ComponentDefinition(org.talend.components.api.component.ComponentDefinition) Test(org.junit.Test)

Aggregations

ComponentDefinition (org.talend.components.api.component.ComponentDefinition)47 Test (org.junit.Test)28 IndexedRecord (org.apache.avro.generic.IndexedRecord)16 TSalesforceOutputProperties (org.talend.components.salesforce.tsalesforceoutput.TSalesforceOutputProperties)14 TSalesforceOutputDefinition (org.talend.components.salesforce.tsalesforceoutput.TSalesforceOutputDefinition)12 ArrayList (java.util.ArrayList)11 Result (org.talend.components.api.component.runtime.Result)11 TSalesforceInputProperties (org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties)10 List (java.util.List)9 DefaultComponentRuntimeContainerImpl (org.talend.components.api.container.DefaultComponentRuntimeContainerImpl)8 ComponentProperties (org.talend.components.api.properties.ComponentProperties)7 Schema (org.apache.avro.Schema)6 DefinitionDTO (org.talend.components.service.rest.dto.DefinitionDTO)6 MockComponentDefinition (org.talend.components.service.rest.mock.MockComponentDefinition)6 Response (com.jayway.restassured.response.Response)5 Arrays.asList (java.util.Arrays.asList)5 GenericData (org.apache.avro.generic.GenericData)3 ExecutionEngine (org.talend.components.api.component.runtime.ExecutionEngine)3 IComponent (org.talend.core.model.components.IComponent)3 File (java.io.File)2