Search in sources :

Example 1 with InputEntry

use of org.camunda.bpm.model.dmn.instance.InputEntry in project camunda-dmn-model by camunda.

the class ExampleCompatibilityTest method shouldGetElements.

@Test
public void shouldGetElements() {
    // Definitions
    Definitions definitions = modelInstance.getDefinitions();
    assertThat(definitions).isNotNull();
    assertThat(definitions.getId()).isEqualTo("definitions");
    assertThat(definitions.getName()).isEqualTo("definitions");
    assertThat(definitions.getNamespace()).isEqualTo(TEST_NAMESPACE);
    assertElementIsEqualToId(definitions, "definitions");
    // Imports
    Collection<Import> imports = definitions.getImports();
    assertThat(imports).isEmpty();
    // Item definitions
    Collection<ItemDefinition> itemDefinitions = definitions.getItemDefinitions();
    assertThat(itemDefinitions).isEmpty();
    // DRG elements
    Collection<DrgElement> drgElements = definitions.getDrgElements();
    assertThat(drgElements).isNotEmpty().hasSize(1);
    // Decision
    Decision decision = (Decision) drgElements.iterator().next();
    assertThat(decision).isNotNull();
    assertThat(decision.getId()).isEqualTo("decision");
    assertThat(decision.getName()).isEqualTo("Check Order");
    assertElementIsEqualToId(decision, "decision");
    // Decision table
    DecisionTable decisionTable = (DecisionTable) decision.getExpression();
    assertThat(decisionTable).isNotNull();
    assertThat(decisionTable.getId()).isEqualTo("decisionTable");
    assertElementIsEqualToId(decisionTable, "decisionTable");
    // Input clauses
    List<Input> inputs = new ArrayList<>(decisionTable.getInputs());
    assertThat(inputs).hasSize(2);
    Iterator<Input> inputIterator = inputs.iterator();
    // 1. Input clause
    Input input = inputIterator.next();
    assertThat(input.getId()).isEqualTo("input1");
    assertThat(input.getLabel()).isEqualTo("Customer Status");
    InputExpression inputExpression = input.getInputExpression();
    assertThat(inputExpression.getId()).isEqualTo("inputExpression1");
    assertThat(inputExpression.getTypeRef()).isEqualTo("string");
    assertThat(inputExpression.getText().getTextContent()).isEqualTo("status");
    InputValues inputValues = input.getInputValues();
    assertThat(inputValues.getText().getTextContent()).isEqualTo("\"bronze\",\"silver\",\"gold\"");
    // 2. Input clause
    input = inputIterator.next();
    assertThat(input.getId()).isEqualTo("input2");
    assertThat(input.getLabel()).isEqualTo("Order Sum");
    inputExpression = input.getInputExpression();
    assertThat(inputExpression.getId()).isEqualTo("inputExpression2");
    assertThat(inputExpression.getTypeRef()).isEqualTo("double");
    // Output clause
    List<Output> outputs = new ArrayList<>(decisionTable.getOutputs());
    assertThat(outputs).hasSize(2);
    // 1. Output clause
    Output output = outputs.get(0);
    assertThat(output.getId()).isEqualTo("output1");
    assertThat(output.getLabel()).isEqualTo("Check Result");
    assertThat(output.getName()).isEqualTo("result");
    assertThat(output.getTypeRef()).isEqualTo("string");
    OutputValues outputValues = output.getOutputValues();
    assertThat(outputValues.getText().getTextContent()).isEqualTo("\"ok\",\"notok\"");
    // 2. Output clause
    output = outputs.get(1);
    assertThat(output.getId()).isEqualTo("output2");
    assertThat(output.getLabel()).isEqualTo("Reason");
    assertThat(output.getName()).isEqualTo("reason");
    assertThat(output.getTypeRef()).isEqualTo("string");
    // Rules
    List<Rule> rules = new ArrayList<>(decisionTable.getRules());
    // 1. Rule
    Rule rule = rules.get(0);
    assertThat(rule.getId()).isEqualTo("rule1");
    List<InputEntry> inputEntries = new ArrayList<>(rule.getInputEntries());
    assertThat(inputEntries).hasSize(2);
    assertThat(inputEntries.get(0).getText().getTextContent()).isEqualTo("\"bronze\"");
    assertThat(inputEntries.get(1).getText().getTextContent()).isEmpty();
    List<OutputEntry> outputEntries = new ArrayList<>(rule.getOutputEntries());
    assertThat(outputEntries).hasSize(2);
    assertThat(outputEntries.get(0).getText().getTextContent()).isEqualTo("\"notok\"");
    assertThat(outputEntries.get(1).getText().getTextContent()).isEqualTo("\"work on your status first, as bronze you're not going to get anything\"");
    // 2. Rule
    rule = rules.get(1);
    assertThat(rule.getId()).isEqualTo("rule2");
    inputEntries = new ArrayList<>(rule.getInputEntries());
    assertThat(inputEntries).hasSize(2);
    assertThat(inputEntries.get(0).getText().getTextContent()).isEqualTo("\"silver\"");
    assertThat(inputEntries.get(1).getText().getTextContent()).isEqualTo("< 1000");
    outputEntries = new ArrayList<>(rule.getOutputEntries());
    assertThat(outputEntries).hasSize(2);
    assertThat(outputEntries.get(0).getText().getTextContent()).isEqualTo("\"ok\"");
    assertThat(outputEntries.get(1).getText().getTextContent()).isEqualTo("\"you little fish will get what you want\"");
    // 3. Rule
    rule = rules.get(2);
    assertThat(rule.getId()).isEqualTo("rule3");
    inputEntries = new ArrayList<>(rule.getInputEntries());
    assertThat(inputEntries).hasSize(2);
    assertThat(inputEntries.get(0).getText().getTextContent()).isEqualTo("\"silver\"");
    assertThat(inputEntries.get(1).getText().getTextContent()).isEqualTo(">= 1000");
    outputEntries = new ArrayList<>(rule.getOutputEntries());
    assertThat(outputEntries).hasSize(2);
    assertThat(outputEntries.get(0).getText().getTextContent()).isEqualTo("\"notok\"");
    assertThat(outputEntries.get(1).getText().getTextContent()).isEqualTo("\"you took too much man, you took too much!\"");
    // 4. Rule
    rule = rules.get(3);
    assertThat(rule.getId()).isEqualTo("rule4");
    inputEntries = new ArrayList<>(rule.getInputEntries());
    assertThat(inputEntries).hasSize(2);
    assertThat(inputEntries.get(0).getText().getTextContent()).isEqualTo("\"gold\"");
    assertThat(inputEntries.get(1).getText().getTextContent()).isEmpty();
    outputEntries = new ArrayList<>(rule.getOutputEntries());
    assertThat(outputEntries).hasSize(2);
    assertThat(outputEntries.get(0).getText().getTextContent()).isEqualTo("\"ok\"");
    assertThat(outputEntries.get(1).getText().getTextContent()).isEqualTo("\"you get anything you want\"");
    // Element collections
    Collection<ElementCollection> elementCollections = definitions.getElementCollections();
    assertThat(elementCollections).isEmpty();
    // Business contexts
    Collection<BusinessContextElement> businessContextElements = definitions.getBusinessContextElements();
    assertThat(businessContextElements).isEmpty();
}
Also used : Import(org.camunda.bpm.model.dmn.instance.Import) OutputEntry(org.camunda.bpm.model.dmn.instance.OutputEntry) ItemDefinition(org.camunda.bpm.model.dmn.instance.ItemDefinition) ArrayList(java.util.ArrayList) BusinessContextElement(org.camunda.bpm.model.dmn.instance.BusinessContextElement) DecisionTable(org.camunda.bpm.model.dmn.instance.DecisionTable) InputValues(org.camunda.bpm.model.dmn.instance.InputValues) Input(org.camunda.bpm.model.dmn.instance.Input) Output(org.camunda.bpm.model.dmn.instance.Output) ElementCollection(org.camunda.bpm.model.dmn.instance.ElementCollection) Definitions(org.camunda.bpm.model.dmn.instance.Definitions) InputExpression(org.camunda.bpm.model.dmn.instance.InputExpression) Decision(org.camunda.bpm.model.dmn.instance.Decision) InputEntry(org.camunda.bpm.model.dmn.instance.InputEntry) DrgElement(org.camunda.bpm.model.dmn.instance.DrgElement) OutputValues(org.camunda.bpm.model.dmn.instance.OutputValues) Rule(org.camunda.bpm.model.dmn.instance.Rule) Test(org.junit.Test)

Example 2 with InputEntry

use of org.camunda.bpm.model.dmn.instance.InputEntry in project camunda-dmn-model by camunda.

the class DmnWriterTest method shouldReadJDK9StyleModel.

/**
 * <p>There is an issue in JDK 9+ that changes how CDATA section are serialized:
 *
 * <p>https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8223291
 *
 * <p>&lt; JDK9:
 *
 * <pre>
 * &lt;inputEntry id="inputEntry1"&gt;
 *   &lt;text&gt;&lt;![CDATA[&gt;= 1000]]&gt;&lt;/text&gt;
 * &lt;/inputEntry&gt;
 * </pre>
 *
 * <p>(the text element has one child node, a CDATA section)
 *
 * <p>&gt;= JDK9:
 *
 * <pre>
 * &lt;inputEntry id="inputEntry1"&gt;
 *   &lt;text&gt;
 *     &lt;![CDATA[&gt;= 1000]]&gt;
 *   &lt;/text&gt;
 * &lt;/inputEntry&gt;
 * </pre>
 *
 * <p>(the text element has three child nodes, a text node, a CDATA section and another text node)
 *
 * <p>This test ensures, that a JDK9-formatted model can be read
 * and the text content method returns the CDATA value only
 */
@Test
public void shouldReadJDK9StyleModel() {
    DmnModelInstance modelInstance = Dmn.readModelFromStream(ExampleCompatibilityTest.class.getResourceAsStream("JDK9-style-CDATA.dmn"));
    Decision decision = (Decision) modelInstance.getDefinitions().getDrgElements().iterator().next();
    DecisionTable decisionTable = (DecisionTable) decision.getExpression();
    Rule rule = decisionTable.getRules().iterator().next();
    InputEntry inputEntry = rule.getInputEntries().iterator().next();
    String textContent = inputEntry.getText().getTextContent();
    assertThat(textContent).isEqualTo(">= 1000");
}
Also used : DecisionTable(org.camunda.bpm.model.dmn.instance.DecisionTable) Rule(org.camunda.bpm.model.dmn.instance.Rule) Decision(org.camunda.bpm.model.dmn.instance.Decision) InputEntry(org.camunda.bpm.model.dmn.instance.InputEntry) Test(org.junit.Test)

Example 3 with InputEntry

use of org.camunda.bpm.model.dmn.instance.InputEntry in project camunda-dmn-model by camunda.

the class ExpressionLanguageTest method shouldWriteExpressionLanguage.

@Test
public void shouldWriteExpressionLanguage() throws Exception {
    modelInstance = Dmn.createEmptyModel();
    Definitions definitions = generateNamedElement(Definitions.class, "definitions");
    definitions.setNamespace(TEST_NAMESPACE);
    definitions.setExpressionLanguage(EXPRESSION_LANGUAGE);
    modelInstance.setDocumentElement(definitions);
    Decision decision = generateNamedElement(Decision.class, "Check Order");
    definitions.addChildElement(decision);
    DecisionTable decisionTable = generateElement(DecisionTable.class);
    decision.addChildElement(decisionTable);
    Input input = generateElement(Input.class);
    decisionTable.getInputs().add(input);
    InputExpression inputExpression = generateElement(InputExpression.class);
    inputExpression.setExpressionLanguage(EXPRESSION_LANGUAGE);
    input.setInputExpression(inputExpression);
    InputValues inputValues = generateElement(InputValues.class);
    inputValues.setExpressionLanguage(EXPRESSION_LANGUAGE);
    inputValues.setText(generateElement(Text.class));
    input.setInputValues(inputValues);
    Output output = generateElement(Output.class);
    decisionTable.getOutputs().add(output);
    OutputValues outputValues = generateElement(OutputValues.class);
    outputValues.setExpressionLanguage(EXPRESSION_LANGUAGE);
    outputValues.setText(generateElement(Text.class));
    output.setOutputValues(outputValues);
    Rule rule = generateElement(Rule.class);
    decisionTable.getRules().add(rule);
    InputEntry inputEntry = generateElement(InputEntry.class);
    inputEntry.setExpressionLanguage(EXPRESSION_LANGUAGE);
    inputEntry.setText(generateElement(Text.class));
    rule.getInputEntries().add(inputEntry);
    OutputEntry outputEntry = generateElement(OutputEntry.class);
    outputEntry.setExpressionLanguage(EXPRESSION_LANGUAGE);
    rule.getOutputEntries().add(outputEntry);
    assertModelEqualsFile(EXPRESSION_LANGUAGE_DMN);
}
Also used : DecisionTable(org.camunda.bpm.model.dmn.instance.DecisionTable) InputValues(org.camunda.bpm.model.dmn.instance.InputValues) Input(org.camunda.bpm.model.dmn.instance.Input) OutputEntry(org.camunda.bpm.model.dmn.instance.OutputEntry) OutputValues(org.camunda.bpm.model.dmn.instance.OutputValues) Definitions(org.camunda.bpm.model.dmn.instance.Definitions) Output(org.camunda.bpm.model.dmn.instance.Output) Text(org.camunda.bpm.model.dmn.instance.Text) Rule(org.camunda.bpm.model.dmn.instance.Rule) InputExpression(org.camunda.bpm.model.dmn.instance.InputExpression) Decision(org.camunda.bpm.model.dmn.instance.Decision) InputEntry(org.camunda.bpm.model.dmn.instance.InputEntry) Test(org.junit.Test)

Example 4 with InputEntry

use of org.camunda.bpm.model.dmn.instance.InputEntry in project camunda-dmn-model by camunda.

the class ExpressionLanguageTest method shouldReadExpressionLanguage.

@Test
@DmnModelResource(resource = EXPRESSION_LANGUAGE_DMN)
public void shouldReadExpressionLanguage() {
    Definitions definitions = modelInstance.getDefinitions();
    assertThat(definitions.getExpressionLanguage()).isEqualTo(EXPRESSION_LANGUAGE);
    DecisionTable decisionTable = modelInstance.getModelElementById("decisionTable");
    Input input = decisionTable.getInputs().iterator().next();
    assertThat(input.getInputExpression().getExpressionLanguage()).isEqualTo(EXPRESSION_LANGUAGE);
    assertThat(input.getInputValues().getExpressionLanguage()).isEqualTo(EXPRESSION_LANGUAGE);
    Output output = decisionTable.getOutputs().iterator().next();
    assertThat(output.getOutputValues().getExpressionLanguage()).isEqualTo(EXPRESSION_LANGUAGE);
    Rule rule = decisionTable.getRules().iterator().next();
    InputEntry inputEntry = rule.getInputEntries().iterator().next();
    assertThat(inputEntry.getExpressionLanguage()).isEqualTo(EXPRESSION_LANGUAGE);
    OutputEntry outputEntry = rule.getOutputEntries().iterator().next();
    assertThat(outputEntry.getExpressionLanguage()).isEqualTo(EXPRESSION_LANGUAGE);
}
Also used : DecisionTable(org.camunda.bpm.model.dmn.instance.DecisionTable) Input(org.camunda.bpm.model.dmn.instance.Input) OutputEntry(org.camunda.bpm.model.dmn.instance.OutputEntry) Definitions(org.camunda.bpm.model.dmn.instance.Definitions) Output(org.camunda.bpm.model.dmn.instance.Output) Rule(org.camunda.bpm.model.dmn.instance.Rule) InputEntry(org.camunda.bpm.model.dmn.instance.InputEntry) Test(org.junit.Test) DmnModelResource(org.camunda.bpm.model.dmn.util.DmnModelResource)

Example 5 with InputEntry

use of org.camunda.bpm.model.dmn.instance.InputEntry in project camunda-engine-dmn by camunda.

the class DefaultDmnTransform method transformDecisionTableRule.

protected DmnDecisionTableRuleImpl transformDecisionTableRule(Rule rule) {
    DmnElementTransformHandler<Rule, DmnDecisionTableRuleImpl> handler = handlerRegistry.getHandler(Rule.class);
    DmnDecisionTableRuleImpl dmnRule = handler.handleElement(this, rule);
    // validate rule id
    if (dmnRule.getId() == null) {
        throw LOG.decisionTableRuleIdIsMissing(decision, dmnRule);
    }
    List<DmnDecisionTableInputImpl> inputs = this.decisionTable.getInputs();
    List<InputEntry> inputEntries = new ArrayList<InputEntry>(rule.getInputEntries());
    if (inputs.size() != inputEntries.size()) {
        throw LOG.differentNumberOfInputsAndInputEntries(inputs.size(), inputEntries.size(), dmnRule);
    }
    for (InputEntry inputEntry : inputEntries) {
        parent = dmnRule;
        DmnExpressionImpl condition = transformInputEntry(inputEntry);
        dmnRule.getConditions().add(condition);
    }
    List<DmnDecisionTableOutputImpl> outputs = this.decisionTable.getOutputs();
    List<OutputEntry> outputEntries = new ArrayList<OutputEntry>(rule.getOutputEntries());
    if (outputs.size() != outputEntries.size()) {
        throw LOG.differentNumberOfOutputsAndOutputEntries(outputs.size(), outputEntries.size(), dmnRule);
    }
    for (OutputEntry outputEntry : outputEntries) {
        parent = dmnRule;
        DmnExpressionImpl conclusion = transformOutputEntry(outputEntry);
        dmnRule.getConclusions().add(conclusion);
    }
    return dmnRule;
}
Also used : OutputEntry(org.camunda.bpm.model.dmn.instance.OutputEntry) ArrayList(java.util.ArrayList) InputEntry(org.camunda.bpm.model.dmn.instance.InputEntry) DmnDecisionTableInputImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionTableInputImpl) DmnDecisionTableOutputImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionTableOutputImpl) DmnExpressionImpl(org.camunda.bpm.dmn.engine.impl.DmnExpressionImpl) DmnDecisionTableRuleImpl(org.camunda.bpm.dmn.engine.impl.DmnDecisionTableRuleImpl) Rule(org.camunda.bpm.model.dmn.instance.Rule)

Aggregations

InputEntry (org.camunda.bpm.model.dmn.instance.InputEntry)9 Rule (org.camunda.bpm.model.dmn.instance.Rule)8 DecisionTable (org.camunda.bpm.model.dmn.instance.DecisionTable)7 OutputEntry (org.camunda.bpm.model.dmn.instance.OutputEntry)7 Test (org.junit.Test)7 Decision (org.camunda.bpm.model.dmn.instance.Decision)6 Definitions (org.camunda.bpm.model.dmn.instance.Definitions)6 Input (org.camunda.bpm.model.dmn.instance.Input)6 Output (org.camunda.bpm.model.dmn.instance.Output)6 InputExpression (org.camunda.bpm.model.dmn.instance.InputExpression)5 InputValues (org.camunda.bpm.model.dmn.instance.InputValues)5 OutputValues (org.camunda.bpm.model.dmn.instance.OutputValues)5 ArrayList (java.util.ArrayList)3 Text (org.camunda.bpm.model.dmn.instance.Text)3 BusinessContextElement (org.camunda.bpm.model.dmn.instance.BusinessContextElement)2 DrgElement (org.camunda.bpm.model.dmn.instance.DrgElement)2 ElementCollection (org.camunda.bpm.model.dmn.instance.ElementCollection)2 Import (org.camunda.bpm.model.dmn.instance.Import)2 ItemDefinition (org.camunda.bpm.model.dmn.instance.ItemDefinition)2 DmnDecisionTableInputImpl (org.camunda.bpm.dmn.engine.impl.DmnDecisionTableInputImpl)1