use of org.talend.components.snowflake.SnowflakeConnectionProperties in project components by Talend.
the class SnowflakeReadersTestIT method testCloseExistingConnection.
@Test
public void testCloseExistingConnection() throws Throwable {
SnowflakeConnectionProperties connProps = (SnowflakeConnectionProperties) getComponentService().getComponentProperties(TSnowflakeConnectionDefinition.COMPONENT_NAME);
setupProps(connProps);
final String currentComponentName = TSnowflakeConnectionDefinition.COMPONENT_NAME + "_1";
RuntimeContainer connContainer = new DefaultComponentRuntimeContainerImpl() {
@Override
public String getCurrentComponentId() {
return currentComponentName;
}
};
SnowflakeSourceOrSink snowflakeSourceOrSink = new SnowflakeSourceOrSink();
snowflakeSourceOrSink.initialize(connContainer, connProps);
assertEquals(ValidationResult.Result.OK, snowflakeSourceOrSink.validate(connContainer).getStatus());
TSnowflakeCloseProperties closeProps = (TSnowflakeCloseProperties) getComponentService().getComponentProperties(TSnowflakeCloseDefinition.COMPONENT_NAME);
closeProps.referencedComponent.componentInstanceId.setValue(currentComponentName);
SnowflakeCloseSourceOrSink snowflakeCloseSourceOrSink = new SnowflakeCloseSourceOrSink();
snowflakeCloseSourceOrSink.initialize(connContainer, closeProps);
assertEquals(ValidationResult.Result.OK, snowflakeCloseSourceOrSink.validate(connContainer).getStatus());
}
use of org.talend.components.snowflake.SnowflakeConnectionProperties in project components by Talend.
the class SnowflakeReadersTestIT method testUseExistingConnection.
@Test
public void testUseExistingConnection() throws Throwable {
SnowflakeConnectionProperties connProps = (SnowflakeConnectionProperties) getComponentService().getComponentProperties(TSnowflakeConnectionDefinition.COMPONENT_NAME);
setupProps(connProps);
final String currentComponentName = TSnowflakeConnectionDefinition.COMPONENT_NAME + "_1";
RuntimeContainer connContainer = new DefaultComponentRuntimeContainerImpl() {
@Override
public String getCurrentComponentId() {
return currentComponentName;
}
};
SnowflakeSourceOrSink SnowflakeSourceOrSink = new SnowflakeSourceOrSink();
SnowflakeSourceOrSink.initialize(connContainer, connProps);
assertEquals(ValidationResult.Result.OK, SnowflakeSourceOrSink.validate(connContainer).getStatus());
// Input component get connection from the tSnowflakeConnection
TSnowflakeInputProperties inProps = (TSnowflakeInputProperties) getComponentService().getComponentProperties(TSnowflakeInputDefinition.COMPONENT_NAME);
inProps.connection.referencedComponent.componentInstanceId.setValue(currentComponentName);
SnowflakeSourceOrSink SnowflakeInputSourceOrSink = new SnowflakeSourceOrSink();
SnowflakeInputSourceOrSink.initialize(connContainer, inProps);
assertEquals(ValidationResult.Result.OK, SnowflakeInputSourceOrSink.validate(connContainer).getStatus());
}
use of org.talend.components.snowflake.SnowflakeConnectionProperties in project components by Talend.
the class SnowflakeReadersTestIT method testSameConnectionForSeveralReaders.
@Test(expected = IOException.class)
public void testSameConnectionForSeveralReaders() throws Throwable {
SnowflakeConnectionProperties connProps = (SnowflakeConnectionProperties) getComponentService().getComponentProperties(TSnowflakeConnectionDefinition.COMPONENT_NAME);
setupProps(connProps);
final String currentComponentName = TSnowflakeConnectionDefinition.COMPONENT_NAME + "_1";
RuntimeContainer connContainer = new DefaultComponentRuntimeContainerImpl() {
@Override
public String getCurrentComponentId() {
return currentComponentName;
}
};
SnowflakeSourceOrSink SnowflakeSourceOrSink = new SnowflakeSourceOrSink();
SnowflakeSourceOrSink.initialize(connContainer, connProps);
assertEquals(ValidationResult.Result.OK, SnowflakeSourceOrSink.validate(connContainer).getStatus());
TSnowflakeOutputProperties props = (TSnowflakeOutputProperties) getComponentService().getComponentProperties(TSnowflakeOutputDefinition.COMPONENT_NAME);
setupProps(props.getConnectionProperties());
setupTableWithStaticValues(props);
props.connection.referencedComponent.componentInstanceId.setValue(currentComponentName);
List<IndexedRecord> rows = readRows(props, connContainer);
assertEquals(100, rows.size());
// Read second time with the same properties but with new reader.
rows = readRows(props, connContainer);
assertEquals(100, rows.size());
TSnowflakeCloseProperties closeProps = (TSnowflakeCloseProperties) getComponentService().getComponentProperties(TSnowflakeCloseDefinition.COMPONENT_NAME);
closeProps.referencedComponent.componentInstanceId.setValue(currentComponentName);
SnowflakeCloseSourceOrSink snowflakeCloseSourceOrSink = new SnowflakeCloseSourceOrSink();
snowflakeCloseSourceOrSink.initialize(connContainer, closeProps);
assertEquals(ValidationResult.Result.OK, snowflakeCloseSourceOrSink.validate(connContainer).getStatus());
// After close, exception should be thrown by the reader, if we try to read with the same connection.
rows = readRows(props, connContainer);
}
use of org.talend.components.snowflake.SnowflakeConnectionProperties in project components by Talend.
the class SnowflakeSinkTest method testValidateWrongPropertiesType.
@Test
public void testValidateWrongPropertiesType() throws Exception {
sink.properties = new SnowflakeConnectionProperties("connectionProperties");
PowerMockito.mockStatic(DriverManagerUtils.class);
Mockito.when(DriverManagerUtils.getConnection(Mockito.any(SnowflakeConnectionProperties.class))).thenReturn(Mockito.mock(Connection.class));
Assert.assertEquals(ValidationResult.Result.ERROR, sink.validate(null).getStatus());
}
use of org.talend.components.snowflake.SnowflakeConnectionProperties in project components by Talend.
the class SnowflakeSourceOrSinkTest method testValidateConnection.
@Test
public void testValidateConnection() 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);
Mockito.when(metaData.getTables(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.eq(new String[] { "TABLE" }))).thenReturn(Mockito.mock(ResultSet.class));
Mockito.when(connection.getMetaData()).thenReturn(metaData);
Mockito.when(DriverManagerUtils.getConnection(Mockito.any(SnowflakeConnectionProperties.class))).thenReturn(connection);
Assert.assertEquals(ValidationResult.Result.OK, SnowflakeSourceOrSink.validateConnection(properties).getStatus());
}
Aggregations