use of org.talend.components.api.container.RuntimeContainer 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.api.container.RuntimeContainer 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.api.container.RuntimeContainer 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.api.container.RuntimeContainer in project components by Talend.
the class SnowflakeRowSinkTest method testInitialize.
@Test
public void testInitialize() {
RuntimeContainer container = Mockito.mock(RuntimeContainer.class);
TSnowflakeRowProperties properties = new TSnowflakeRowProperties("rowProperties");
Assert.assertNull(sink.getRowProperties());
ValidationResult result = sink.initialize(container, properties);
Assert.assertEquals(ValidationResult.OK, result);
Assert.assertEquals(properties, sink.getRowProperties());
}
use of org.talend.components.api.container.RuntimeContainer in project components by Talend.
the class SnowflakeCloseSourceOrSinkTest method testValidate.
@Test
public void testValidate() throws SQLException {
RuntimeContainer container = Mockito.mock(RuntimeContainer.class);
Connection connection = Mockito.mock(Connection.class);
Mockito.doNothing().when(connection).close();
Mockito.when(container.getComponentData(Mockito.anyString(), Mockito.anyString())).thenReturn(connection);
Assert.assertEquals(ValidationResult.Result.OK, closeSourceOrSink.validate(container).getStatus());
}
Aggregations