Search in sources :

Example 1 with TSnowflakeInputProperties

use of org.talend.components.snowflake.tsnowflakeinput.TSnowflakeInputProperties 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 TSnowflakeInputProperties

use of org.talend.components.snowflake.tsnowflakeinput.TSnowflakeInputProperties in project components by Talend.

the class SnowflakeReadersTestIT method testInputManual.

@Test
public void testInputManual() throws Throwable {
    TSnowflakeInputProperties props = (TSnowflakeInputProperties) new TSnowflakeInputDefinition().createProperties();
    setupProps(props.getConnectionProperties());
    Form f = props.getForm(MAIN);
    props.manualQuery.setValue(true);
    props = (TSnowflakeInputProperties) PropertiesTestUtils.checkAndAfter(getComponentService(), f, props.manualQuery.getName(), props);
    props.query.setValue("select ID, C7 from " + testTable + " where ID > 80");
    setupTableWithStaticValues(props);
    List<IndexedRecord> rows = readRows(props);
    assertEquals(19, rows.size());
    Schema schema = rows.get(0).getSchema();
    LOGGER.debug(schema.toString());
    assertEquals(BigDecimal.valueOf(81), rows.get(0).get(0));
    assertThat((String) rows.get(0).get(1), containsString("\"bar\": 81"));
}
Also used : TSnowflakeInputDefinition(org.talend.components.snowflake.tsnowflakeinput.TSnowflakeInputDefinition) IndexedRecord(org.apache.avro.generic.IndexedRecord) Form(org.talend.daikon.properties.presentation.Form) Schema(org.apache.avro.Schema) TSnowflakeInputProperties(org.talend.components.snowflake.tsnowflakeinput.TSnowflakeInputProperties) Test(org.junit.Test)

Example 3 with TSnowflakeInputProperties

use of org.talend.components.snowflake.tsnowflakeinput.TSnowflakeInputProperties in project components by Talend.

the class SnowflakeSourceTest method setup.

@Before
public void setup() {
    source = new SnowflakeSource();
    source.initialize(null, new TSnowflakeInputProperties("inputProperties"));
}
Also used : TSnowflakeInputProperties(org.talend.components.snowflake.tsnowflakeinput.TSnowflakeInputProperties) Before(org.junit.Before)

Example 4 with TSnowflakeInputProperties

use of org.talend.components.snowflake.tsnowflakeinput.TSnowflakeInputProperties 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());
}
Also used : DefaultComponentRuntimeContainerImpl(org.talend.components.api.container.DefaultComponentRuntimeContainerImpl) SnowflakeSourceOrSink(org.talend.components.snowflake.runtime.SnowflakeSourceOrSink) SnowflakeConnectionProperties(org.talend.components.snowflake.SnowflakeConnectionProperties) Matchers.containsString(org.hamcrest.Matchers.containsString) TSnowflakeInputProperties(org.talend.components.snowflake.tsnowflakeinput.TSnowflakeInputProperties) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) Test(org.junit.Test)

Example 5 with TSnowflakeInputProperties

use of org.talend.components.snowflake.tsnowflakeinput.TSnowflakeInputProperties in project components by Talend.

the class SnowflakeReadersTestIT method testInputSchema.

@Test
public void testInputSchema() throws Throwable {
    TSnowflakeInputProperties props = (TSnowflakeInputProperties) getComponentService().getComponentProperties(TSnowflakeInputDefinition.COMPONENT_NAME);
    setupProps(props.connection);
    Form f = props.table.getForm(Form.REFERENCE);
    SnowflakeTableProperties moduleProps = (SnowflakeTableProperties) f.getProperties();
    moduleProps = (SnowflakeTableProperties) PropertiesTestUtils.checkAndBeforeActivate(getComponentService(), f, moduleProps.tableName.getName(), moduleProps);
    moduleProps.tableName.setValue(testTable);
    moduleProps = (SnowflakeTableProperties) PropertiesTestUtils.checkAndAfter(getComponentService(), f, moduleProps.tableName.getName(), moduleProps);
    Schema schema = moduleProps.main.schema.getValue();
    LOGGER.debug(schema.toString());
    for (Schema.Field child : schema.getFields()) {
        LOGGER.debug(child.name());
    }
    assertEquals("ID", schema.getFields().get(0).name());
    LOGGER.debug("Table \"" + testTable + "\" column size:" + schema.getFields().size());
    assertTrue(schema.getFields().size() == NUM_COLUMNS);
}
Also used : Form(org.talend.daikon.properties.presentation.Form) Schema(org.apache.avro.Schema) SnowflakeTableProperties(org.talend.components.snowflake.SnowflakeTableProperties) TSnowflakeInputProperties(org.talend.components.snowflake.tsnowflakeinput.TSnowflakeInputProperties) Test(org.junit.Test)

Aggregations

TSnowflakeInputProperties (org.talend.components.snowflake.tsnowflakeinput.TSnowflakeInputProperties)10 Test (org.junit.Test)7 Form (org.talend.daikon.properties.presentation.Form)4 IndexedRecord (org.apache.avro.generic.IndexedRecord)3 TSnowflakeInputDefinition (org.talend.components.snowflake.tsnowflakeinput.TSnowflakeInputDefinition)3 Schema (org.apache.avro.Schema)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Before (org.junit.Before)2 SnowflakeConnectionProperties (org.talend.components.snowflake.SnowflakeConnectionProperties)2 SnowflakeSourceOrSink (org.talend.components.snowflake.runtime.SnowflakeSourceOrSink)2 ArrayList (java.util.ArrayList)1 DefaultComponentRuntimeContainerImpl (org.talend.components.api.container.DefaultComponentRuntimeContainerImpl)1 RuntimeContainer (org.talend.components.api.container.RuntimeContainer)1 SnowflakeTableProperties (org.talend.components.snowflake.SnowflakeTableProperties)1 SnowflakeReader (org.talend.components.snowflake.runtime.SnowflakeReader)1 ValidationResult (org.talend.daikon.properties.ValidationResult)1