-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[incubator-kie-issues#1411] Adapting code to deal with full href defi…
…nition (namespace#local_part) for local elements. (#6050) Co-authored-by: Gabriele-Cardosi <[email protected]>
- Loading branch information
Showing
6 changed files
with
192 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNCompilerImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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. | ||
*/ | ||
package org.kie.dmn.core.compiler; | ||
|
||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.kie.dmn.model.api.DMNElementReference; | ||
import org.kie.dmn.model.api.Definitions; | ||
import org.kie.dmn.model.api.InformationRequirement; | ||
import org.kie.dmn.model.v1_5.TDMNElementReference; | ||
import org.kie.dmn.model.v1_5.TDefinitions; | ||
import org.kie.dmn.model.v1_5.TInformationRequirement; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class DMNCompilerImplTest { | ||
|
||
private static final String nameSpace = "http://www.montera.com.au/spec/DMN/local-hrefs"; | ||
private static Definitions parent; | ||
|
||
@BeforeAll | ||
static void setup() { | ||
String modelName = "LocalHrefs"; | ||
parent = new TDefinitions(); | ||
parent.setName(modelName); | ||
parent.setNamespace(nameSpace); | ||
} | ||
|
||
@Test | ||
void getId() { | ||
String localPart = "reference"; | ||
DMNElementReference elementReference = new TDMNElementReference(); | ||
elementReference.setHref(String.format("%s#%s", nameSpace, localPart)); | ||
elementReference.setParent(parent); | ||
String retrieved = DMNCompilerImpl.getId(elementReference); | ||
assertThat(retrieved).isNotNull().isEqualTo(localPart); | ||
|
||
String expected = String.format("%s#%s", "http://a-different-namespace", localPart); | ||
elementReference.setHref(expected); | ||
retrieved = DMNCompilerImpl.getId(elementReference); | ||
assertThat(retrieved).isNotNull().isEqualTo(expected); | ||
} | ||
|
||
@Test | ||
void getRootElement() { | ||
String localPart = "reference"; | ||
DMNElementReference elementReference = new TDMNElementReference(); | ||
String href = String.format("%s#%s", nameSpace, localPart); | ||
elementReference.setHref(href); | ||
elementReference.setParent(parent); | ||
Definitions retrieved = DMNCompilerImpl.getRootElement(elementReference); | ||
assertThat(retrieved).isNotNull().isEqualTo(parent); | ||
|
||
InformationRequirement informationRequirement = new TInformationRequirement(); | ||
elementReference.setParent(informationRequirement); | ||
assertThrows(RuntimeException.class, () -> DMNCompilerImpl.getRootElement(elementReference)); | ||
|
||
informationRequirement.setParent(parent); | ||
retrieved = DMNCompilerImpl.getRootElement(elementReference); | ||
assertThat(retrieved).isNotNull().isEqualTo(parent); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
kie-dmn/kie-dmn-test-resources/src/test/resources/valid_models/DMNv1_5/LocalHrefs.dmn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<definitions namespace="http://www.montera.com.au/spec/DMN/local-hrefs" | ||
name="LocalHrefs" | ||
xmlns="https://www.omg.org/spec/DMN/20230324/MODEL/"> | ||
|
||
<description>Local (non-imported) qualified hrefs</description> | ||
|
||
<inputData name="input_001" id="_input_001"> | ||
<variable name="input_001" typeRef="string"/> | ||
</inputData> | ||
|
||
<decision name="decision_001" id="_decision_001"> | ||
<variable name="decision_001" typeRef="string"/> | ||
<literalExpression> | ||
<text>"decision_001"</text> | ||
</literalExpression> | ||
</decision> | ||
|
||
<businessKnowledgeModel name="bkm_001" id="_bkm_001"> | ||
<variable name="bkm_001"/> | ||
<encapsulatedLogic> | ||
<literalExpression> | ||
<text>"bkm_001"</text> | ||
</literalExpression> | ||
</encapsulatedLogic> | ||
</businessKnowledgeModel> | ||
|
||
<!-- requirements hrefs refer to elements in this model --> | ||
<decision name="decision_002" id="_decision_002"> | ||
<variable name="decision_002" typeRef="string"/> | ||
<informationRequirement> | ||
<requiredDecision href="http://www.montera.com.au/spec/DMN/local-hrefs#_decision_001"/> | ||
</informationRequirement> | ||
<informationRequirement> | ||
<requiredInput href="http://www.montera.com.au/spec/DMN/local-hrefs#_input_001"/> | ||
</informationRequirement> | ||
<knowledgeRequirement> | ||
<requiredKnowledge href="http://www.montera.com.au/spec/DMN/local-hrefs#_bkm_001"/> | ||
</knowledgeRequirement> | ||
<literalExpression> | ||
<text>decision_001 + " " + input_001 + " " + bkm_001()</text> | ||
</literalExpression> | ||
</decision> | ||
|
||
</definitions> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters