Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deployment): Added support for form deployment response #649

Merged
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
32 changes: 26 additions & 6 deletions Client.UnitTests/DeploymentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Zeebe.Client
public class DeploymentTest : BaseZeebeTest
{
private readonly string _demoProcessPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", "demo-process.bpmn");
private readonly string _demoFormPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", "demo-form.form");

[Test]
public async Task ShouldSendDeployResourceFileAsExpected()
Expand Down Expand Up @@ -240,16 +241,16 @@ public async Task ShouldSendMultipleDeployResourceAsExpected()
},
new Resource
{
Content = ByteString.FromStream(File.OpenRead(_demoProcessPath)),
Name = _demoProcessPath,
Content = ByteString.FromStream(File.OpenRead(_demoFormPath)),
Name = _demoFormPath,
}
}
};

// when
await ZeebeClient.NewDeployCommand()
.AddResourceFile(_demoProcessPath)
.AddResourceStream(File.OpenRead(_demoProcessPath), _demoProcessPath)
.AddResourceStream(File.OpenRead(_demoFormPath), _demoFormPath)
.Send();

// then
Expand Down Expand Up @@ -299,24 +300,36 @@ public async Task ShouldSendMultipleDeployResourceAndGetResponseAsExpected()
DmnDecisionRequirementsId = "id",
DmnDecisionRequirementsName = "nameRequirement"
}
},
new Deployment
{
Form = new FormMetadata
{
FormKey = 3,
Version = 1,
ResourceName = "form",
FormId = "demoForm",
TenantId = "formTenantId"
}
}
}
};

TestService.AddRequestHandler(typeof(DeployResourceRequest), request => expectedResponse);

// when
var fileContent = File.ReadAllText(_demoProcessPath);
var processFileContent = await File.ReadAllTextAsync(_demoProcessPath);
var deployProcessResponse = await ZeebeClient.NewDeployCommand()
.AddResourceFile(_demoProcessPath)
.AddResourceString(fileContent, Encoding.UTF8, _demoProcessPath)
.AddResourceString(processFileContent, Encoding.UTF8, _demoProcessPath)
.AddResourceFile(_demoFormPath)
.Send();

// then
Assert.AreEqual(1, deployProcessResponse.Key);
Assert.AreEqual(1, deployProcessResponse.Processes.Count);
Assert.AreEqual(1, deployProcessResponse.Decisions.Count);
Assert.AreEqual(1, deployProcessResponse.DecisionRequirements.Count);
Assert.AreEqual(1, deployProcessResponse.Forms.Count);

var processMetadata = deployProcessResponse.Processes[0];
Assert.AreEqual("process", processMetadata.BpmnProcessId);
Expand All @@ -338,6 +351,13 @@ public async Task ShouldSendMultipleDeployResourceAndGetResponseAsExpected()
Assert.AreEqual("requirement", decisionRequirementsMetadata.ResourceName);
Assert.AreEqual("nameRequirement", decisionRequirementsMetadata.DmnDecisionRequirementsName);
Assert.AreEqual("id", decisionRequirementsMetadata.DmnDecisionRequirementsId);

var formMetadata = deployProcessResponse.Forms[0];
Assert.AreEqual(3, formMetadata.FormKey);
Assert.AreEqual(1, formMetadata.Version);
Assert.AreEqual("form", formMetadata.ResourceName);
Assert.AreEqual("demoForm", formMetadata.FormId);
Assert.AreEqual("formTenantId", formMetadata.TenantId);
}

[Test]
Expand Down
23 changes: 23 additions & 0 deletions Client.UnitTests/Resources/demo-form.form
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"components": [
{
"label": "Demo checkbox",
"type": "checkbox",
"layout": {
"row": "Row_0b67lfv",
"columns": null
},
"id": "Field_18jrp23",
"key": "demoCheckbox"
}
],
"type": "default",
"id": "demoForm",
"executionPlatform": "Camunda Cloud",
"executionPlatformVersion": "8.4.0",
"exporter": {
"name": "Camunda Modeler",
"version": "5.19.0"
},
"schemaVersion": 14
}
3 changes: 3 additions & 0 deletions Client/Api/Responses/IDeployResourceResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ public interface IDeployResourceResponse

/// <returns>the decision requirements which are deployed </returns>
IList<IDecisionRequirementsMetadata> DecisionRequirements { get; }

/// <returns>the forms which are deployed</returns>
IList<IFormMetadata> Forms { get; }
}
}
19 changes: 19 additions & 0 deletions Client/Api/Responses/IFormMetadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Zeebe.Client.Api.Responses;

public interface IFormMetadata
{
/// <returns>the form ID of the deployed form.</returns>
string FormId { get; }

/// <returns>the version of the deployed form.</returns>
int Version { get; }

/// <returns>the key of the deployed form.</returns>
long FormKey { get; }

/// <returns>the name of the deployment resource which contains the form.</returns>
string ResourceName { get; }

/// <returns>the tenant ID of the deployed form.</returns>
string TenantId { get; }
}
sindremb marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 5 additions & 1 deletion Client/Impl/Responses/DeployResourceResponse.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using GatewayProtocol;
using Zeebe.Client.Api.Responses;

Expand All @@ -12,13 +11,15 @@ public class DeployResourceResponse : IDeployResourceResponse
public IList<IProcessMetadata> Processes { get; }
public IList<IDecisionMetadata> Decisions { get; }
public IList<IDecisionRequirementsMetadata> DecisionRequirements { get; }
public IList<IFormMetadata> Forms { get; }

public DeployResourceResponse(GatewayProtocol.DeployResourceResponse response)
{
Key = response.Key;
Processes = new List<IProcessMetadata>();
Decisions = new List<IDecisionMetadata>();
DecisionRequirements = new List<IDecisionRequirementsMetadata>();
Forms = new List<IFormMetadata>();

foreach (var deployment in response.Deployments)
{
Expand All @@ -33,6 +34,9 @@ public DeployResourceResponse(GatewayProtocol.DeployResourceResponse response)
case Deployment.MetadataOneofCase.DecisionRequirements:
DecisionRequirements.Add(new DecisionRequirementsMetadata(deployment.DecisionRequirements));
break;
case Deployment.MetadataOneofCase.Form:
Forms.Add(new FormMetadata(deployment.Form));
break;
default:
throw new NotImplementedException("Got deployment response for unexpected type: " +
deployment.MetadataCase);
Expand Down
21 changes: 21 additions & 0 deletions Client/Impl/Responses/FormMetadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Zeebe.Client.Api.Responses;

namespace Zeebe.Client.Impl.Responses;

public class FormMetadata : IFormMetadata
{
public string FormId { get; }
public int Version { get; }
public long FormKey { get; }
public string ResourceName { get; }
public string TenantId { get; }

public FormMetadata(GatewayProtocol.FormMetadata metadata)
{
FormId = metadata.FormId;
Version = metadata.Version;
FormKey = metadata.FormKey;
ResourceName = metadata.ResourceName;
TenantId = metadata.TenantId;
}
}