Search in sources :

Example 21 with SnowflakeConnectionProperties

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

the class SnowflakeSourceOrSinkTest method setUp.

@Before
public void setUp() throws Exception {
    snowflakeSourceOrSink = new SnowflakeSourceOrSink();
    SnowflakeConnectionProperties properties = new SnowflakeConnectionProperties("test");
    properties.referencedComponent.componentInstanceId.setValue("referencedComponentId");
    this.snowflakeSourceOrSink.initialize(runtimeContainerMock, properties);
    PowerMockito.mockStatic(DriverManagerUtils.class);
}
Also used : SnowflakeConnectionProperties(org.talend.components.snowflake.SnowflakeConnectionProperties) Before(org.junit.Before)

Example 22 with SnowflakeConnectionProperties

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

the class SnowflakeSourceOrSinkTest method testGetSchemaAddKeyProperty.

/**
 * Checks {@link SnowflakeSourceOrSink#getSchema(RuntimeContainer, Connection, String)} adds property key to the
 * field
 * TODO remove this test as we it check the code we removed
 */
@Ignore
@Test
public void testGetSchemaAddKeyProperty() throws Exception {
    Schema schemaToEdit = SchemaBuilder.builder().record("Schema").fields().name("field").type().stringType().noDefault().endRecord();
    LOGGER.debug("schema to add key property: " + schemaToEdit);
    Schema expectedSchema = SchemaBuilder.builder().record("Schema").fields().name("field").type().stringType().noDefault().endRecord();
    expectedSchema.getField("field").addProp(SchemaConstants.TALEND_COLUMN_IS_KEY, "true");
    LOGGER.debug("expected schema: " + expectedSchema);
    Connection connectionMock = Mockito.mock(Connection.class);
    Mockito.when(runtimeContainerMock.getComponentData(Matchers.anyString(), Matchers.anyString())).thenReturn(snowflakeSourceOrSink.properties);
    DatabaseMetaData databaseMetaDataMock = Mockito.mock(DatabaseMetaData.class);
    ResultSet resultSetMock = Mockito.mock(ResultSet.class);
    ResultSet resultSetMockKeys = Mockito.mock(ResultSet.class);
    Mockito.when(connectionMock.getMetaData()).thenReturn(databaseMetaDataMock);
    final SnowflakeAvroRegistry snowflakeAvroRegistryMock = Mockito.mock(SnowflakeAvroRegistry.class);
    class SnowflakeSourceOrSinkChild extends SnowflakeSourceOrSink {

        private static final long serialVersionUID = 1L;

        @Override
        public SnowflakeAvroRegistry getSnowflakeAvroRegistry() {
            return snowflakeAvroRegistryMock;
        }
    }
    SnowflakeSourceOrSink sfSourceOrSink = new SnowflakeSourceOrSinkChild();
    SnowflakeConnectionProperties properties = new SnowflakeConnectionProperties("test");
    properties.referencedComponent.componentInstanceId.setValue("referencedComponentId");
    properties.db.setValue("database");
    sfSourceOrSink.initialize(runtimeContainerMock, properties);
    Mockito.when(databaseMetaDataMock.getColumns(sfSourceOrSink.getCatalog(sfSourceOrSink.getEffectiveConnectionProperties(runtimeContainerMock)), sfSourceOrSink.getDbSchema(sfSourceOrSink.getEffectiveConnectionProperties(runtimeContainerMock)), "tableName", null)).thenReturn(resultSetMock);
    Mockito.when(databaseMetaDataMock.getPrimaryKeys(sfSourceOrSink.getCatalog(sfSourceOrSink.getEffectiveConnectionProperties(runtimeContainerMock)), sfSourceOrSink.getDbSchema(sfSourceOrSink.getEffectiveConnectionProperties(runtimeContainerMock)), "tableName")).thenReturn(resultSetMockKeys);
    Mockito.when(resultSetMockKeys.next()).thenReturn(true).thenReturn(false);
    Mockito.when(resultSetMockKeys.getString("COLUMN_NAME")).thenReturn("field");
    Mockito.when(snowflakeAvroRegistryMock.inferSchema(resultSetMock)).thenReturn(schemaToEdit);
    Schema resultSchema = sfSourceOrSink.getSchema(runtimeContainerMock, connectionMock, "tableName");
    LOGGER.debug("result schema: " + resultSchema);
    Assert.assertNotNull(resultSchema);
    Assert.assertEquals(expectedSchema.getField("field").getProp(SchemaConstants.TALEND_COLUMN_IS_KEY), resultSchema.getField("field").getProp(SchemaConstants.TALEND_COLUMN_IS_KEY));
    Assert.assertEquals(expectedSchema, resultSchema);
}
Also used : Schema(org.apache.avro.Schema) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) SnowflakeConnectionProperties(org.talend.components.snowflake.SnowflakeConnectionProperties) DatabaseMetaData(java.sql.DatabaseMetaData) Ignore(org.junit.Ignore) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 23 with SnowflakeConnectionProperties

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

the class SpringSnowflakeTestIT method testModuleWizard.

@Test
public void testModuleWizard() throws Throwable {
    ComponentWizard connectionWizard = getComponentService().getComponentWizard(SnowflakeConnectionWizardDefinition.COMPONENT_WIZARD_NAME, "nodeSnowflake");
    List<Form> forms = connectionWizard.getForms();
    Form connFormWizard = forms.get(0);
    SnowflakeConnectionProperties connProps = (SnowflakeConnectionProperties) connFormWizard.getProperties();
    ComponentWizard[] subWizards = getComponentService().getComponentWizardsForProperties(connProps, "location").toArray(new ComponentWizard[2]);
    Arrays.sort(subWizards, new WizardNameComparator());
    assertEquals(2, subWizards.length);
    assertTrue(subWizards[0].getDefinition().isTopLevel());
    assertEquals("Snowflake Connection", subWizards[0].getDefinition().getMenuItemName());
    // Edit connection wizard - we copy the connection properties, as we present the UI, so we use the
    // connection properties object created by the new wizard
    assertFalse(connProps == subWizards[1].getForms().get(0).getProperties());
// will remove the edit wizard in future, no need to test more about it
// Add module wizard - we refer to the existing connection properties as we don't present the UI
// for them.
// assertTrue(connProps == ((SnowflakeTableListProperties) subWizards[2].getForms().get(0).getProperties())
// .getConnectionProperties());
// assertFalse(subWizards[2].getDefinition().isTopLevel());
// assertEquals("Snowflake Tables", subWizards[2].getDefinition().getMenuItemName());
}
Also used : ComponentWizard(org.talend.components.api.wizard.ComponentWizard) WizardNameComparator(org.talend.components.api.wizard.WizardNameComparator) 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 24 with SnowflakeConnectionProperties

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

the class SpringSnowflakeTestIT method testLoginFail.

@Test
public void testLoginFail() throws Throwable {
    SnowflakeConnectionProperties props = (SnowflakeConnectionProperties) setupProps(null);
    props.userPassword.userId.setValue("blah");
    Form f = props.getForm(SnowflakeConnectionProperties.FORM_WIZARD);
    props = (SnowflakeConnectionProperties) PropertiesTestUtils.checkAndValidate(getComponentService(), f, "testConnection", props);
    LOGGER.debug(props.getValidationResult().toString());
    assertEquals(ValidationResult.Result.ERROR, 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)

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