use of org.kie.workbench.common.dmn.api.definition.model.UnaryTests in project kie-wb-common by kiegroup.
the class ItemDefinitionUtilsTest method testGetConstraintTextWhenItemDefinitionHasAllowedValues.
@Test
public void testGetConstraintTextWhenItemDefinitionHasAllowedValues() {
final ItemDefinition itemDefinition = mock(ItemDefinition.class);
final UnaryTests allowedValues = mock(UnaryTests.class);
final String expectedText = "(1..10)";
when(allowedValues.getText()).thenReturn(new Text(expectedText));
when(itemDefinition.getAllowedValues()).thenReturn(allowedValues);
final String actualText = utils.getConstraintText(itemDefinition);
assertEquals(expectedText, actualText);
}
use of org.kie.workbench.common.dmn.api.definition.model.UnaryTests in project kie-wb-common by kiegroup.
the class ItemDefinitionUpdateHandlerTest method testMakeAllowedValuesWhenDataTypeAndItemDefinitionConstraintAreNotEqual.
@Test
public void testMakeAllowedValuesWhenDataTypeAndItemDefinitionConstraintAreNotEqual() {
final DataType dataType = mock(DataType.class);
final ItemDefinition itemDefinition = mock(ItemDefinition.class);
final String expectedText = "(1..20)";
final ConstraintType expectedConstraintType = ConstraintType.RANGE;
when(dataType.getConstraint()).thenReturn(expectedText);
when(dataType.getConstraintType()).thenReturn(expectedConstraintType);
final UnaryTests actualAllowedValues = handler.makeAllowedValues(dataType, itemDefinition);
assertNotNull(actualAllowedValues.getId());
assertNotNull(actualAllowedValues.getDescription());
assertEquals(expectedText, actualAllowedValues.getText().getValue());
assertNull(actualAllowedValues.getExpressionLanguage());
assertEquals(expectedConstraintType, actualAllowedValues.getConstraintType());
}
use of org.kie.workbench.common.dmn.api.definition.model.UnaryTests in project kie-wb-common by kiegroup.
the class ItemDefinitionUpdateHandlerTest method testMakeAllowedValuesWhenDataTypeConstraintIsBlank.
@Test
public void testMakeAllowedValuesWhenDataTypeConstraintIsBlank() {
final DataType dataType = mock(DataType.class);
final ItemDefinition itemDefinition = mock(ItemDefinition.class);
when(dataType.getConstraint()).thenReturn("");
final UnaryTests actualAllowedValues = handler.makeAllowedValues(dataType, itemDefinition);
assertNull(actualAllowedValues);
}
use of org.kie.workbench.common.dmn.api.definition.model.UnaryTests in project kie-wb-common by kiegroup.
the class DataTypeManagerTest method makeItem.
private ItemDefinition makeItem(final String itemName, final String itemType, final String constraint, final ItemDefinition... subItemDefinitions) {
final ItemDefinition itemDefinition = makeItem(itemName, itemType, false, subItemDefinitions);
final UnaryTests unaryTests = mock(UnaryTests.class);
when(unaryTests.getText()).thenReturn(new Text(constraint));
when(itemDefinition.getAllowedValues()).thenReturn(unaryTests);
return itemDefinition;
}
use of org.kie.workbench.common.dmn.api.definition.model.UnaryTests in project kie-wb-common by kiegroup.
the class MoveColumnsCommand method newGraphCommand.
@Override
protected Command<GraphCommandExecutionContext, RuleViolation> newGraphCommand(final AbstractCanvasHandler context) {
return new AbstractGraphCommand() {
@Override
protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext context) {
return isColumnInValidSection() ? GraphCommandResultBuilder.SUCCESS : GraphCommandResultBuilder.failed();
}
private boolean isColumnInValidSection() {
final DecisionTableSection section = DecisionTableUIModelMapperHelper.getSection(dtable, index);
return section == DecisionTableSection.INPUT_CLAUSES || section == DecisionTableSection.OUTPUT_CLAUSES || section == DecisionTableSection.ANNOTATION_CLAUSES;
}
@Override
public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) {
return moveClauses(index);
}
@Override
public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context) {
return moveClauses(oldIndex);
}
private CommandResult<RuleViolation> moveClauses(final int index) {
final DecisionTableSection section = DecisionTableUIModelMapperHelper.getSection(dtable, index);
if (section == DecisionTableSection.INPUT_CLAUSES) {
final int oldIndex = uiModel.getColumns().indexOf(columns.get(0));
final int relativeIndex = DecisionTableUIModelMapperHelper.getInputEntryIndex(dtable, index);
final int relativeOldIndex = DecisionTableUIModelMapperHelper.getInputEntryIndex(dtable, oldIndex);
final List<Integer> uiColumnIndexesToMove = columns.stream().map(c -> uiModel.getColumns().indexOf(c)).collect(Collectors.toList());
final List<Integer> inputClauseIndexesToMove = uiColumnIndexesToMove.stream().map(i -> DecisionTableUIModelMapperHelper.getInputEntryIndex(dtable, i)).collect(Collectors.toList());
moveClauses(relativeIndex, relativeOldIndex, dtable.getInput(), inputClauseIndexesToMove);
CommandUtils.moveComponentWidths(index, oldIndex, dtable.getComponentWidths(), uiColumnIndexesToMove);
final List<List<UnaryTests>> decisionRulesInputEntries = dtable.getRule().stream().map(DecisionRule::getInputEntry).collect(Collectors.toList());
updateDecisionRules(relativeIndex, relativeOldIndex, decisionRulesInputEntries, inputClauseIndexesToMove);
return GraphCommandResultBuilder.SUCCESS;
} else if (section == DecisionTableSection.OUTPUT_CLAUSES) {
final int oldIndex = uiModel.getColumns().indexOf(columns.get(0));
final int relativeIndex = DecisionTableUIModelMapperHelper.getOutputEntryIndex(dtable, index);
final int relativeOldIndex = DecisionTableUIModelMapperHelper.getOutputEntryIndex(dtable, oldIndex);
final List<Integer> uiColumnIndexesToMove = columns.stream().map(c -> uiModel.getColumns().indexOf(c)).collect(Collectors.toList());
final List<Integer> outputClauseIndexesToMove = uiColumnIndexesToMove.stream().map(i -> DecisionTableUIModelMapperHelper.getOutputEntryIndex(dtable, i)).collect(Collectors.toList());
moveClauses(relativeIndex, relativeOldIndex, dtable.getOutput(), outputClauseIndexesToMove);
CommandUtils.moveComponentWidths(index, oldIndex, dtable.getComponentWidths(), uiColumnIndexesToMove);
final List<List<LiteralExpression>> decisionRulesOutputEntries = dtable.getRule().stream().map(DecisionRule::getOutputEntry).collect(Collectors.toList());
updateDecisionRules(relativeIndex, relativeOldIndex, decisionRulesOutputEntries, outputClauseIndexesToMove);
return GraphCommandResultBuilder.SUCCESS;
} else if (section == DecisionTableSection.ANNOTATION_CLAUSES) {
final int oldIndex = uiModel.getColumns().indexOf(columns.get(0));
final int relativeIndex = DecisionTableUIModelMapperHelper.getAnnotationEntryIndex(dtable, index);
final int relativeOldIndex = DecisionTableUIModelMapperHelper.getAnnotationEntryIndex(dtable, oldIndex);
final List<Integer> uiColumnIndexesToMove = columns.stream().map(c -> uiModel.getColumns().indexOf(c)).collect(Collectors.toList());
final List<Integer> annotationClauseIndexesToMove = uiColumnIndexesToMove.stream().map(i -> DecisionTableUIModelMapperHelper.getAnnotationEntryIndex(dtable, i)).collect(Collectors.toList());
moveClauses(relativeIndex, relativeOldIndex, dtable.getAnnotations(), annotationClauseIndexesToMove);
CommandUtils.moveComponentWidths(index, oldIndex, dtable.getComponentWidths(), uiColumnIndexesToMove);
final List<List<RuleAnnotationClauseText>> decisionRulesAnnotationEntries = dtable.getRule().stream().map(DecisionRule::getAnnotationEntry).collect(Collectors.toList());
updateDecisionRules(relativeIndex, relativeOldIndex, decisionRulesAnnotationEntries, annotationClauseIndexesToMove);
return GraphCommandResultBuilder.SUCCESS;
} else {
return GraphCommandResultBuilder.failed();
}
}
private <T> void moveClauses(final int relativeIndex, final int relativeOldIndex, final List<T> clauses, final List<Integer> clauseIndexesToMove) {
final List<T> clausesToMove = clauseIndexesToMove.stream().map(clauses::get).collect(Collectors.toList());
clauses.removeAll(clausesToMove);
if (relativeIndex < relativeOldIndex) {
clauses.addAll(relativeIndex, clausesToMove);
} else if (relativeIndex > relativeOldIndex) {
clauses.addAll(relativeIndex - clausesToMove.size() + 1, clausesToMove);
}
}
private <T> void updateDecisionRules(final int relativeIndex, final int relativeOldIndex, final List<List<T>> clauses, final List<Integer> clauseIndexesToMove) {
clauses.forEach(row -> moveClauses(relativeIndex, relativeOldIndex, row, clauseIndexesToMove));
}
};
}
Aggregations