diff --git a/build/projects/Business Foundation/.AL-Go/CompileAppInBcContainer.ps1 b/build/projects/Business Foundation/.AL-Go/CompileAppInBcContainer.ps1
index 790922120e..c5e7ea9ca7 100644
--- a/build/projects/Business Foundation/.AL-Go/CompileAppInBcContainer.ps1
+++ b/build/projects/Business Foundation/.AL-Go/CompileAppInBcContainer.ps1
@@ -3,6 +3,4 @@ Param(
)
$scriptPath = Join-Path $PSScriptRoot "../../../scripts/CompileAppInBcContainer.ps1" -Resolve
-$projectFolder = Join-Path $PSScriptRoot "../../Business Foundation"
-
-. $scriptPath -parameters $parameters -currentProjectFolder $projectFolder
\ No newline at end of file
+. $scriptPath -parameters $parameters
\ No newline at end of file
diff --git a/build/projects/Performance Toolkit/.AL-Go/CompileAppInBcContainer.ps1 b/build/projects/Performance Toolkit/.AL-Go/CompileAppInBcContainer.ps1
index c0e5df90db..c5e7ea9ca7 100644
--- a/build/projects/Performance Toolkit/.AL-Go/CompileAppInBcContainer.ps1
+++ b/build/projects/Performance Toolkit/.AL-Go/CompileAppInBcContainer.ps1
@@ -3,6 +3,4 @@ Param(
)
$scriptPath = Join-Path $PSScriptRoot "../../../scripts/CompileAppInBcContainer.ps1" -Resolve
-$projectFolder = Join-Path $PSScriptRoot "../../Performance Toolkit" -Resolve
-
-. $scriptPath -parameters $parameters -currentProjectFolder $projectFolder
\ No newline at end of file
+. $scriptPath -parameters $parameters
\ No newline at end of file
diff --git a/build/projects/System Application Tests (No Isolation)/.AL-Go/CompileAppInBcContainer.ps1 b/build/projects/System Application Tests (No Isolation)/.AL-Go/CompileAppInBcContainer.ps1
new file mode 100644
index 0000000000..c5e7ea9ca7
--- /dev/null
+++ b/build/projects/System Application Tests (No Isolation)/.AL-Go/CompileAppInBcContainer.ps1
@@ -0,0 +1,6 @@
+Param(
+ [Hashtable] $parameters
+)
+
+$scriptPath = Join-Path $PSScriptRoot "../../../scripts/CompileAppInBcContainer.ps1" -Resolve
+. $scriptPath -parameters $parameters
\ No newline at end of file
diff --git a/build/projects/System Application Tests (No Isolation)/.AL-Go/ImportTestToolkitToBcContainer.ps1 b/build/projects/System Application Tests (No Isolation)/.AL-Go/ImportTestToolkitToBcContainer.ps1
new file mode 100644
index 0000000000..f12f84eb9d
--- /dev/null
+++ b/build/projects/System Application Tests (No Isolation)/.AL-Go/ImportTestToolkitToBcContainer.ps1
@@ -0,0 +1,6 @@
+[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', 'parameters', Justification = 'The parameter is not used, but it''s script needs to match this format')]
+Param(
+ [hashtable] $parameters
+)
+
+Write-Host "Skipping Test Toolkit import"
\ No newline at end of file
diff --git a/build/projects/System Application Tests (No Isolation)/.AL-Go/NewBcContainer.ps1 b/build/projects/System Application Tests (No Isolation)/.AL-Go/NewBcContainer.ps1
new file mode 100644
index 0000000000..2db3e316e7
--- /dev/null
+++ b/build/projects/System Application Tests (No Isolation)/.AL-Go/NewBcContainer.ps1
@@ -0,0 +1,6 @@
+Param(
+ [Hashtable]$parameters
+)
+
+$script = Join-Path $PSScriptRoot "../../../scripts/NewBcContainer.ps1" -Resolve
+. $script -parameters $parameters
\ No newline at end of file
diff --git a/build/projects/System Application Tests (No Isolation)/.AL-Go/RunTestsInBcContainer.ps1 b/build/projects/System Application Tests (No Isolation)/.AL-Go/RunTestsInBcContainer.ps1
new file mode 100644
index 0000000000..6295e6f5b6
--- /dev/null
+++ b/build/projects/System Application Tests (No Isolation)/.AL-Go/RunTestsInBcContainer.ps1
@@ -0,0 +1,6 @@
+Param(
+ [Hashtable]$parameters
+)
+
+$script = Join-Path $PSScriptRoot "../../../scripts/RunTestsInBcContainer.ps1" -Resolve
+. $script -parameters $parameters -DisableTestIsolation
\ No newline at end of file
diff --git a/build/projects/System Application Tests (No Isolation)/.AL-Go/settings.json b/build/projects/System Application Tests (No Isolation)/.AL-Go/settings.json
new file mode 100644
index 0000000000..eb5c37dda5
--- /dev/null
+++ b/build/projects/System Application Tests (No Isolation)/.AL-Go/settings.json
@@ -0,0 +1,7 @@
+{
+ "projectName": "System Application Tests (No Isolation)",
+ "testFolders": [
+ "../../../src/System Application/Test",
+ "../../../src/System Application/Test Library"
+ ]
+}
diff --git a/build/projects/System Application Tests/.AL-Go/CompileAppInBcContainer.ps1 b/build/projects/System Application Tests/.AL-Go/CompileAppInBcContainer.ps1
index 4edf364b08..c5e7ea9ca7 100644
--- a/build/projects/System Application Tests/.AL-Go/CompileAppInBcContainer.ps1
+++ b/build/projects/System Application Tests/.AL-Go/CompileAppInBcContainer.ps1
@@ -3,6 +3,4 @@ Param(
)
$scriptPath = Join-Path $PSScriptRoot "../../../scripts/CompileAppInBcContainer.ps1" -Resolve
-$projectFolder = Join-Path $PSScriptRoot "../../System Application Tests"
-
-. $scriptPath -parameters $parameters -currentProjectFolder $projectFolder
\ No newline at end of file
+. $scriptPath -parameters $parameters
\ No newline at end of file
diff --git a/build/scripts/RunTestsInBcContainer.ps1 b/build/scripts/RunTestsInBcContainer.ps1
index 7039c88d77..92ef4c8c4b 100644
--- a/build/scripts/RunTestsInBcContainer.ps1
+++ b/build/scripts/RunTestsInBcContainer.ps1
@@ -1,5 +1,6 @@
Param(
- [Hashtable]$parameters
+ [Hashtable] $parameters,
+ [switch] $DisableTestIsolation
)
Import-Module $PSScriptRoot\EnlistmentHelperFunctions.psm1
@@ -18,7 +19,45 @@ function Get-DisabledTests
return @($disabledTests)
}
-$disabledTests = Get-DisabledTests
+function Get-TestsInGroup {
+ param(
+ [Parameter(Mandatory = $true)]
+ [string] $groupName
+ )
+
+ $baseFolder = Get-BaseFolder
+
+ $groupFiles = Get-ChildItem -Path $baseFolder -Filter 'TestGroups.json' -Recurse -File
+
+ $testsInGroup = @()
+ foreach($groupFile in $groupFiles)
+ {
+ $testsInGroup += Get-Content -Raw -Path $groupFile.FullName | ConvertFrom-Json | Where-Object { $_.group -eq $groupName }
+ }
+
+ return $testsInGroup
+}
+
+$disabledTests = @(Get-DisabledTests)
+$noIsolationTests = Get-TestsInGroup -groupName "No Test Isolation"
+
+if ($DisableTestIsolation)
+{
+ $parameters["testRunnerCodeunitId"] = "130451" # Test Runner with disabled test isolation
+
+ # When test isolation is disabled, only tests from the "No Test Isolation" group should be run
+ $parameters["testCodeunitRange"] = @($noIsolationTests | ForEach-Object { $_.codeunitId }) -join "|"
+}
+else { # Test isolation is enabled
+ # Manually disable the test codeunits, as they need to be run without test isolation
+ $noIsolationTests | ForEach-Object {
+ $disabledTests += @{
+ "codeunitId" = $_.codeunitId
+ "codeunitName" = $_.codeunitName
+ "method" = "*"
+ }
+ }
+}
if ($disabledTests)
{
diff --git a/src/System Application/App/Retention Policy/app.json b/src/System Application/App/Retention Policy/app.json
index 50314ff6d2..2a1e4b38a3 100644
--- a/src/System Application/App/Retention Policy/app.json
+++ b/src/System Application/App/Retention Policy/app.json
@@ -74,8 +74,8 @@
],
"internalsVisibleTo": [
{
- "id": "489a0bcb-0619-4bd1-b626-9f30dbe8af4d",
- "name": "Retention Policy Test",
+ "id": "33003b8a-f6d8-4efe-af22-1a8cb8fbacbe",
+ "name": "Retention Policy Test Library",
"publisher": "Microsoft"
}
],
diff --git a/src/System Application/App/Retention Policy/src/Apply Retention Policy/ApplyRetentionPolicyImpl.Codeunit.al b/src/System Application/App/Retention Policy/src/Apply Retention Policy/ApplyRetentionPolicyImpl.Codeunit.al
index 1366ad4253..9f25194213 100644
--- a/src/System Application/App/Retention Policy/src/Apply Retention Policy/ApplyRetentionPolicyImpl.Codeunit.al
+++ b/src/System Application/App/Retention Policy/src/Apply Retention Policy/ApplyRetentionPolicyImpl.Codeunit.al
@@ -162,9 +162,9 @@ codeunit 3904 "Apply Retention Policy Impl."
RetentionPolicyLog.LogInfo(LogCategory(), StrSubstNo(StartRetentionPolicyRecordCountLbl, RetentionPolicySetup."Table Id", RetentionPolicySetup."Table Caption"));
if GetExpiredRecords(RetentionPolicySetup, RecordRef, ExpiredRecordExpirationDate) then begin
- ExpiredRecordCount := Count(RecordRef);
+ ExpiredRecordCount := this.Count(RecordRef);
RecordRef.Reset();
- TotalRecordCount := Count(RecordRef);
+ TotalRecordCount := this.Count(RecordRef);
end;
RetentionPolicyLog.LogInfo(LogCategory(), StrSubstNo(EndRetentionPolicyRecordCountLbl, RetentionPolicySetup."Table Id", RetentionPolicySetup."Table Caption"));
RetentionPolicyLog.LogInfo(LogCategory(), StrSubstNo(NumberOfExpiredRecordsLbl, ExpiredRecordCount, TotalRecordCount, RetentionPolicySetup."Table Id", RetentionPolicySetup."Table Caption"));
@@ -226,10 +226,10 @@ codeunit 3904 "Apply Retention Policy Impl."
RecordCountBefore: Integer;
RecordCountAfter: Integer;
begin
- RecordCountBefore := Count(RecordRef);
RecordRefDuplicate := RecordRef.Duplicate();
FillTempRetenPolDeletingParamTable(TempRetenPolDeletingParam, RecordRef);
+ RecordCountBefore := TempRetenPolDeletingParam."Record Count Before Delete";
RetenPolDeleting := RetenPolAllowedTables.GetRetenPolDeleting(RecordRef.Number);
RetenPolDeleting.DeleteRecords(RecordRef, TempRetenPolDeletingParam);
@@ -249,7 +249,7 @@ codeunit 3904 "Apply Retention Policy Impl."
RetenPolicyTelemetryImpl.SendTelemetryOnRecordsDeleted(RecordRefDuplicate.Number, RecordRefDuplicate.Name, NumberOfRecordsDeleted, IsUserInvokedRun);
if not TempRetenPolDeletingParam."Skip Event Rec. Limit Exceeded" then
- RaiseRecordLimitExceededEvent(RecordRefDuplicate);
+ RaiseRecordLimitExceededEvent(RecordRefDuplicate, RecordCountAfter);
end;
local procedure CheckAndContinueWithRerun(var RetentionPolicySetup: Record "Retention Policy Setup")
@@ -265,15 +265,16 @@ codeunit 3904 "Apply Retention Policy Impl."
local procedure FillTempRetenPolDeletingParamTable(var TempRetenPolDeletingParam: Record "Reten. Pol. Deleting Param" temporary; var RecordRef: RecordRef)
begin
+ TempRetenPolDeletingParam."Record Count Before Delete" := this.Count(RecordRef);
TempRetenPolDeletingParam."Indirect Permission Required" := VerifyIndirectDeletePermission(RecordRef.Number);
TempRetenPolDeletingParam."Skip Event Indirect Perm. Req." := not TempRetenPolDeletingParam."Indirect Permission Required";
TempRetenPolDeletingParam."Max. Number of Rec. to Delete" := MaxNumberOfRecordsToDelete() - TotalNumberOfRecordsDeleted;
- TempRetenPolDeletingParam."Skip Event Rec. Limit Exceeded" := TempRetenPolDeletingParam."Max. Number of Rec. to Delete" > Count(RecordRef);
+ TempRetenPolDeletingParam."Skip Event Rec. Limit Exceeded" := TempRetenPolDeletingParam."Max. Number of Rec. to Delete" > TempRetenPolDeletingParam."Record Count Before Delete";
TempRetenPolDeletingParam."Total Max. Nr. of Rec. to Del." := MaxNumberOfRecordsToDelete();
TempRetenPolDeletingParam."User Invoked Run" := IsUserInvokedRun;
end;
- local procedure RaiseRecordLimitExceededEvent(var RecordRefDuplicate: RecordRef)
+ local procedure RaiseRecordLimitExceededEvent(var RecordRefDuplicate: RecordRef; RecordCountAfter: Integer)
var
RetentionPolicyLog: Codeunit "Retention Policy Log";
ApplyRetentionPolicyFacade: Codeunit "Apply Retention Policy";
@@ -281,7 +282,7 @@ codeunit 3904 "Apply Retention Policy Impl."
begin
EndCurrentRun := true;
RetentionPolicyLog.LogWarning(LogCategory(), EndCurrentRunLbl);
- ApplyRetentionPolicyFacade.OnApplyRetentionPolicyRecordLimitExceeded(RecordRefDuplicate.Number, Count(RecordRefDuplicate), ApplyAllRetentionPolicies, IsUserInvokedRun, Handled);
+ ApplyRetentionPolicyFacade.OnApplyRetentionPolicyRecordLimitExceeded(RecordRefDuplicate.Number, RecordCountAfter, ApplyAllRetentionPolicies, IsUserInvokedRun, Handled);
if IsUserInvokedRun and (not Handled) and GuiAllowed() then begin
Commit();
if Confirm(ConfirmRerunMsg, true, MaxNumberOfRecordsToDelete()) then
@@ -431,6 +432,11 @@ codeunit 3904 "Apply Retention Policy Impl."
exit(10000)
end;
+ internal procedure NumberOfRecordsToDeleteBuffer(): Integer
+ begin
+ exit(0)
+ end;
+
local procedure Count(RecordRef: RecordRef): Integer;
begin
if RecordRef.ReadPermission() then
diff --git a/src/System Application/App/Retention Policy/src/Apply Retention Policy/RetenPolDeleteImpl.Codeunit.al b/src/System Application/App/Retention Policy/src/Apply Retention Policy/RetenPolDeleteImpl.Codeunit.al
index 7dda60a1e3..8681eb43a8 100644
--- a/src/System Application/App/Retention Policy/src/Apply Retention Policy/RetenPolDeleteImpl.Codeunit.al
+++ b/src/System Application/App/Retention Policy/src/Apply Retention Policy/RetenPolDeleteImpl.Codeunit.al
@@ -14,6 +14,8 @@ codeunit 3916 "Reten. Pol. Delete. Impl." implements "Reten. Pol. Deleting"
InherentPermissions = X;
var
+ TooManyRecordsToDeleteLbl: Label 'Reached the maximum number of records that can be deleted at the same time. The maximum number allowed is %1.', Comment = '%1 = integer';
+ LimitNumberOfRecordsLbl: Label 'Limited the number of records to delete for table %1, %2 to %3 records. The maximum number of records that can be deleted at the same time is %4, and %5 records were previously deleted in one or more tables.', Comment = '%1 = a id of a table (integer), %2 = the caption of the table, %3, %4, %5 = integer';
MissingReadPermissionLbl: Label 'Unable to check number of records to delete due to missing read permission for table %1, %2', Comment = '%1 = table number, %2 = table caption';
MaxNumberofRecToDeleteNegLbl: Label 'Max. Number of Rec. To Delete is less than 0.';
@@ -31,7 +33,13 @@ codeunit 3916 "Reten. Pol. Delete. Impl." implements "Reten. Pol. Deleting"
RecordReference.Initialize(RecordRef, RecordReferenceIndirectPermission);
if not RecordReferenceIndirectPermission.ReadPermission(RecordRef) then
- RetentionPolicyLog.LogWarning(LogCategory(), StrSubstNo(MissingReadPermissionLbl, RecordRef.Number, RecordRef.Caption));
+ RetentionPolicyLog.LogWarning(LogCategory(), StrSubstNo(MissingReadPermissionLbl, RecordRef.Number, RecordRef.Caption))
+ else
+ if not RecordReferenceIndirectPermission.IsEmpty(RecordRef) then
+ if (RetenPolDeletingParam."Record Count Before Delete" > (RetenPolDeletingParam."Max. Number of Rec. To Delete" + NumberOfRecordsToDeleteBuffer())) then begin
+ RetentionPolicyLog.LogWarning(LogCategory(), StrSubstNo(TooManyRecordsToDeleteLbl, RetenPolDeletingParam."Total Max. Nr. of Rec. to Del."));
+ LimitRecordsToBeDeleted(RecordRef, RecordReferenceIndirectPermission, RetenPolDeletingParam."Skip Event Rec. Limit Exceeded", RetenPolDeletingParam."Max. Number of Rec. To Delete", RetenPolDeletingParam."Total Max. Nr. of Rec. to Del.");
+ end;
if not RetenPolDeletingParam."Indirect Permission Required" then
RecordReferenceIndirectPermission.DeleteAll(RecordRef, true);
@@ -39,6 +47,40 @@ codeunit 3916 "Reten. Pol. Delete. Impl." implements "Reten. Pol. Deleting"
RecordRef.Close();
end;
+ local procedure LimitRecordsToBeDeleted(var RecordRef: RecordRef; RecordReferenceIndirectPermission: Interface "Record Reference"; var SkipOnApplyRetentionPolicyRecordLimitExceeded: Boolean; MaxNumberOfRecordsToDelete: Integer; TotalMaxNumberOfRecordsToDelete: Integer)
+ var
+ RetentionPolicyLog: Codeunit "Retention Policy Log";
+ begin
+ RetentionPolicyLog.LogInfo(LogCategory(), StrSubstNo(LimitNumberOfRecordsLbl, RecordRef.Number, RecordRef.Caption, MaxNumberOfRecordsToDelete, TotalMaxNumberOfRecordsToDelete, TotalMaxNumberOfRecordsToDelete - MaxNumberOfRecordsToDelete));
+ FilterRecordsToLimit(RecordRef, RecordReferenceIndirectPermission, MaxNumberOfRecordsToDelete);
+ SkipOnApplyRetentionPolicyRecordLimitExceeded := false;
+ end;
+
+ local procedure FilterRecordsToLimit(var RecordRef: RecordRef; RecordReferenceIndirectPermission: Interface "Record Reference"; StartRecordIndex: Integer)
+ var
+ FieldRef: FieldRef;
+ KeyRef: KeyRef;
+ i: integer;
+ begin
+ RecordReferenceIndirectPermission.FindSet(RecordRef);
+ RecordReferenceIndirectPermission.Next(RecordRef, StartRecordIndex);
+
+ RecordRef.FilterGroup := 15;
+ KeyRef := RecordRef.KeyIndex(RecordRef.CurrentKeyIndex());
+ for i := 1 to KeyRef.FieldCount() do begin
+ FieldRef := KeyRef.FieldIndex(i);
+ FieldRef.SetFilter('<%1', FieldRef.Value);
+ end;
+ RecordRef.FilterGroup := 0;
+ end;
+
+ local procedure NumberOfRecordsToDeleteBuffer(): Integer
+ var
+ ApplyRetentionPolicyImpl: Codeunit "Apply Retention Policy Impl.";
+ begin
+ exit(ApplyRetentionPolicyImpl.NumberOfRecordsToDeleteBuffer())
+ end;
+
local procedure LogCategory(): Enum "Retention Policy Log Category"
var
RetentionPolicyLogCategory: Enum "Retention Policy Log Category";
diff --git a/src/System Application/App/Retention Policy/src/Apply Retention Policy/RetenPolDeletingParam.Table.al b/src/System Application/App/Retention Policy/src/Apply Retention Policy/RetenPolDeletingParam.Table.al
index c80302101b..1ff1b0f3aa 100644
--- a/src/System Application/App/Retention Policy/src/Apply Retention Policy/RetenPolDeletingParam.Table.al
+++ b/src/System Application/App/Retention Policy/src/Apply Retention Policy/RetenPolDeletingParam.Table.al
@@ -84,6 +84,14 @@ table 3907 "Reten. Pol. Deleting Param"
{
DataClassification = SystemMetadata;
}
+ ///
+ /// The number of records in the table before the deletion.
+ /// The count is calculated once before passing this table to the deletion implementation and is used to limit the number of records to be deleted as well as record the number of records actually deleted.
+ ///
+ field(8; "Record Count Before Delete"; Integer)
+ {
+ DataClassification = SystemMetadata;
+ }
}
keys
diff --git a/src/System Application/App/Retention Policy/src/Apply Retention Policy/RetenPolFilteringImpl.Codeunit.al b/src/System Application/App/Retention Policy/src/Apply Retention Policy/RetenPolFilteringImpl.Codeunit.al
index 9900b45f37..b0525a7cde 100644
--- a/src/System Application/App/Retention Policy/src/Apply Retention Policy/RetenPolFilteringImpl.Codeunit.al
+++ b/src/System Application/App/Retention Policy/src/Apply Retention Policy/RetenPolFilteringImpl.Codeunit.al
@@ -275,13 +275,18 @@ codeunit 3915 "Reten. Pol. Filtering Impl." implements "Reten. Pol. Filtering"
// Keep track of the result set of expired records in a hash set (in addition to marks on the RecordRef) for performance reasons (i. e. to have efficient Count() calls).
local procedure SetSelectedSystemId(SelectedSystemId: Guid; IsSelected: Boolean; var SelectedSystemIds: Dictionary of [Guid, Boolean])
+ var
+ ContainsKey: Boolean;
begin
- if IsSelected then
- if not SelectedSystemIds.ContainsKey(SelectedSystemId) then
- SelectedSystemIds.Add(SelectedSystemId, true)
- else
- if SelectedSystemIds.ContainsKey(SelectedSystemId) then
- SelectedSystemIds.Remove(SelectedSystemId)
+ ContainsKey := SelectedSystemIds.ContainsKey(SelectedSystemId);
+ case true of
+ // Selected, not yet added -> add
+ IsSelected and (not ContainsKey):
+ SelectedSystemIds.Add(SelectedSystemId, true);
+ // Not selected, already added -> remove
+ (not IsSelected) and ContainsKey:
+ SelectedSystemIds.Remove(SelectedSystemId);
+ end;
end;
local procedure SetRetentionPolicyLineTableFilter(TableFilterView: Text; var RecordRef: RecordRef; FilterGroup: Integer);
diff --git a/src/System Application/Test Library/Retention Policy/src/RetentionPolicyTestLibrary.Codeunit.al b/src/System Application/Test Library/Retention Policy/src/RetentionPolicyTestLibrary.Codeunit.al
index e2d9b55d9b..854e76e2d6 100644
--- a/src/System Application/Test Library/Retention Policy/src/RetentionPolicyTestLibrary.Codeunit.al
+++ b/src/System Application/Test Library/Retention Policy/src/RetentionPolicyTestLibrary.Codeunit.al
@@ -10,10 +10,15 @@ using System.DataAdministration;
codeunit 138709 "Retention Policy Test Library"
{
EventSubscriberInstance = Manual;
+ Permissions = tabledata "Retention Policy Log Entry" = r;
var
RecordLimitExceededSubscriberCount: Integer;
+ ///
+ /// Returns how many times the subscriber to the OnApplyRetentionPolicyRecordLimitExceeded event was raised.
+ ///
+ /// Returns how many times the subscriber to the OnApplyRetentionPolicyRecordLimitExceeded event was raised.
procedure GetRecordLimitExceededSubscriberCount(): Integer
begin
exit(RecordLimitExceededSubscriberCount);
@@ -24,4 +29,116 @@ codeunit 138709 "Retention Policy Test Library"
begin
RecordLimitExceededSubscriberCount += 1;
end;
+
+ ///
+ /// Gets the value for maximum number of records to delete in one retention policy run.
+ ///
+ /// The maximum number of records to delete.
+ procedure MaxNumberOfRecordsToDelete(): Integer
+ var
+ ApplyRetentionPolicyImpl: Codeunit "Apply Retention Policy Impl.";
+ begin
+ exit(ApplyRetentionPolicyImpl.MaxNumberOfRecordsToDelete());
+ end;
+
+ ///
+ /// Gets the value of the buffer added to the max number of records to delete.
+ ///
+ /// The maximum number of records to delete buffer.
+ procedure MaxNumberOfRecordsToDeleteBuffer(): Integer
+ var
+ ApplyRetentionPolicyImpl: Codeunit "Apply Retention Policy Impl.";
+ begin
+ exit(ApplyRetentionPolicyImpl.NumberOfRecordsToDeleteBuffer());
+ end;
+
+ ///
+ /// Gets the table ID for the Retention Policy Log Entry.
+ ///
+ /// The table ID for the Retention Policy Log Entry.
+ procedure RetentionPolicyLogEntryTableId(): Integer
+ begin
+ exit(Database::"Retention Policy Log Entry")
+ end;
+
+ ///
+ /// Gets the field number for the SystemCreatedAt field in the Retention Policy Log Entry table.
+ ///
+ /// The field number for the SystemCreatedAt field.
+ procedure RetentionPolicyLogEntrySystemCreatedAtFieldNo(): Integer
+ var
+ RetentionPolicyLogEntry: Record "Retention Policy Log Entry";
+ begin
+ exit(RetentionPolicyLogEntry.FieldNo(SystemCreatedAt))
+ end;
+
+ ///
+ /// Gets the entry number of the last record in the Retention Policy Log Entry table.
+ ///
+ /// The entry number of the last record.
+ procedure RetenionPolicyLogLastEntryNo(): Integer
+ var
+ RetentionPolicyLogEntry: Record "Retention Policy Log Entry";
+ begin
+ if RetentionPolicyLogEntry.FindLast() then;
+ exit(RetentionPolicyLogEntry."Entry No.");
+ end;
+
+ ///
+ /// Gets the field values of a specific Retention Policy Log Entry.
+ ///
+ /// The entry number of the log entry.
+ /// A dictionary containing the field values of the log entry.
+ procedure GetRetentionPolicyLogEntry(EntryNo: Integer) FieldValues: Dictionary of [Text, Text]
+ var
+ RetentionPolicyLogEntry: Record "Retention Policy Log Entry";
+ begin
+ SelectLatestVersion(Database::"Retention Policy Log Entry");
+ RetentionPolicyLogEntry.Get(EntryNo);
+ FieldValues.Add('MessageType', Format(RetentionPolicyLogEntry."Message Type"));
+ FieldValues.Add('Category', Format(RetentionPolicyLogEntry.Category));
+ FieldValues.Add('Message', RetentionPolicyLogEntry.Message);
+ end;
+
+ ///
+ /// Raises the OnRefreshAllowedTables event in the Reten. Pol. Allowed Tables codeunit.
+ ///
+ procedure RaiseOnRefreshAllowedTables()
+ var
+ RetenPolAllowedTables: Codeunit "Reten. Pol. Allowed Tables";
+ begin
+ RetenPolAllowedTables.OnRefreshAllowedTables();
+ end;
+
+ ///
+ /// Runs the Apply Retention Policy Implementation codeunit.
+ ///
+ /// The Retention Policy Setup record.
+ /// True if the codeunit runs successfully; otherwise, false.
+ procedure RunApplyRetentionPolicyImpl(var RetentionPolicySetup: Record "Retention Policy Setup"): Boolean
+ begin
+ exit(Codeunit.Run(Codeunit::"Apply Retention Policy Impl.", RetentionPolicySetup))
+ end;
+
+ ///
+ /// Sets the Locked field on a Retention Policy Setup Line record.
+ ///
+ /// The Retention Policy Setup Line record.
+ /// The value to set for the Locked field.
+ procedure SetLockedFieldOnRetentionPolicySetupLine(var RetentionPolicySetupLine: Record "Retention Policy Setup Line"; Locked: Boolean)
+ begin
+ RetentionPolicySetupLine.Locked := Locked;
+ end;
+
+ ///
+ /// Sets a range filter on the Locked field of a Retention Policy Setup Line record.
+ ///
+ /// The Retention Policy Setup Line record.
+ /// The value to set for the range filter on the Locked field.
+ procedure SetRangeFilterOnLockedFieldOnRetentionPolicySetupLine(var RetentionPolicySetupLine: Record "Retention Policy Setup Line"; Locked: Boolean)
+ begin
+#pragma warning disable AA0210 // The table Retention Policy Setup Line does not contain a key with the field Locked.
+ RetentionPolicySetupLine.SetRange(Locked, Locked);
+#pragma warning restore AA0210
+ end;
}
\ No newline at end of file
diff --git a/src/System Application/Test/DisabledTests/RetentionPolicyLogTest.json b/src/System Application/Test/DisabledTests/RetentionPolicyLogTest.json
deleted file mode 100644
index a9653c3270..0000000000
--- a/src/System Application/Test/DisabledTests/RetentionPolicyLogTest.json
+++ /dev/null
@@ -1,6 +0,0 @@
-{
- "bug": "488830",
- "codeunitId": 138705,
- "CodeunitName": "Retention Policy Log Test",
- "Method": "*"
-}
diff --git a/src/System Application/Test/DisabledTests/RetentionPolicyTest.json b/src/System Application/Test/DisabledTests/RetentionPolicyTest.json
deleted file mode 100644
index ed705086fc..0000000000
--- a/src/System Application/Test/DisabledTests/RetentionPolicyTest.json
+++ /dev/null
@@ -1,6 +0,0 @@
-{
- "bug": "488830",
- "codeunitId": 138702,
- "CodeunitName": "Retention Policy Test",
- "Method": "*"
-}
\ No newline at end of file
diff --git a/src/System Application/Test/Retention Policy/src/RetenPolAllowedTblTest.Codeunit.al b/src/System Application/Test/Retention Policy/src/RetenPolAllowedTblTest.Codeunit.al
index 69280d8559..6563d67ae1 100644
--- a/src/System Application/Test/Retention Policy/src/RetenPolAllowedTblTest.Codeunit.al
+++ b/src/System Application/Test/Retention Policy/src/RetenPolAllowedTblTest.Codeunit.al
@@ -20,6 +20,7 @@ codeunit 138703 "Reten. Pol. Allowed Tbl. Test"
var
Assert: Codeunit "Library Assert";
PermissionsMock: Codeunit "Permissions Mock";
+ RetentionPolicyTestLibrary: Codeunit "Retention Policy Test Library";
TableIdinFilterNotListLbl: Label 'Table %1 appears in the filter but not in the list', Locked = true;
DatefieldIsWrongLbl: Label 'The datefield number is wrong for table %1', Locked = true;
MandatoryMinRetentionDaysLbl: Label 'The mandatory minimum number of retention days is wrong for table %1', Locked = true;
@@ -75,7 +76,7 @@ codeunit 138703 "Reten. Pol. Allowed Tbl. Test"
// verify
Assert.IsTrue(AllowedTables.Contains(Database::"Retention Policy Test Data"), 'Table Retention Policy Test Data should be allowed');
Assert.IsTrue(AllowedTables.Contains(Database::"Retention Policy Test Data 3"), 'Table Retention Policy Test Data 3 should be allowed');
- Assert.IsTrue(AllowedTables.Contains(Database::"Retention Policy Log Entry"), 'Table Retention Policy Log Entry should be allowed');
+ Assert.IsTrue(AllowedTables.Contains(RetentionPolicyTestLibrary.RetentionPolicyLogEntryTableId()), 'Table Retention Policy Log Entry should be allowed');
Assert.IsFalse(AllowedTables.Contains(Database::"Retention Policy Test Data Two"), 'Table Retention Policy Test Data Two should not be allowed');
Assert.IsFalse(AllowedTables.Contains(17), 'Table G/L Entry should not be allowed');
end;
@@ -95,7 +96,7 @@ codeunit 138703 "Reten. Pol. Allowed Tbl. Test"
RetenPolAllowedTables.RemoveAllowedTable(OldAllowedTables.Get(TableIndex));
// [WHEN] Tables are refreshed
- RetenPolAllowedTables.OnRefreshAllowedTables();
+ RetentionPolicyTestLibrary.RaiseOnRefreshAllowedTables();
// [THEN] The same tables exist
RetenPolAllowedTables.GetAllowedTables(NewAllowedTables);
@@ -104,7 +105,7 @@ codeunit 138703 "Reten. Pol. Allowed Tbl. Test"
Assert.AreEqual(OldAllowedTables.Get(TableIndex), NewAllowedTables.Get(TableIndex), 'Not all allowed tables were refreshed.');
// [THEN] It's possible to refresh the table again, even though entries already exist
- RetenPolAllowedTables.OnRefreshAllowedTables();
+ RetentionPolicyTestLibrary.RaiseOnRefreshAllowedTables();
end;
[Test]
@@ -139,7 +140,6 @@ codeunit 138703 "Reten. Pol. Allowed Tbl. Test"
var
RetentionPolicyTestData: Record "Retention Policy Test Data";
RetentionPolicyTestData3: Record "Retention Policy Test Data 3";
- RetentionPolicyLogEntry: Record "Retention Policy Log Entry";
RetenPolAllowedTables: Codeunit "Reten. Pol. Allowed Tables";
begin
PermissionsMock.Set('Retention Pol. Admin');
@@ -150,7 +150,7 @@ codeunit 138703 "Reten. Pol. Allowed Tbl. Test"
// verify
Assert.AreEqual(RetentionPolicyTestData.FieldNo("Datetime Field"), RetenPolAllowedTables.GetDefaultDateFieldNo(Database::"Retention Policy Test Data"), StrSubsTNo(DatefieldIsWrongLbl, Database::"Retention Policy Test Data"));
Assert.AreEqual(RetentionPolicyTestData3.FieldNo("Date Field"), RetenPolAllowedTables.GetDefaultDateFieldNo(Database::"Retention Policy Test Data 3"), StrSubsTNo(DatefieldIsWrongLbl, Database::"Retention Policy Test Data 3"));
- Assert.AreEqual(RetentionPolicyLogEntry.FieldNo(SystemCreatedAt), RetenPolAllowedTables.GetDefaultDateFieldNo(Database::"Retention Policy Log Entry"), StrSubsTNo(DatefieldIsWrongLbl, Database::"Retention Policy Log Entry"));
+ Assert.AreEqual(RetentionPolicyTestLibrary.RetentionPolicyLogEntrySystemCreatedAtFieldNo(), RetenPolAllowedTables.GetDefaultDateFieldNo(RetentionPolicyTestLibrary.RetentionPolicyLogEntryTableId()), StrSubsTNo(DatefieldIsWrongLbl, RetentionPolicyTestLibrary.RetentionPolicyLogEntryTableId()));
Assert.AreEqual(0, RetenPolAllowedTables.GetDefaultDateFieldNo(17), StrSubsTNo(DatefieldIsWrongLbl, 17));
end;
@@ -167,7 +167,7 @@ codeunit 138703 "Reten. Pol. Allowed Tbl. Test"
// verify
Assert.AreEqual(7, RetenPolAllowedTables.GetMandatoryMinimumRetentionDays(Database::"Retention Policy Test Data"), StrSubsTNo(MandatoryMinRetentionDaysLbl, Database::"Retention Policy Test Data"));
Assert.AreEqual(0, RetenPolAllowedTables.GetMandatoryMinimumRetentionDays(Database::"Retention Policy Test Data 3"), StrSubsTNo(MandatoryMinRetentionDaysLbl, Database::"Retention Policy Test Data 3"));
- Assert.AreEqual(28, RetenPolAllowedTables.GetMandatoryMinimumRetentionDays(Database::"Retention Policy Log Entry"), StrSubsTNo(MandatoryMinRetentionDaysLbl, Database::"Retention Policy Log Entry"));
+ Assert.AreEqual(28, RetenPolAllowedTables.GetMandatoryMinimumRetentionDays(RetentionPolicyTestLibrary.RetentionPolicyLogEntryTableId()), StrSubsTNo(MandatoryMinRetentionDaysLbl, RetentionPolicyTestLibrary.RetentionPolicyLogEntryTableId()));
Assert.AreEqual(0, RetenPolAllowedTables.GetMandatoryMinimumRetentionDays(17), StrSubsTNo(MandatoryMinRetentionDaysLbl, 17));
end;
diff --git a/src/System Application/Test/Retention Policy/src/RetenPolicySetupTest.Codeunit.al b/src/System Application/Test/Retention Policy/src/RetenPolicySetupTest.Codeunit.al
index 31648a27d2..0f7f1a3134 100644
--- a/src/System Application/Test/Retention Policy/src/RetenPolicySetupTest.Codeunit.al
+++ b/src/System Application/Test/Retention Policy/src/RetenPolicySetupTest.Codeunit.al
@@ -19,6 +19,7 @@ codeunit 138701 "Reten. Policy Setup Test"
Assert: Codeunit "Library Assert";
PermissionsMock: Codeunit "Permissions Mock";
LibraryVariableStorage: Codeunit "Library - Variable Storage";
+ RetentionPolicyTestLibrary: Codeunit "Retention Policy Test Library";
MinExpirationDateErr: Label 'The expiration date for this retention policy must be equal to or before %1.', Comment = '%1 = Date';
RetentionPolicySetupLineLockedErr: Label 'The retention policy setup for table %1, %2 has mandatory filters that cannot be modified.', Comment = '%1 = table number, %2 = table caption';
RetenPolSetupRenameErr: Label 'You cannot rename retention policy setup records. Table ID %1. Renamed to %2.', Comment = '%1, %2 = table number';
@@ -356,7 +357,7 @@ codeunit 138701 "Reten. Policy Setup Test"
RetentionPolicySetup."Table Id" := Database::"Retention Policy Test Data";
RetentionPolicySetup.Insert();
RetentionPolicySetupLine."Table ID" := RetentionPolicySetup."Table Id";
- RetentionPolicySetupLine.Locked := true;
+ RetentionPolicyTestLibrary.SetLockedFieldOnRetentionPolicySetupLine(RetentionPolicySetupLine, true);
RetentionPolicySetupLine.Insert();
RetentionPolicySetupLine.CalcFields("Table Caption");
@@ -397,7 +398,7 @@ codeunit 138701 "Reten. Policy Setup Test"
RetentionPolicySetup."Table Id" := Database::"Retention Policy Test Data";
RetentionPolicySetup.Insert();
RetentionPolicySetupLine."Table ID" := RetentionPolicySetup."Table Id";
- RetentionPolicySetupLine.Locked := true;
+ RetentionPolicyTestLibrary.SetLockedFieldOnRetentionPolicySetupLine(RetentionPolicySetupLine, true);
RetentionPolicySetupLine.Insert();
RetentionPolicySetupLine.CalcFields("Table Caption");
ClearLastError();
@@ -424,12 +425,12 @@ codeunit 138701 "Reten. Policy Setup Test"
RetentionPolicySetup."Table Id" := Database::"Retention Policy Test Data";
RetentionPolicySetup.Insert();
RetentionPolicySetupLine."Table ID" := RetentionPolicySetup."Table Id";
- RetentionPolicySetupLine.Locked := true;
+ RetentionPolicyTestLibrary.SetLockedFieldOnRetentionPolicySetupLine(RetentionPolicySetupLine, true);
RetentionPolicySetupLine.Insert();
RetentionPolicySetupLine.CalcFields("Table Caption");
// Exercise
- RetentionPolicySetupLine.Locked := false;
+ RetentionPolicyTestLibrary.SetLockedFieldOnRetentionPolicySetupLine(RetentionPolicySetupLine, false);
asserterror RetentionPolicySetupLine.Modify();
// Verify
@@ -447,7 +448,7 @@ codeunit 138701 "Reten. Policy Setup Test"
RetentionPolicySetup."Table Id" := Database::"Retention Policy Test Data";
RetentionPolicySetup.Insert();
RetentionPolicySetupLine."Table ID" := RetentionPolicySetup."Table Id";
- RetentionPolicySetupLine.Locked := true;
+ RetentionPolicyTestLibrary.SetLockedFieldOnRetentionPolicySetupLine(RetentionPolicySetupLine, true);
RetentionPolicySetupLine.Insert();
// Exercise
@@ -551,9 +552,7 @@ codeunit 138701 "Reten. Policy Setup Test"
RetentionPolicySetup."Table Id" := Database::"Retention Policy Test Data 4";
RetentionPolicySetup.Insert();
RetentionPolicySetupLine.SetRange("Table ID", Database::"Retention Policy Test Data 4");
-#pragma warning disable AA0210 // The table Retention Policy Setup Line does not contain a key with the field Locked.
- RetentionPolicySetupLine.SetRange(Locked, true);
-#pragma warning restore AA0210
+ RetentionPolicyTestLibrary.SetRangeFilterOnLockedFieldOnRetentionPolicySetupLine(RetentionPolicySetupLine, true);
RetentionPolicySetupLine.FindFirst();
// exercise
@@ -585,9 +584,7 @@ codeunit 138701 "Reten. Policy Setup Test"
RetentionPolicySetup."Table Id" := Database::"Retention Policy Test Data 4";
RetentionPolicySetup.Insert();
RetentionPolicySetupLine.SetRange("Table ID", Database::"Retention Policy Test Data 4");
-#pragma warning disable AA0210 // The table Retention Policy Setup Line does not contain a key with the field Locked.
- RetentionPolicySetupLine.SetRange(Locked, true);
-#pragma warning restore AA0210
+ RetentionPolicyTestLibrary.SetRangeFilterOnLockedFieldOnRetentionPolicySetupLine(RetentionPolicySetupLine, true);
RetentionPolicySetupLine.FindFirst();
// exercise
@@ -612,9 +609,7 @@ codeunit 138701 "Reten. Policy Setup Test"
RetentionPolicySetup."Table Id" := Database::"Retention Policy Test Data 4";
RetentionPolicySetup.Insert();
RetentionPolicySetupLine.SetRange("Table ID", Database::"Retention Policy Test Data 4");
-#pragma warning disable AA0210 // The table Retention Policy Setup Line does not contain a key with the field Locked.
- RetentionPolicySetupLine.SetRange(Locked, true);
-#pragma warning restore AA0210
+ RetentionPolicyTestLibrary.SetRangeFilterOnLockedFieldOnRetentionPolicySetupLine(RetentionPolicySetupLine, true);
RetentionPolicySetupLine.FindFirst();
// exercise
diff --git a/src/System Application/Test/Retention Policy/src/RetentionPolicyLogTest.Codeunit.al b/src/System Application/Test/Retention Policy/src/RetentionPolicyLogTest.Codeunit.al
index 72ac5f0068..7b448ce236 100644
--- a/src/System Application/Test/Retention Policy/src/RetentionPolicyLogTest.Codeunit.al
+++ b/src/System Application/Test/Retention Policy/src/RetentionPolicyLogTest.Codeunit.al
@@ -15,11 +15,11 @@ using System.TestLibraries.Security.AccessControl;
codeunit 138705 "Retention Policy Log Test"
{
Subtype = Test;
- Permissions = tabledata "Retention Policy Log Entry" = r;
var
Assert: Codeunit "Library Assert";
PermissionsMock: Codeunit "Permissions Mock";
+ RetentionPolicyTestLibrary: Codeunit "Retention Policy Test Library";
RetentionPolicyLogCategory: Enum "Retention Policy Log Category";
ErrorOccuredDuringApplyErrLbl: Label 'An error occured while applying the retention policy for table %1 %2.\\%3', Comment = '%1 = table number, %2 = table name, %3 = error message';
TestLogMessageLbl: Label 'TestLog %1 Entry No. %2', Locked = true;
@@ -29,139 +29,126 @@ codeunit 138705 "Retention Policy Log Test"
[Test]
procedure TestLogInfo()
var
- RetentionPolicyLogEntry: Record "Retention Policy Log Entry";
RetentionPolicyLog: Codeunit "Retention Policy Log";
LastRetentionPolicyLogEntryNo: BigInteger;
begin
PermissionsMock.Set('Retention Pol. Admin');
//Setup
- if RetentionPolicyLogEntry.FindLast() then;
- LastRetentionPolicyLogEntryNo := RetentionPolicyLogEntry."Entry No.";
+ LastRetentionPolicyLogEntryNo := RetentionPolicyTestLibrary.RetenionPolicyLogLastEntryNo();
//Exercise
- RetentionPolicyLog.LogInfo(RetentionPolicyLogCategory::"Retention Policy - Period", StrSubstNo(TestLogMessageLbl, RetentionPolicyLogEntry."Message Type"::Info, LastRetentionPolicyLogEntryNo + 1)); // runs a background task
+ RetentionPolicyLog.LogInfo(RetentionPolicyLogCategory::"Retention Policy - Period", StrSubstNo(TestLogMessageLbl, enum::"Retention Policy Log Message Type"::Info, LastRetentionPolicyLogEntryNo + 1)); // runs a background task
sleep(50); // need some time for background session
- VerifyLogEntry(LastRetentionPolicyLogEntryNo + 1, RetentionPolicyLogEntry."Message Type"::Info, RetentionPolicyLogCategory::"Retention Policy - Period", StrSubstNo(TestLogMessageLbl, RetentionPolicyLogEntry."Message Type"::Info, LastRetentionPolicyLogEntryNo + 1));
+ VerifyLogEntry(LastRetentionPolicyLogEntryNo + 1, enum::"Retention Policy Log Message Type"::Info, RetentionPolicyLogCategory::"Retention Policy - Period", StrSubstNo(TestLogMessageLbl, enum::"Retention Policy Log Message Type"::Info, LastRetentionPolicyLogEntryNo + 1));
// verify
asserterror
error('An error to ensure rollback');
- VerifyLogEntry(LastRetentionPolicyLogEntryNo + 1, RetentionPolicyLogEntry."Message Type"::Info, RetentionPolicyLogCategory::"Retention Policy - Period", StrSubstNo(TestLogMessageLbl, RetentionPolicyLogEntry."Message Type"::Info, LastRetentionPolicyLogEntryNo + 1));
+ VerifyLogEntry(LastRetentionPolicyLogEntryNo + 1, enum::"Retention Policy Log Message Type"::Info, RetentionPolicyLogCategory::"Retention Policy - Period", StrSubstNo(TestLogMessageLbl, enum::"Retention Policy Log Message Type"::Info, LastRetentionPolicyLogEntryNo + 1));
end;
[Test]
procedure TestLogWarning()
var
- RetentionPolicyLogEntry: Record "Retention Policy Log Entry";
RetentionPolicyLog: Codeunit "Retention Policy Log";
LastRetentionPolicyLogEntryNo: BigInteger;
begin
PermissionsMock.Set('Retention Pol. Admin');
//Setup
- if RetentionPolicyLogEntry.FindLast() then;
- LastRetentionPolicyLogEntryNo := RetentionPolicyLogEntry."Entry No.";
+ LastRetentionPolicyLogEntryNo := RetentionPolicyTestLibrary.RetenionPolicyLogLastEntryNo();
//Exercise
- RetentionPolicyLog.LogWarning(RetentionPolicyLogCategory::"Retention Policy - Period", StrSubstNo(TestLogMessageLbl, RetentionPolicyLogEntry."Message Type"::Warning, LastRetentionPolicyLogEntryNo + 1)); // runs a background task
+ RetentionPolicyLog.LogWarning(RetentionPolicyLogCategory::"Retention Policy - Period", StrSubstNo(TestLogMessageLbl, enum::"Retention Policy Log Message Type"::Warning, LastRetentionPolicyLogEntryNo + 1)); // runs a background task
sleep(50); // need some time for background session
- VerifyLogEntry(LastRetentionPolicyLogEntryNo + 1, RetentionPolicyLogEntry."Message Type"::Warning, RetentionPolicyLogCategory::"Retention Policy - Period", StrSubstNo(TestLogMessageLbl, RetentionPolicyLogEntry."Message Type"::Warning, LastRetentionPolicyLogEntryNo + 1));
+ VerifyLogEntry(LastRetentionPolicyLogEntryNo + 1, enum::"Retention Policy Log Message Type"::Warning, RetentionPolicyLogCategory::"Retention Policy - Period", StrSubstNo(TestLogMessageLbl, enum::"Retention Policy Log Message Type"::Warning, LastRetentionPolicyLogEntryNo + 1));
// verify
asserterror
error('An error to ensure rollback');
- VerifyLogEntry(LastRetentionPolicyLogEntryNo + 1, RetentionPolicyLogEntry."Message Type"::Warning, RetentionPolicyLogCategory::"Retention Policy - Period", StrSubstNo(TestLogMessageLbl, RetentionPolicyLogEntry."Message Type"::Warning, LastRetentionPolicyLogEntryNo + 1));
+ VerifyLogEntry(LastRetentionPolicyLogEntryNo + 1, enum::"Retention Policy Log Message Type"::Warning, RetentionPolicyLogCategory::"Retention Policy - Period", StrSubstNo(TestLogMessageLbl, enum::"Retention Policy Log Message Type"::Warning, LastRetentionPolicyLogEntryNo + 1));
end;
[Test]
procedure TestLogError()
var
- RetentionPolicyLogEntry: Record "Retention Policy Log Entry";
RetentionPolicyLog: Codeunit "Retention Policy Log";
LastRetentionPolicyLogEntryNo: BigInteger;
begin
PermissionsMock.Set('Retention Pol. Admin');
//Setup
- if RetentionPolicyLogEntry.FindLast() then;
- LastRetentionPolicyLogEntryNo := RetentionPolicyLogEntry."Entry No.";
+ LastRetentionPolicyLogEntryNo := RetentionPolicyTestLibrary.RetenionPolicyLogLastEntryNo();
//Exercise
asserterror
- RetentionPolicyLog.LogError(RetentionPolicyLogCategory::"Retention Policy - Period", StrSubstNo(TestLogMessageLbl, RetentionPolicyLogEntry."Message Type"::Error, LastRetentionPolicyLogEntryNo + 1)); // runs a background task
+ RetentionPolicyLog.LogError(RetentionPolicyLogCategory::"Retention Policy - Period", StrSubstNo(TestLogMessageLbl, enum::"Retention Policy Log Message Type"::Error, LastRetentionPolicyLogEntryNo + 1)); // runs a background task
// Verify
sleep(50); // need some time for background session
- VerifyLogEntry(LastRetentionPolicyLogEntryNo + 1, RetentionPolicyLogEntry."Message Type"::Error, RetentionPolicyLogCategory::"Retention Policy - Period", StrSubstNo(TestLogMessageLbl, RetentionPolicyLogEntry."Message Type"::Error, LastRetentionPolicyLogEntryNo + 1));
+ VerifyLogEntry(LastRetentionPolicyLogEntryNo + 1, enum::"Retention Policy Log Message Type"::Error, RetentionPolicyLogCategory::"Retention Policy - Period", StrSubstNo(TestLogMessageLbl, enum::"Retention Policy Log Message Type"::Error, LastRetentionPolicyLogEntryNo + 1));
end;
[Test]
procedure TestLogErrorWithDisplay()
var
- RetentionPolicyLogEntry: Record "Retention Policy Log Entry";
RetentionPolicyLog: Codeunit "Retention Policy Log";
LastRetentionPolicyLogEntryNo: BigInteger;
begin
PermissionsMock.Set('Retention Pol. Admin');
//Setup
- if RetentionPolicyLogEntry.FindLast() then;
- LastRetentionPolicyLogEntryNo := RetentionPolicyLogEntry."Entry No.";
+ LastRetentionPolicyLogEntryNo := RetentionPolicyTestLibrary.RetenionPolicyLogLastEntryNo();
//Exercise
asserterror
- RetentionPolicyLog.LogError(RetentionPolicyLogCategory::"Retention Policy - Period", StrSubstNo(TestLogMessageLbl, RetentionPolicyLogEntry."Message Type"::Error, LastRetentionPolicyLogEntryNo + 1), true); // runs a background task
+ RetentionPolicyLog.LogError(RetentionPolicyLogCategory::"Retention Policy - Period", StrSubstNo(TestLogMessageLbl, enum::"Retention Policy Log Message Type"::Error, LastRetentionPolicyLogEntryNo + 1), true); // runs a background task
// Verify
sleep(50); // need some time for background session
- VerifyLogEntry(LastRetentionPolicyLogEntryNo + 1, RetentionPolicyLogEntry."Message Type"::Error, RetentionPolicyLogCategory::"Retention Policy - Period", StrSubstNo(TestLogMessageLbl, RetentionPolicyLogEntry."Message Type"::Error, LastRetentionPolicyLogEntryNo + 1));
+ VerifyLogEntry(LastRetentionPolicyLogEntryNo + 1, enum::"Retention Policy Log Message Type"::Error, RetentionPolicyLogCategory::"Retention Policy - Period", StrSubstNo(TestLogMessageLbl, enum::"Retention Policy Log Message Type"::Error, LastRetentionPolicyLogEntryNo + 1));
end;
[Test]
procedure TestLogErrorWithoutDisplay()
var
- RetentionPolicyLogEntry: Record "Retention Policy Log Entry";
RetentionPolicyLog: Codeunit "Retention Policy Log";
LastRetentionPolicyLogEntryNo: BigInteger;
begin
PermissionsMock.Set('Retention Pol. Admin');
//Setup
- if RetentionPolicyLogEntry.FindLast() then;
- LastRetentionPolicyLogEntryNo := RetentionPolicyLogEntry."Entry No.";
+ LastRetentionPolicyLogEntryNo := RetentionPolicyTestLibrary.RetenionPolicyLogLastEntryNo();
//Exercise
- RetentionPolicyLog.LogError(RetentionPolicyLogCategory::"Retention Policy - Period", StrSubstNo(TestLogMessageLbl, RetentionPolicyLogEntry."Message Type"::Error, LastRetentionPolicyLogEntryNo + 1), false); // runs a background task
+ RetentionPolicyLog.LogError(RetentionPolicyLogCategory::"Retention Policy - Period", StrSubstNo(TestLogMessageLbl, enum::"Retention Policy Log Message Type"::Error, LastRetentionPolicyLogEntryNo + 1), false); // runs a background task
// Verify
sleep(50); // need some time for background session
- VerifyLogEntry(LastRetentionPolicyLogEntryNo + 1, RetentionPolicyLogEntry."Message Type"::Error, RetentionPolicyLogCategory::"Retention Policy - Period", StrSubstNo(TestLogMessageLbl, RetentionPolicyLogEntry."Message Type"::Error, LastRetentionPolicyLogEntryNo + 1));
+ VerifyLogEntry(LastRetentionPolicyLogEntryNo + 1, enum::"Retention Policy Log Message Type"::Error, RetentionPolicyLogCategory::"Retention Policy - Period", StrSubstNo(TestLogMessageLbl, enum::"Retention Policy Log Message Type"::Error, LastRetentionPolicyLogEntryNo + 1));
end;
[Test]
procedure TestApplyRetentionPolicyRecordMustBeTemp()
var
RetentionPolicySetup: Record "Retention Policy Setup";
- RetentionPolicyLogEntry: Record "Retention Policy Log Entry";
RetentionPolicyLog: Codeunit "Retention Policy Log";
LastRetentionPolicyLogEntryNo: BigInteger;
begin
PermissionsMock.Set('Retention Pol. Admin');
// Setup
- if RetentionPolicyLogEntry.FindLast() then;
- LastRetentionPolicyLogEntryNo := RetentionPolicyLogEntry."Entry No.";
+ LastRetentionPolicyLogEntryNo := RetentionPolicyTestLibrary.RetenionPolicyLogLastEntryNo();
RetentionPolicySetup.SystemId := CreateGuid();
RetentionPolicySetup."Table Id" := Database::"Retention Policy Test Data";
RetentionPolicySetup.CalcFields("Table Name");
ClearLastError();
// Exercise
- if not Codeunit.Run(Codeunit::"Apply Retention Policy Impl.", RetentionPolicySetup) then
+ if not RetentionPolicyTestLibrary.RunApplyRetentionPolicyImpl(RetentionPolicySetup) then
RetentionPolicyLog.LogError(RetentionPolicyLogCategory::"Retention Policy - Apply", StrSubstNo(ErrorOccuredDuringApplyErrLbl, RetentionPolicySetup."Table Id", RetentionPolicySetup."Table Name", GetLastErrorText()), false);
// Verify
sleep(50);
Assert.ExpectedError(RetentionPolicySetupRecordNotTempErr);
- RetentionPolicyLogEntry.FindLast();
- VerifyLogEntry(LastRetentionPolicyLogEntryNo + 1, RetentionPolicyLogEntry."Message Type"::Error, RetentionPolicyLogCategory::"Retention Policy - Apply",
+ VerifyLogEntry(LastRetentionPolicyLogEntryNo + 1, enum::"Retention Policy Log Message Type"::Error, RetentionPolicyLogCategory::"Retention Policy - Apply",
StrSubstNo(ErrorOccuredDuringApplyErrLbl, RetentionPolicySetup."Table Id", RetentionPolicySetup."Table Name", RetentionPolicySetupRecordNotTempErr));
end;
@@ -169,39 +156,35 @@ codeunit 138705 "Retention Policy Log Test"
procedure TestApplyRetentionPolicyRecordMustExist()
var
TempRetentionPolicySetup: Record "Retention Policy Setup" temporary;
- RetentionPolicyLogEntry: Record "Retention Policy Log Entry";
RetentionPolicyLog: Codeunit "Retention Policy Log";
LastRetentionPolicyLogEntryNo: BigInteger;
begin
PermissionsMock.Set('Retention Pol. Admin');
// Setup
- if RetentionPolicyLogEntry.FindLast() then;
- LastRetentionPolicyLogEntryNo := RetentionPolicyLogEntry."Entry No.";
+ LastRetentionPolicyLogEntryNo := RetentionPolicyTestLibrary.RetenionPolicyLogLastEntryNo();
TempRetentionPolicySetup.SystemId := CreateGuid();
TempRetentionPolicySetup."Table Id" := Database::"Retention Policy Test Data";
TempRetentionPolicySetup.CalcFields("Table Name");
ClearLastError();
// Exercise
- if not Codeunit.Run(Codeunit::"Apply Retention Policy Impl.", TempRetentionPolicySetup) then
+ if not RetentionPolicyTestLibrary.RunApplyRetentionPolicyImpl(TempRetentionPolicySetup) then
RetentionPolicyLog.LogError(RetentionPolicyLogCategory::"Retention Policy - Apply", StrSubstNo(ErrorOccuredDuringApplyErrLbl, TempRetentionPolicySetup."Table Id", TempRetentionPolicySetup."Table Name", GetLastErrorText()), false);
// Verify
sleep(50);
Assert.ExpectedError(StrSubstNo(RecordDoesNotExistErr, TempRetentionPolicySetup.SystemId));
- RetentionPolicyLogEntry.FindLast();
- VerifyLogEntry(LastRetentionPolicyLogEntryNo + 1, RetentionPolicyLogEntry."Message Type"::Error, RetentionPolicyLogCategory::"Retention Policy - Apply",
+ VerifyLogEntry(LastRetentionPolicyLogEntryNo + 1, enum::"Retention Policy Log Message Type"::Error, RetentionPolicyLogCategory::"Retention Policy - Apply",
StrSubstNo(ErrorOccuredDuringApplyErrLbl, TempRetentionPolicySetup."Table Id", TempRetentionPolicySetup."Table Name", StrSubstNo(RecordDoesNotExistErr, TempRetentionPolicySetup.SystemId)));
end;
local procedure VerifyLogEntry(EntryNo: BigInteger; MessageType: Enum "Retention Policy Log Message Type"; Category: Enum "Retention Policy Log Category"; Message: Text)
var
- RetentionPolicyLogEntry: Record "Retention Policy Log Entry";
+ FieldValues: Dictionary of [Text, Text];
begin
- SelectLatestVersion();
- RetentionPolicyLogEntry.Get(EntryNo);
- Assert.AreEqual(MessageType, RetentionPolicyLogEntry."Message Type", 'wrong message type');
- Assert.AreEqual(Category, RetentionPolicyLogEntry.Category, 'wrong category');
- Assert.AreEqual(Message, RetentionPolicyLogEntry.Message, 'wrong message');
+ FieldValues := RetentionPolicyTestLibrary.GetRetentionPolicyLogEntry(EntryNo);
+ Assert.AreEqual(Format(MessageType), FieldValues.Get('MessageType'), 'wrong message type');
+ Assert.AreEqual(Format(Category), FieldValues.Get('Category'), 'wrong category');
+ Assert.AreEqual(Message, FieldValues.Get('Message'), 'wrong message');
end;
}
\ No newline at end of file
diff --git a/src/System Application/Test/Retention Policy/src/RetentionPolicyTest.Codeunit.al b/src/System Application/Test/Retention Policy/src/RetentionPolicyTest.Codeunit.al
index a2051cf8dd..1c377170b4 100644
--- a/src/System Application/Test/Retention Policy/src/RetentionPolicyTest.Codeunit.al
+++ b/src/System Application/Test/Retention Policy/src/RetentionPolicyTest.Codeunit.al
@@ -20,6 +20,7 @@ codeunit 138702 "Retention Policy Test"
Assert: Codeunit "Library Assert";
LibraryVariableStorage: Codeunit "Library - Variable Storage";
PermissionsMock: Codeunit "Permissions Mock";
+ RetentionPolicyTestLibrary: Codeunit "Retention Policy Test Library";
DateFieldNoMustHaveAValueErr: Label 'The field Date Field No. must have a value in the retention policy for table %1, %2', Comment = '%1 = table number, %2 = table caption';
trigger OnRun()
@@ -1140,6 +1141,95 @@ codeunit 138702 "Retention Policy Test"
Assert.AreEqual(7, RetentionPolicyTestData.Count(), 'Incorrect number of records after applying retention policy');
end;
+ [HandlerFunctions('RetentionPolicyFilterPageHandler')]
+ [Test]
+ procedure TestApplyRetentionPolicyConflictWithBlankFilter()
+ var
+ RetentionPeriod: Record "Retention Period";
+ RetentionPolicySetup: Record "Retention Policy Setup";
+ RetentionPolicyTestData: Record "Retention Policy Test Data";
+ ApplyRetentionPolicy: Codeunit "Apply Retention Policy";
+ begin
+ PermissionsMock.Set('Retention Pol. Admin');
+ // Setup
+ ClearTestData();
+ InsertEnabledRetentionPolicySetupForSubsets(RetentionPolicySetup, RetentionPolicyTestData.FieldNo("Date Field"));
+ InsertOneWeekRetentionPeriod(RetentionPeriod);
+ InsertEnabledRetentionPolicySetupLine(RetentionPolicySetup, RetentionPeriod, RetentionPolicySetup."Date Field No.", 'Subset A', RetentionPolicyTestData.FieldNo(Description));
+ InsertOneMonthRetentionPeriod(RetentionPeriod);
+ InsertEnabledRetentionPolicySetupLine(RetentionPolicySetup, RetentionPeriod, RetentionPolicySetup."Date Field No.", 'Subset D', RetentionPolicyTestData.FieldNo("Description 2"));
+ InsertEnabledRetentionPolicySetupLine(RetentionPolicySetup, RetentionPeriod, RetentionPolicySetup."Date Field No.");
+
+ InsertRetentionPolicyTestData('<-3D>', 'Subset A', 'Subset D'); // keep because of A, D and ''
+ InsertRetentionPolicyTestData('<-5D>', 'Subset B', 'Subset D'); // keep because of D and ''
+ InsertRetentionPolicyTestData('<-2W>', 'Subset B', 'Subset E'); // keep because of ''
+ InsertRetentionPolicyTestData('<-3W>', 'Subset A', 'Subset E'); // keep because of ''
+ InsertRetentionPolicyTestData('<-5W>', 'Subset B', 'Subset D'); // delete because of D
+ InsertRetentionPolicyTestData('<-6W>', 'Subset A', 'Subset E'); // delete because of A
+ InsertRetentionPolicyTestData('<-2Y>', 'Subset B', 'Subset E'); // delete because of ''
+
+ Assert.AreEqual(7, RetentionPolicyTestData.Count(), 'Incorrect number of records before applying retention policy');
+
+ // Exercise
+ ApplyRetentionPolicy.ApplyRetentionPolicy(RetentionPolicySetup, false);
+
+ // Verify
+ Assert.RecordIsNotEmpty(RetentionPolicyTestData);
+ Assert.AreEqual(4, RetentionPolicyTestData.Count(), 'Incorrect total number of records after applying retention policy');
+ RetentionPolicyTestData.SetRange(Description, 'Subset A');
+ Assert.AreEqual(2, RetentionPolicyTestData.Count(), 'Incorrect number of records for Subset A after applying retention policy for Subset A');
+ RetentionPolicyTestData.SetRange(Description);
+ RetentionPolicyTestData.SetRange("Description 2", 'Subset D');
+ Assert.AreEqual(2, RetentionPolicyTestData.Count(), 'Incorrect number of records for Subset D after applying retention policy');
+ RetentionPolicyTestData.SetRange(Description, 'Subset A');
+ RetentionPolicyTestData.SetRange("Description 2", 'Subset E');
+ Assert.AreEqual(1, RetentionPolicyTestData.Count(), 'Incorrect number of records for Subset A, E after applying retention policy');
+ end;
+
+ [HandlerFunctions('RetentionPolicyFilterPageHandler')]
+ [Test]
+ procedure TestApplyRetentionPolicyConflictWithoutBlankFilter()
+ var
+ RetentionPeriod: Record "Retention Period";
+ RetentionPolicySetup: Record "Retention Policy Setup";
+ RetentionPolicyTestData: Record "Retention Policy Test Data";
+ ApplyRetentionPolicy: Codeunit "Apply Retention Policy";
+ begin
+ PermissionsMock.Set('Retention Pol. Admin');
+ // Setup
+ ClearTestData();
+ InsertEnabledRetentionPolicySetupForSubsets(RetentionPolicySetup, RetentionPolicyTestData.FieldNo("Date Field"));
+ InsertOneWeekRetentionPeriod(RetentionPeriod);
+ InsertEnabledRetentionPolicySetupLine(RetentionPolicySetup, RetentionPeriod, RetentionPolicySetup."Date Field No.", 'Subset A', RetentionPolicyTestData.FieldNo(Description));
+ InsertOneMonthRetentionPeriod(RetentionPeriod);
+ InsertEnabledRetentionPolicySetupLine(RetentionPolicySetup, RetentionPeriod, RetentionPolicySetup."Date Field No.", 'Subset D', RetentionPolicyTestData.FieldNo("Description 2"));
+
+ InsertRetentionPolicyTestData('<-3D>', 'Subset A', 'Subset D'); // keep because of A and D
+ InsertRetentionPolicyTestData('<-5D>', 'Subset B', 'Subset D'); // keep because of D
+ InsertRetentionPolicyTestData('<-2W>', 'Subset B', 'Subset E'); // keep (no policy)
+ InsertRetentionPolicyTestData('<-3W>', 'Subset A', 'Subset E'); // delete because of A
+ InsertRetentionPolicyTestData('<-5W>', 'Subset B', 'Subset D'); // delete because of D
+ InsertRetentionPolicyTestData('<-6W>', 'Subset A', 'Subset E'); // delete because of A
+ InsertRetentionPolicyTestData('<-2Y>', 'Subset B', 'Subset E'); // keep (no policy)
+
+ Assert.AreEqual(7, RetentionPolicyTestData.Count(), 'Incorrect number of records before applying retention policy');
+
+ // Exercise
+ ApplyRetentionPolicy.ApplyRetentionPolicy(RetentionPolicySetup, false);
+
+ // Verify
+ Assert.RecordIsNotEmpty(RetentionPolicyTestData);
+ Assert.AreEqual(4, RetentionPolicyTestData.Count(), 'Incorrect total number of records after applying retention policy');
+ RetentionPolicyTestData.SetRange(Description, 'Subset A');
+ Assert.AreEqual(1, RetentionPolicyTestData.Count(), 'Incorrect number of records for Subset A after applying retention policy for');
+ RetentionPolicyTestData.SetRange(Description);
+ RetentionPolicyTestData.SetRange("Description 2", 'Subset D');
+ Assert.AreEqual(2, RetentionPolicyTestData.Count(), 'Incorrect number of records for Subset D after applying retention policy');
+ RetentionPolicyTestData.SetRange(Description, 'Subset A');
+ RetentionPolicyTestData.SetRange("Description 2", 'Subset E');
+ Assert.RecordIsEmpty(RetentionPolicyTestData);
+ end;
+
[HandlerFunctions('RetentionPolicyFilterPageHandler')]
[Test]
procedure TestApplyRetentionPolicy1KLines()
@@ -1235,13 +1325,13 @@ codeunit 138702 "Retention Policy Test"
begin
PermissionsMock.Set('Retention Pol. Admin');
// Setup
- MaxRecordsToDelete := 250000;
- Buffer := 1000;
+ MaxRecordsToDelete := RetentionPolicyTestLibrary.MaxNumberOfRecordsToDelete();
+ Buffer := RetentionPolicyTestLibrary.MaxNumberOfRecordsToDeleteBuffer() + 10000;
ClearTestData();
InsertOneMonthRetentionPeriod(RetentionPeriod);
InsertEnabledRetentionPolicySetupForAllRecords(RetentionPolicySetup, RetentionPeriod, RetentionPolicyTestData.FieldNo("Date Field"));
- for i := 1 to (MaxRecordsToDelete + Buffer) do // must exceed the hardcoded limit by >1k
+ for i := 1 to (MaxRecordsToDelete + Buffer) do // must exceed the hardcoded limit by > Buffer
InsertRetentionPolicyTestData('<-2M>');
Assert.AreEqual((MaxRecordsToDelete + Buffer), RetentionPolicyTestData.Count(), 'Incorrect number of records before applying retention policy');
@@ -1267,13 +1357,13 @@ codeunit 138702 "Retention Policy Test"
begin
PermissionsMock.Set('Retention Pol. Admin');
// Setup
- MaxRecordsToDelete := 250000;
- Buffer := 999;
+ MaxRecordsToDelete := RetentionPolicyTestLibrary.MaxNumberOfRecordsToDelete();
+ Buffer := RetentionPolicyTestLibrary.MaxNumberOfRecordsToDeleteBuffer() - 1;
ClearTestData();
InsertOneMonthRetentionPeriod(RetentionPeriod);
InsertEnabledRetentionPolicySetupForAllRecords(RetentionPolicySetup, RetentionPeriod, RetentionPolicyTestData.FieldNo("Date Field"));
- for i := 1 to (MaxRecordsToDelete + Buffer) do // must exceed the hardcoded limit by <1k
+ for i := 1 to (MaxRecordsToDelete + Buffer) do // must exceed the hardcoded limit by < Buffer
InsertRetentionPolicyTestData('<-2M>');
Assert.AreEqual(MaxRecordsToDelete + Buffer, RetentionPolicyTestData.Count(), 'Incorrect number of records before applying retention policy');
@@ -1300,9 +1390,9 @@ codeunit 138702 "Retention Policy Test"
begin
PermissionsMock.Set('Retention Pol. Admin');
// Setup
- MaxRecordsToDelete := 250000;
- RecordsTableOne := 150000;
- Buffer := 1000;
+ MaxRecordsToDelete := RetentionPolicyTestLibrary.MaxNumberOfRecordsToDelete();
+ RecordsTableOne := Round(MaxRecordsToDelete * (2 / 3), 1, '>');
+ Buffer := RetentionPolicyTestLibrary.MaxNumberOfRecordsToDeleteBuffer() + 1;
ClearTestData();
InsertOneMonthRetentionPeriod(RetentionPeriod);
InsertEnabledRetentionPolicySetupForAllRecords(RetentionPolicySetup, RetentionPeriod, RetentionPolicyTestData.FieldNo("Date Field"));
@@ -1315,8 +1405,6 @@ codeunit 138702 "Retention Policy Test"
Assert.AreEqual(RecordsTableOne, RetentionPolicyTestData.Count(), 'Incorrect number of records before applying retention policy');
Assert.AreEqual(MaxRecordsToDelete + Buffer - RecordsTableOne, RetentionPolicyTestData3.Count(), 'Incorrect number of records before applying retention policy');
- Assert.AreEqual(150000, RetentionPolicyTestData.Count(), 'Incorrect number of records before applying retention policy');
- Assert.AreEqual(101000, RetentionPolicyTestData3.Count(), 'Incorrect number of records before applying retention policy');
// Exercise
ApplyRetentionPolicy.ApplyRetentionPolicy(false);
@@ -1342,9 +1430,9 @@ codeunit 138702 "Retention Policy Test"
begin
PermissionsMock.Set('Retention Pol. Admin');
// Setup
- MaxRecordsToDelete := 250000;
- RecordsTableOne := 150000;
- Buffer := 999;
+ MaxRecordsToDelete := RetentionPolicyTestLibrary.MaxNumberOfRecordsToDelete();
+ RecordsTableOne := Round(MaxRecordsToDelete * (2 / 3), 1, '>');
+ Buffer := RetentionPolicyTestLibrary.MaxNumberOfRecordsToDeleteBuffer() - 1;
ClearTestData();
InsertOneMonthRetentionPeriod(RetentionPeriod);
@@ -1381,13 +1469,13 @@ codeunit 138702 "Retention Policy Test"
begin
PermissionsMock.Set('Retention Pol. Admin');
// Setup
- MaxRecordsToDelete := 250000;
- Buffer := 1500;
+ MaxRecordsToDelete := RetentionPolicyTestLibrary.MaxNumberOfRecordsToDelete();
+ Buffer := RetentionPolicyTestLibrary.MaxNumberOfRecordsToDeleteBuffer() + 500;
ClearTestData();
InsertOneMonthRetentionPeriod(RetentionPeriod);
InsertEnabledRetentionPolicySetupForAllRecords(RetentionPolicySetup, RetentionPeriod, RetentionPolicyTestData.FieldNo("Date Field"));
- for i := 1 to (MaxRecordsToDelete + Buffer) do // must exceed the hardcoded limit by >1k
+ for i := 1 to (MaxRecordsToDelete + Buffer) do // must exceed the hardcoded limit by > Buffer
InsertRetentionPolicyTestData('<-2M>');
Assert.AreEqual((MaxRecordsToDelete + Buffer), RetentionPolicyTestData.Count(), 'Incorrect number of records before applying retention policy');
@@ -1413,13 +1501,13 @@ codeunit 138702 "Retention Policy Test"
begin
PermissionsMock.Set('Retention Pol. Admin');
// Setup
- MaxRecordsToDelete := 250000;
- Buffer := 1500;
+ MaxRecordsToDelete := RetentionPolicyTestLibrary.MaxNumberOfRecordsToDelete();
+ Buffer := RetentionPolicyTestLibrary.MaxNumberOfRecordsToDeleteBuffer() + 500;
ClearTestData();
InsertOneMonthRetentionPeriod(RetentionPeriod);
InsertEnabledRetentionPolicySetupForAllRecords(RetentionPolicySetup, RetentionPeriod, RetentionPolicyTestData.FieldNo("Date Field"));
- for i := 1 to (MaxRecordsToDelete + Buffer) do // must exceed the hardcoded limit by >1k
+ for i := 1 to (MaxRecordsToDelete + Buffer) do // must exceed the hardcoded limit by > Buffer
InsertRetentionPolicyTestData('<-2M>');
Assert.AreEqual((MaxRecordsToDelete + Buffer), RetentionPolicyTestData.Count(), 'Incorrect number of records before applying retention policy');
@@ -1439,15 +1527,15 @@ codeunit 138702 "Retention Policy Test"
RetentionPolicyTestData: Record "Retention Policy Test Data";
RetentionPolicyTestData3: Record "Retention Policy Test Data 3";
ApplyRetentionPolicy: Codeunit "Apply Retention Policy";
- RetentionPolicyTestLibrary: Codeunit "Retention Policy Test Library";
+ RetentionPolicyTestLibrarySubs: Codeunit "Retention Policy Test Library";
RecordsTableOne: Integer;
RecordsTableThree: Integer;
i: Integer;
begin
PermissionsMock.Set('Retention Pol. Admin');
// Setup
- RecordsTableOne := 50000;
- RecordsTableThree := 60000;
+ RecordsTableOne := RetentionPolicyTestLibrary.MaxNumberOfRecordsToDelete() * 2;
+ RecordsTableThree := RetentionPolicyTestLibrary.MaxNumberOfRecordsToDelete() * 2;
ClearTestData();
InsertOneMonthRetentionPeriod(RetentionPeriod);
InsertEnabledRetentionPolicySetupForAllRecords(RetentionPolicySetup, RetentionPeriod, RetentionPolicyTestData.FieldNo("Date Field"));
@@ -1462,102 +1550,14 @@ codeunit 138702 "Retention Policy Test"
Assert.AreEqual(RecordsTableThree, RetentionPolicyTestData3.Count(), 'Incorrect number of records before applying retention policy');
// Exercise
- BindSubscription(RetentionPolicyTestLibrary);
+ BindSubscription(RetentionPolicyTestLibrarySubs);
ApplyRetentionPolicy.ApplyRetentionPolicy(RetentionPolicySetup, false);
- UnbindSubscription(RetentionPolicyTestLibrary);
+ UnbindSubscription(RetentionPolicyTestLibrarySubs);
// Verify
Assert.RecordIsNotEmpty(RetentionPolicyTestData);
- Assert.AreEqual(1, RetentionPolicyTestLibrary.GetRecordLimitExceededSubscriberCount(), 'OnApplyRetentionPolicyRecordLimitExceeded event called more than once.');
- end;
-
- [HandlerFunctions('RetentionPolicyFilterPageHandler')]
- [Test]
- procedure TestApplyRetentionPolicyConflictWithBlankFilter()
- var
- RetentionPeriod: Record "Retention Period";
- RetentionPolicySetup: Record "Retention Policy Setup";
- RetentionPolicyTestData: Record "Retention Policy Test Data";
- ApplyRetentionPolicy: Codeunit "Apply Retention Policy";
- begin
- PermissionsMock.Set('Retention Pol. Admin');
- // Setup
- ClearTestData();
- InsertEnabledRetentionPolicySetupForSubsets(RetentionPolicySetup, RetentionPolicyTestData.FieldNo("Date Field"));
- InsertOneWeekRetentionPeriod(RetentionPeriod);
- InsertEnabledRetentionPolicySetupLine(RetentionPolicySetup, RetentionPeriod, RetentionPolicySetup."Date Field No.", 'Subset A', RetentionPolicyTestData.FieldNo(Description));
- InsertOneMonthRetentionPeriod(RetentionPeriod);
- InsertEnabledRetentionPolicySetupLine(RetentionPolicySetup, RetentionPeriod, RetentionPolicySetup."Date Field No.", 'Subset D', RetentionPolicyTestData.FieldNo("Description 2"));
- InsertEnabledRetentionPolicySetupLine(RetentionPolicySetup, RetentionPeriod, RetentionPolicySetup."Date Field No.");
-
- InsertRetentionPolicyTestData('<-3D>', 'Subset A', 'Subset D'); // keep because of A, D and ''
- InsertRetentionPolicyTestData('<-5D>', 'Subset B', 'Subset D'); // keep because of D and ''
- InsertRetentionPolicyTestData('<-2W>', 'Subset B', 'Subset E'); // keep because of ''
- InsertRetentionPolicyTestData('<-3W>', 'Subset A', 'Subset E'); // keep because of ''
- InsertRetentionPolicyTestData('<-5W>', 'Subset B', 'Subset D'); // delete because of D
- InsertRetentionPolicyTestData('<-6W>', 'Subset A', 'Subset E'); // delete because of A
- InsertRetentionPolicyTestData('<-2Y>', 'Subset B', 'Subset E'); // delete because of ''
-
- Assert.AreEqual(7, RetentionPolicyTestData.Count(), 'Incorrect number of records before applying retention policy');
-
- // Exercise
- ApplyRetentionPolicy.ApplyRetentionPolicy(RetentionPolicySetup, false);
-
- // Verify
- Assert.RecordIsNotEmpty(RetentionPolicyTestData);
- Assert.AreEqual(4, RetentionPolicyTestData.Count(), 'Incorrect total number of records after applying retention policy');
- RetentionPolicyTestData.SetRange(Description, 'Subset A');
- Assert.AreEqual(2, RetentionPolicyTestData.Count(), 'Incorrect number of records for Subset A after applying retention policy for Subset A');
- RetentionPolicyTestData.SetRange(Description);
- RetentionPolicyTestData.SetRange("Description 2", 'Subset D');
- Assert.AreEqual(2, RetentionPolicyTestData.Count(), 'Incorrect number of records for Subset D after applying retention policy');
- RetentionPolicyTestData.SetRange(Description, 'Subset A');
- RetentionPolicyTestData.SetRange("Description 2", 'Subset E');
- Assert.AreEqual(1, RetentionPolicyTestData.Count(), 'Incorrect number of records for Subset A, E after applying retention policy');
- end;
-
- [HandlerFunctions('RetentionPolicyFilterPageHandler')]
- [Test]
- procedure TestApplyRetentionPolicyConflictWithoutBlankFilter()
- var
- RetentionPeriod: Record "Retention Period";
- RetentionPolicySetup: Record "Retention Policy Setup";
- RetentionPolicyTestData: Record "Retention Policy Test Data";
- ApplyRetentionPolicy: Codeunit "Apply Retention Policy";
- begin
- PermissionsMock.Set('Retention Pol. Admin');
- // Setup
- ClearTestData();
- InsertEnabledRetentionPolicySetupForSubsets(RetentionPolicySetup, RetentionPolicyTestData.FieldNo("Date Field"));
- InsertOneWeekRetentionPeriod(RetentionPeriod);
- InsertEnabledRetentionPolicySetupLine(RetentionPolicySetup, RetentionPeriod, RetentionPolicySetup."Date Field No.", 'Subset A', RetentionPolicyTestData.FieldNo(Description));
- InsertOneMonthRetentionPeriod(RetentionPeriod);
- InsertEnabledRetentionPolicySetupLine(RetentionPolicySetup, RetentionPeriod, RetentionPolicySetup."Date Field No.", 'Subset D', RetentionPolicyTestData.FieldNo("Description 2"));
-
- InsertRetentionPolicyTestData('<-3D>', 'Subset A', 'Subset D'); // keep because of A and D
- InsertRetentionPolicyTestData('<-5D>', 'Subset B', 'Subset D'); // keep because of D
- InsertRetentionPolicyTestData('<-2W>', 'Subset B', 'Subset E'); // keep (no policy)
- InsertRetentionPolicyTestData('<-3W>', 'Subset A', 'Subset E'); // delete because of A
- InsertRetentionPolicyTestData('<-5W>', 'Subset B', 'Subset D'); // delete because of D
- InsertRetentionPolicyTestData('<-6W>', 'Subset A', 'Subset E'); // delete because of A
- InsertRetentionPolicyTestData('<-2Y>', 'Subset B', 'Subset E'); // keep (no policy)
-
- Assert.AreEqual(7, RetentionPolicyTestData.Count(), 'Incorrect number of records before applying retention policy');
-
- // Exercise
- ApplyRetentionPolicy.ApplyRetentionPolicy(RetentionPolicySetup, false);
-
- // Verify
- Assert.RecordIsNotEmpty(RetentionPolicyTestData);
- Assert.AreEqual(4, RetentionPolicyTestData.Count(), 'Incorrect total number of records after applying retention policy');
- RetentionPolicyTestData.SetRange(Description, 'Subset A');
- Assert.AreEqual(1, RetentionPolicyTestData.Count(), 'Incorrect number of records for Subset A after applying retention policy for');
- RetentionPolicyTestData.SetRange(Description);
- RetentionPolicyTestData.SetRange("Description 2", 'Subset D');
- Assert.AreEqual(2, RetentionPolicyTestData.Count(), 'Incorrect number of records for Subset D after applying retention policy');
- RetentionPolicyTestData.SetRange(Description, 'Subset A');
- RetentionPolicyTestData.SetRange("Description 2", 'Subset E');
- Assert.RecordIsEmpty(RetentionPolicyTestData);
+ Assert.RecordIsNotEmpty(RetentionPolicyTestData3);
+ Assert.AreEqual(1, RetentionPolicyTestLibrarySubs.GetRecordLimitExceededSubscriberCount(), 'OnApplyRetentionPolicyRecordLimitExceeded event called more than once.');
end;
[HandlerFunctions('RetentionPolicyFilterPageHandler')]
diff --git a/src/System Application/Test/TestGroups.json b/src/System Application/Test/TestGroups.json
new file mode 100644
index 0000000000..4e39d9b6d5
--- /dev/null
+++ b/src/System Application/Test/TestGroups.json
@@ -0,0 +1,7 @@
+[
+ {
+ "group": "No Test Isolation",
+ "codeunitId": "138705",
+ "codeunitName": "Retention Policy Log Test"
+ }
+]
\ No newline at end of file