use of org.talend.components.snowflake.SnowflakeConnectionProperties in project components by Talend.
the class SnowflakeSourceOrSinkTest method setUp.
@Before
public void setUp() throws Exception {
snowflakeSourceOrSink = new SnowflakeSourceOrSink();
SnowflakeConnectionProperties properties = new SnowflakeConnectionProperties("test");
properties.referencedComponent.componentInstanceId.setValue("referencedComponentId");
this.snowflakeSourceOrSink.initialize(runtimeContainerMock, properties);
PowerMockito.mockStatic(DriverManagerUtils.class);
}
use of org.talend.components.snowflake.SnowflakeConnectionProperties in project components by Talend.
the class SnowflakeSourceOrSinkTest method testGetSchemaAddKeyProperty.
/**
* Checks {@link SnowflakeSourceOrSink#getSchema(RuntimeContainer, Connection, String)} adds property key to the
* field
* TODO remove this test as we it check the code we removed
*/
@Ignore
@Test
public void testGetSchemaAddKeyProperty() throws Exception {
Schema schemaToEdit = SchemaBuilder.builder().record("Schema").fields().name("field").type().stringType().noDefault().endRecord();
LOGGER.debug("schema to add key property: " + schemaToEdit);
Schema expectedSchema = SchemaBuilder.builder().record("Schema").fields().name("field").type().stringType().noDefault().endRecord();
expectedSchema.getField("field").addProp(SchemaConstants.TALEND_COLUMN_IS_KEY, "true");
LOGGER.debug("expected schema: " + expectedSchema);
Connection connectionMock = Mockito.mock(Connection.class);
Mockito.when(runtimeContainerMock.getComponentData(Matchers.anyString(), Matchers.anyString())).thenReturn(snowflakeSourceOrSink.properties);
DatabaseMetaData databaseMetaDataMock = Mockito.mock(DatabaseMetaData.class);
ResultSet resultSetMock = Mockito.mock(ResultSet.class);
ResultSet resultSetMockKeys = Mockito.mock(ResultSet.class);
Mockito.when(connectionMock.getMetaData()).thenReturn(databaseMetaDataMock);
final SnowflakeAvroRegistry snowflakeAvroRegistryMock = Mockito.mock(SnowflakeAvroRegistry.class);
class SnowflakeSourceOrSinkChild extends SnowflakeSourceOrSink {
private static final long serialVersionUID = 1L;
@Override
public SnowflakeAvroRegistry getSnowflakeAvroRegistry() {
return snowflakeAvroRegistryMock;
}
}
SnowflakeSourceOrSink sfSourceOrSink = new SnowflakeSourceOrSinkChild();
SnowflakeConnectionProperties properties = new SnowflakeConnectionProperties("test");
properties.referencedComponent.componentInstanceId.setValue("referencedComponentId");
properties.db.setValue("database");
sfSourceOrSink.initialize(runtimeContainerMock, properties);
Mockito.when(databaseMetaDataMock.getColumns(sfSourceOrSink.getCatalog(sfSourceOrSink.getEffectiveConnectionProperties(runtimeContainerMock)), sfSourceOrSink.getDbSchema(sfSourceOrSink.getEffectiveConnectionProperties(runtimeContainerMock)), "tableName", null)).thenReturn(resultSetMock);
Mockito.when(databaseMetaDataMock.getPrimaryKeys(sfSourceOrSink.getCatalog(sfSourceOrSink.getEffectiveConnectionProperties(runtimeContainerMock)), sfSourceOrSink.getDbSchema(sfSourceOrSink.getEffectiveConnectionProperties(runtimeContainerMock)), "tableName")).thenReturn(resultSetMockKeys);
Mockito.when(resultSetMockKeys.next()).thenReturn(true).thenReturn(false);
Mockito.when(resultSetMockKeys.getString("COLUMN_NAME")).thenReturn("field");
Mockito.when(snowflakeAvroRegistryMock.inferSchema(resultSetMock)).thenReturn(schemaToEdit);
Schema resultSchema = sfSourceOrSink.getSchema(runtimeContainerMock, connectionMock, "tableName");
LOGGER.debug("result schema: " + resultSchema);
Assert.assertNotNull(resultSchema);
Assert.assertEquals(expectedSchema.getField("field").getProp(SchemaConstants.TALEND_COLUMN_IS_KEY), resultSchema.getField("field").getProp(SchemaConstants.TALEND_COLUMN_IS_KEY));
Assert.assertEquals(expectedSchema, resultSchema);
}
use of org.talend.components.snowflake.SnowflakeConnectionProperties in project components by Talend.
the class SpringSnowflakeTestIT method testModuleWizard.
@Test
public void testModuleWizard() throws Throwable {
ComponentWizard connectionWizard = getComponentService().getComponentWizard(SnowflakeConnectionWizardDefinition.COMPONENT_WIZARD_NAME, "nodeSnowflake");
List<Form> forms = connectionWizard.getForms();
Form connFormWizard = forms.get(0);
SnowflakeConnectionProperties connProps = (SnowflakeConnectionProperties) connFormWizard.getProperties();
ComponentWizard[] subWizards = getComponentService().getComponentWizardsForProperties(connProps, "location").toArray(new ComponentWizard[2]);
Arrays.sort(subWizards, new WizardNameComparator());
assertEquals(2, subWizards.length);
assertTrue(subWizards[0].getDefinition().isTopLevel());
assertEquals("Snowflake Connection", subWizards[0].getDefinition().getMenuItemName());
// Edit connection wizard - we copy the connection properties, as we present the UI, so we use the
// connection properties object created by the new wizard
assertFalse(connProps == subWizards[1].getForms().get(0).getProperties());
// will remove the edit wizard in future, no need to test more about it
// Add module wizard - we refer to the existing connection properties as we don't present the UI
// for them.
// assertTrue(connProps == ((SnowflakeTableListProperties) subWizards[2].getForms().get(0).getProperties())
// .getConnectionProperties());
// assertFalse(subWizards[2].getDefinition().isTopLevel());
// assertEquals("Snowflake Tables", subWizards[2].getDefinition().getMenuItemName());
}
use of org.talend.components.snowflake.SnowflakeConnectionProperties in project components by Talend.
the class SpringSnowflakeTestIT method testLoginFail.
@Test
public void testLoginFail() throws Throwable {
SnowflakeConnectionProperties props = (SnowflakeConnectionProperties) setupProps(null);
props.userPassword.userId.setValue("blah");
Form f = props.getForm(SnowflakeConnectionProperties.FORM_WIZARD);
props = (SnowflakeConnectionProperties) PropertiesTestUtils.checkAndValidate(getComponentService(), f, "testConnection", props);
LOGGER.debug(props.getValidationResult().toString());
assertEquals(ValidationResult.Result.ERROR, props.getValidationResult().getStatus());
}
Aggregations