Search in sources :

Example 1 with SalesforceModuleProperties

use of org.talend.components.salesforce.SalesforceModuleProperties in project tdi-studio-se by Talend.

the class RepositoryUpdateTest method prepareTableForTest.

private MetadataTable prepareTableForTest(String id) {
    MetadataTable table = ConnectionFactory.eINSTANCE.createMetadataTable();
    table.setLabel("myTableTest");
    MetadataColumn col1 = ConnectionFactory.eINSTANCE.createMetadataColumn();
    col1.setLabel("myColumn1");
    col1.setTalendType(JavaTypesManager.STRING.getId());
    col1.setLength(25);
    table.getColumns().add(col1);
    Schema avroSchema = MetadataToolAvroHelper.convertToAvro(table);
    TaggedValue tv = CoreFactory.eINSTANCE.createTaggedValue();
    tv.setTag(IComponentConstants.COMPONENT_PROPERTIES_TAG);
    SalesforceModuleProperties smp = new SalesforceModuleProperties("test");
    smp.connection.init();
    // because we should get connection always from the main
    smp.connection.userPassword.userId.setValue("old");
    // SalesforceConnectionProperties
    smp.moduleName.setStoredValue("myModule");
    smp.main.schema.setStoredValue(avroSchema);
    GenericRepository gr = new GenericRepository();
    gr.storeProperties(smp, table.getLabel(), id + "#", "main.schema");
    return table;
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) SalesforceModuleProperties(org.talend.components.salesforce.SalesforceModuleProperties) GenericRepository(org.talend.repository.generic.persistence.GenericRepository) TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue) Schema(org.apache.avro.Schema) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable)

Example 2 with SalesforceModuleProperties

use of org.talend.components.salesforce.SalesforceModuleProperties in project components by Talend.

the class TSalesforceInputPropertiesIT method testValidateGuessQueryEmptySchema.

/**
 * Checks {@link TSalesforceInputProperties#guessQuery} returns empty {@link java.lang.String}
 * when schema does not include any fields
 */
@Test
public void testValidateGuessQueryEmptySchema() throws Exception {
    final String field1 = "Id";
    final String field2 = "Name";
    final String moduleName = "Module";
    String expectedQuery = "";
    Schema schema = SchemaBuilder.record("Result").fields().endRecord();
    SalesforceModuleProperties salesforceModuleProperties = new SalesforceModuleProperties("properties");
    salesforceModuleProperties.moduleName.setValue(moduleName);
    salesforceModuleProperties.main.schema.setValue(schema);
    properties.module = salesforceModuleProperties;
    ValidationResult.Result resultStatus = properties.validateGuessQuery().getStatus();
    String expectedMessage = properties.validateGuessQuery().getMessage();
    LOGGER.debug("validation result status: " + resultStatus);
    Assert.assertEquals(ValidationResult.Result.ERROR, resultStatus);
    Assert.assertNotNull(expectedMessage);
    Assert.assertEquals(expectedMessage, "Schema does not contain any field. Query cannot be guessed.");
    String resultQuery = properties.query.getValue();
    LOGGER.debug("result query: " + resultQuery);
    Assert.assertNotNull(resultQuery);
    Assert.assertEquals(expectedQuery, resultQuery);
}
Also used : SalesforceModuleProperties(org.talend.components.salesforce.SalesforceModuleProperties) Schema(org.apache.avro.Schema) ValidationResult(org.talend.daikon.properties.ValidationResult) Test(org.junit.Test)

Example 3 with SalesforceModuleProperties

use of org.talend.components.salesforce.SalesforceModuleProperties in project components by Talend.

the class SalesforceComponentTestIT method testWizard.

@Test
public void testWizard() throws Throwable {
    final List<RepoProps> repoProps = new ArrayList<>();
    Repository repo = new TestRepository(repoProps);
    getComponentService().setRepository(repo);
    Set<ComponentWizardDefinition> wizards = getComponentService().getTopLevelComponentWizards();
    int connectionWizardDefinitionNumber = 0;
    ComponentWizardDefinition wizardDef = null;
    for (ComponentWizardDefinition wizardDefinition : wizards) {
        if (wizardDefinition instanceof SalesforceConnectionWizardDefinition) {
            wizardDef = wizardDefinition;
            connectionWizardDefinitionNumber++;
        }
    }
    assertEquals(1, connectionWizardDefinitionNumber);
    assertEquals("Salesforce Connection", wizardDef.getMenuItemName());
    ComponentWizard connectionWizard = getComponentService().getComponentWizard(SalesforceConnectionWizardDefinition.COMPONENT_WIZARD_NAME, "nodeSalesforce");
    assertNotNull(connectionWizard);
    assertEquals("nodeSalesforce", connectionWizard.getRepositoryLocation());
    List<Form> forms = connectionWizard.getForms();
    Form connFormWizard = forms.get(0);
    assertEquals("Wizard", connFormWizard.getName());
    assertFalse(connFormWizard.isAllowBack());
    assertFalse(connFormWizard.isAllowForward());
    assertFalse(connFormWizard.isAllowFinish());
    // Main from SalesforceModuleListProperties
    assertEquals("Main", forms.get(1).getName());
    assertEquals("Salesforce Connection Settings", connFormWizard.getTitle());
    assertEquals("Complete these fields in order to connect to your Salesforce account.", connFormWizard.getSubtitle());
    SalesforceConnectionProperties connProps = (SalesforceConnectionProperties) connFormWizard.getProperties();
    Form advancedForm = connProps.getForm(Form.ADVANCED);
    assertTrue(((PresentationItem) connFormWizard.getWidget("advanced").getContent()).getFormtoShow() + " should be == to " + advancedForm, ((PresentationItem) connFormWizard.getWidget("advanced").getContent()).getFormtoShow() == advancedForm);
    Object image = getComponentService().getWizardPngImage(SalesforceConnectionWizardDefinition.COMPONENT_WIZARD_NAME, WizardImageType.TREE_ICON_16X16);
    assertNotNull(image);
    image = getComponentService().getWizardPngImage(SalesforceConnectionWizardDefinition.COMPONENT_WIZARD_NAME, WizardImageType.WIZARD_BANNER_75X66);
    assertNotNull(image);
    // Check the non-top-level wizard
    // check password i18n
    assertEquals("Name", connProps.getProperty("name").getDisplayName());
    connProps.name.setValue("connName");
    setupProps(connProps, !ADD_QUOTES);
    Form userPassword = (Form) connFormWizard.getWidget("userPassword").getContent();
    Property passwordSe = (Property) userPassword.getWidget("password").getContent();
    assertEquals("Password", passwordSe.getDisplayName());
    // check name i18n
    // $NON-NLS-1$
    NamedThing nameProp = connFormWizard.getWidget("name").getContent();
    assertEquals("Name", nameProp.getDisplayName());
    connProps = (SalesforceConnectionProperties) PropertiesTestUtils.checkAndValidate(getComponentService(), connFormWizard, "testConnection", connProps);
    assertTrue(connFormWizard.isAllowForward());
    Form modForm = forms.get(1);
    SalesforceModuleListProperties mlProps = (SalesforceModuleListProperties) modForm.getProperties();
    assertFalse(modForm.isCallAfterFormBack());
    assertFalse(modForm.isCallAfterFormNext());
    assertTrue(modForm.isCallAfterFormFinish());
    assertTrue(modForm.isCallBeforeFormPresent());
    assertFalse(modForm.isAllowBack());
    assertFalse(modForm.isAllowForward());
    assertFalse(modForm.isAllowFinish());
    mlProps = (SalesforceModuleListProperties) getComponentService().beforeFormPresent(modForm.getName(), mlProps);
    assertTrue(modForm.isAllowBack());
    assertFalse(modForm.isAllowForward());
    assertTrue(modForm.isAllowFinish());
    @SuppressWarnings("unchecked") List<NamedThing> all = mlProps.selectedModuleNames.getValue();
    assertNull(all);
    // TCOMP-9 Change the module list to use getPossibleValues() for SalesforceModuleListProperties
    List<NamedThing> possibleValues = (List<NamedThing>) mlProps.selectedModuleNames.getPossibleValues();
    assertTrue(possibleValues.size() > 50);
    List<NamedThing> selected = new ArrayList<>();
    selected.add(possibleValues.get(0));
    selected.add(possibleValues.get(2));
    selected.add(possibleValues.get(3));
    mlProps.selectedModuleNames.setValue(selected);
    getComponentService().afterFormFinish(modForm.getName(), mlProps);
    LOGGER.debug(repoProps.toString());
    assertEquals(4, repoProps.size());
    int i = 0;
    for (RepoProps rp : repoProps) {
        if (i == 0) {
            assertEquals("connName", rp.name);
            SalesforceConnectionProperties storedConnProps = (SalesforceConnectionProperties) rp.props;
            assertEquals(userId, storedConnProps.userPassword.userId.getValue());
            assertEquals(password, storedConnProps.userPassword.password.getValue());
        } else {
            SalesforceModuleProperties storedModule = (SalesforceModuleProperties) rp.props;
            assertEquals(selected.get(i - 1).getName(), storedModule.moduleName.getValue());
            assertTrue(rp.schema.getFields().size() > 10);
            assertThat(storedModule.main.schema.getStringValue(), is(rp.schema.toString()));
        }
        i++;
    }
}
Also used : SalesforceConnectionProperties(org.talend.components.salesforce.SalesforceConnectionProperties) PresentationItem(org.talend.daikon.properties.PresentationItem) Form(org.talend.daikon.properties.presentation.Form) ArrayList(java.util.ArrayList) NamedThing(org.talend.daikon.NamedThing) SalesforceConnectionWizardDefinition(org.talend.components.salesforce.SalesforceConnectionWizardDefinition) SalesforceModuleProperties(org.talend.components.salesforce.SalesforceModuleProperties) Repository(org.talend.daikon.properties.service.Repository) ComponentWizard(org.talend.components.api.wizard.ComponentWizard) SalesforceModuleListProperties(org.talend.components.salesforce.SalesforceModuleListProperties) ComponentWizardDefinition(org.talend.components.api.wizard.ComponentWizardDefinition) List(java.util.List) ArrayList(java.util.ArrayList) Property(org.talend.daikon.properties.property.Property) Test(org.junit.Test)

Example 4 with SalesforceModuleProperties

use of org.talend.components.salesforce.SalesforceModuleProperties in project components by Talend.

the class SalesforceComponentTestIT method testSchemaWithAPIVersion.

protected void testSchemaWithAPIVersion(String version) throws Throwable {
    TSalesforceInputProperties props = (TSalesforceInputProperties) getComponentService().getComponentProperties(TSalesforceInputDefinition.COMPONENT_NAME);
    props.connection.endpoint.setValue("https://login.salesforce.com/services/Soap/u/" + version);
    setupProps(props.connection, !ADD_QUOTES);
    Form f = props.module.getForm(Form.REFERENCE);
    SalesforceModuleProperties moduleProps = (SalesforceModuleProperties) f.getProperties();
    moduleProps = (SalesforceModuleProperties) PropertiesTestUtils.checkAndBeforeActivate(getComponentService(), f, "moduleName", moduleProps);
    moduleProps.moduleName.setValue("Account");
    moduleProps = (SalesforceModuleProperties) checkAndAfter(f, "moduleName", moduleProps);
    Schema schema = moduleProps.main.schema.getValue();
    LOGGER.debug(schema.toString());
    for (Schema.Field child : schema.getFields()) {
        LOGGER.debug(child.name());
    }
    assertEquals("Id", schema.getFields().get(0).name());
    LOGGER.debug("Endpoint:" + props.connection.endpoint.getValue());
    LOGGER.debug("Module \"Account\" column size:" + schema.getFields().size());
    assertTrue(schema.getFields().size() > 40);
}
Also used : SalesforceModuleProperties(org.talend.components.salesforce.SalesforceModuleProperties) Form(org.talend.daikon.properties.presentation.Form) Schema(org.apache.avro.Schema) TSalesforceInputProperties(org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties)

Example 5 with SalesforceModuleProperties

use of org.talend.components.salesforce.SalesforceModuleProperties in project components by Talend.

the class TSalesforceInputPropertiesIT method testValidateGuessQueryPositiveCase.

/**
 * Checks {@link TSalesforceInputProperties#guessQuery} returns correct soql-query
 */
@Test
public void testValidateGuessQueryPositiveCase() throws Exception {
    final String field1 = "Id";
    final String field2 = "Name";
    final String moduleName = "Module";
    String expectedQuery = "\"SELECT Id, Name FROM Module\"";
    Schema schema = SchemaBuilder.record("Result").fields().name(field1).type().stringType().noDefault().name(field2).type().stringType().noDefault().endRecord();
    SalesforceModuleProperties salesforceModuleProperties = new SalesforceModuleProperties("properties");
    salesforceModuleProperties.moduleName.setValue(moduleName);
    salesforceModuleProperties.main.schema.setValue(schema);
    properties.module = salesforceModuleProperties;
    ValidationResult.Result resultStatus = properties.validateGuessQuery().getStatus();
    String expectedMessage = properties.validateGuessQuery().getMessage();
    LOGGER.debug("validation result status: " + resultStatus);
    Assert.assertEquals(ValidationResult.Result.OK, resultStatus);
    String resultQuery = properties.query.getValue();
    LOGGER.debug("result query: " + resultQuery);
    Assert.assertNotNull(resultQuery);
    Assert.assertEquals(expectedQuery, resultQuery);
    Assert.assertNull(expectedMessage);
}
Also used : SalesforceModuleProperties(org.talend.components.salesforce.SalesforceModuleProperties) Schema(org.apache.avro.Schema) ValidationResult(org.talend.daikon.properties.ValidationResult) Test(org.junit.Test)

Aggregations

SalesforceModuleProperties (org.talend.components.salesforce.SalesforceModuleProperties)5 Schema (org.apache.avro.Schema)4 Test (org.junit.Test)3 ValidationResult (org.talend.daikon.properties.ValidationResult)2 Form (org.talend.daikon.properties.presentation.Form)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ComponentWizard (org.talend.components.api.wizard.ComponentWizard)1 ComponentWizardDefinition (org.talend.components.api.wizard.ComponentWizardDefinition)1 SalesforceConnectionProperties (org.talend.components.salesforce.SalesforceConnectionProperties)1 SalesforceConnectionWizardDefinition (org.talend.components.salesforce.SalesforceConnectionWizardDefinition)1 SalesforceModuleListProperties (org.talend.components.salesforce.SalesforceModuleListProperties)1 TSalesforceInputProperties (org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties)1 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)1 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)1 NamedThing (org.talend.daikon.NamedThing)1 PresentationItem (org.talend.daikon.properties.PresentationItem)1 Property (org.talend.daikon.properties.property.Property)1 Repository (org.talend.daikon.properties.service.Repository)1 GenericRepository (org.talend.repository.generic.persistence.GenericRepository)1