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);
}
}
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());
}
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]);
}
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());
}
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));
}
Aggregations