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());
}
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);
}
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());
}
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");
}
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());
}
Aggregations