diff --git a/source/Example.Orchestrations.Tests/Example.Orchestrations.Tests.csproj b/source/Example.Orchestrations.Tests/Example.Orchestrations.Tests.csproj
index 07b17f18..8ea0b1ba 100644
--- a/source/Example.Orchestrations.Tests/Example.Orchestrations.Tests.csproj
+++ b/source/Example.Orchestrations.Tests/Example.Orchestrations.Tests.csproj
@@ -10,6 +10,7 @@
+
@@ -27,6 +28,7 @@
+
diff --git a/source/Example.Orchestrations.Tests/Fixtures/ExampleOrchestrationsAppFixture.cs b/source/Example.Orchestrations.Tests/Fixtures/ExampleOrchestrationsAppFixture.cs
index f1bdf35a..e243caca 100644
--- a/source/Example.Orchestrations.Tests/Fixtures/ExampleOrchestrationsAppFixture.cs
+++ b/source/Example.Orchestrations.Tests/Fixtures/ExampleOrchestrationsAppFixture.cs
@@ -12,35 +12,83 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+using Energinet.DataHub.Core.FunctionApp.TestCommon.Azurite;
+using Energinet.DataHub.Core.FunctionApp.TestCommon.Configuration;
+using Energinet.DataHub.ProcessManager.Core.Tests.Fixtures;
+using Energinet.DataHub.ProcessManager.Tests.Fixtures;
using Xunit.Abstractions;
namespace Energinet.DataHub.Example.Orchestrations.Tests.Fixtures;
///
-/// Support testing Process Manager Orchestrations app using default fixture configuration.
+/// Support testing the interactions between Example.Orchestrations and
+/// Process Manager Api, by coordinating the startup of the dependent applications
+/// Example.Orchestrations and ProcessManager (Api).
///
-public class ExampleOrchestrationsAppFixture
- : IAsyncLifetime
+public class ExampleOrchestrationsAppFixture : IAsyncLifetime
{
+ private const string TaskHubName = "ExampleOrchestrationsAppTest01";
+
public ExampleOrchestrationsAppFixture()
{
- ExampleOrchestrationsAppManager = new ExampleOrchestrationsAppManager();
+ DatabaseManager = new ProcessManagerDatabaseManager("ExampleOrchestrationsAppTests");
+ AzuriteManager = new AzuriteManager(useOAuth: true);
+
+ IntegrationTestConfiguration = new IntegrationTestConfiguration();
+
+ ExampleOrchestrationsAppManager = new ExampleOrchestrationsAppManager(
+ DatabaseManager,
+ IntegrationTestConfiguration,
+ AzuriteManager,
+ taskHubName: TaskHubName,
+ appPort: 8113,
+ manageDatabase: false,
+ manageAzurite: false);
+
+ ProcessManagerAppManager = new ProcessManagerAppManager(
+ DatabaseManager,
+ IntegrationTestConfiguration,
+ AzuriteManager,
+ taskHubName: TaskHubName,
+ appPort: 8114,
+ manageDatabase: false,
+ manageAzurite: false);
}
+ public IntegrationTestConfiguration IntegrationTestConfiguration { get; }
+
public ExampleOrchestrationsAppManager ExampleOrchestrationsAppManager { get; }
+ public ProcessManagerAppManager ProcessManagerAppManager { get; }
+
+ private ProcessManagerDatabaseManager DatabaseManager { get; }
+
+ private AzuriteManager AzuriteManager { get; }
+
public async Task InitializeAsync()
{
+ AzuriteManager.CleanupAzuriteStorage();
+ AzuriteManager.StartAzurite();
+
+ await DatabaseManager.CreateDatabaseAsync();
+
await ExampleOrchestrationsAppManager.StartAsync();
+ await ProcessManagerAppManager.StartAsync();
}
public async Task DisposeAsync()
{
await ExampleOrchestrationsAppManager.DisposeAsync();
+ await ProcessManagerAppManager.DisposeAsync();
+
+ await DatabaseManager.DeleteDatabaseAsync();
+
+ AzuriteManager.Dispose();
}
public void SetTestOutputHelper(ITestOutputHelper? testOutputHelper)
{
ExampleOrchestrationsAppManager.SetTestOutputHelper(testOutputHelper);
+ ProcessManagerAppManager.SetTestOutputHelper(testOutputHelper);
}
}
diff --git a/source/Example.Orchestrations.Tests/Integration/Processes/BRS_X01/Examples/MonitorExampleUsingApiScenario.cs b/source/Example.Orchestrations.Tests/Integration/Processes/BRS_X01/Examples/MonitorExampleUsingApiScenario.cs
new file mode 100644
index 00000000..5890aced
--- /dev/null
+++ b/source/Example.Orchestrations.Tests/Integration/Processes/BRS_X01/Examples/MonitorExampleUsingApiScenario.cs
@@ -0,0 +1,123 @@
+// Copyright 2020 Energinet DataHub A/S
+//
+// Licensed under the Apache License, Version 2.0 (the "License2");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+using System.Net.Http.Json;
+using System.Text;
+using System.Text.Json;
+using Energinet.DataHub.Core.TestCommon;
+using Energinet.DataHub.Example.Orchestrations.Abstractions.Processes.BRS_X01.Example.V1.Model;
+using Energinet.DataHub.Example.Orchestrations.Tests.Fixtures;
+using Energinet.DataHub.ProcessManager.Abstractions.Api.Model;
+using Energinet.DataHub.ProcessManager.Abstractions.Api.Model.OrchestrationInstance;
+using FluentAssertions;
+using Xunit.Abstractions;
+
+namespace Energinet.DataHub.ProcessManager.Tests.Integration.Processes;
+
+///
+/// Test case where we verify the Process Manager clients can be used to start a
+/// calculation orchestration (with input parameter) and monitor its status during its lifetime.
+///
+[Collection(nameof(ExampleOrchestrationsAppCollection))]
+public class MonitorExampleUsingApiScenario : IAsyncLifetime
+{
+ public MonitorExampleUsingApiScenario(
+ ExampleOrchestrationsAppFixture fixture,
+ ITestOutputHelper testOutputHelper)
+ {
+ Fixture = fixture;
+ Fixture.SetTestOutputHelper(testOutputHelper);
+ }
+
+ private ExampleOrchestrationsAppFixture Fixture { get; }
+
+ public Task InitializeAsync()
+ {
+ Fixture.ProcessManagerAppManager.AppHostManager.ClearHostLog();
+ Fixture.ExampleOrchestrationsAppManager.AppHostManager.ClearHostLog();
+
+ return Task.CompletedTask;
+ }
+
+ public Task DisposeAsync()
+ {
+ Fixture.ProcessManagerAppManager.SetTestOutputHelper(null!);
+ Fixture.ExampleOrchestrationsAppManager.SetTestOutputHelper(null!);
+
+ return Task.CompletedTask;
+ }
+
+ [Fact]
+ public async Task Example_WhenStarted_CanMonitorLifecycle()
+ {
+ var orchestration = new Brs_X01_Example_V1();
+ var input = new InputV1(false);
+
+ var command = new StartExampleCommandV1(
+ operatingIdentity: new UserIdentityDto(
+ Guid.NewGuid(),
+ Guid.NewGuid()),
+ input);
+
+ using var scheduleRequest = new HttpRequestMessage(
+ HttpMethod.Post,
+ $"/api/orchestrationinstance/command/start/custom/{orchestration.Name}/{orchestration.Version}");
+ scheduleRequest.Content = new StringContent(
+ JsonSerializer.Serialize(command),
+ Encoding.UTF8,
+ "application/json");
+
+ // Step 1: Start new example orchestration instance
+ using var response = await Fixture.ExampleOrchestrationsAppManager.AppHostManager
+ .HttpClient
+ .SendAsync(scheduleRequest);
+ response.EnsureSuccessStatusCode();
+
+ var calculationId = await response.Content
+ .ReadFromJsonAsync();
+
+ // Step 2: Query until terminated with succeeded
+ var getRequest = new GetOrchestrationInstanceByIdQuery(
+ new UserIdentityDto(
+ Guid.NewGuid(),
+ Guid.NewGuid()),
+ calculationId);
+
+ var isTerminated = await Awaiter.TryWaitUntilConditionAsync(
+ async () =>
+ {
+ using var queryRequest = new HttpRequestMessage(
+ HttpMethod.Post,
+ "/api/orchestrationinstance/query/id");
+ queryRequest.Content = new StringContent(
+ JsonSerializer.Serialize(getRequest),
+ Encoding.UTF8,
+ "application/json");
+
+ using var queryResponse = await Fixture.ProcessManagerAppManager.AppHostManager
+ .HttpClient
+ .SendAsync(queryRequest);
+ queryResponse.EnsureSuccessStatusCode();
+
+ var orchestrationInstance = await queryResponse.Content
+ .ReadFromJsonAsync();
+
+ return orchestrationInstance!.Lifecycle.State == OrchestrationInstanceLifecycleStates.Terminated;
+ },
+ timeLimit: TimeSpan.FromSeconds(40),
+ delay: TimeSpan.FromSeconds(2));
+
+ isTerminated.Should().BeTrue("because we expects the orchestration instance can complete within given wait time");
+ }
+}
diff --git a/source/ProcessManager.Client.Tests/Fixtures/ProcessManagerClientFixture.cs b/source/ProcessManager.Client.Tests/Fixtures/ProcessManagerClientFixture.cs
index fb99bcc5..0cfda011 100644
--- a/source/ProcessManager.Client.Tests/Fixtures/ProcessManagerClientFixture.cs
+++ b/source/ProcessManager.Client.Tests/Fixtures/ProcessManagerClientFixture.cs
@@ -80,7 +80,9 @@ public async Task DisposeAsync()
{
await ExampleOrchestrationsAppManager.DisposeAsync();
await ProcessManagerAppManager.DisposeAsync();
+
await DatabaseManager.DeleteDatabaseAsync();
+
AzuriteManager.Dispose();
}