Skip to content

Commit

Permalink
test: add multiple dmn deployment test
Browse files Browse the repository at this point in the history
Our testcases were missing a scenario where we deploy multiple DRGs at once.
  • Loading branch information
remcowesterhoud committed May 20, 2022
1 parent 751140f commit 4a912e0
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public final class DeploymentDmnTest {
private static final String DMN_DECISION_TABLE_V2 = "/dmn/decision-table_v2.dmn";
private static final String DMN_DECISION_TABLE_RENAMED_DRG =
"/dmn/decision-table-with-renamed-drg.dmn";
private static final String DMN_DECISION_TABLE_RENAMED_DRG_AND_DECISION =
"/dmn/decision-table-with-renamed-drg-and-decision.dmn";

private static final String DMN_INVALID_EXPRESSION =
"/dmn/decision-table-with-invalid-expression.dmn";
Expand Down Expand Up @@ -373,6 +375,55 @@ public void shouldDeployDecisionWithTwoDrg() {
tuple("jedi_or_sith", 3, "force_users"));
}

@Test
public void shouldDeployIfMultipleDrgHaveDifferentId() {
// when
final var deploymentEvent =
engine
.deployment()
.withXmlClasspathResource(DMN_DECISION_TABLE)
.withXmlClasspathResource(DMN_DECISION_TABLE_RENAMED_DRG_AND_DECISION)
.deploy();

// then
Assertions.assertThat(deploymentEvent)
.hasIntent(DeploymentIntent.CREATED)
.hasValueType(ValueType.DEPLOYMENT)
.hasRecordType(RecordType.EVENT);

assertThat(deploymentEvent.getValue().getDecisionRequirementsMetadata()).hasSize(2);

final var drgMetadata = deploymentEvent.getValue().getDecisionRequirementsMetadata().get(0);
Assertions.assertThat(drgMetadata).hasDecisionRequirementsId("force_users");
assertThat(drgMetadata.getDecisionRequirementsKey()).isPositive();
assertThat(drgMetadata.getChecksum())
.describedAs("Expect the MD5 checksum of the DMN resource")
.isEqualTo(getChecksum(DMN_DECISION_TABLE));

assertThat(deploymentEvent.getValue().getDecisionsMetadata()).hasSize(2);

final var decisionMetadata = deploymentEvent.getValue().getDecisionsMetadata().get(0);
Assertions.assertThat(decisionMetadata)
.hasDecisionId("jedi_or_sith")
.hasDecisionRequirementsKey(drgMetadata.getDecisionRequirementsKey());
assertThat(decisionMetadata.getDecisionKey()).isPositive();

final var drgMetadata2 = deploymentEvent.getValue().getDecisionRequirementsMetadata().get(1);
Assertions.assertThat(drgMetadata2).hasDecisionRequirementsId("star-wars");
assertThat(drgMetadata2.getDecisionRequirementsKey()).isPositive();
assertThat(drgMetadata2.getChecksum())
.describedAs("Expect the MD5 checksum of the DMN resource")
.isEqualTo(getChecksum(DMN_DECISION_TABLE_RENAMED_DRG_AND_DECISION));

assertThat(deploymentEvent.getValue().getDecisionsMetadata()).hasSize(2);

final var decisionMetadata2 = deploymentEvent.getValue().getDecisionsMetadata().get(1);
Assertions.assertThat(decisionMetadata2)
.hasDecisionId("sith_or_jedi")
.hasDecisionRequirementsKey(drgMetadata2.getDecisionRequirementsKey());
assertThat(decisionMetadata2.getDecisionKey()).isPositive();
}

@Test
public void shouldRejectIfMultipleDrgHaveTheSameId() {
// when
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="https://www.omg.org/spec/DMN/20191111/MODEL/" xmlns:dmndi="https://www.omg.org/spec/DMN/20191111/DMNDI/" xmlns:dc="http://www.omg.org/spec/DMN/20180521/DC/" xmlns:biodi="http://bpmn.io/schema/dmn/biodi/2.0" id="star-wars" name="Star Wars" namespace="http://camunda.org/schema/1.0/dmn" exporter="Camunda Modeler" exporterVersion="5.0.0">
<decision id="sith_or_jedi" name="Jedi or Sith">
<decisionTable id="DecisionTable_14n3bxx">
<input id="Input_1" label="Lightsaber color" biodi:width="192">
<inputExpression id="InputExpression_1" typeRef="string">
<text>lightsaberColor</text>
</inputExpression>
</input>
<output id="Output_1" label="Jedi or Sith" name="jedi_or_sith" typeRef="string" biodi:width="192">
<outputValues id="UnaryTests_0hj346a">
<text>"Jedi","Sith"</text>
</outputValues>
</output>
<rule id="DecisionRule_0zumznl">
<inputEntry id="UnaryTests_0leuxqi">
<text>"blue"</text>
</inputEntry>
<outputEntry id="LiteralExpression_0c9vpz8">
<text>"Jedi"</text>
</outputEntry>
</rule>
<rule id="DecisionRule_1utwb1e">
<inputEntry id="UnaryTests_1v3sd4m">
<text>"green"</text>
</inputEntry>
<outputEntry id="LiteralExpression_0tgh8k1">
<text>"Jedi"</text>
</outputEntry>
</rule>
<rule id="DecisionRule_1bwgcym">
<inputEntry id="UnaryTests_0n1ewm3">
<text>"red"</text>
</inputEntry>
<outputEntry id="LiteralExpression_19xnlkw">
<text>"Sith"</text>
</outputEntry>
</rule>
</decisionTable>
</decision>
<dmndi:DMNDI>
<dmndi:DMNDiagram>
<dmndi:DMNShape dmnElementRef="sith_or_jedi">
<dc:Bounds height="80" width="180" x="160" y="100" />
</dmndi:DMNShape>
</dmndi:DMNDiagram>
</dmndi:DMNDI>
</definitions>

0 comments on commit 4a912e0

Please sign in to comment.