Search in sources :

Example 31 with TSalesforceOutputProperties

use of org.talend.components.salesforce.tsalesforceoutput.TSalesforceOutputProperties in project components by Talend.

the class SalesforceTestBase method writeRows.

// Returns the rows written (having been re-read so they have their Ids)
protected List<IndexedRecord> writeRows(String random, SalesforceConnectionModuleProperties props, List<IndexedRecord> outputRows) throws Exception {
    // $NON-NLS-1$
    TSalesforceOutputProperties outputProps = new TSalesforceOutputProperties("output");
    outputProps.copyValuesFrom(props);
    outputProps.outputAction.setValue(TSalesforceOutputProperties.OutputAction.INSERT);
    doWriteRows(outputProps, outputRows);
    return readAndCheckRows(random, props, outputRows.size());
}
Also used : TSalesforceOutputProperties(org.talend.components.salesforce.tsalesforceoutput.TSalesforceOutputProperties)

Example 32 with TSalesforceOutputProperties

use of org.talend.components.salesforce.tsalesforceoutput.TSalesforceOutputProperties in project components by Talend.

the class SalesforceSessionReuseTestIT method testOutputReuseSession.

@Ignore("Need to solve test failed randomly")
@Test(timeout = 30_000)
public void testOutputReuseSession() throws Throwable {
    File sessionFolder = new File(tempFolder.getRoot().getPath() + "/tsalesforceoutput/");
    assertEquals(0, sessionFolder.getTotalSpace());
    LOGGER.debug("session folder: " + sessionFolder.getAbsolutePath());
    // $NON-NLS-1$
    TSalesforceOutputProperties props = (TSalesforceOutputProperties) new TSalesforceOutputProperties("foo").init();
    props.module.moduleName.setValue(EXISTING_MODULE_NAME);
    props.module.main.schema.setValue(getMakeRowSchema(false));
    props.connection = setupProps(null, !ADD_QUOTES);
    // setup session function
    props.connection.reuseSession.setValue(true);
    props.connection.sessionDirectory.setValue(sessionFolder.getAbsolutePath());
    // Init session
    assertEquals(ValidationResult.Result.OK, testConnection(props).getStatus());
    assertNotEquals(0, sessionFolder.getTotalSpace());
    // Invalid session, test whether it can be renew the session
    invalidSession(props.connection, null);
    // length=260
    String invalidName = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
    List<IndexedRecord> records = new ArrayList<>();
    IndexedRecord r1 = new GenericData.Record(props.module.main.schema.getValue());
    r1.put(0, invalidName);
    records.add(r1);
    try {
        doWriteRows(props, records);
    } catch (IOException e) {
        // means exception caused by "Name" too long
        assertTrue(e.getMessage().contains(invalidName));
        LOGGER.debug("expect exception: " + e.getMessage());
    }
    // Set wrong pwd to test reuse session from session folder
    props.connection.userPassword.password.setValue(WRONG_PWD);
    try {
        doWriteRows(props, records);
    } catch (IOException e) {
        Throwable caused = e.getCause();
        if (caused != null && caused instanceof LoginFault) {
            // Maybe throw exception when same account run in parallel
            // The session maybe disabled by other test
            assertEquals(ExceptionCode.INVALID_LOGIN, ((LoginFault) caused).getExceptionCode());
            LOGGER.debug("session is disabled by other test!");
        } else {
            // means exception caused by "Name" too long
            assertTrue(e.getMessage().contains(invalidName));
            LOGGER.debug("expect exception: " + e.getMessage());
            // This means that the session not disabled by other test
            invalidSession(props.connection, null);
        // This means that the session is disabled by current test
        }
    }
    // Test reuse session fails with wrong pwd
    try {
        doWriteRows(props, records);
    } catch (IOException e) {
        Throwable caused = e.getCause();
        // Should login fails with wrong pwd
        assertThat(caused, instanceOf(LoginFault.class));
        assertEquals(ExceptionCode.INVALID_LOGIN, ((LoginFault) caused).getExceptionCode());
        LOGGER.debug("expect login fails: " + e.getMessage());
    }
    // Disable reuse session function
    props.connection.reuseSession.setValue(false);
    LOGGER.debug("expect login fails:");
    assertEquals(ValidationResult.Result.ERROR, testConnection(props).getStatus());
}
Also used : TSalesforceOutputProperties(org.talend.components.salesforce.tsalesforceoutput.TSalesforceOutputProperties) IndexedRecord(org.apache.avro.generic.IndexedRecord) LoginFault(com.sforce.soap.partner.fault.LoginFault) ArrayList(java.util.ArrayList) IndexedRecord(org.apache.avro.generic.IndexedRecord) IOException(java.io.IOException) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

TSalesforceOutputProperties (org.talend.components.salesforce.tsalesforceoutput.TSalesforceOutputProperties)32 IndexedRecord (org.apache.avro.generic.IndexedRecord)18 Test (org.junit.Test)16 ComponentDefinition (org.talend.components.api.component.ComponentDefinition)14 Result (org.talend.components.api.component.runtime.Result)13 TSalesforceOutputDefinition (org.talend.components.salesforce.tsalesforceoutput.TSalesforceOutputDefinition)13 ArrayList (java.util.ArrayList)10 TSalesforceInputProperties (org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties)9 Schema (org.apache.avro.Schema)7 DefaultComponentRuntimeContainerImpl (org.talend.components.api.container.DefaultComponentRuntimeContainerImpl)7 File (java.io.File)3 IOException (java.io.IOException)3 List (java.util.List)3 GenericData (org.apache.avro.generic.GenericData)3 Ignore (org.junit.Ignore)2 LoginFault (com.sforce.soap.partner.fault.LoginFault)1 NoSuchElementException (java.util.NoSuchElementException)1 AfterClass (org.junit.AfterClass)1 Before (org.junit.Before)1 Connector (org.talend.components.api.component.Connector)1