use of org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenParentIsBKM.
@Test
public void testModelEnrichmentWhenParentIsBKM() {
final FunctionDefinition functionDefinition = mock(FunctionDefinition.class);
final DMNModelInstrumentedBase dmnModelInstrumentedBase = mock(DMNModelInstrumentedBase.class);
final BusinessKnowledgeModel businessKnowledgeModel = new BusinessKnowledgeModel();
businessKnowledgeModel.setVariable(new InformationItemPrimary(new Id(), new Name(), OUTPUT_DATA_QNAME));
businessKnowledgeModel.setEncapsulatedLogic(functionDefinition);
final Optional<DecisionTable> oModel = definition.getModelClass();
oModel.get().setParent(functionDefinition);
when(functionDefinition.asDMNModelInstrumentedBase()).thenReturn(dmnModelInstrumentedBase);
when(dmnModelInstrumentedBase.getParent()).thenReturn(businessKnowledgeModel);
definition.enrich(Optional.empty(), functionDefinition, oModel);
final DecisionTable model = oModel.get();
assertBasicEnrichment(model);
assertStandardInputClauseEnrichment(model);
final List<OutputClause> output = model.getOutput();
assertThat(output.size()).isEqualTo(1);
assertThat(output.get(0).getName()).isEqualTo(DEFAULT_OUTPUT_NAME);
assertThat(output.get(0).getTypeRef()).isEqualTo(OUTPUT_DATA_QNAME);
assertStandardDecisionRuleEnrichment(model);
assertParentHierarchyEnrichment(model);
}
use of org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase 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();
}
use of org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase in project kie-wb-common by kiegroup.
the class HasTypeRefHelperTest method testGetFlatHasTypeRefsFromExpressions.
@Test
public void testGetFlatHasTypeRefsFromExpressions() {
final Expression expression1 = mock(Expression.class);
final Expression expression2 = mock(Expression.class);
final DMNModelInstrumentedBase parent = mock(DMNModelInstrumentedBase.class);
final HasExpression hasExpression1 = HasExpression.wrap(parent, expression1);
final HasExpression hasExpression2 = HasExpression.wrap(parent, expression2);
final List<HasExpression> hasExpressions = asList(hasExpression1, hasExpression2);
final HasTypeRef hasTypeRef1 = mock(HasTypeRef.class);
final HasTypeRef hasTypeRef2 = mock(HasTypeRef.class);
final HasTypeRef hasTypeRef3 = mock(HasTypeRef.class);
final HasTypeRef hasTypeRef4 = mock(HasTypeRef.class);
final List<HasTypeRef> typeRefList1 = asList(hasTypeRef1, hasTypeRef2);
final List<HasTypeRef> typeRefList2 = asList(hasTypeRef3, hasTypeRef4);
when(expression1.getHasTypeRefs()).thenReturn(typeRefList1);
when(expression2.getHasTypeRefs()).thenReturn(typeRefList2);
final List<HasTypeRef> actual = HasTypeRefHelper.getFlatHasTypeRefsFromExpressions(hasExpressions);
final List<HasTypeRef> expected = asList(hasTypeRef1, hasTypeRef2, hasTypeRef3, hasTypeRef4);
assertEquals(expected, actual);
}
use of org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase 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;
}
use of org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase in project kie-wb-common by kiegroup.
the class RelationGridTest method testAsDMNModelInstrumentedBase.
@Test
public void testAsDMNModelInstrumentedBase() {
setupGrid(0);
final DMNModelInstrumentedBase actual = extractHeaderMetaData().asDMNModelInstrumentedBase();
assertThat(actual).isInstanceOf(InformationItem.class);
}
Aggregations