-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from nfdi4plants/tests-Invenio-#1
Add integration tests for testing Invenio package
- Loading branch information
Showing
49 changed files
with
769 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,41 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.0.31903.59 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "ValidationPackages.Tests", "tests\ValidationPackages.Tests.fsproj", "{D9970D1D-9603-4C7A-9252-6A56CBE21062}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sln", "sln", "{55422101-E1FF-4846-B42C-445298D60D5C}" | ||
ProjectSection(SolutionItems) = preProject | ||
.gitignore = .gitignore | ||
global.json = global.json | ||
LICENSE = LICENSE | ||
README.md = README.md | ||
EndProjectSection | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".ci", ".ci", "{8CF8F7A6-E0A5-4B72-8FEF-52084354A4CF}" | ||
ProjectSection(SolutionItems) = preProject | ||
.github\workflows\manage-issues.yml = .github\workflows\manage-issues.yml | ||
.github\workflows\run-tests.yml = .github\workflows\run-tests.yml | ||
EndProjectSection | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{D9970D1D-9603-4C7A-9252-6A56CBE21062}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{D9970D1D-9603-4C7A-9252-6A56CBE21062}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{D9970D1D-9603-4C7A-9252-6A56CBE21062}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{D9970D1D-9603-4C7A-9252-6A56CBE21062}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {761E9831-7AB0-48D9-B549-413DD7A390FF} | ||
EndGlobalSection | ||
EndGlobal | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.0.31903.59 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "ValidationPackages.Tests", "tests\ValidationPackages.Tests.fsproj", "{D9970D1D-9603-4C7A-9252-6A56CBE21062}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sln", "sln", "{55422101-E1FF-4846-B42C-445298D60D5C}" | ||
ProjectSection(SolutionItems) = preProject | ||
.gitignore = .gitignore | ||
global.json = global.json | ||
integrationTests_script.fsx = integrationTests_script.fsx | ||
LICENSE = LICENSE | ||
playground.fsx = playground.fsx | ||
README.md = README.md | ||
EndProjectSection | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".ci", ".ci", "{8CF8F7A6-E0A5-4B72-8FEF-52084354A4CF}" | ||
ProjectSection(SolutionItems) = preProject | ||
.github\workflows\manage-issues.yml = .github\workflows\manage-issues.yml | ||
.github\workflows\run-tests.yml = .github\workflows\run-tests.yml | ||
EndProjectSection | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{D9970D1D-9603-4C7A-9252-6A56CBE21062}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{D9970D1D-9603-4C7A-9252-6A56CBE21062}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{D9970D1D-9603-4C7A-9252-6A56CBE21062}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{D9970D1D-9603-4C7A-9252-6A56CBE21062}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {761E9831-7AB0-48D9-B549-413DD7A390FF} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#r "nuget: Xunit" | ||
#r "nuget: Fake.DotNet.Cli" | ||
|
||
|
||
open Xunit | ||
open Fake.Core | ||
|
||
open System.Xml | ||
|
||
|
||
let runTool (tool: string) (args: string []) (dir:string) = | ||
CreateProcess.fromRawCommand tool args | ||
|> CreateProcess.withWorkingDirectory dir | ||
|> CreateProcess.redirectOutput | ||
|> Proc.run | ||
|
||
|
||
//let result = runTool "dotnet" [|"fsi"; @"C:\Repos\nfdi4plants\arc-validation-packages\validation_packages\invenio\[email protected]"|] @"C:\Repos\nfdi4plants\arc-validation-packages\tests\fixtures\testARC_empty\" | ||
let result = runTool "dotnet" [|"fsi"; @"C:\Repos\nfdi4plants\arc-validation-packages\validation_packages\invenio\[email protected]"|] @"C:\Repos\nfdi4plants\arc-validation-packages\tests\fixtures\testARC_emptyContactsColumn\" | ||
|
||
|
||
type JUnitResults = { | ||
PassedTests: string list | ||
FailedTests: string list | ||
ErroredTests: string list | ||
} with | ||
static member fromJUnitFile (path:string) = | ||
let doc = new XmlDocument() | ||
doc.Load(path) | ||
let suite = doc.SelectNodes("/testsuites/testsuite[@name='arc-validate']").Item(0); | ||
let testCases = suite.SelectNodes("testcase") |> Seq.cast<XmlNode> | ||
{ | ||
PassedTests = | ||
testCases | ||
|> Seq.filter (fun tc -> tc.SelectNodes("failure").Count = 0) | ||
|> Seq.map (fun tc -> tc.Attributes.["name"].Value) | ||
|> Seq.toList | ||
|> List.sort | ||
|
||
FailedTests = | ||
testCases | ||
|> Seq.filter (fun tc -> tc.SelectNodes("failure").Count > 0) | ||
|> Seq.map (fun tc -> tc.Attributes.["name"].Value) | ||
|> Seq.toList | ||
|> List.sort | ||
|
||
ErroredTests = | ||
testCases | ||
|> Seq.filter (fun tc -> tc.SelectNodes("error").Count > 0) | ||
|> Seq.map (fun tc -> tc.Attributes.["name"].Value) | ||
|> Seq.toList | ||
|> List.sort | ||
} | ||
|
||
static member getTotalTestCount (res : JUnitResults) = | ||
res.ErroredTests.Length + res.FailedTests.Length + res.PassedTests.Length | ||
|
||
|
||
let jUnitRes = JUnitResults.fromJUnitFile @"C:\Repos\nfdi4plants\arc-validation-packages\tests\fixtures\ArcPrototype\.arc-validate-results\[email protected]\validation_report.xml" | ||
|
||
null = null | ||
|
||
let doc = new XmlDocument() | ||
doc.Load(@"C:\Repos\nfdi4plants\arc-validation-packages\tests\fixtures\ArcPrototype\.arc-validate-results\[email protected]\validation_report.xml") | ||
let suite = | ||
doc.SelectNodes("/testsuites/testsuite[@name='arc-validate']").Item(0) | ||
|> fun r -> | ||
if isNull r then | ||
doc.SelectNodes("/testsuites/testsuite[@name='fsi']").Item(0) | ||
else r | ||
let testCases = suite.SelectNodes("testcase") |> Seq.cast<XmlNode> | ||
{ | ||
PassedTests = | ||
testCases | ||
|> Seq.filter (fun tc -> tc.SelectNodes("failure").Count = 0) | ||
|> Seq.map (fun tc -> tc.Attributes.["name"].Value) | ||
|> Seq.toList | ||
|> List.sort | ||
|
||
FailedTests = | ||
testCases | ||
|> Seq.filter (fun tc -> tc.SelectNodes("failure").Count > 0) | ||
|> Seq.map (fun tc -> tc.Attributes.["name"].Value) | ||
|> Seq.toList | ||
|> List.sort | ||
|
||
ErroredTests = | ||
testCases | ||
|> Seq.filter (fun tc -> tc.SelectNodes("error").Count > 0) | ||
|> Seq.map (fun tc -> tc.Attributes.["name"].Value) | ||
|> Seq.toList | ||
|> List.sort | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
let [<Literal>]PACKAGE_METADATA = """(* | ||
--- | ||
Name: invenio | ||
Summary: Validates if the ARC contains the necessary metadata to be publishable via Invenio. | ||
Description: | | ||
Validates if the ARC contains the necessary metadata to be publishable via Invenio. | ||
The following metadata is required: | ||
- Investigation has title and description | ||
- All persons in Investigation Contacts must have a name, last name, affiliation and valid email | ||
MajorVersion: 3 | ||
MinorVersion: 0 | ||
PatchVersion: 0 | ||
Publish: true | ||
Authors: | ||
- FullName: Oliver Maus | ||
Affiliation: DataPLANT | ||
- FullName: Christopher Lux | ||
Email: [email protected] | ||
Affiliation: RPTU Kaiserslautern | ||
AffiliationLink: http://rptu.de/startseite | ||
- FullName: Lukas Weil | ||
Email: [email protected] | ||
Affiliation: DataPLANT | ||
Tags: | ||
- Name: ARC | ||
- Name: data publication | ||
ReleaseNotes: | | ||
- Fix package passing validation against Investigation file containing only section keys | ||
--- | ||
*)""" | ||
|
||
#r "nuget: ARCExpect, 4.0.1" | ||
|
||
open ControlledVocabulary | ||
open Expecto | ||
open ARCExpect | ||
open ARCTokenization | ||
open ARCTokenization.StructuralOntology | ||
open System.IO | ||
|
||
// Input: | ||
//let arcDir = Directory.GetCurrentDirectory() | ||
let arcDir = @"C:\Repos\nfdi4plants\arc-validation-packages\tests\fixtures\ArcPrototype\" | ||
|
||
// Values: | ||
let absoluteDirectoryPaths = FileSystem.parseARCFileSystem arcDir | ||
|
||
let investigationMetadata = | ||
absoluteDirectoryPaths | ||
|> Investigation.parseMetadataSheetsFromTokens() arcDir | ||
|> List.concat | ||
|
||
#r "nuget: Xunit" | ||
open Xunit | ||
|
||
investigationMetadata | ||
|> List.exists ( | ||
fun ip -> | ||
Param.getCvAccession ip = "INVMSO:00000009" && | ||
Param.getValueAsString ip |> String.isNullOrWhiteSpace |> not && | ||
match Param.getParamValue ip with | CvValue x -> x.Accession = "AGMO:00000001" | _ -> false | ||
) | ||
investigationMetadata |> List.filter (fun ip -> Param.getValueAsString ip |> String.isNullOrWhiteSpace |> not && Param.getCvAccession ip = "INVMSO:00000009") | ||
|
||
|
||
|
||
let expectedTitleCvPExists = | ||
investigationMetadata | ||
|> List.exists ( | ||
fun ip -> | ||
Param.getCvAccession ip = "INVMSO:00000009" && | ||
Param.getValueAsString ip |> String.isNullOrWhiteSpace |> not && | ||
match Param.getParamValue ip with | CvValue x -> x.Accession = "AGMO:00000001" | _ -> false | ||
) | ||
|
||
Assert.True expectedTitleCvPExists | ||
|
||
|
||
// Validation Cases: | ||
let cases = | ||
testList INVMSO.``Investigation Metadata``.INVESTIGATION.key.Name [ | ||
// Investigation has title | ||
ARCExpect.validationCase (TestID.Name INVMSO.``Investigation Metadata``.INVESTIGATION.``Investigation Title``.Name) { | ||
investigationMetadata | ||
|> Validate.ParamCollection.ContainsNonKeyParamWithTerm | ||
INVMSO.``Investigation Metadata``.INVESTIGATION.``Investigation Title`` | ||
} | ||
// Investigation has description | ||
ARCExpect.validationCase (TestID.Name INVMSO.``Investigation Metadata``.INVESTIGATION.``Investigation Description``.Name) { | ||
investigationMetadata | ||
|> Validate.ParamCollection.ContainsNonKeyParamWithTerm | ||
INVMSO.``Investigation Metadata``.INVESTIGATION.``Investigation Description`` | ||
} | ||
// Investigation has contacts with name, last name, affiliation and email | ||
// Investigation Person First Name | ||
ARCExpect.validationCase (TestID.Name $"{INVMSO.``Investigation Metadata``.``INVESTIGATION CONTACTS``.``Investigation Person First Name``.Name} exists") { | ||
investigationMetadata | ||
|> Validate.ParamCollection.ContainsNonKeyParamWithTerm INVMSO.``Investigation Metadata``.``INVESTIGATION CONTACTS``.``Investigation Person First Name`` | ||
} | ||
ARCExpect.validationCase (TestID.Name $"{INVMSO.``Investigation Metadata``.``INVESTIGATION CONTACTS``.``Investigation Person First Name``.Name} is not empty") { | ||
investigationMetadata | ||
|> Seq.filter (Param.getTerm >> (=) INVMSO.``Investigation Metadata``.``INVESTIGATION CONTACTS``.``Investigation Person First Name``) | ||
|> Seq.iter Validate.Param.ValueIsNotEmpty | ||
} | ||
// Investigation Person Last Name | ||
ARCExpect.validationCase (TestID.Name $"{INVMSO.``Investigation Metadata``.``INVESTIGATION CONTACTS``.``Investigation Person Last Name``.Name} exists") { | ||
investigationMetadata | ||
|> Validate.ParamCollection.ContainsNonKeyParamWithTerm INVMSO.``Investigation Metadata``.``INVESTIGATION CONTACTS``.``Investigation Person Last Name`` | ||
} | ||
ARCExpect.validationCase (TestID.Name $"{INVMSO.``Investigation Metadata``.``INVESTIGATION CONTACTS``.``Investigation Person Last Name``.Name} is not empty") { | ||
investigationMetadata | ||
|> Seq.filter (Param.getTerm >> (=) INVMSO.``Investigation Metadata``.``INVESTIGATION CONTACTS``.``Investigation Person Last Name``) | ||
|> Seq.iter Validate.Param.ValueIsNotEmpty | ||
} | ||
// Investigation Person Affiliation | ||
ARCExpect.validationCase (TestID.Name $"{INVMSO.``Investigation Metadata``.``INVESTIGATION CONTACTS``.``Investigation Person Affiliation``.Name} exists") { | ||
investigationMetadata | ||
|> Validate.ParamCollection.ContainsNonKeyParamWithTerm INVMSO.``Investigation Metadata``.``INVESTIGATION CONTACTS``.``Investigation Person Affiliation`` | ||
} | ||
ARCExpect.validationCase (TestID.Name $"{INVMSO.``Investigation Metadata``.``INVESTIGATION CONTACTS``.``Investigation Person Affiliation``.Name} is not empty") { | ||
investigationMetadata | ||
|> Seq.filter (Param.getTerm >> (=) INVMSO.``Investigation Metadata``.``INVESTIGATION CONTACTS``.``Investigation Person Affiliation``) | ||
|> Seq.filter (Param.getValueAsString >> (<>) "Metadata Section Key") | ||
|> Seq.iter Validate.Param.ValueIsNotEmpty | ||
} | ||
// Investigation Person Email | ||
ARCExpect.validationCase (TestID.Name $"{INVMSO.``Investigation Metadata``.``INVESTIGATION CONTACTS``.``Investigation Person Email``.Name} exists") { | ||
investigationMetadata | ||
|> Validate.ParamCollection.ContainsNonKeyParamWithTerm INVMSO.``Investigation Metadata``.``INVESTIGATION CONTACTS``.``Investigation Person Email`` | ||
} | ||
ARCExpect.validationCase (TestID.Name INVMSO.``Investigation Metadata``. ``INVESTIGATION CONTACTS``.``Investigation Person Email``.Name) { | ||
investigationMetadata | ||
|> Seq.filter (Param.getTerm >> (=) INVMSO.``Investigation Metadata``.``INVESTIGATION CONTACTS``.``Investigation Person Email``) | ||
|> Seq.filter (Param.getValueAsString >> (<>) "Metadata Section Key") | ||
|> Seq.iter (Validate.Param.ValueMatchesRegex StringValidationPattern.email) | ||
} | ||
] | ||
|
||
// Execution: | ||
|
||
Setup.ValidationPackage( | ||
metadata = Setup.Metadata(PACKAGE_METADATA), | ||
CriticalValidationCases = [cases] | ||
) | ||
|> Execute.ValidationPipeline( | ||
basePath = arcDir | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.