Search in sources :

Example 6 with SnowflakeConnectionProperties

use of org.talend.components.snowflake.SnowflakeConnectionProperties in project components by Talend.

the class SnowflakeTestIT method setupProps.

public ComponentProperties setupProps(SnowflakeConnectionProperties props) {
    if (props == null) {
        props = (SnowflakeConnectionProperties) new SnowflakeConnectionProperties("foo").init();
    }
    props.userPassword.userId.setStoredValue(USER);
    props.userPassword.password.setStoredValue(PASSWORD);
    props.account.setStoredValue(ACCOUNT_STR);
    props.warehouse.setStoredValue(WAREHOUSE);
    props.db.setStoredValue(DB);
    props.schemaName.setStoredValue(testSchema);
    return props;
}
Also used : SnowflakeConnectionProperties(org.talend.components.snowflake.SnowflakeConnectionProperties)

Example 7 with SnowflakeConnectionProperties

use of org.talend.components.snowflake.SnowflakeConnectionProperties 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 8 with SnowflakeConnectionProperties

use of org.talend.components.snowflake.SnowflakeConnectionProperties in project components by Talend.

the class SpringSnowflakeTestIT method testGetSchema.

@Test
public void testGetSchema() throws IOException {
    SnowflakeConnectionProperties scp = (SnowflakeConnectionProperties) setupProps(null);
    Schema schema = SnowflakeSourceOrSink.getSchema(null, scp, testTable);
    assertNotNull(schema);
    assertThat(schema.getFields(), Matchers.hasSize(NUM_COLUMNS));
}
Also used : Schema(org.apache.avro.Schema) SnowflakeConnectionProperties(org.talend.components.snowflake.SnowflakeConnectionProperties) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with SnowflakeConnectionProperties

use of org.talend.components.snowflake.SnowflakeConnectionProperties in project components by Talend.

the class SpringSnowflakeTestIT method testLogin.

@Test
public void testLogin() throws Throwable {
    SnowflakeConnectionProperties props = (SnowflakeConnectionProperties) setupProps(null);
    LOGGER.debug(String.valueOf(props));
    Form f = props.getForm(SnowflakeConnectionProperties.FORM_WIZARD);
    props = (SnowflakeConnectionProperties) PropertiesTestUtils.checkAndValidate(getComponentService(), f, "testConnection", props);
    LOGGER.debug(props.getValidationResult().toString());
    assertEquals(ValidationResult.Result.OK, props.getValidationResult().getStatus());
}
Also used : Form(org.talend.daikon.properties.presentation.Form) SnowflakeConnectionProperties(org.talend.components.snowflake.SnowflakeConnectionProperties) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with SnowflakeConnectionProperties

use of org.talend.components.snowflake.SnowflakeConnectionProperties in project components by Talend.

the class SnowflakeSourceOrSink method getEffectiveConnectionProperties.

public SnowflakeConnectionProperties getEffectiveConnectionProperties(RuntimeContainer container) {
    SnowflakeConnectionProperties connProps = properties.getConnectionProperties();
    String refComponentId = connProps.getReferencedComponentId();
    // Using another component's connection
    if (refComponentId != null) {
        // In a runtime container
        if (container != null) {
            return (SnowflakeConnectionProperties) container.getComponentData(refComponentId, SnowflakeRuntime.KEY_CONNECTION_PROPERTIES);
        }
        // Design time
        return connProps.getReferencedConnectionProperties();
    }
    return connProps;
}
Also used : SnowflakeConnectionProperties(org.talend.components.snowflake.SnowflakeConnectionProperties)

Aggregations

SnowflakeConnectionProperties (org.talend.components.snowflake.SnowflakeConnectionProperties)24 Test (org.junit.Test)16 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 Connection (java.sql.Connection)6 DatabaseMetaData (java.sql.DatabaseMetaData)5 ResultSet (java.sql.ResultSet)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 SQLException (java.sql.SQLException)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 SnowflakeSourceOrSink (org.talend.components.snowflake.runtime.SnowflakeSourceOrSink)4 Form (org.talend.daikon.properties.presentation.Form)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Schema (org.apache.avro.Schema)3 DefaultComponentRuntimeContainerImpl (org.talend.components.api.container.DefaultComponentRuntimeContainerImpl)3 RuntimeContainer (org.talend.components.api.container.RuntimeContainer)3 ComponentWizard (org.talend.components.api.wizard.ComponentWizard)2 SnowflakeCloseSourceOrSink (org.talend.components.snowflake.runtime.SnowflakeCloseSourceOrSink)2 TSnowflakeCloseProperties (org.talend.components.snowflake.tsnowflakeclose.TSnowflakeCloseProperties)2 TSnowflakeInputProperties (org.talend.components.snowflake.tsnowflakeinput.TSnowflakeInputProperties)2