Search in sources :

Example 16 with NamedThing

use of org.talend.daikon.NamedThing in project components by Talend.

the class SpringSnowflakeTestIT 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 connectionWizardNumber = 0;
    ComponentWizardDefinition wizardDef = null;
    for (ComponentWizardDefinition wizardDefinition : wizards) {
        if (wizardDefinition instanceof SnowflakeConnectionWizardDefinition) {
            wizardDef = wizardDefinition;
            connectionWizardNumber++;
        }
    }
    assertEquals(1, connectionWizardNumber);
    assertEquals("Snowflake Connection", wizardDef.getMenuItemName());
    ComponentWizard connectionWizard = getComponentService().getComponentWizard(SnowflakeConnectionWizardDefinition.COMPONENT_WIZARD_NAME, "nodeSnowflake");
    assertNotNull(connectionWizard);
    assertEquals("nodeSnowflake", 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 SnowflakeTableListProperties
    assertEquals("Main", forms.get(1).getName());
    assertEquals("Snowflake Connection Settings", connFormWizard.getTitle());
    assertEquals("Complete these fields in order to connect to your Snowflake account.", connFormWizard.getSubtitle());
    SnowflakeConnectionProperties connProps = (SnowflakeConnectionProperties) 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);
    assertEquals("Name", connProps.getProperty("name").getDisplayName());
    connProps.name.setValue("connName");
    setupProps(connProps);
    Form userPassword = (Form) connFormWizard.getWidget("userPassword").getContent();
    Property passwordSe = (Property) userPassword.getWidget("password").getContent();
    assertEquals("Password", passwordSe.getDisplayName());
    // $NON-NLS-1$
    NamedThing nameProp = connFormWizard.getWidget("name").getContent();
    assertEquals("Name", nameProp.getDisplayName());
    PropertiesTestUtils.checkAndValidate(getComponentService(), connFormWizard, "testConnection", connProps);
    assertTrue(connFormWizard.isAllowForward());
    Form modForm = forms.get(1);
    SnowflakeTableListProperties mlProps = (SnowflakeTableListProperties) modForm.getProperties();
    assertFalse(modForm.isCallAfterFormBack());
    assertFalse(modForm.isCallAfterFormNext());
    assertTrue(modForm.isCallAfterFormFinish());
    assertTrue(modForm.isCallBeforeFormPresent());
    assertFalse(modForm.isAllowBack());
    assertFalse(modForm.isAllowForward());
    assertFalse(modForm.isAllowFinish());
    mlProps = (SnowflakeTableListProperties) getComponentService().beforeFormPresent(modForm.getName(), mlProps);
    assertTrue(modForm.isAllowBack());
    assertFalse(modForm.isAllowForward());
    assertTrue(modForm.isAllowFinish());
    List<NamedThing> all = mlProps.selectedTableNames.getValue();
    assertNull(all);
    List<NamedThing> possibleValues = (List<NamedThing>) mlProps.selectedTableNames.getPossibleValues();
    LOGGER.info("possibleValues: " + possibleValues);
    assertEquals(1, possibleValues.size());
    List<NamedThing> selected = new ArrayList<>();
    selected.add(possibleValues.get(0));
    mlProps.selectedTableNames.setValue(selected);
    getComponentService().afterFormFinish(modForm.getName(), mlProps);
    LOGGER.debug(repoProps.toString());
    assertEquals(2, repoProps.size());
    int i = 0;
    for (RepoProps rp : repoProps) {
        if (i == 0) {
            assertEquals("connName", rp.name);
            SnowflakeConnectionProperties storedConnProps = (SnowflakeConnectionProperties) rp.props;
            assertEquals(USER, storedConnProps.userPassword.userId.getValue());
            assertEquals(PASSWORD, storedConnProps.userPassword.password.getValue());
        } else {
            SnowflakeTableProperties storedModule = (SnowflakeTableProperties) rp.props;
            assertEquals(selected.get(i - 1).getName(), storedModule.tableName.getValue());
            assertTrue(rp.schema.getFields().size() == NUM_COLUMNS);
            assertThat(storedModule.main.schema.getStringValue(), Matchers.is(rp.schema.toString()));
        }
        i++;
    }
}
Also used : PresentationItem(org.talend.daikon.properties.PresentationItem) Form(org.talend.daikon.properties.presentation.Form) ArrayList(java.util.ArrayList) SnowflakeConnectionProperties(org.talend.components.snowflake.SnowflakeConnectionProperties) NamedThing(org.talend.daikon.NamedThing) SnowflakeTableListProperties(org.talend.components.snowflake.SnowflakeTableListProperties) Repository(org.talend.daikon.properties.service.Repository) SnowflakeConnectionWizardDefinition(org.talend.components.snowflake.SnowflakeConnectionWizardDefinition) ComponentWizard(org.talend.components.api.wizard.ComponentWizard) ComponentWizardDefinition(org.talend.components.api.wizard.ComponentWizardDefinition) ArrayList(java.util.ArrayList) List(java.util.List) SnowflakeTableProperties(org.talend.components.snowflake.SnowflakeTableProperties) Property(org.talend.daikon.properties.property.Property) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 17 with NamedThing

use of org.talend.daikon.NamedThing in project components by Talend.

the class SnowflakeTableListPropertiesTest method testAfterFormFinishMain.

@Test
public void testAfterFormFinishMain() throws Exception {
    String tableId = "tableId";
    properties.setRepositoryLocation("repo");
    properties.setConnection(new SnowflakeConnectionProperties("connection"));
    properties.selectedTableNames.setValue(Arrays.asList(new NamedThing[] { new SimpleNamedThing(tableId) }));
    PowerMockito.mockStatic(SnowflakeSourceOrSink.class);
    Mockito.when(SnowflakeSourceOrSink.validateConnection(properties)).thenReturn(ValidationResult.OK);
    Schema schema = SchemaBuilder.record("record").fields().requiredString("id").endRecord();
    Mockito.when(SnowflakeSourceOrSink.getSchema(null, properties, tableId)).thenReturn(schema);
    Mockito.when(repo.storeProperties(Mockito.any(Properties.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenReturn("connRepoLocation");
    Assert.assertEquals(ValidationResult.OK, properties.afterFormFinishMain(repo));
    Mockito.verify(repo, Mockito.times(2)).storeProperties(Mockito.any(Properties.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
}
Also used : SimpleNamedThing(org.talend.daikon.SimpleNamedThing) Schema(org.apache.avro.Schema) NamedThing(org.talend.daikon.NamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) Properties(org.talend.daikon.properties.Properties) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 18 with NamedThing

use of org.talend.daikon.NamedThing in project components by Talend.

the class SnowflakeTableListPropertiesTest method testBeforeFormPresentMain.

@Test
public void testBeforeFormPresentMain() throws Exception {
    List<NamedThing> tableNames = new ArrayList<>();
    tableNames.add(new SimpleNamedThing());
    PowerMockito.mockStatic(SnowflakeSourceOrSink.class);
    Mockito.when(SnowflakeSourceOrSink.getSchemaNames(null, properties.getConnectionProperties())).thenReturn(tableNames);
    properties.setupLayout();
    properties.beforeFormPresentMain();
    Assert.assertTrue(properties.getForm(Form.MAIN).isAllowBack());
    Assert.assertTrue(properties.getForm(Form.MAIN).isAllowFinish());
    Assert.assertEquals(tableNames, properties.selectedTableNames.getPossibleValues());
}
Also used : SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ArrayList(java.util.ArrayList) NamedThing(org.talend.daikon.NamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 19 with NamedThing

use of org.talend.daikon.NamedThing in project components by Talend.

the class SnowflakeSourceOrSink method getSchemaNames.

protected List<NamedThing> getSchemaNames(RuntimeContainer container, Connection connection) throws IOException {
    // Returns the list with a table names (for the wh, db and schema)
    List<NamedThing> returnList = new ArrayList<>();
    SnowflakeConnectionProperties connProps = getEffectiveConnectionProperties(container);
    try {
        DatabaseMetaData metaData = connection.getMetaData();
        // Fetch all tables in the db and schema provided
        String[] types = { "TABLE" };
        ResultSet resultIter = metaData.getTables(getCatalog(connProps), getDbSchema(connProps), null, types);
        String tableName = null;
        while (resultIter.next()) {
            tableName = resultIter.getString("TABLE_NAME");
            returnList.add(new SimpleNamedThing(tableName, tableName));
        }
    } catch (SQLException se) {
        throw new IOException(i18nMessages.getMessage("error.searchingTable", getCatalog(connProps), getDbSchema(connProps), se.getMessage()), se);
    }
    return returnList;
}
Also used : SQLException(java.sql.SQLException) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) SnowflakeConnectionProperties(org.talend.components.snowflake.SnowflakeConnectionProperties) IOException(java.io.IOException) NamedThing(org.talend.daikon.NamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) DatabaseMetaData(java.sql.DatabaseMetaData)

Example 20 with NamedThing

use of org.talend.daikon.NamedThing in project components by Talend.

the class SnowflakeTableProperties method beforeTableName.

public ValidationResult beforeTableName() throws Exception {
    ValidationResultMutable vr = new ValidationResultMutable();
    try {
        List<NamedThing> tableNames = SnowflakeSourceOrSink.getSchemaNames(null, connection);
        tableName.setPossibleNamedThingValues(tableNames);
    } catch (Exception ex) {
        vr.setMessage(ex.getMessage());
        vr.setStatus(ValidationResult.Result.ERROR);
    }
    return vr;
}
Also used : ValidationResultMutable(org.talend.daikon.properties.ValidationResultMutable) NamedThing(org.talend.daikon.NamedThing)

Aggregations

NamedThing (org.talend.daikon.NamedThing)71 SimpleNamedThing (org.talend.daikon.SimpleNamedThing)34 ArrayList (java.util.ArrayList)33 Test (org.junit.Test)21 Property (org.talend.daikon.properties.property.Property)17 ComponentProperties (org.talend.components.api.properties.ComponentProperties)15 ComponentException (org.talend.components.api.exception.ComponentException)14 Schema (org.apache.avro.Schema)11 SandboxedInstance (org.talend.daikon.sandbox.SandboxedInstance)9 ValidationResult (org.talend.daikon.properties.ValidationResult)8 Form (org.talend.daikon.properties.presentation.Form)8 List (java.util.List)7 IOException (java.io.IOException)6 PresentationItem (org.talend.daikon.properties.PresentationItem)6 Properties (org.talend.daikon.properties.Properties)6 ComponentWizard (org.talend.components.api.wizard.ComponentWizard)5 GenericElementParameter (org.talend.designer.core.generic.model.GenericElementParameter)5 PropertyPathConnector (org.talend.components.api.component.PropertyPathConnector)4 ComponentWizardDefinition (org.talend.components.api.wizard.ComponentWizardDefinition)4 SearchRecordTypeDesc (org.talend.components.netsuite.client.model.SearchRecordTypeDesc)4