Search in sources :

Example 6 with HasTypeRef

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

the class ContextEntryTest method testGetHasTypeRefs.

@Test
public void testGetHasTypeRefs() {
    final Expression expression = mock(Expression.class);
    final InformationItem variable = mock(InformationItem.class);
    final HasTypeRef hasTypeRef1 = mock(HasTypeRef.class);
    final HasTypeRef hasTypeRef2 = mock(HasTypeRef.class);
    final HasTypeRef hasTypeRef3 = mock(HasTypeRef.class);
    final HasTypeRef hasTypeRef4 = mock(HasTypeRef.class);
    doReturn(expression).when(contextEntry).getExpression();
    doReturn(variable).when(contextEntry).getVariable();
    when(expression.getHasTypeRefs()).thenReturn(asList(hasTypeRef1, hasTypeRef2));
    when(variable.getHasTypeRefs()).thenReturn(asList(hasTypeRef3, hasTypeRef4));
    final List<HasTypeRef> actualHasTypeRefs = contextEntry.getHasTypeRefs();
    final List<HasTypeRef> expectedHasTypeRefs = asList(hasTypeRef1, hasTypeRef2, hasTypeRef3, hasTypeRef4);
    assertEquals(expectedHasTypeRefs, actualHasTypeRefs);
}
Also used : HasTypeRef(org.kie.workbench.common.dmn.api.definition.HasTypeRef) Test(org.junit.Test)

Example 7 with HasTypeRef

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

the class OutputClauseTest method testGetHasTypeRefs.

@Test
public void testGetHasTypeRefs() {
    final OutputClauseLiteralExpression outputClauseLiteralExpression = mock(OutputClauseLiteralExpression.class);
    final HasTypeRef hasTypeRef1 = mock(HasTypeRef.class);
    final HasTypeRef hasTypeRef2 = mock(HasTypeRef.class);
    doReturn(outputClauseLiteralExpression).when(outputClause).getDefaultOutputEntry();
    when(outputClauseLiteralExpression.getHasTypeRefs()).thenReturn(asList(hasTypeRef1, hasTypeRef2));
    final List<HasTypeRef> actualHasTypeRefs = outputClause.getHasTypeRefs();
    final List<HasTypeRef> expectedHasTypeRefs = asList(outputClause, hasTypeRef1, hasTypeRef2);
    assertEquals(expectedHasTypeRefs, actualHasTypeRefs);
}
Also used : HasTypeRef(org.kie.workbench.common.dmn.api.definition.HasTypeRef) Test(org.junit.Test)

Example 8 with HasTypeRef

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

the class BindingTest method testGetHasTypeRefs.

@Test
public void testGetHasTypeRefs() {
    final Expression expression = mock(Expression.class);
    final InformationItem parameter = mock(InformationItem.class);
    final HasTypeRef hasTypeRef1 = mock(HasTypeRef.class);
    final HasTypeRef hasTypeRef2 = mock(HasTypeRef.class);
    final HasTypeRef hasTypeRef3 = mock(HasTypeRef.class);
    final HasTypeRef hasTypeRef4 = mock(HasTypeRef.class);
    doReturn(expression).when(binding).getExpression();
    doReturn(parameter).when(binding).getParameter();
    when(expression.getHasTypeRefs()).thenReturn(asList(hasTypeRef1, hasTypeRef2));
    when(parameter.getHasTypeRefs()).thenReturn(asList(hasTypeRef3, hasTypeRef4));
    final List<HasTypeRef> actualHasTypeRefs = binding.getHasTypeRefs();
    final List<HasTypeRef> expectedHasTypeRefs = asList(hasTypeRef1, hasTypeRef2, hasTypeRef3, hasTypeRef4);
    assertEquals(expectedHasTypeRefs, actualHasTypeRefs);
}
Also used : HasTypeRef(org.kie.workbench.common.dmn.api.definition.HasTypeRef) Test(org.junit.Test)

Example 9 with HasTypeRef

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

the class TypeRefUtils method getTypeRefOfExpression.

public static <E extends Expression> HasTypeRef getTypeRefOfExpression(final E expression, final HasExpression hasExpression) {
    HasTypeRef hasTypeRef = expression;
    final DMNModelInstrumentedBase base = hasExpression.asDMNModelInstrumentedBase();
    if (base instanceof HasVariable) {
        final HasVariable hasVariable = (HasVariable) base;
        hasTypeRef = hasVariable.getVariable();
    }
    return hasTypeRef;
}
Also used : HasTypeRef(org.kie.workbench.common.dmn.api.definition.HasTypeRef) HasVariable(org.kie.workbench.common.dmn.api.definition.HasVariable) DMNModelInstrumentedBase(org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase)

Example 10 with HasTypeRef

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

the class DecisionTableEditorDefinitionEnricher method getOutputClauseTypeRef.

private Optional<QName> getOutputClauseTypeRef(final HasVariable hasVariable) {
    final IsInformationItem variable = hasVariable.getVariable();
    if (Objects.nonNull(variable)) {
        return Optional.ofNullable(variable.getTypeRef());
    }
    final DMNModelInstrumentedBase base = hasVariable.asDMNModelInstrumentedBase().getParent();
    final DMNModelInstrumentedBase parent = base.getParent();
    if (parent instanceof HasTypeRef) {
        return Optional.ofNullable(((HasTypeRef) parent).getTypeRef());
    }
    if (parent instanceof HasVariable) {
        return getOutputClauseTypeRef((HasVariable) parent);
    }
    return Optional.empty();
}
Also used : HasTypeRef(org.kie.workbench.common.dmn.api.definition.HasTypeRef) HasVariable(org.kie.workbench.common.dmn.api.definition.HasVariable) DMNModelInstrumentedBase(org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase) IsInformationItem(org.kie.workbench.common.dmn.api.definition.model.IsInformationItem)

Aggregations

HasTypeRef (org.kie.workbench.common.dmn.api.definition.HasTypeRef)22 Test (org.junit.Test)18 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)5 DMNModelInstrumentedBase (org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase)4 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)4 Node (org.kie.workbench.common.stunner.core.graph.Node)4 HasVariable (org.kie.workbench.common.dmn.api.definition.HasVariable)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)2 InformationItem (org.kie.workbench.common.dmn.api.definition.model.InformationItem)2 IsInformationItem (org.kie.workbench.common.dmn.api.definition.model.IsInformationItem)2 Arrays.asList (java.util.Arrays.asList)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1