use of org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary 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.InformationItemPrimary in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenHasExpressionIsHasVariable.
@Test
public void testModelEnrichmentWhenHasExpressionIsHasVariable() {
decision.setVariable(new InformationItemPrimary(new Id(), new Name(), OUTPUT_DATA_QNAME));
final Optional<DecisionTable> oModel = definition.getModelClass();
definition.enrich(Optional.empty(), decision, 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.InformationItemPrimary in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenDecisionTypeRefIsStructureWithMultipleFields.
@Test
public void testModelEnrichmentWhenDecisionTypeRefIsStructureWithMultipleFields() {
final DMNGraphUtils dmnGraphUtils = mock(DMNGraphUtils.class);
final Definitions definitions = mock(Definitions.class);
final HasExpression hasExpression = mock(HasExpression.class);
final Decision decision = mock(Decision.class);
final InformationItemPrimary informationItemPrimary = mock(InformationItemPrimary.class);
final ItemDefinition tPerson = mockTPersonStructure();
when(dmnGraphUtils.getModelDefinitions()).thenReturn(definitions);
when(definitions.getItemDefinition()).thenReturn(Collections.singletonList(tPerson));
when(hasExpression.asDMNModelInstrumentedBase()).thenReturn(decision);
when(decision.getVariable()).thenReturn(informationItemPrimary);
when(informationItemPrimary.getTypeRef()).thenReturn(new QName("", TYPE_PERSON));
final DecisionTableEditorDefinitionEnricher enricher = new DecisionTableEditorDefinitionEnricher(null, dmnGraphUtils, itemDefinitionUtils);
final Optional<DecisionTable> oModel = definition.getModelClass();
final DecisionTable model = oModel.get();
enricher.buildOutputClausesByDataType(hasExpression, model, new DecisionRule());
final List<OutputClause> outputClauses = model.getOutput();
assertThat(outputClauses.size()).isEqualTo(2);
final OutputClause outputClause1 = outputClauses.get(0);
final OutputClause outputClause2 = outputClauses.get(1);
assertEquals("age", outputClause1.getName());
assertEquals(NUMBER.asQName(), outputClause1.getTypeRef());
assertEquals("name", outputClause2.getName());
assertEquals(STRING.asQName(), outputClause2.getTypeRef());
}
use of org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary in project kie-wb-common by kiegroup.
the class MonacoFEELSuggestionsTest method makeDecisionNode.
private NodeImpl<Definition<Decision>> makeDecisionNode(final String name, final BuiltInType builtInType) {
final NodeImpl<Definition<Decision>> node = makeNodeImpl();
final Definition<Decision> definition = makeDefinition();
final Decision decision = spy(new Decision());
final InformationItemPrimary informationItemPrimary = mock(InformationItemPrimary.class);
final QName qName = builtInType == null ? null : new QName(builtInType);
when(informationItemPrimary.getTypeRef()).thenReturn(qName);
when(node.getContent()).thenReturn(definition);
when(definition.getDefinition()).thenReturn(decision);
decision.setName(new Name(name));
decision.setVariable(informationItemPrimary);
return node;
}
use of org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary in project kie-wb-common by kiegroup.
the class BaseNameAndDataTypeHeaderMetaDataTest method testRender.
@Test
public void testRender() {
final QName typeRef = BuiltInType.DATE.asQName();
final GridRenderer renderer = mock(GridRenderer.class);
final GridRendererTheme theme = mock(GridRendererTheme.class);
final Text tName = mock(Text.class);
final InformationItemPrimary hasExpressionVariable = new InformationItemPrimary();
hasExpressionVariable.setTypeRef(typeRef);
hasExpression.setVariable(hasExpressionVariable);
final Decision decision = new Decision();
decision.setName(NAME);
setup(Optional.of(decision));
when(theme.getHeaderText()).thenReturn(tName);
when(context.getRenderer()).thenReturn(renderer);
when(renderer.getTheme()).thenReturn(theme);
when(hasTypeRef.getTypeRef()).thenReturn(typeRef);
metaData.render(context, BLOCK_WIDTH, BLOCK_HEIGHT);
verify(tName).setText(NAME.getValue());
verify(tName, times(2)).setListening(false);
verify(tName, times(2)).setX(BLOCK_WIDTH / 2);
verify(tName).setY(BLOCK_HEIGHT / 2 - SPACING);
verify(tName).setFontStyle(FONT_STYLE_TYPE_REF);
verify(tName).setFontSize(BaseExpressionGridTheme.FONT_SIZE - 2.0);
verify(tName).setText("(" + typeRef.toString() + ")");
verify(tName).setY(BLOCK_HEIGHT / 2 + SPACING);
}
Aggregations