Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

using Ardalis.GuardClauses;
using Monai.Deploy.Messaging.Events;
using Monai.Deploy.WorkflowManager.Contracts.Models;

namespace Monai.Deploy.WorkflowManager.PayloadListener.Extensions
{
Expand All @@ -38,6 +39,16 @@ public static bool IsValid(this WorkflowRequestEvent workflowRequestMessage, out
return valid;
}

public static bool IsInformaticsGatewayNotNull(string source, InformaticsGateway informaticsGateway, IList<string> validationErrors)
{
Guard.Against.NullOrWhiteSpace(source, nameof(source));

if (informaticsGateway is not null) return true;

validationErrors?.Add($"'{nameof(informaticsGateway)}' cannot be null (source: {source}).");
return false;
}

public static bool IsAeTitleValid(string source, string aeTitle, IList<string> validationErrors)
{
Guard.Against.NullOrWhiteSpace(source, nameof(source));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,11 @@ public static bool IsDescriptionValid(string source, string description, IList<s
public static bool IsInformaticsGatewayValid(string source, InformaticsGateway informaticsGateway, IList<string> validationErrors = null)
{
Guard.Against.NullOrWhiteSpace(source, nameof(source));
Guard.Against.Null(informaticsGateway, nameof(informaticsGateway));

var valid = true;

valid &= ValidationExtensions.IsAeTitleValid(informaticsGateway.GetType().Name, informaticsGateway.AeTitle, validationErrors);
valid &= IsExportDestinationsValid(informaticsGateway.GetType().Name, informaticsGateway.ExportDestinations, validationErrors);
valid &= ValidationExtensions.IsInformaticsGatewayNotNull(source, informaticsGateway, validationErrors);
valid &= ValidationExtensions.IsAeTitleValid(nameof(informaticsGateway), informaticsGateway?.AeTitle, validationErrors);
valid &= IsExportDestinationsValid(nameof(informaticsGateway), informaticsGateway?.ExportDestinations, validationErrors);

return valid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ Scenario Outline: Update workflow with invalid details
| /workflows/c86a437d-d026-4bdf-b1df-c7a6372b89e3 | Invalid_Workflow_0_Tasks | Missing Workflow Tasks |
| /workflows/c86a437d-d026-4bdf-b1df-c7a6372b89e3 | Invalid_Workflow_Version_Null | Missing Workflow Version |
| /workflows/c86a437d-d026-4bdf-b1df-c7a6372b89e3 | Invalid_Workflow_Version_Blank | Missing Workflow Version |
| /workflows/c86a437d-d026-4bdf-b1df-c7a6372b89e3 | Invalid_Workflow_Body_Object | 'informaticsGateway' cannot be null |
| /workflows/c86a437d-d026-4bdf-b1df-c7a6372b89e3 | Empty_Workflow_Body | '' is not a valid Workflow Description |


@UpdateWorkflows
Expand Down Expand Up @@ -158,9 +160,11 @@ Scenario Outline: Add workflow with invalid details
| Invalid_Workflow_TaskID_Content | Contains Invalid Characters. |
| Invalid_Workflow_Unreferenced_Task | Found Task(s) without any task destinations to it |
| Invalid_Workflow_Loopback_Task | Detected task convergence on path |
| Invalid_Workflow_0_Tasks | Missing Workflow Tasks |
| Invalid_Workflow_0_Tasks | Missing Workflow Tasks |
| Invalid_Workflow_Version_Null | Missing Workflow Version |
| Invalid_Workflow_Version_Blank | Missing Workflow Version |
| Invalid_Workflow_Body_Object | 'informaticsGateway' cannot be null |
| Empty_Workflow_Body | '' is not a valid Workflow Description |

@DeleteWorkflows
Scenario: Delete a workflow with one revision
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,21 @@ public static class WorkflowObjectsTestData
}
}
},
new WorkflowObjectTestData()
{
Name = "Invalid_Workflow_Body_Object",
Workflow = new Workflow()
{
Name = "Artifact 1",
Description = "Artifact 1",
Version = ""
}
},
new WorkflowObjectTestData()
{
Name = "Empty_Workflow_Body",
Workflow = new Workflow()
},
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -663,5 +663,43 @@ public void ValidateWorkflow_ValidatesAWorkflow_ReturnsTrueAndHasCorrectValidati
WorkflowValidator.Reset();
}
}

[Fact]
public void ValidateWorkflow_ValidatesEmptyWorkflow_ReturnsTrueAndHasCorrectValidationResultsAsync()
{
for (var i = 0; i < 15; i++)
{
var workflow = new Workflow();

var workflowHasErrors = WorkflowValidator.ValidateWorkflow(workflow, out var results);

Assert.True(workflowHasErrors);

Assert.Equal(7, results.Errors.Count);

var error1 = "'' is not a valid Workflow Description (source: Unnamed workflow).";
Assert.Contains(error1, results.Errors);

var error2 = "'informaticsGateway' cannot be null (source: Unnamed workflow).";
Assert.Contains(error2, results.Errors);

var error3 = "'' is not a valid AE Title (source: informaticsGateway).";
Assert.Contains(error3, results.Errors);

var error4 = "'' is not a valid Informatics Gateway - exportDestinations (source: informaticsGateway).";
Assert.Contains(error4, results.Errors);

var error5 = "Missing Workflow Name.";
Assert.Contains(error5, results.Errors);

var error6 = "Missing Workflow Version.";
Assert.Contains(error6, results.Errors);

var error7 = "Missing Workflow Tasks.";
Assert.Contains(error7, results.Errors);

WorkflowValidator.Reset();
}
}
}
}