Skip to content

Commit 19cfae1

Browse files
authored
Merge branch 'develop' into dependabot/github_actions/docker/metadata-action-4.4.0
2 parents 2c95020 + 5b9cc6a commit 19cfae1

File tree

3 files changed

+171
-3
lines changed

3 files changed

+171
-3
lines changed

src/WorkflowManager/Monai.Deploy.WorkflowManager.Services/InformaticsGateway/InformaticsGatewayService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public async Task<bool> OriginExists(string aetitle)
5454
}
5555
catch (Exception ex)
5656
{
57-
throw new MonaiInternalServerException($"An error occured when cheking if the origin '{aetitle}' existed.", ex);
57+
throw new MonaiInternalServerException($"An error occured when checking if the origin '{aetitle}' existed.", ex);
5858
}
5959
}
6060
}

tests/UnitTests/WorkflowManager.Services.Tests/InformaticsGateway/InformaticsGatewayServiceTests.cs

+9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
using System.Net;
1818
using Microsoft.Extensions.Options;
19+
using Monai.Deploy.WorkflowManager.Common.Exceptions;
1920
using Monai.Deploy.WorkflowManager.Configuration;
2021
using Monai.Deploy.WorkflowManager.Services.InformaticsGateway;
2122
using Moq;
@@ -66,6 +67,14 @@ public async Task OriginsExist_InvalidSource_ReturnsFalse()
6667
Assert.Equal(expected, result);
6768
}
6869

70+
[Fact]
71+
public async Task OriginsExist_ExternalServiceError_ThrowsMonaiInternalErrorException()
72+
{
73+
var source = "any_source";
74+
75+
await Assert.ThrowsAsync<MonaiInternalServerException>(async () => await InformaticsGatewayService.OriginExists(source));
76+
}
77+
6978
[Fact]
7079
public async Task OriginsExist_ValidSource_ReturnsTrue()
7180
{

tests/UnitTests/WorkflowManager.Tests/Controllers/WorkflowsControllerTests.cs

+161-2
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,165 @@ public async void GetList_ServiceException_ReturnProblem()
132132
Assert.StartsWith(expectedInstance, ((ProblemDetails)objectResult.Value).Instance);
133133
}
134134

135+
[Fact]
136+
public async Task CreateAsync_ValidWorkflow_ReturnsWorkflowId()
137+
{
138+
var newWorkflow = new Workflow
139+
{
140+
Name = "Workflowname",
141+
Description = "Workflowdesc",
142+
Version = "1",
143+
InformaticsGateway = new InformaticsGateway
144+
{
145+
AeTitle = "aetitle",
146+
ExportDestinations = new[] { "test" }
147+
},
148+
Tasks = new TaskObject[]
149+
{
150+
new TaskObject {
151+
Id = Guid.NewGuid().ToString(),
152+
Type = "export",
153+
Description = "taskdesc",
154+
Args = new Dictionary<string, string>
155+
{
156+
{ "test", "test" }
157+
},
158+
Artifacts = new ArtifactMap
159+
{
160+
Input = new Artifact[]
161+
{
162+
new Artifact
163+
{
164+
Name = "test",
165+
Value = "{{ context.input.dicom }}"
166+
}
167+
}
168+
},
169+
ExportDestinations = new ExportDestination[] {
170+
new ExportDestination
171+
{
172+
Name = "test"
173+
}
174+
}
175+
}
176+
}
177+
};
178+
179+
var workflowId = Guid.NewGuid().ToString();
180+
181+
var response = new CreateWorkflowResponse(workflowId);
182+
183+
_workflowService.Setup(w => w.CreateAsync(newWorkflow)).ReturnsAsync(workflowId);
184+
185+
var result = await WorkflowsController.CreateAsync(newWorkflow);
186+
187+
var objectResult = Assert.IsType<ObjectResult>(result);
188+
189+
Assert.Equal(201, objectResult.StatusCode);
190+
objectResult.Value.Should().BeEquivalentTo(response);
191+
}
192+
193+
[Fact]
194+
public async Task CreateAsync_InvalidWorkflow_ReturnsBadRequest()
195+
{
196+
var newWorkflow = new Workflow
197+
{
198+
Name = "Workflowname",
199+
Description = "Workflowdesc",
200+
Version = "1",
201+
InformaticsGateway = new InformaticsGateway
202+
{
203+
AeTitle = "aetitle"
204+
},
205+
Tasks = new TaskObject[]
206+
{
207+
new TaskObject {
208+
Id = Guid.NewGuid().ToString(),
209+
Type = "type",
210+
Description = "taskdesc",
211+
Args = new Dictionary<string, string>
212+
{
213+
{ "test", "test" }
214+
}
215+
}
216+
}
217+
};
218+
219+
var workflowId = Guid.NewGuid().ToString();
220+
221+
var response = new CreateWorkflowResponse(workflowId);
222+
223+
var result = await WorkflowsController.CreateAsync(newWorkflow);
224+
225+
var objectResult = Assert.IsType<ObjectResult>(result);
226+
227+
Assert.Equal(400, objectResult.StatusCode);
228+
229+
const string expectedInstance = "/workflows";
230+
Assert.StartsWith(expectedInstance, ((ProblemDetails)objectResult.Value).Instance);
231+
}
232+
233+
[Fact]
234+
public async Task CreateAsync_InvalidWorkflow_ReturnsInternalServerError()
235+
{
236+
var newWorkflow = new Workflow
237+
{
238+
Name = "Workflowname",
239+
Description = "Workflowdesc",
240+
Version = "1",
241+
InformaticsGateway = new InformaticsGateway
242+
{
243+
AeTitle = "aetitle",
244+
ExportDestinations = new[] { "test" },
245+
DataOrigins = new string[] { "invalid_origin" }
246+
},
247+
Tasks = new TaskObject[]
248+
{
249+
new TaskObject {
250+
Id = Guid.NewGuid().ToString(),
251+
Type = "export",
252+
Description = "taskdesc",
253+
Args = new Dictionary<string, string>
254+
{
255+
{ "test", "test" }
256+
},
257+
Artifacts = new ArtifactMap
258+
{
259+
Input = new Artifact[]
260+
{
261+
new Artifact
262+
{
263+
Name = "test",
264+
Value = "{{ context.input.dicom }}"
265+
}
266+
}
267+
},
268+
ExportDestinations = new ExportDestination[] {
269+
new ExportDestination
270+
{
271+
Name = "test"
272+
}
273+
}
274+
}
275+
}
276+
};
277+
278+
_informaticsGatewayService.Setup(x => x.OriginExists(It.IsAny<string>()))
279+
.ThrowsAsync(new MonaiInternalServerException(
280+
$"An error occured when checking if the origin '{newWorkflow.InformaticsGateway.DataOrigins[0]}' existed.",
281+
new Exception()
282+
));
283+
284+
var result = await WorkflowsController.CreateAsync(newWorkflow);
285+
286+
var objectResult = Assert.IsType<ObjectResult>(result);
287+
288+
Assert.Equal(500, objectResult.StatusCode);
289+
290+
const string expectedInstance = "/workflows";
291+
Assert.StartsWith(expectedInstance, ((ProblemDetails)objectResult.Value).Instance);
292+
}
293+
135294
[Fact]
136295
public async Task ValidateAsync_InvalidWorkflow_ReturnsBadRequest()
137296
{
@@ -501,7 +660,7 @@ public async Task ValidateAsync_InvalidWorkflow_ReturnsInternalServerError()
501660

502661
_informaticsGatewayService.Setup(x => x.OriginExists(It.IsAny<string>()))
503662
.ThrowsAsync(new MonaiInternalServerException(
504-
$"An error occured when cheking if the origin '{newWorkflow.InformaticsGateway.DataOrigins[0]}' existed.",
663+
$"An error occured when checking if the origin '{newWorkflow.InformaticsGateway.DataOrigins[0]}' existed.",
505664
new Exception()
506665
));
507666

@@ -809,7 +968,7 @@ public async Task UpdateAsync_InvalidWorkflow_ReturnsInternalServerException()
809968

810969
_informaticsGatewayService.Setup(x => x.OriginExists(It.IsAny<string>()))
811970
.ThrowsAsync(new MonaiInternalServerException(
812-
$"An error occured when cheking if the origin '{newWorkflow.InformaticsGateway.DataOrigins[0]}' existed.",
971+
$"An error occured when checking if the origin '{newWorkflow.InformaticsGateway.DataOrigins[0]}' existed.",
813972
new Exception()
814973
));
815974

0 commit comments

Comments
 (0)