Search in sources :

Example 1 with UnaryTests

use of org.kie.workbench.common.dmn.api.definition.model.UnaryTests in project kie-wb-common by kiegroup.

the class UnaryTestsPropertyConverter method wbFromDMN.

public static UnaryTests wbFromDMN(final org.kie.dmn.model.api.UnaryTests dmn) {
    if (dmn == null) {
        return null;
    }
    final Id id = new Id(dmn.getId());
    final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    final ExpressionLanguage expressionLanguage = ExpressionLanguagePropertyConverter.wbFromDMN(dmn.getExpressionLanguage());
    final ConstraintType constraintTypeField;
    final QName key = new QName(DMNModelInstrumentedBase.Namespace.KIE.getUri(), ConstraintType.CONSTRAINT_KEY, DMNModelInstrumentedBase.Namespace.KIE.getPrefix());
    if (dmn.getAdditionalAttributes().containsKey(key)) {
        constraintTypeField = ConstraintTypeFieldPropertyConverter.wbFromDMN(dmn.getAdditionalAttributes().get(key));
    } else {
        constraintTypeField = NONE;
    }
    final UnaryTests result = new UnaryTests(id, description, new Text(dmn.getText()), expressionLanguage, constraintTypeField);
    return result;
}
Also used : Description(org.kie.workbench.common.dmn.api.property.dmn.Description) QName(javax.xml.namespace.QName) ConstraintType(org.kie.workbench.common.dmn.api.definition.model.ConstraintType) Text(org.kie.workbench.common.dmn.api.property.dmn.Text) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) ExpressionLanguage(org.kie.workbench.common.dmn.api.property.dmn.ExpressionLanguage) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) IsUnaryTests(org.kie.workbench.common.dmn.api.definition.model.IsUnaryTests)

Example 2 with UnaryTests

use of org.kie.workbench.common.dmn.api.definition.model.UnaryTests in project kie-wb-common by kiegroup.

the class MoveColumnsCommandTest method setUp.

@Before
public void setUp() {
    this.dtable = new DecisionTable();
    this.uiModel = new DMNGridData();
    dtable.getInput().add(inputClauseOne);
    dtable.getInput().add(inputClauseTwo);
    dtable.getInput().add(inputClauseThree);
    dtable.getOutput().add(outputClauseOne);
    dtable.getOutput().add(outputClauseTwo);
    dtable.getOutput().add(outputClauseThree);
    dtable.getAnnotations().add(annotationClauseOne);
    dtable.getAnnotations().add(annotationClauseTwo);
    dtable.getAnnotations().add(annotationClauseThree);
    dtable.getRule().add(new DecisionRule() {

        {
            getInputEntry().add(new UnaryTests());
            getInputEntry().add(new UnaryTests());
            getInputEntry().add(new UnaryTests());
            getOutputEntry().add(new LiteralExpression());
            getOutputEntry().add(new LiteralExpression());
            getOutputEntry().add(new LiteralExpression());
            getAnnotationEntry().add(new RuleAnnotationClauseText());
            getAnnotationEntry().add(new RuleAnnotationClauseText());
            getAnnotationEntry().add(new RuleAnnotationClauseText());
        }
    });
    uiModel.appendColumn(uiRowNumberColumn);
    uiModel.appendColumn(uiInputClauseColumnOne);
    uiModel.appendColumn(uiInputClauseColumnTwo);
    uiModel.appendColumn(uiInputClauseColumnThree);
    uiModel.appendColumn(uiOutputClauseColumnOne);
    uiModel.appendColumn(uiOutputClauseColumnTwo);
    uiModel.appendColumn(uiOutputClauseColumnThree);
    uiModel.appendColumn(uiRuleAnnotationClauseColumnOne);
    uiModel.appendColumn(uiRuleAnnotationClauseColumnTwo);
    uiModel.appendColumn(uiRuleAnnotationClauseColumnThree);
    doReturn(0).when(uiRowNumberColumn).getIndex();
    doReturn(1).when(uiInputClauseColumnOne).getIndex();
    doReturn(2).when(uiInputClauseColumnTwo).getIndex();
    doReturn(3).when(uiInputClauseColumnThree).getIndex();
    doReturn(4).when(uiOutputClauseColumnOne).getIndex();
    doReturn(5).when(uiOutputClauseColumnTwo).getIndex();
    doReturn(6).when(uiOutputClauseColumnThree).getIndex();
    doReturn(7).when(uiRuleAnnotationClauseColumnOne).getIndex();
    doReturn(8).when(uiRuleAnnotationClauseColumnTwo).getIndex();
    doReturn(9).when(uiRuleAnnotationClauseColumnThree).getIndex();
}
Also used : DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) DMNGridData(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) Before(org.junit.Before)

Example 3 with UnaryTests

use of org.kie.workbench.common.dmn.api.definition.model.UnaryTests in project kie-wb-common by kiegroup.

the class AddInputClauseCommandTest method testGraphCommandExecuteExistingNotAffected.

@Test
public void testGraphCommandExecuteExistingNotAffected() throws Exception {
    makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT);
    final String ruleOneOldInput = "old rule 1";
    final String ruleTwoOldInput = "old rule 2";
    dtable.getInput().add(new InputClause());
    addRuleWithInputClauseValues(ruleOneOldInput);
    addRuleWithInputClauseValues(ruleTwoOldInput);
    assertEquals(1, dtable.getInput().size());
    // Graph command will insert new InputClause at index 0 of the InputEntries
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext));
    assertEquals(2, dtable.getInput().size());
    assertEquals(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_PREFIX + "1", dtable.getInput().get(0).getInputExpression().getText().getValue());
    assertNotNull(dtable.getInput().get(1).getInputExpression());
    // first rule
    final List<UnaryTests> inputEntriesRuleOne = dtable.getRule().get(0).getInputEntry();
    assertEquals(2, inputEntriesRuleOne.size());
    assertEquals(ruleOneOldInput, inputEntriesRuleOne.get(1).getText().getValue());
    assertEquals(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT, inputEntriesRuleOne.get(0).getText().getValue());
    assertEquals(dtable.getRule().get(0), inputEntriesRuleOne.get(0).getParent());
    // second rule
    final List<UnaryTests> inputEntriesRuleTwo = dtable.getRule().get(1).getInputEntry();
    assertEquals(2, inputEntriesRuleTwo.size());
    assertEquals(ruleTwoOldInput, inputEntriesRuleTwo.get(1).getText().getValue());
    assertEquals(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT, inputEntriesRuleTwo.get(0).getText().getValue());
    assertEquals(dtable.getRule().get(1), inputEntriesRuleTwo.get(0).getParent());
    assertEquals(dtable, inputClause.getParent());
}
Also used : GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause) Test(org.junit.Test)

Example 4 with UnaryTests

use of org.kie.workbench.common.dmn.api.definition.model.UnaryTests in project kie-wb-common by kiegroup.

the class DeleteInputClauseCommandTest method testGraphCommandExecuteRemoveMiddle.

@Test
public void testGraphCommandExecuteRemoveMiddle() {
    final InputClause firstInput = mock(InputClause.class);
    final InputClause lastInput = mock(InputClause.class);
    dtable.getInput().add(0, firstInput);
    dtable.getInput().add(lastInput);
    final UnaryTests inputOneValue = mock(UnaryTests.class);
    final UnaryTests inputTwoValue = mock(UnaryTests.class);
    final UnaryTests inputThreeValue = mock(UnaryTests.class);
    final DecisionRule rule = new DecisionRule();
    rule.getInputEntry().add(inputOneValue);
    rule.getInputEntry().add(inputTwoValue);
    rule.getInputEntry().add(inputThreeValue);
    dtable.getRule().add(rule);
    makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT + 1);
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext));
    assertEquals(2, dtable.getInput().size());
    assertEquals(firstInput, dtable.getInput().get(0));
    assertEquals(lastInput, dtable.getInput().get(1));
    assertEquals(2, dtable.getRule().get(0).getInputEntry().size());
    assertEquals(inputOneValue, dtable.getRule().get(0).getInputEntry().get(0));
    assertEquals(inputThreeValue, dtable.getRule().get(0).getInputEntry().get(1));
}
Also used : GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) Test(org.junit.Test)

Example 5 with UnaryTests

use of org.kie.workbench.common.dmn.api.definition.model.UnaryTests in project kie-wb-common by kiegroup.

the class ItemDefinitionPropertyConverterTest method testSetUnaryTestsWhenUnaryTestsIsNull.

@Test
public void testSetUnaryTestsWhenUnaryTestsIsNull() {
    final ItemDefinition wb = mock(ItemDefinition.class);
    final UnaryTests wbAllowedValues = mock(UnaryTests.class);
    final org.kie.dmn.model.api.ItemDefinition dmn = mock(org.kie.dmn.model.api.ItemDefinition.class);
    final org.kie.dmn.model.api.UnaryTests dmnAllowedValues = null;
    when(dmn.getAllowedValues()).thenReturn(dmnAllowedValues);
    setUnaryTests(wb, dmn);
    verify(wb, never()).setAllowedValues(wbAllowedValues);
    verify(wbAllowedValues, never()).setParent(wb);
}
Also used : ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) ItemDefinitionPropertyConverter.setUnaryTests(org.kie.workbench.common.dmn.backend.definition.v1_1.ItemDefinitionPropertyConverter.setUnaryTests) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) Test(org.junit.Test)

Aggregations

UnaryTests (org.kie.workbench.common.dmn.api.definition.model.UnaryTests)36 DecisionRule (org.kie.workbench.common.dmn.api.definition.model.DecisionRule)16 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)16 Test (org.junit.Test)15 RuleAnnotationClauseText (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText)13 ItemDefinition (org.kie.workbench.common.dmn.api.definition.model.ItemDefinition)10 InputClause (org.kie.workbench.common.dmn.api.definition.model.InputClause)9 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)8 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)8 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)6 Text (org.kie.workbench.common.dmn.api.property.dmn.Text)6 ConstraintType (org.kie.workbench.common.dmn.api.definition.model.ConstraintType)5 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)5 InputClauseLiteralExpression (org.kie.workbench.common.dmn.api.definition.model.InputClauseLiteralExpression)4 RuleAnnotationClause (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause)4 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)4 DataType (org.kie.workbench.common.dmn.client.editors.types.common.DataType)4 JSITUnaryTests (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITUnaryTests)4 List (java.util.List)3 Before (org.junit.Before)3