Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data source/amazon redshift #149

Merged
merged 4 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion e2e/Sandbox/DashboardCreators/AmazonRedshiftDashboard.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Reveal.Sdk.Dom;
using Reveal.Sdk.Dom.Data;
using Reveal.Sdk.Dom.Visualizations;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -13,7 +15,31 @@ internal class AmazonRedshiftDashboard : IDashboardCreator

public RdashDocument CreateDashboard()
{
throw new NotImplementedException();
var document = new RdashDocument();
var dataSource = new AmazonRedshiftDataSource()
{
Title = "Redshift DS",
Host = "reveal-redshift.cmeyu4xjvffl.us-east-1.redshift.amazonaws.com",
Database = "reveal"
};
var dataSourceItem = new AmazonRedshiftDataSourceItem("Redshift DSI", dataSource)
{
Id = "redshiftDSItemId",
Title = "Redshift DS Item",
Table = "employees",
Fields = new List<IField>
{
new NumberField("employeeid"),
new TextField("firstname"),
new TextField("lastname"),
new TextField("address"),
}
};

document.Visualizations.Add(new GridVisualization("List employees", dataSourceItem)
.SetColumns("employeeid", "firstname", "lastname", "address"));

return document;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Newtonsoft.Json.Linq;
using Reveal.Sdk.Dom.Core.Constants;
using Reveal.Sdk.Dom.Data;
using Xunit;

Expand All @@ -6,16 +8,107 @@ namespace Reveal.Sdk.Dom.Tests.Data.DataSourceItems
public class AmazonRedshiftDataSourceItemFixture
{
[Fact]
public void Constructor_SetsTitleAndDataSource_ValidDataSource()
public void Constructor_CreateRedshiftDSItem_WithTitle()
{
// Arrange
var expectedTitle = "DS Item Title";

// Act
var dataSourceItem = new AmazonRedshiftDataSourceItem(expectedTitle);

// Assert
Assert.Equal(SchemaTypeNames.DataSourceItemType, dataSourceItem.SchemaTypeName);
Assert.Equal(expectedTitle, dataSourceItem.Title);
Assert.Equal(expectedTitle, dataSourceItem.DataSource.Title);
Assert.NotNull(dataSourceItem.DataSource);
Assert.IsType<AmazonRedshiftDataSource>(dataSourceItem.DataSource);
}

[Theory]
[InlineData("DS Title", "DS Title", "DS Item Title", "DS Item Title")]
[InlineData(null, "DS Item Title", "DS Item Title", "DS Item Title")]
public void Constructor_CreateRedshiftDSItem_WithTitleAndDataSource(string dsTitle, string expectedDSTitle, string dsItemTitle, string expectedDSItemTitle)
{
// Arrange
var dataSource = new DataSource() { Title = dsTitle };

// Act
var dataSourceItem = new AmazonRedshiftDataSourceItem(dsItemTitle, dataSource);

// Assert
Assert.Equal(SchemaTypeNames.DataSourceItemType, dataSourceItem.SchemaTypeName);
Assert.Equal(expectedDSTitle, dataSourceItem.DataSource.Title);
Assert.Equal(expectedDSItemTitle, dataSourceItem.Title);
Assert.Equal(dataSource.Id, dataSourceItem.DataSource.Id);
Assert.Equal(dataSource.Id, dataSourceItem.DataSourceId);
Assert.NotSame(dataSource, dataSourceItem.DataSource);
Assert.IsType<AmazonRedshiftDataSource>(dataSourceItem.DataSource);
}

[Theory]
[InlineData("DS Title", "DS Title", "DS Item Title", "DS Item Title")]
[InlineData(null, "DS Item Title", "DS Item Title", "DS Item Title")]
public void Constructor_CreateRedshiftDSItem_WithTitleAndRedshiftDataSource(string dsTitle, string expectedDSTitle, string dsItemTitle, string expectedDSItemTitle)
{
// Arrange
var dataSource = new AmazonRedshiftDataSource() { Title = dsTitle };

// Act
var dataSourceItem = new AmazonRedshiftDataSourceItem(dsItemTitle, dataSource);

// Assert
Assert.Equal(SchemaTypeNames.DataSourceItemType, dataSourceItem.SchemaTypeName);
Assert.Equal(expectedDSTitle, dataSourceItem.DataSource.Title);
Assert.Equal(expectedDSItemTitle, dataSourceItem.Title);
Assert.Equal(dataSource.Id, dataSourceItem.DataSource.Id);
Assert.Equal(dataSource.Id, dataSourceItem.DataSourceId);
Assert.Same(dataSource, dataSourceItem.DataSource);
}

[Fact]
public void ToJsonString_CreatesFormattedJson_NoConditions()
{
// Arrange
string title = "Test Item";
var dataSource = new AmazonRedshiftDataSource();
var item = new AmazonRedshiftDataSourceItem(title, dataSource);
var expectedJson = """
{
"_type": "DataSourceItemType",
"Id": "redshiftDSItemId",
"Title": "Redshift DSItem",
"SubTitle": "Northwind Employees",
"DataSourceId": "redshiftId",
"HasTabularData": true,
"HasAsset": false,
"Properties": {
"Table": "employees",
"Schema": "public",
"Database": "RedshiftDB"
},
"Parameters": {}
}
""";
var dataSource = new AmazonRedshiftDataSource()
{
Id = "redshiftId",
};
var dataSourceItem = new AmazonRedshiftDataSourceItem("Redshift DSItem", dataSource)
{
Id = "redshiftDSItemId",
Title = "Redshift DSItem",
Subtitle = "Northwind Employees",
Database = "RedshiftDB",
Table = "employees",
Schema = "public",
HasTabularData = true,
HasAsset = false,
};
var expectedJObject = JObject.Parse(expectedJson);

// Act
var json = dataSourceItem.ToJsonString();
var actualJObject = JObject.Parse(json);

// Assert
Assert.Equal(title, item.Title);
Assert.Equal(dataSource, item.DataSource);
Assert.Equal(expectedJObject, actualJObject);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Newtonsoft.Json.Linq;
using Reveal.Sdk.Dom.Core.Extensions;
using Reveal.Sdk.Dom.Data;
using Xunit;
Expand All @@ -7,62 +8,67 @@ namespace Reveal.Sdk.Dom.Tests.Data.DataSources
public class AmazonRedshiftDataSourceFixture
{
[Fact]
public void Constructor_SetsProviderToAmazonRedshift_Always()
public void Constructor_SetsProviderToAmazonRedshift_WithoutParameters()
{
// Arrange
var dataSource = new AmazonRedshiftDataSource();

// Act
var actualProvider = dataSource.Provider;
var dataSource = new AmazonRedshiftDataSource();

// Assert
Assert.Equal(DataSourceProvider.AmazonRedshift, actualProvider);
Assert.Equal(DataSourceProvider.AmazonRedshift, dataSource.Provider);
}

[Fact]
public void Schema_SetsAndGetsValue_ValidSchema()
public void GetSchema_ReturnSameValue_WithSetValue()
{
// Arrange
var dataSource = new AmazonRedshiftDataSource();
var expectedSchema = "TestSchema";

// Act
dataSource.Schema = expectedSchema;
var actualSchema = dataSource.Schema;

// Assert
Assert.Equal(expectedSchema, actualSchema);
Assert.Equal(expectedSchema, dataSource.Schema);
Assert.Equal(expectedSchema, dataSource.Properties.GetValue<string>("Schema"));
}

[Fact]
public void Schema_SetsValue_NullSchema()
public void ToJsonString_CreatesFormattedJson_NoConditions()
{
// Arrange
var dataSource = new AmazonRedshiftDataSource();
var expectedJson = """
{
"_type": "DataSourceType",
"Id": "redshiftId",
"Provider": "AMAZON_REDSHIFT",
"Description": "Redshift DS",
"Properties": {
"Host": "RedshiftHost",
"Database": "RedshiftDB",
"Schema": "RedshiftSchema"
},
"Settings": {
"DefaultRefreshRate": 180
}
}
""";
var dataSource = new AmazonRedshiftDataSource()
{
Id = "redshiftId",
Title = "Redshift DS",
Host = "RedshiftHost",
Database = "RedshiftDB",
Schema = "RedshiftSchema",
DefaultRefreshRate = "180"
};
var expectedJObject = JObject.Parse(expectedJson);

// Act
dataSource.Schema = null;
var actualSchema = dataSource.Schema;
var actualPropertySchema = dataSource.Properties.GetValue<string>("Schema");

// Assert
Assert.Null(actualSchema);
Assert.Null(actualPropertySchema);
}

[Fact]
public void Properties_StoresSchemaValueCorrectly_ValidSchema()
{
// Arrange
var dataSource = new AmazonRedshiftDataSource();
var expectedSchema = "TestSchema";

// Act
dataSource.Schema = expectedSchema;
var actualPropertySchema = dataSource.Properties.GetValue<string>("Schema");
var json = dataSource.ToJsonString();
var actualJObject = JObject.Parse(json);

// Assert
Assert.Equal(expectedSchema, actualPropertySchema);
Assert.Equal(expectedJObject, actualJObject);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
namespace Reveal.Sdk.Dom.Data
{
internal class AmazonRedshiftDataSourceItem : FunctionDataSourceItem
public class AmazonRedshiftDataSourceItem : FunctionDataSourceItem
{
public AmazonRedshiftDataSourceItem(string title)
: base(title, new AmazonRedshiftDataSource())
{ }

public AmazonRedshiftDataSourceItem(string title, DataSource dataSource) :
base(title, dataSource)
{ }

public AmazonRedshiftDataSourceItem(string title, AmazonRedshiftDataSource dataSource) :
base(title, dataSource)
{ }

protected override DataSource CreateDataSourceInstance(DataSource dataSource)
{
return Create<AmazonRedshiftDataSource>(dataSource);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Reveal.Sdk.Dom.Data
{
internal class AmazonRedshiftDataSource : HostDataSource
public class AmazonRedshiftDataSource : HostDataSource
{
public AmazonRedshiftDataSource()
{
Expand Down
Loading