Search in sources :

Example 1 with SnowflakeConnectionProperties

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

the class SnowflakeReadersTestIT method testInputConnectionRef.

@Test
public void testInputConnectionRef() throws Throwable {
    TSnowflakeInputProperties props = (TSnowflakeInputProperties) getComponentService().getComponentProperties(TSnowflakeInputDefinition.COMPONENT_NAME);
    setupProps(props.connection);
    SnowflakeSourceOrSink SnowflakeSourceOrSink = new SnowflakeSourceOrSink();
    SnowflakeSourceOrSink.initialize(null, props);
    assertEquals(ValidationResult.Result.OK, SnowflakeSourceOrSink.validate(null).getStatus());
    // Referenced properties simulating Snowflake connect component
    SnowflakeConnectionProperties cProps = (SnowflakeConnectionProperties) getComponentService().getComponentProperties(TSnowflakeConnectionDefinition.COMPONENT_NAME);
    setupProps(cProps);
    cProps.userPassword.password.setValue("xxx");
    String compId = "comp1";
    // Use the connection props of the Snowflake connect component
    props.connection.referencedComponent.referenceType.setValue(ComponentReferenceProperties.ReferenceType.COMPONENT_INSTANCE);
    props.connection.referencedComponent.componentInstanceId.setValue(compId);
    props.connection.referencedComponent.setReference(cProps);
    PropertiesTestUtils.checkAndAfter(getComponentService(), props.connection.getForm(Form.REFERENCE), "referencedComponent", props.connection);
    resetUser();
    SnowflakeSourceOrSink = new SnowflakeSourceOrSink();
    SnowflakeSourceOrSink.initialize(null, props);
    SnowflakeSourceOrSink.validate(null);
    assertEquals(ValidationResult.Result.ERROR, SnowflakeSourceOrSink.validate(null).getStatus());
    resetUser();
    setupProps(cProps);
    setupTableWithStaticValues(props);
    // Back to using the connection props of the Snowflake input component
    props.connection.referencedComponent.referenceType.setValue(ComponentReferenceProperties.ReferenceType.THIS_COMPONENT);
    props.connection.referencedComponent.componentInstanceId.setValue(null);
    props.connection.referencedComponent.setReference(null);
    // Check that the null referenced component works.
    PropertiesTestUtils.checkAndAfter(getComponentService(), props.connection.getForm(Form.REFERENCE), "referencedComponent", props.connection);
    resetUser();
    SnowflakeSourceOrSink = new SnowflakeSourceOrSink();
    SnowflakeSourceOrSink.initialize(null, props);
    ValidationResult result = SnowflakeSourceOrSink.validate(null);
    LOGGER.info(String.valueOf(result));
    assertEquals(ValidationResult.Result.OK, result.getStatus());
}
Also used : SnowflakeSourceOrSink(org.talend.components.snowflake.runtime.SnowflakeSourceOrSink) SnowflakeConnectionProperties(org.talend.components.snowflake.SnowflakeConnectionProperties) Matchers.containsString(org.hamcrest.Matchers.containsString) ValidationResult(org.talend.daikon.properties.ValidationResult) TSnowflakeInputProperties(org.talend.components.snowflake.tsnowflakeinput.TSnowflakeInputProperties) Test(org.junit.Test)

Example 2 with SnowflakeConnectionProperties

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

the class SnowflakeSourceOrSinkTest method testValidatePropertiesWhenSchemaAndDBIsMissed.

@Test
public void testValidatePropertiesWhenSchemaAndDBIsMissed() {
    SnowflakeConnectionProperties connectionProperties = new SnowflakeConnectionProperties("test");
    connectionProperties.account.setValue("notEmptyValue");
    connectionProperties.userPassword.userId.setValue("notEmpty");
    connectionProperties.userPassword.password.setValue("notEmpty");
    connectionProperties.warehouse.setValue("notEmptyWH");
    // Leave schema and db empty
    ValidationResult vr = SnowflakeSourceOrSink.validateConnectionProperties(connectionProperties);
    Assert.assertTrue(vr.getStatus() == ValidationResult.Result.ERROR);
}
Also used : SnowflakeConnectionProperties(org.talend.components.snowflake.SnowflakeConnectionProperties) ValidationResult(org.talend.daikon.properties.ValidationResult) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with SnowflakeConnectionProperties

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

the class SnowflakeSourceOrSinkTest method testValidateConnectionStaticCallMissingAllProperties.

@Test
public void testValidateConnectionStaticCallMissingAllProperties() {
    SnowflakeConnectionProperties properties = new SnowflakeConnectionProperties("connection");
    Assert.assertEquals(ValidationResult.Result.ERROR, SnowflakeSourceOrSink.validateConnection(properties).getStatus());
}
Also used : SnowflakeConnectionProperties(org.talend.components.snowflake.SnowflakeConnectionProperties) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with SnowflakeConnectionProperties

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

the class SnowflakeSourceOrSinkTest method testGetSchemaNames.

@Test(expected = IOException.class)
public void testGetSchemaNames() throws Exception {
    snowflakeSourceOrSink.properties.getConnectionProperties().referencedComponent.setReference(new SnowflakeConnectionProperties("connection"));
    SnowflakeConnectionProperties properties = snowflakeSourceOrSink.getEffectiveConnectionProperties(null);
    properties.account.setValue("talend");
    properties.userPassword.password.setValue("teland_password");
    properties.userPassword.userId.setValue("talend_dev");
    properties.schemaName.setValue("LOAD");
    properties.db.setValue("TestDB");
    Connection connection = Mockito.mock(Connection.class);
    Mockito.when(connection.isClosed()).thenReturn(false);
    DatabaseMetaData metaData = Mockito.mock(DatabaseMetaData.class);
    ResultSet rs = Mockito.mock(ResultSet.class);
    Mockito.when(metaData.getColumns(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenReturn(rs);
    Mockito.when(connection.getMetaData()).thenReturn(metaData);
    Mockito.when(DriverManagerUtils.getConnection(Mockito.any(SnowflakeConnectionProperties.class))).thenReturn(connection);
    snowflakeSourceOrSink.getEndpointSchema(null, "table1");
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) SnowflakeConnectionProperties(org.talend.components.snowflake.SnowflakeConnectionProperties) DatabaseMetaData(java.sql.DatabaseMetaData) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with SnowflakeConnectionProperties

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

the class SnowflakeSourceOrSinkTest method testValidateConnectionInvalidValueInResultSet.

@Test
public void testValidateConnectionInvalidValueInResultSet() throws Exception {
    SnowflakeConnectionProperties properties = new SnowflakeConnectionProperties("connection");
    properties.account.setValue("talend");
    properties.userPassword.password.setValue("teland_password");
    properties.userPassword.userId.setValue("talend_dev");
    properties.schemaName.setValue("LOAD");
    properties.db.setValue("TestDB");
    Connection connection = Mockito.mock(Connection.class);
    Mockito.when(connection.isClosed()).thenReturn(false);
    DatabaseMetaData metaData = Mockito.mock(DatabaseMetaData.class);
    ResultSet rs = Mockito.mock(ResultSet.class);
    Mockito.when(rs.next()).thenReturn(true, true, false);
    Mockito.when(rs.getString("TABLE_NAME")).thenReturn("table 1").thenThrow(new SQLException("Unexpected result in resultset"));
    Mockito.when(metaData.getTables(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.eq(new String[] { "TABLE" }))).thenReturn(rs);
    Mockito.when(connection.getMetaData()).thenReturn(metaData);
    Mockito.when(DriverManagerUtils.getConnection(Mockito.any(SnowflakeConnectionProperties.class))).thenReturn(connection);
    Assert.assertEquals(ValidationResult.Result.ERROR, SnowflakeSourceOrSink.validateConnection(properties).getStatus());
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) SnowflakeConnectionProperties(org.talend.components.snowflake.SnowflakeConnectionProperties) DatabaseMetaData(java.sql.DatabaseMetaData) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

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