Search in sources :

Example 6 with ConstraintType

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

the class OutputClauseUnaryTestsPropertyConverter method wbFromDMN.

/**
 * Returns a non-null instance of OutputClauseUnaryTestsPropertyConverter. The Properties Panel needs
 * non-null objects to bind therefore a concrete object must always be returned.
 * @param dmn
 * @return
 */
public static OutputClauseUnaryTests wbFromDMN(final JSITUnaryTests dmn) {
    if (Objects.isNull(dmn)) {
        return new OutputClauseUnaryTests();
    }
    final Id id = IdPropertyConverter.wbFromDMN(dmn.getId());
    final QName key = new QName(DMNModelInstrumentedBase.Namespace.KIE.getUri(), ConstraintType.CONSTRAINT_KEY, DMNModelInstrumentedBase.Namespace.KIE.getPrefix());
    final Map<QName, String> otherAttributes = JSITUnaryTests.getOtherAttributesMap(dmn);
    final String constraintString = otherAttributes.getOrDefault(key, "");
    final ConstraintType constraint = ConstraintType.fromString(constraintString);
    final OutputClauseUnaryTests result = new OutputClauseUnaryTests(id, new Text(dmn.getText()), constraint);
    return result;
}
Also used : 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) OutputClauseUnaryTests(org.kie.workbench.common.dmn.api.definition.model.OutputClauseUnaryTests)

Example 7 with ConstraintType

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

the class DataTypeConstraintModalTest method testSetupComponentWhenConstraintTypeIsExpression.

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

Example 8 with ConstraintType

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

the class DataTypeConstraintModalTest method testInferComponentTypeWhenItReturnsEnumeration.

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

Example 9 with ConstraintType

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

the class DataTypeConstraintModalTest method testLoadWhenConstraintTypeIsNotNone.

@Test
public void testLoadWhenConstraintTypeIsNotNone() {
    final String expectedConstraintValueType = "string";
    final String expectedConstraintValue = "1,2,3";
    final ConstraintType expectedConstraintType = ENUMERATION;
    modal.load(expectedConstraintValueType, expectedConstraintValue, expectedConstraintType);
    final String actualConstraintValueType = modal.getConstraintValueType();
    final String actualConstraintValue = modal.getConstraintValue();
    final ConstraintType actualConstraintType = modal.getConstraintType();
    verify(modal).prepareView();
    assertEquals(expectedConstraintValueType, actualConstraintValueType);
    assertEquals(expectedConstraintValue, actualConstraintValue);
    assertEquals(expectedConstraintType, actualConstraintType);
}
Also used : ConstraintType(org.kie.workbench.common.dmn.api.definition.model.ConstraintType) Test(org.junit.Test)

Example 10 with ConstraintType

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

the class DataTypeConstraintTest method testInit.

@Test
public void testInit() {
    final DataTypeListItem expectedListItem = mock(DataTypeListItem.class);
    final DataType datatype = mock(DataType.class);
    final String expectedConstraint = "constraint";
    final ConstraintType expectedType = mock(ConstraintType.class);
    when(expectedListItem.getDataType()).thenReturn(datatype);
    when(datatype.getConstraint()).thenReturn(expectedConstraint);
    when(datatype.getConstraintType()).thenReturn(expectedType);
    dataTypeConstraint.init(expectedListItem);
    final DataTypeListItem actualListItem = dataTypeConstraint.getListItem();
    final String actualConstraint = dataTypeConstraint.getValue();
    final ConstraintType actualType = dataTypeConstraint.getConstraintType();
    assertEquals(expectedType, actualType);
    assertEquals(expectedListItem, actualListItem);
    assertEquals(expectedConstraint, actualConstraint);
    verify(dataTypeConstraint).refreshView();
}
Also used : DataTypeListItem(org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeListItem) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) 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