Search in sources :

Example 6 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)

Example 7 with UnaryTests

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

the class UnaryTestsPropertyConverterTest method testWbFromDMN.

public void testWbFromDMN(final ConstraintType constraintType) {
    when(additionalAttributes.get(CONSTRAINT_KEY)).thenReturn(constraintType.value());
    final UnaryTests unaryTests = UnaryTestsPropertyConverter.wbFromDMN(dmnUnary);
    assertEquals(ID, unaryTests.getId().getValue());
    assertEquals(DESCRIPTION, unaryTests.getDescription().getValue());
    assertEquals(TEXT, unaryTests.getText().getValue());
    assertEquals(EXPRESSION_LANGUAGE, unaryTests.getExpressionLanguage().getValue());
    assertEquals(constraintType, unaryTests.getConstraintType());
}
Also used : UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) IsUnaryTests(org.kie.workbench.common.dmn.api.definition.model.IsUnaryTests)

Example 8 with UnaryTests

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

the class DMNDocumentationFactoryTest method testCreate.

@Test
public void testCreate() {
    final String diagramName = "Diagram name";
    final String diagramDescription = "Diagram description";
    final String image = "<image>";
    final String admin = "admin";
    final String currentDate = "2 January 1992";
    final String namespace = "://namespace";
    final String expectedDroolsLogo = "droolsLogo";
    final String expectedSupportedByRedHatLogo = "supportedByRedHatLogo";
    final List<DRGElement> drgElements = singletonList(mock(DRGElement.class));
    final ItemDefinition uuid = makeItemDefinition("tUUID", "String");
    final ItemDefinition id = makeItemDefinition("id", "tUUID");
    final ItemDefinition name = makeItemDefinition("name", "String");
    final ItemDefinition person = makeItemDefinition("tPerson", null, id, name);
    final List<ItemDefinition> itemDefinitions = asList(uuid, person);
    final UnaryTests unaryTests = new UnaryTests();
    unaryTests.setText(new Text("[1, 2, 3]"));
    id.setAllowedValues(unaryTests);
    id.setIsCollection(true);
    doReturn(image).when(documentationFactory).getDiagramImage();
    doReturn(i18n).when(documentationFactory).getDocumentationI18n();
    doReturn(moment).when(documentationFactory).moment();
    when(definitions.getNamespace()).thenReturn(new Text(namespace));
    when(graphUtils.getDefinitions(diagram)).thenReturn(definitions);
    when(definitions.getName()).thenReturn(new Name(diagramName));
    when(definitions.getDescription()).thenReturn(new Description(diagramDescription));
    when(graphUtils.getDRGElements(diagram)).thenReturn(drgElements);
    when(definitions.getItemDefinition()).thenReturn(itemDefinitions);
    when(sessionInfo.getIdentity()).thenReturn(user);
    when(user.getIdentifier()).thenReturn(admin);
    when(moment.format("D MMMM YYYY")).thenReturn(currentDate);
    final DMNDocumentation documentation = documentationFactory.create(diagram);
    assertEquals(namespace, documentation.getNamespace());
    assertEquals(diagramName, documentation.getDiagramName());
    assertEquals(diagramDescription, documentation.getDiagramDescription());
    assertEquals(image, documentation.getDiagramImage());
    assertEquals(admin, documentation.getCurrentUser());
    assertEquals(currentDate, documentation.getCurrentDate());
    assertEquals(expectedDroolsLogo, documentation.getDroolsLogoURI());
    assertEquals(expectedSupportedByRedHatLogo, documentation.getSupportedByRedHatLogoURI());
    assertEquals(i18n, documentation.getI18n());
    assertNotNull(documentation.getModuleName());
    assertNotNull(documentation.getDataTypes());
    assertTrue(documentation.hasGraphNodes());
    final List<DMNDocumentationDataType> dataTypes = documentation.getDataTypesList();
    assertEquals(4, dataTypes.size());
    assertEquals("", dataTypes.get(0).getConstraint());
    assertEquals("tUUID", dataTypes.get(0).getName());
    assertEquals("String", dataTypes.get(0).getType());
    assertEquals("", dataTypes.get(0).getListLabel());
    assertEquals(0, dataTypes.get(0).getLevel());
    assertTrue(dataTypes.get(0).isTopLevel());
    assertEquals("", dataTypes.get(1).getConstraint());
    assertEquals("tPerson", dataTypes.get(1).getName());
    assertEquals("Structure", dataTypes.get(1).getType());
    assertEquals("", dataTypes.get(1).getListLabel());
    assertEquals(0, dataTypes.get(1).getLevel());
    assertTrue(dataTypes.get(1).isTopLevel());
    assertEquals("Constraints: [1, 2, 3]", dataTypes.get(2).getConstraint());
    assertEquals("id", dataTypes.get(2).getName());
    assertEquals("tUUID", dataTypes.get(2).getType());
    assertEquals("List: Yes", dataTypes.get(2).getListLabel());
    assertEquals(1, dataTypes.get(2).getLevel());
    assertFalse(dataTypes.get(2).isTopLevel());
    assertEquals("", dataTypes.get(3).getConstraint());
    assertEquals("name", dataTypes.get(3).getName());
    assertEquals("String", dataTypes.get(3).getType());
    assertEquals("", dataTypes.get(3).getListLabel());
    assertEquals(1, dataTypes.get(3).getLevel());
    assertFalse(dataTypes.get(3).isTopLevel());
}
Also used : Description(org.kie.workbench.common.dmn.api.property.dmn.Description) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) Text(org.kie.workbench.common.dmn.api.property.dmn.Text) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Test(org.junit.Test)

Example 9 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 10 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)

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