Skip to content

Commit

Permalink
enhance showcase with post validations on service and basic function …
Browse files Browse the repository at this point in the history
…tests (#792)

* add postValidation on showcase relationalStore/Service/Basic

* update engine

* change example name

* function tests

* fix test

---------

Co-authored-by: Yannan <[email protected]>
  • Loading branch information
MauricioUyaguari and YannanGao-gs authored Jan 30, 2024
1 parent 30412d8 commit b15de6c
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 2 deletions.
26 changes: 26 additions & 0 deletions showcases/data/Function/Function Tests/code.pure
Original file line number Diff line number Diff line change
@@ -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!';
}
6 changes: 6 additions & 0 deletions showcases/data/Function/Function Tests/info.md
Original file line number Diff line number Diff line change
@@ -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.
28 changes: 28 additions & 0 deletions showcases/data/Store/Relational Store/Service/Basic/code.pure
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion showcases/data/Store/Relational Store/Service/Basic/info.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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.

8 changes: 7 additions & 1 deletion showcases/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<maven.compiler.target>1.8</maven.compiler.target>
<maven.surefire.thread.count>3</maven.surefire.thread.count>
<showcase.projects.location>data</showcase.projects.location>
<legend.engine.version>4.37.7</legend.engine.version>
<legend.engine.version>4.37.8</legend.engine.version>

</properties>

Expand All @@ -42,6 +42,12 @@
<version>${legend.engine.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-test-runner-function</artifactId>
<version>${legend.engine.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-test-runner-mapping</artifactId>
Expand Down

0 comments on commit b15de6c

Please sign in to comment.