Search in sources :

Example 16 with ConstraintType

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

the class UnaryTestsPropertyConverter method dmnFromWB.

public static org.kie.dmn.model.api.UnaryTests dmnFromWB(final IsUnaryTests wb) {
    if (wb == null) {
        return null;
    }
    final org.kie.dmn.model.api.UnaryTests result = new org.kie.dmn.model.v1_2.TUnaryTests();
    result.setId(wb.getId().getValue());
    result.setText(wb.getText().getValue());
    final ConstraintType constraint = wb.getConstraintType();
    if (isNotNone(constraint)) {
        final QName key = new QName(DMNModelInstrumentedBase.Namespace.KIE.getUri(), ConstraintType.CONSTRAINT_KEY, DMNModelInstrumentedBase.Namespace.KIE.getPrefix());
        result.getAdditionalAttributes().put(key, constraint.value());
    }
    return result;
}
Also used : QName(javax.xml.namespace.QName) ConstraintType(org.kie.workbench.common.dmn.api.definition.model.ConstraintType)

Example 17 with ConstraintType

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

the class DataTypeConstraintModalTest method testSetupComponentWhenConstraintTypeIsRangeAndValueIsEmpty.

@Test
public void testSetupComponentWhenConstraintTypeIsRangeAndValueIsEmpty() {
    final ConstraintType type = RANGE;
    final String constraint = "";
    final String constraintValueType = "number";
    doReturn(constraint).when(modal).getConstraintValue();
    doReturn(constraintValueType).when(modal).getConstraintValueType();
    when(constraintRange.getElement()).thenReturn(element);
    modal.setupComponent(type);
    assertEquals(constraintRange, modal.getCurrentComponent());
    final InOrder inOrder = inOrder(constraintRange);
    inOrder.verify(constraintRange).setConstraintValueType(constraintValueType);
    inOrder.verify(constraintRange).setValue(constraint);
    verify(modal, never()).enableOkButton();
    verify(element).setAttribute("class", "kie-number");
}
Also used : InOrder(org.mockito.InOrder) ConstraintType(org.kie.workbench.common.dmn.api.definition.model.ConstraintType) Test(org.junit.Test)

Example 18 with ConstraintType

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

the class DataTypeConstraintModalTest method testInferComponentTypeWhenItReturnsRange.

@Test
public void testInferComponentTypeWhenItReturnsRange() {
    final ConstraintType expectedType = RANGE;
    final ConstraintType actualType = modal.inferComponentType("(1..3]");
    assertEquals(expectedType, actualType);
}
Also used : ConstraintType(org.kie.workbench.common.dmn.api.definition.model.ConstraintType) Test(org.junit.Test)

Example 19 with ConstraintType

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

the class DataTypeConstraintModalTest method testSetupComponentWhenConstraintTypeIsRange.

@Test
public void testSetupComponentWhenConstraintTypeIsRange() {
    final ConstraintType type = RANGE;
    final String constraint = "(1..2)";
    final String constraintValueType = "number";
    doReturn(constraint).when(modal).getConstraintValue();
    doReturn(constraintValueType).when(modal).getConstraintValueType();
    when(constraintRange.getElement()).thenReturn(element);
    modal.setupComponent(type);
    assertEquals(constraintRange, modal.getCurrentComponent());
    final InOrder inOrder = inOrder(constraintRange);
    inOrder.verify(constraintRange).setConstraintValueType(constraintValueType);
    inOrder.verify(constraintRange).setValue(constraint);
    verify(element).setAttribute("class", "kie-number");
}
Also used : InOrder(org.mockito.InOrder) ConstraintType(org.kie.workbench.common.dmn.api.definition.model.ConstraintType) Test(org.junit.Test)

Example 20 with ConstraintType

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

the class DataTypeConstraintModalTest method testDoSave.

@Test
public void testDoSave() {
    final String expectedConstraint = "1,2,3";
    final ConstraintType expectedConstraintType = ENUMERATION;
    final BiConsumer<String, ConstraintType> onSave = mock(BiConsumer.class);
    doNothing().when(modal).hide();
    doReturn(onSave).when(modal).getOnSave();
    modal.setConstraintType(expectedConstraintType);
    modal.doSave(expectedConstraint);
    final String actualConstraint = modal.getConstraintValue();
    assertEquals(expectedConstraint, actualConstraint);
    verify(onSave).accept(expectedConstraint, expectedConstraintType);
    verify(modal).hide();
}
Also used : ConstraintType(org.kie.workbench.common.dmn.api.definition.model.ConstraintType) Test(org.junit.Test)

Aggregations

ConstraintType (org.kie.workbench.common.dmn.api.definition.model.ConstraintType)28 Test (org.junit.Test)19 QName (javax.xml.namespace.QName)8 Text (org.kie.workbench.common.dmn.api.property.dmn.Text)7 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)6 UnaryTests (org.kie.workbench.common.dmn.api.definition.model.UnaryTests)4 DataType (org.kie.workbench.common.dmn.client.editors.types.common.DataType)4 InOrder (org.mockito.InOrder)4 HTMLElement (elemental2.dom.HTMLElement)2 InputClauseUnaryTests (org.kie.workbench.common.dmn.api.definition.model.InputClauseUnaryTests)2 IsUnaryTests (org.kie.workbench.common.dmn.api.definition.model.IsUnaryTests)2 ItemDefinition (org.kie.workbench.common.dmn.api.definition.model.ItemDefinition)2 OutputClauseUnaryTests (org.kie.workbench.common.dmn.api.definition.model.OutputClauseUnaryTests)2 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)2 ExpressionLanguage (org.kie.workbench.common.dmn.api.property.dmn.ExpressionLanguage)2 DataTypeListItem (org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeListItem)2 JSITUnaryTests (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITUnaryTests)2 GwtMockitoTestRunner (com.google.gwtmockito.GwtMockitoTestRunner)1 Element (elemental2.dom.Element)1 HTMLAnchorElement (elemental2.dom.HTMLAnchorElement)1