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

Add integration tests for testing Invenio package #3

Merged
merged 39 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
08bf120
Add Invenio 3.0.0 script
omaus Sep 4, 2024
092df9e
Add test-ARCs
omaus Sep 6, 2024
82db6f6
Add ARCTokenization dependency
omaus Sep 10, 2024
2945887
Update Invenio package unit tests
omaus Sep 10, 2024
7551cfa
Add playground file
omaus Sep 20, 2024
ef326ec
Add Invenio unit test
omaus Sep 20, 2024
d3d7532
Add validation summary json to fixtures
omaus Oct 2, 2024
29b4c23
Update invenio 3.0.0 package
omaus Oct 2, 2024
e39098d
Add dependecy to ARCExpect
omaus Oct 2, 2024
2063b9f
Add ref objects and restructure namespace hereof
omaus Oct 2, 2024
60633e9
Add Invenio unit tests
omaus Oct 2, 2024
6fe780b
Delete unused source file
omaus Oct 4, 2024
329684e
Move validation summary files per fixture
omaus Oct 4, 2024
b789f98
Add tests and ref objects
omaus Oct 4, 2024
3f8efef
Add validation summary JSON files for all test ARCs
omaus Oct 7, 2024
34fe92b
Add script for scripting with integration tests
omaus Oct 7, 2024
9a5fc6b
Update Invenio unit tests with test ARCs + Ref. Obj.s
omaus Oct 7, 2024
ca89b04
Add `runTool` command to tests
omaus Oct 8, 2024
9015592
Update ArcPrototype
omaus Oct 9, 2024
1360d0d
Add class fixtures (prototypic)
omaus Oct 9, 2024
9d4c887
Set public members as immutable members
omaus Oct 9, 2024
739593a
Repeat for every integ. test ARC
omaus Oct 10, 2024
5877eae
Comment out for testing purposes
omaus Oct 15, 2024
f467a28
Uncomment a test
omaus Oct 15, 2024
9ed6061
Uncomment a second test
omaus Oct 15, 2024
3430d82
Uncomment another test
omaus Oct 15, 2024
af8782a
Comment out some of the tests for testing the VM(s)
omaus Oct 15, 2024
f912e67
Singly uncommenting out test
omaus Oct 15, 2024
00f68be
Last test's outcommenting
omaus Oct 15, 2024
e04199b
Re-Commenting out all tests
omaus Oct 15, 2024
3fb00e4
Update CI file for new testing workflow
omaus Oct 16, 2024
f5d6b58
Add `submodules` to CI file
omaus Oct 16, 2024
b9cf9e1
Add xUnit runner JSON to test project
omaus Oct 16, 2024
7198c88
Add verbosity to integration test in CI file
omaus Oct 16, 2024
2c690e0
Add validation report XML files for fixtures
omaus Oct 16, 2024
098cc00
Update test utils
omaus Oct 16, 2024
9f3ccc5
Add new test cases to invenio integ. tests
omaus Oct 16, 2024
72aba15
Workaround critical bug in JUnit file parsing
omaus Oct 16, 2024
364221f
Update tests with testing validation report XML
omaus Oct 16, 2024
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
22 changes: 15 additions & 7 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,18 @@ on:
- '.github/**'

jobs:
build-and-test:
name: "Build and test"
uses: nfdi4plants/actions-workflows/.github/workflows/build-and-test-solution.yml@main
with:
solution: ./arc-validation-packages.sln
checkout-submodules: true
configuration: Release
build-and-test-linux:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x.x
- name: Run integration test
working-directory: ./
run: dotnet test -v:normal
80 changes: 41 additions & 39 deletions arc-validation-packages.sln
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
93 changes: 93 additions & 0 deletions integrationTests_script.fsx
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
}
147 changes: 147 additions & 0 deletions playground.fsx
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
)
3 changes: 2 additions & 1 deletion tests/GitSubmodulesTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
open System
open System.IO
open Xunit
open ValidationPackages.Tests

[<Fact>]
let ``ArcPrototype commit hash is correct`` () =
Assert.Equal(
ReferenceObjects.expected_prototype_commit_hash,
ReferenceObjects.General.expected_prototype_commit_hash,
TestObjects.prototypeCommitHash
)
Loading