From b15de6c367ac5af6c1c3d03b10c06eb4fac1606f Mon Sep 17 00:00:00 2001 From: Mauricio Uyaguari Date: Tue, 30 Jan 2024 17:47:51 -0500 Subject: [PATCH] enhance showcase with post validations on service and basic function tests (#792) * add postValidation on showcase relationalStore/Service/Basic * update engine * change example name * function tests * fix test --------- Co-authored-by: Yannan --- .../Build a relational service/code.pure | 0 .../Build a relational service/info.md | 0 .../Build an M2M hosted service/code.pure | 0 .../Build an M2M hosted service/info.md | 0 .../Build model from database/code.pure | 0 .../Build model from database/info.md | 0 .../Integrate Mappings/code.pure | 0 .../Integrate Mappings/info.md | 0 .../data/Function/Function Tests/code.pure | 26 +++++++++++++++++ .../data/Function/Function Tests/info.md | 6 ++++ .../Relational Store/Service/Basic/code.pure | 28 +++++++++++++++++++ .../Relational Store/Service/Basic/info.md | 3 +- showcases/pom.xml | 8 +++++- 13 files changed, 69 insertions(+), 2 deletions(-) rename showcases/data/{End-to-end examples => End To End Examples}/Build a relational service/code.pure (100%) rename showcases/data/{End-to-end examples => End To End Examples}/Build a relational service/info.md (100%) rename showcases/data/{End-to-end examples => End To End Examples}/Build an M2M hosted service/code.pure (100%) rename showcases/data/{End-to-end examples => End To End Examples}/Build an M2M hosted service/info.md (100%) rename showcases/data/{End-to-end examples => End To End Examples}/Build model from database/code.pure (100%) rename showcases/data/{End-to-end examples => End To End Examples}/Build model from database/info.md (100%) rename showcases/data/{End-to-end examples => End To End Examples}/Integrate Mappings/code.pure (100%) rename showcases/data/{End-to-end examples => End To End Examples}/Integrate Mappings/info.md (100%) create mode 100644 showcases/data/Function/Function Tests/code.pure create mode 100644 showcases/data/Function/Function Tests/info.md diff --git a/showcases/data/End-to-end examples/Build a relational service/code.pure b/showcases/data/End To End Examples/Build a relational service/code.pure similarity index 100% rename from showcases/data/End-to-end examples/Build a relational service/code.pure rename to showcases/data/End To End Examples/Build a relational service/code.pure diff --git a/showcases/data/End-to-end examples/Build a relational service/info.md b/showcases/data/End To End Examples/Build a relational service/info.md similarity index 100% rename from showcases/data/End-to-end examples/Build a relational service/info.md rename to showcases/data/End To End Examples/Build a relational service/info.md diff --git a/showcases/data/End-to-end examples/Build an M2M hosted service/code.pure b/showcases/data/End To End Examples/Build an M2M hosted service/code.pure similarity index 100% rename from showcases/data/End-to-end examples/Build an M2M hosted service/code.pure rename to showcases/data/End To End Examples/Build an M2M hosted service/code.pure diff --git a/showcases/data/End-to-end examples/Build an M2M hosted service/info.md b/showcases/data/End To End Examples/Build an M2M hosted service/info.md similarity index 100% rename from showcases/data/End-to-end examples/Build an M2M hosted service/info.md rename to showcases/data/End To End Examples/Build an M2M hosted service/info.md diff --git a/showcases/data/End-to-end examples/Build model from database/code.pure b/showcases/data/End To End Examples/Build model from database/code.pure similarity index 100% rename from showcases/data/End-to-end examples/Build model from database/code.pure rename to showcases/data/End To End Examples/Build model from database/code.pure diff --git a/showcases/data/End-to-end examples/Build model from database/info.md b/showcases/data/End To End Examples/Build model from database/info.md similarity index 100% rename from showcases/data/End-to-end examples/Build model from database/info.md rename to showcases/data/End To End Examples/Build model from database/info.md diff --git a/showcases/data/End-to-end examples/Integrate Mappings/code.pure b/showcases/data/End To End Examples/Integrate Mappings/code.pure similarity index 100% rename from showcases/data/End-to-end examples/Integrate Mappings/code.pure rename to showcases/data/End To End Examples/Integrate Mappings/code.pure diff --git a/showcases/data/End-to-end examples/Integrate Mappings/info.md b/showcases/data/End To End Examples/Integrate Mappings/info.md similarity index 100% rename from showcases/data/End-to-end examples/Integrate Mappings/info.md rename to showcases/data/End To End Examples/Integrate Mappings/info.md diff --git a/showcases/data/Function/Function Tests/code.pure b/showcases/data/Function/Function Tests/code.pure new file mode 100644 index 000000000..e4468589f --- /dev/null +++ b/showcases/data/Function/Function Tests/code.pure @@ -0,0 +1,26 @@ +function model::Simple(): String[1] +{ + 'Hello' + ' World!' +} +{ + testPass | Simple() => 'Hello World!'; +} + +function model::Hello(name: String[1]): String[1] +{ + 'Hello World! My name is ' + $name + '.' +} +{ + testSuite_1 + ( + testPass | Hello('John') => 'Hello World! My name is John.'; + ) +} + +function model::SimpleReference(): String[1] +{ + model::Simple() +} +{ + testPass | SimpleReference() => 'Hello World!'; +} diff --git a/showcases/data/Function/Function Tests/info.md b/showcases/data/Function/Function Tests/info.md new file mode 100644 index 000000000..dd71f59de --- /dev/null +++ b/showcases/data/Function/Function Tests/info.md @@ -0,0 +1,6 @@ +--- +title: Function Tests +description: Simple Function with Tests +--- + +The following showcase shows how to write tests for simple functions with and without parameters. Adding tests to your functions will help ensure your function behaves as expected as it is changed by other users. \ No newline at end of file diff --git a/showcases/data/Store/Relational Store/Service/Basic/code.pure b/showcases/data/Store/Relational Store/Service/Basic/code.pure index c47a370e0..d18d42271 100644 --- a/showcases/data/Store/Relational Store/Service/Basic/code.pure +++ b/showcases/data/Store/Relational Store/Service/Basic/code.pure @@ -372,6 +372,20 @@ Service showcase::northwind::services::tds::OrderDetailsByIdTDS mapping: showcase::northwind::mapping::NorthwindMapping; runtime: showcase::northwind::runtime::NorthwindRuntime; } + postValidations: + [ + { + description: 'a simple passing validation with static parameter'; + params:[ + |10248 + ]; + assertions:[ + rowCountGreaterThan10: tds: TabularDataSet[1]|$tds->filter( + row: meta::pure::tds::TDSRow[1]|$row.getString('Employee/First Name')->startsWith('T') +)->meta::legend::service::validation::assertTabularDataSetEmpty('Expected no Employee/First Name to begin with the letter T') + ]; + } + ] } Service showcase::northwind::services::tds::ProductRankingWithinCategory @@ -445,6 +459,20 @@ Service showcase::northwind::services::tds::Customers mapping: showcase::northwind::mapping::NorthwindMapping; runtime: showcase::northwind::runtime::NorthwindRuntime; } + postValidations: + [ + { + description: 'A simple passing validation'; + params:[ + + ]; + assertions:[ + noCompanyNamedAroundtheHorn: tds: TabularDataSet[1]|$tds->filter( + row: meta::pure::tds::TDSRow[1]|$row.getString('Company Name')->contains('Around the Hornsss') +)->meta::legend::service::validation::assertTabularDataSetEmpty('Expected there is no company named Around the Hornsss') + ]; + } + ] } Service showcase::northwind::services::graph::ShipperValidationDefects diff --git a/showcases/data/Store/Relational Store/Service/Basic/info.md b/showcases/data/Store/Relational Store/Service/Basic/info.md index 3389a90e4..5abf67be1 100644 --- a/showcases/data/Store/Relational Store/Service/Basic/info.md +++ b/showcases/data/Store/Relational Store/Service/Basic/info.md @@ -3,4 +3,5 @@ title: Relational Service - Querying Product Northwind Data description: Example of Relational Service querying northwind test data with Mapping and Service Tests --- -The connection uses here loads sample data from northwind. See https://github.com/pthom/northwind_psql for more info as well as the model. It includes a sample service querying products. Additionally it includes services and mapping tests. \ No newline at end of file +The connection used here loads sample data from [northwind](https://github.com/pthom/northwind_psql). It includes a sample service querying products. Additionally it includes services and mapping tests. Some of the services include [post validations](https://github.com/finos/legend-engine/blob/master/docs/data-quality/service-post-validations.md) for better data quality. + diff --git a/showcases/pom.xml b/showcases/pom.xml index a2de84855..710938f94 100644 --- a/showcases/pom.xml +++ b/showcases/pom.xml @@ -16,7 +16,7 @@ 1.8 3 data - 4.37.7 + 4.37.8 @@ -42,6 +42,12 @@ ${legend.engine.version} test + + org.finos.legend.engine + legend-engine-test-runner-function + ${legend.engine.version} + test + org.finos.legend.engine legend-engine-test-runner-mapping