diff --git a/src/Tools/AI Test Toolkit/src/AITCommandLineCard.Page.al b/src/Tools/AI Test Toolkit/src/AITCommandLineCard.Page.al index b31b92c1c1..27f58d63eb 100644 --- a/src/Tools/AI Test Toolkit/src/AITCommandLineCard.Page.al +++ b/src/Tools/AI Test Toolkit/src/AITCommandLineCard.Page.al @@ -80,7 +80,7 @@ page 149042 "AIT CommandLine Card" InputDatasetOutStream := TempBlob.CreateOutStream(); InputDatasetOutStream.WriteText(InputDataset); TempBlob.CreateInStream(InputDatasetInStream); - TestInputsManagement.UploadAndImportDataInputsFromJson(InputDatasetFilename, InputDatasetInStream); + TestInputsManagement.UploadAndImportDataInputs(InputDatasetFilename, InputDatasetInStream); end; } } diff --git a/src/Tools/AI Test Toolkit/src/TestSuite/AITALTestSuiteMgt.Codeunit.al b/src/Tools/AI Test Toolkit/src/TestSuite/AITALTestSuiteMgt.Codeunit.al index c184619179..d533d5c52a 100644 --- a/src/Tools/AI Test Toolkit/src/TestSuite/AITALTestSuiteMgt.Codeunit.al +++ b/src/Tools/AI Test Toolkit/src/TestSuite/AITALTestSuiteMgt.Codeunit.al @@ -226,7 +226,7 @@ codeunit 149037 "AIT AL Test Suite Mgt" Error(SameDatasetNameErr, DatasetFileName, StrSubstNo(SourceOfTheDatasetIsAppIdLbl, TestInputGroup."Imported by AppId")); end; - TestInputsManagement.UploadAndImportDataInputsFromJson(DatasetFileName, DatasetInStream, CallerModuleInfo.Id); + TestInputsManagement.UploadAndImportDataInputs(DatasetFileName, DatasetInStream, CallerModuleInfo.Id); end; /// diff --git a/src/Tools/Test Framework/Test Runner/src/DataDrivenTest/DataDrivenTestTool.PageExt.al b/src/Tools/Test Framework/Test Runner/src/DataDrivenTest/DataDrivenTestTool.PageExt.al index 4b5182758a..1b7f0b3654 100644 --- a/src/Tools/Test Framework/Test Runner/src/DataDrivenTest/DataDrivenTestTool.PageExt.al +++ b/src/Tools/Test Framework/Test Runner/src/DataDrivenTest/DataDrivenTestTool.PageExt.al @@ -42,7 +42,7 @@ pageextension 130451 "Data Driven Test Tool" extends "AL Test Tool" var TestInputsManagement: Codeunit "Test Inputs Management"; begin - TestInputsManagement.UploadAndImportDataInputsFromJson(); + TestInputsManagement.UploadAndImportDataInputs(); end; } action(DataInputs) diff --git a/src/Tools/Test Framework/Test Runner/src/DataDrivenTest/DataInputs/TestInputGroups.Page.al b/src/Tools/Test Framework/Test Runner/src/DataDrivenTest/DataInputs/TestInputGroups.Page.al index 1de2bcc5d0..70bcef281d 100644 --- a/src/Tools/Test Framework/Test Runner/src/DataDrivenTest/DataInputs/TestInputGroups.Page.al +++ b/src/Tools/Test Framework/Test Runner/src/DataDrivenTest/DataInputs/TestInputGroups.Page.al @@ -45,8 +45,8 @@ page 130462 "Test Input Groups" { Caption = 'Import data-driven test inputs'; AllowMultipleFiles = true; - ToolTip = 'Import data-driven test inputs from a JSON or JSONL file'; - AllowedFileExtensions = '.jsonl', '.json'; + ToolTip = 'Import data-driven test inputs from a JSON, JSONL or YAML file'; + AllowedFileExtensions = '.jsonl', '.json', '.yaml'; Image = Attach; trigger OnAction(Files: List of [FileUpload]) @@ -55,9 +55,9 @@ page 130462 "Test Input Groups" CurrentFile: FileUpload; FileDataInStream: InStream; begin - foreach CurrentFile in files do begin + foreach CurrentFile in Files do begin CurrentFile.CreateInStream(FileDataInStream, TextEncoding::UTF8); - TestInputsManagement.UploadAndImportDataInputsFromJson(CurrentFile.FileName, FileDataInStream); + TestInputsManagement.UploadAndImportDataInputs(CurrentFile.FileName, FileDataInStream); end; end; } diff --git a/src/Tools/Test Framework/Test Runner/src/DataDrivenTest/DataInputs/TestInputPart.Page.al b/src/Tools/Test Framework/Test Runner/src/DataDrivenTest/DataInputs/TestInputPart.Page.al index d6acc6ea4e..b0a8ff7095 100644 --- a/src/Tools/Test Framework/Test Runner/src/DataDrivenTest/DataInputs/TestInputPart.Page.al +++ b/src/Tools/Test Framework/Test Runner/src/DataDrivenTest/DataInputs/TestInputPart.Page.al @@ -52,15 +52,13 @@ page 130459 "Test Input Part" { Caption = 'Import'; Image = ImportCodes; - ToolTip = 'Import data-driven test inputs from a JSON file'; + ToolTip = 'Import data-driven test inputs from a JSON, JSONL or YAML file'; trigger OnAction() var - TestInputGroup: Record "Test Input Group"; TestInputsManagement: Codeunit "Test Inputs Management"; begin - TestInputGroup.Get(Rec."Test Input Group Code"); - TestInputsManagement.UploadAndImportDataInputsFromJson(TestInputGroup); + TestInputsManagement.UploadAndImportDataInputs(); end; } } diff --git a/src/Tools/Test Framework/Test Runner/src/DataDrivenTest/DataInputs/TestInputsManagement.Codeunit.al b/src/Tools/Test Framework/Test Runner/src/DataDrivenTest/DataInputs/TestInputsManagement.Codeunit.al index 7214f950c1..0b51276ff0 100644 --- a/src/Tools/Test Framework/Test Runner/src/DataDrivenTest/DataInputs/TestInputsManagement.Codeunit.al +++ b/src/Tools/Test Framework/Test Runner/src/DataDrivenTest/DataInputs/TestInputsManagement.Codeunit.al @@ -10,7 +10,6 @@ codeunit 130458 "Test Inputs Management" EventSubscriberInstance = Manual; procedure SelectTestGroupsAndExpandTestLine(var TestMethodLine: Record "Test Method Line") - var TestInputGroup: Record "Test Input Group"; TestInput: Record "Test Input"; @@ -99,21 +98,27 @@ codeunit 130458 "Test Inputs Management" CodeunitTestMethodLine.ModifyAll("Data Input", DataInput.Code); end; - procedure UploadAndImportDataInputsFromJson() + procedure UploadAndImportDataInputs() var - TestInputGroup: Record "Test Input Group"; + TempDummyTestInput: Record "Test Input" temporary; + TestInputInStream: InStream; + FileName: Text; begin - UploadAndImportDataInputsFromJson(TestInputGroup); + TempDummyTestInput."Test Input".CreateInStream(TestInputInStream); + if not UploadIntoStream(ChooseFileLbl, '', '', FileName, TestInputInStream) then + exit; + + UploadAndImportDataInputs(FileName, TestInputInStream); end; - procedure UploadAndImportDataInputsFromJson(FileName: Text; TestInputInStream: InStream) + procedure UploadAndImportDataInputs(FileName: Text; TestInputInStream: InStream) var EmptyGuid: Guid; begin - UploadAndImportDataInputsFromJson(FileName, TestInputInStream, EmptyGuid); + UploadAndImportDataInputs(FileName, TestInputInStream, EmptyGuid); end; - procedure UploadAndImportDataInputsFromJson(FileName: Text; TestInputInStream: InStream; ImportedByAppId: Guid) + procedure UploadAndImportDataInputs(FileName: Text; TestInputInStream: InStream; ImportedByAppId: Guid) var TestInputGroup: Record "Test Input Group"; TestInput: Record "Test Input"; @@ -135,6 +140,12 @@ codeunit 130458 "Test Inputs Management" ParseDataInputsJsonl(TestInputInStream, TestInputGroup); end; + if FileName.EndsWith(YamlFileExtensionTxt) then begin + FileType := YamlFileExtensionTxt; + TestInputInStream.Read(InputText); + ParseDataInputsYaml(InputText, TestInputGroup); + end; + // Log telemetry for the number of lines imported and the file type TestInput.SetRange("Test Input Group Code", TestInputGroup.Code); TelemetryCD.Add('File Type', FileType); @@ -142,18 +153,31 @@ codeunit 130458 "Test Inputs Management" Session.LogMessage('0000NF1', 'Data Driven Test: Test Input Imported', Verbosity::Normal, DataClassification::SystemMetadata, TelemetryScope::All, TelemetryCD); end; +#if not CLEAN26 + [Obsolete('Replaced by UploadAndImportDataInputs.', '26.0')] + procedure UploadAndImportDataInputsFromJson() + begin + UploadAndImportDataInputs(); + end; + + [Obsolete('Replaced by UploadAndImportDataInputs.', '26.0')] procedure UploadAndImportDataInputsFromJson(var TestInputGroup: Record "Test Input Group") - var - TempDummyTestInput: Record "Test Input" temporary; - TestInputInStream: InStream; - FileName: Text; begin - TempDummyTestInput."Test Input".CreateInStream(TestInputInStream); - if not UploadIntoStream(ChooseFileLbl, '', '', FileName, TestInputInStream) then - exit; + UploadAndImportDataInputs() + end; + + [Obsolete('Replaced by UploadAndImportDataInputs.', '26.0')] + procedure UploadAndImportDataInputsFromJson(FileName: Text; TestInputInStream: InStream) + begin + UploadAndImportDataInputs(FileName, TestInputInStream); + end; - UploadAndImportDataInputsFromJson(FileName, TestInputInStream); + [Obsolete('Replaced by UploadAndImportDataInputs.', '26.0')] + procedure UploadAndImportDataInputsFromJson(FileName: Text; TestInputInStream: InStream; ImportedByAppId: Guid) + begin + UploadAndImportDataInputs(FileName, TestInputInStream, ImportedByAppId); end; +#endif procedure ImportDataInputsFromText(var TestInputGroup: Record "Test Input Group"; DataInputText: Text) begin @@ -212,6 +236,29 @@ codeunit 130458 "Test Inputs Management" Error(CouldNotParseJsonlInputErr, JsonLine); end; + local procedure ParseDataInputsYaml(TestData: Text; var TestInputGroup: Record "Test Input Group") + var + DataInputJsonObject: JsonObject; + DataInputJsonToken: JsonToken; + DataInputJsonArray: JsonArray; + begin + if not DataInputJsonObject.ReadFromYaml(TestData) then + Error(CouldNotParseInputErr); + + if not DataInputJsonObject.Get(TestsTok, DataInputJsonToken) then begin + InsertDataInputLine(DataInputJsonObject, TestInputGroup); + exit; + end; + + if DataInputJsonToken.IsArray() then begin + DataInputJsonArray := DataInputJsonToken.AsArray(); + InsertDataInputsFromJsonArray(TestInputGroup, DataInputJsonArray); + exit; + end; + + InsertDataInputLine(DataInputJsonObject, TestInputGroup); + end; + local procedure InsertDataInputsFromJsonArray(var TestInputGroup: Record "Test Input Group"; var DataOnlyTestInputsArray: JsonArray) var TestInputJsonToken: JsonToken; @@ -302,6 +349,7 @@ codeunit 130458 "Test Inputs Management" var DataNameTok: Label 'name', Locked = true; DescriptionTok: Label 'description', Locked = true; + TestsTok: Label 'tests', Locked = true; TestInputTok: Label 'testInput', Locked = true; ChooseFileLbl: Label 'Choose a file to import'; TestInputNameTok: Label 'INPUT-', Locked = true; @@ -310,4 +358,5 @@ codeunit 130458 "Test Inputs Management" LineTypeMustBeCodeunitErr: Label 'Line type must be Codeunit.'; JsonFileExtensionTxt: Label '.json', Locked = true; JsonlFileExtensionTxt: Label '.jsonl', Locked = true; + YamlFileExtensionTxt: Label '.yaml', Locked = true; } \ No newline at end of file