use of org.talend.components.salesforce.SalesforceConnectionWizardDefinition 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++;
}
}
Aggregations