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

Add evaluate decision feature #548

Merged
merged 6 commits into from
Jul 19, 2023
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
3 changes: 3 additions & 0 deletions Client.IntegrationTests/Client.IntegrationTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
<None Update="Resources\oneTaskProcess.bpmn">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Resources\dinnerDecisions.dmn">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
Expand Down
69 changes: 69 additions & 0 deletions Client.IntegrationTests/EvaluateDecisionTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//
// Copyright (c) 2021 camunda services GmbH (info@camunda.com)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// 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;
using System.IO;
using System.Threading.Tasks;
using NUnit.Framework;
using Zeebe.Client;

namespace Client.IntegrationTests;

[TestFixture]
public class EvaluateDecisionTest
{
private static readonly string DecisionPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", "dinnerDecisions.dmn");
private static readonly string DevisionEvaluationVariables = "{\"season\":\"Fall\", \"guestCount\":12}";

private readonly ZeebeIntegrationTestHelper testHelper = ZeebeIntegrationTestHelper.Latest();
private IZeebeClient zeebeClient;

[OneTimeSetUp]
public async Task Setup()
{
zeebeClient = await testHelper.SetupIntegrationTest();
}

[OneTimeTearDown]
public async Task Stop()
{
await testHelper.TearDownIntegrationTest();
}

[Test]
public async Task ShouldEvaluateDecision()
{
// given
var deployResponse = await zeebeClient.NewDeployCommand()
.AddResourceFile(DecisionPath)
.Send();
var decisionKey = deployResponse.Decisions[0].DecisionKey;

// when
var evaluateDecisionResponse = await zeebeClient
.NewEvaluateDecisionCommand()
.DecisionKey(decisionKey)
.Variables(DevisionEvaluationVariables)
.Send();

// then
Assert.AreEqual(evaluateDecisionResponse.DecisionVersion, 1);
Assert.AreEqual(decisionKey, evaluateDecisionResponse.DecisionKey);
Assert.AreEqual("dish", evaluateDecisionResponse.DecisionId);
Assert.Greater(evaluateDecisionResponse.DecisionKey, 1);
// right now it seems the DMN engine returns an double quated string
Assert.AreEqual("\"Stew\"", evaluateDecisionResponse.DecisionOutput);
}
}
95 changes: 95 additions & 0 deletions Client.IntegrationTests/Resources/dinnerDecisions.dmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="https://www.omg.org/spec/DMN/20191111/MODEL/" xmlns:camunda="http://camunda.org/schema/1.0/dmn" xmlns:dmndi="https://www.omg.org/spec/DMN/20191111/DMNDI/" xmlns:dc="http://www.omg.org/spec/DMN/20180521/DC/" id="dinnerDecisions" name="Dinner Decisions" namespace="http://camunda.org/schema/1.0/dmn" exporter="Camunda Modeler" exporterVersion="4.2.0">
<decision id="dish" name="Dish">
<decisionTable id="decisionTable">
<input id="input1" label="Season" camunda:inputVariable="">
<inputExpression id="inputExpression1" typeRef="string">
<text>season</text>
</inputExpression>
</input>
<input id="InputClause_0rwlbk7" label="How many guests" camunda:inputVariable="">
<inputExpression id="LiteralExpression_0h5951a" typeRef="integer">
<text>guestCount</text>
</inputExpression>
</input>
<output id="output1" label="Dish" name="desiredDish" typeRef="string" />
<rule id="row-129502239-1">
<description></description>
<inputEntry id="UnaryTests_0e47zyl">
<text>"Fall"</text>
</inputEntry>
<inputEntry id="UnaryTests_1132erh">
<text>&lt;= 8</text>
</inputEntry>
<outputEntry id="LiteralExpression_0wv4x30">
<text>"Spareribs"</text>
</outputEntry>
</rule>
<rule id="row-129502239-2">
<inputEntry id="UnaryTests_0iwabd6">
<text>"Winter"</text>
</inputEntry>
<inputEntry id="UnaryTests_10qbns7">
<text>&lt;= 8</text>
</inputEntry>
<outputEntry id="LiteralExpression_0ysj59c">
<text>"Roastbeef"</text>
</outputEntry>
</rule>
<rule id="row-129502239-3">
<inputEntry id="UnaryTests_1nu2fxo">
<text>"Spring"</text>
</inputEntry>
<inputEntry id="UnaryTests_1b4mcpz">
<text>&lt;= 4</text>
</inputEntry>
<outputEntry id="LiteralExpression_1osqv9r">
<text>"Dry Aged Gourmet Steak"</text>
</outputEntry>
</rule>
<rule id="row-129502239-4">
<description>Save money</description>
<inputEntry id="UnaryTests_0vux2zw">
<text>"Spring"</text>
</inputEntry>
<inputEntry id="UnaryTests_07v2n3t">
<text>[5..8]</text>
</inputEntry>
<outputEntry id="LiteralExpression_11v4xrs">
<text>"Steak"</text>
</outputEntry>
</rule>
<rule id="row-129502239-5">
<description>Less effort</description>
<inputEntry id="UnaryTests_0p7gr7e">
<text>"Fall","Winter","Spring"</text>
</inputEntry>
<inputEntry id="UnaryTests_0zebpmx">
<text>&gt; 8</text>
</inputEntry>
<outputEntry id="LiteralExpression_0maai06">
<text>"Stew"</text>
</outputEntry>
</rule>
<rule id="row-129502239-6">
<description>Hey, why not?</description>
<inputEntry id="UnaryTests_1e1us67">
<text>"Summer"</text>
</inputEntry>
<inputEntry id="UnaryTests_0q3acue">
<text></text>
</inputEntry>
<outputEntry id="LiteralExpression_0ewtv5x">
<text>"Light Salad and nice Steak"</text>
</outputEntry>
</rule>
</decisionTable>
</decision>
<dmndi:DMNDI>
<dmndi:DMNDiagram id="DMNDiagram_0lnw6sm">
<dmndi:DMNShape id="DMNShape_0h820uh" dmnElementRef="dish">
<dc:Bounds height="80" width="180" x="150" y="80" />
</dmndi:DMNShape>
</dmndi:DMNDiagram>
</dmndi:DMNDI>
</definitions>
Loading