Search in sources :

Example 16 with TSnowflakeOutputProperties

use of org.talend.components.snowflake.tsnowflakeoutput.TSnowflakeOutputProperties in project components by Talend.

the class SnowflakeWritersTestIT method testSchemaSerialized2.

@Test
public void testSchemaSerialized2() throws Throwable {
    ComponentDefinition definition = getComponentService().getComponentDefinition(TSnowflakeOutputDefinition.COMPONENT_NAME);
    TSnowflakeOutputProperties outputProps = (TSnowflakeOutputProperties) getComponentService().getComponentProperties(TSnowflakeOutputDefinition.COMPONENT_NAME);
    Schema reject = SchemaBuilder.record("Reject").fields().name("A").type().stringType().noDefault().name("B").type().stringType().noDefault().endRecord();
    Schema main = SchemaBuilder.record("Main").fields().name("C").type().stringType().noDefault().name("D").type().stringType().noDefault().endRecord();
    outputProps.setValue("table.main.schema", main);
    outputProps.setValue("schemaReject.schema", reject);
    Schema main2 = (Schema) outputProps.getValuedProperty("table.main.schema").getValue();
    Schema reject2 = (Schema) outputProps.getValuedProperty("schemaReject.schema").getValue();
    assertEquals(main.toString(), main2.toString());
    assertEquals(reject.toString(), reject2.toString());
    String serialized = outputProps.toSerialized();
    TSnowflakeOutputProperties afterSerialized = org.talend.daikon.properties.Properties.Helper.fromSerializedPersistent(serialized, TSnowflakeOutputProperties.class).object;
    main2 = (Schema) afterSerialized.getValuedProperty("table.main.schema").getValue();
    reject2 = (Schema) afterSerialized.getValuedProperty("schemaReject.schema").getValue();
    assertEquals(main.toString(), main2.toString());
    assertEquals(reject.toString(), reject2.toString());
}
Also used : TSnowflakeOutputProperties(org.talend.components.snowflake.tsnowflakeoutput.TSnowflakeOutputProperties) Schema(org.apache.avro.Schema) Matchers.containsString(org.hamcrest.Matchers.containsString) ComponentDefinition(org.talend.components.api.component.ComponentDefinition) Test(org.junit.Test)

Example 17 with TSnowflakeOutputProperties

use of org.talend.components.snowflake.tsnowflakeoutput.TSnowflakeOutputProperties in project components by Talend.

the class SnowflakeWriterTest method setup.

@Before
public void setup() throws Exception {
    properties = new TSnowflakeOutputProperties("outputProperties");
    properties.init();
    sink = Mockito.mock(SnowflakeSink.class);
    Mockito.when(sink.getSnowflakeOutputProperties()).thenReturn(properties);
    writeOperation = new SnowflakeWriteOperation(sink);
    writer = new SnowflakeWriter(writeOperation, null);
    Schema schema = SchemaBuilder.record("record").fields().name("id").prop(SchemaConstants.TALEND_COLUMN_IS_KEY, Boolean.TRUE.toString()).prop(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, "id").type().stringType().noDefault().requiredString("column").requiredString("field").endRecord();
    schema.getField("column").addProp(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, "column");
    schema.getField("field").addProp(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, "field");
    Mockito.when(sink.createConnection(null)).thenReturn(Mockito.mock(Connection.class));
    Mockito.when(sink.getRuntimeSchema(null)).thenReturn(schema);
    properties.table.main.schema.setValue(schema);
    properties.table.tableName.setValue("Table");
    properties.connection.schemaName.setValue("dbSchema");
    properties.connection.db.setValue("db");
    properties.outputAction.setValue(OutputAction.INSERT);
    PowerMockito.mockStatic(LoaderFactory.class);
    loader = Mockito.mock(StreamLoader.class);
    Mockito.when(LoaderFactory.createLoader(Mockito.anyMapOf(LoaderProperty.class, Object.class), Mockito.any(Connection.class), Mockito.any(Connection.class))).thenReturn(loader);
}
Also used : TSnowflakeOutputProperties(org.talend.components.snowflake.tsnowflakeoutput.TSnowflakeOutputProperties) LoaderProperty(net.snowflake.client.loader.LoaderProperty) StreamLoader(net.snowflake.client.loader.StreamLoader) Schema(org.apache.avro.Schema) Connection(java.sql.Connection) Before(org.junit.Before)

Aggregations

TSnowflakeOutputProperties (org.talend.components.snowflake.tsnowflakeoutput.TSnowflakeOutputProperties)17 Test (org.junit.Test)10 Schema (org.apache.avro.Schema)3 IndexedRecord (org.apache.avro.generic.IndexedRecord)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 Before (org.junit.Before)3 Form (org.talend.daikon.properties.presentation.Form)3 ComponentDefinition (org.talend.components.api.component.ComponentDefinition)2 Result (org.talend.components.api.component.runtime.Result)2 DefaultComponentRuntimeContainerImpl (org.talend.components.api.container.DefaultComponentRuntimeContainerImpl)2 SnowflakeTableProperties (org.talend.components.snowflake.SnowflakeTableProperties)2 ValidationResult (org.talend.daikon.properties.ValidationResult)2 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 LoaderProperty (net.snowflake.client.loader.LoaderProperty)1 StreamLoader (net.snowflake.client.loader.StreamLoader)1 Connector (org.talend.components.api.component.Connector)1 RuntimeContainer (org.talend.components.api.container.RuntimeContainer)1 SnowflakeConnectionProperties (org.talend.components.snowflake.SnowflakeConnectionProperties)1