Skip to content

Commit 0577d09

Browse files
committed
fix(Sdk): Added missing validation pass for SwitchState's default condition property
fix(Sdk): Renamed the ConditionType enum into SwitchCaseOutputType fix(Sdk): Fixed the DefaultCaseDefinition to inherit the SwitchCaseDefinition class
1 parent fbb18b5 commit 0577d09

15 files changed

+239
-231
lines changed

src/ServerlessWorkflow.Sdk.UnitTests/Cases/Services/WorkflowValidatorTests.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public async Task Validate_Yaml_ShouldWork()
3434
public async Task Validate_Json_ShouldWork()
3535
{
3636
//arrange
37-
var yaml = File.ReadAllText(Path.Combine("Resources", "Workflows", "operation.json"));
38-
var workflow = await this.Reader.ParseAsync(yaml);
37+
var json = File.ReadAllText(Path.Combine("Resources", "Workflows", "operation.json"));
38+
var workflow = await this.Reader.ParseAsync(json);
3939

4040
//act
4141
var validationResult = await this.Validator.ValidateAsync(workflow);
@@ -45,6 +45,21 @@ public async Task Validate_Json_ShouldWork()
4545
validationResult.IsValid.Should().BeTrue();
4646
}
4747

48+
[Fact]
49+
public async Task Validate_Invalid_Json_ShouldFail()
50+
{
51+
//arrange
52+
var json = File.ReadAllText(Path.Combine("Resources", "Workflows", "missing-transition.json"));
53+
var workflow = await this.Reader.ParseAsync(json);
54+
//act
55+
var validationResult = await this.Validator.ValidateAsync(workflow);
56+
57+
//assert
58+
validationResult.Should().NotBeNull();
59+
validationResult.IsValid.Should().BeFalse();
60+
validationResult.DslValidationErrors.Should().NotBeEmpty();
61+
}
62+
4863
}
4964

5065
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"id": "compensation-test",
3+
"name": "Compensation Test",
4+
"version": "0.1.0",
5+
"specVersion": "0.8",
6+
"functions": [
7+
{
8+
"name": "is-odd",
9+
"type": "expression",
10+
"operation": ".number % 2 == 1"
11+
},
12+
{
13+
"name": "i-fail",
14+
"type": "rest",
15+
"operation": "http://somefail.com/fails#fake"
16+
}
17+
],
18+
"states": [
19+
{
20+
"name": "Good odds",
21+
"type": "switch",
22+
"dataConditions": [
23+
{
24+
"name": "Is Odd",
25+
"condition": "${ fn:is-odd }",
26+
"end": true
27+
}
28+
],
29+
"defaultCondition": {
30+
"transition": "Non existing state, should not be valid"
31+
}
32+
},
33+
{
34+
"name": "I have something to compensate...",
35+
"type": "operation",
36+
"actions": [
37+
{
38+
"name": "Call i-fail",
39+
"functionRef": {
40+
"refName": "i-fail"
41+
}
42+
}
43+
],
44+
"compensatedBy": "Compensate",
45+
"end": true
46+
},
47+
{
48+
"name": "Compensate",
49+
"type": "inject",
50+
"data": {
51+
"status": "compensated"
52+
},
53+
"usedForCompensation": true,
54+
"end": true
55+
}
56+
]
57+
}

src/ServerlessWorkflow.Sdk.UnitTests/ServerlessWorkflow.Sdk.UnitTests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@
6565
<None Update="Resources\workflows\externalref.json">
6666
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
6767
</None>
68+
<None Update="Resources\workflows\missing-transition.json">
69+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
70+
</None>
6871
<None Update="Resources\workflows\operation.json">
6972
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
7073
</None>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2021-Present The Serverless Workflow Specification Authors
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
namespace ServerlessWorkflow.Sdk.Models
19+
{
20+
21+
/// <summary>
22+
/// Represents an object used to define the transition of the workflow if there is no matching cases or event timeout is reached
23+
/// </summary>
24+
[ProtoContract]
25+
[DataContract]
26+
public class DefaultCaseDefinition
27+
: SwitchCaseDefinition
28+
{
29+
30+
31+
32+
}
33+
34+
}

src/ServerlessWorkflow.Sdk/Models/DefaultConditionDefinition.cs

Lines changed: 0 additions & 163 deletions
This file was deleted.

src/ServerlessWorkflow.Sdk/Models/SwitchCaseDefinition.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ public abstract class SwitchCaseDefinition
3838
[YamlIgnore]
3939
[ProtoIgnore]
4040
[IgnoreDataMember]
41-
public ConditionType Type
41+
public SwitchCaseOutcomeType OutcomeType
4242
{
4343
get
4444
{
4545
if (this.Transition != null)
46-
return ConditionType.Transition;
46+
return SwitchCaseOutcomeType.Transition;
4747
else
48-
return ConditionType.End;
48+
return SwitchCaseOutcomeType.End;
4949
}
5050
}
5151

src/ServerlessWorkflow.Sdk/Models/SwitchStateDefinition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public virtual SwitchStateType SwitchType
8787
[Newtonsoft.Json.JsonRequired]
8888
[ProtoMember(3, IsRequired = true)]
8989
[DataMember(Order = 3, IsRequired = true)]
90-
public virtual DefaultConditionDefinition DefaultCondition { get; set; } = null!;
90+
public virtual DefaultCaseDefinition DefaultCondition { get; set; } = null!;
9191

9292
/// <summary>
9393
/// Gets the <see cref="SwitchCaseDefinition"/> with the specified name

src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
<TargetFramework>net6.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<NeutralLanguage>en</NeutralLanguage>
7-
<AssemblyVersion>0.8.1.13</AssemblyVersion>
8-
<FileVersion>0.8.1.13</FileVersion>
9-
<Version>0.8.1.13</Version>
7+
<AssemblyVersion>0.8.1.14</AssemblyVersion>
8+
<FileVersion>0.8.1.14</FileVersion>
9+
<Version>0.8.1.14</Version>
1010
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1111
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
1212
<PackageLicenseFile>LICENSE</PackageLicenseFile>

0 commit comments

Comments
 (0)