Search in sources :

Example 21 with InformationItemPrimary

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

the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenDecisionTypeRefIsStructureWithNoFields.

@Test
public void testModelEnrichmentWhenDecisionTypeRefIsStructureWithNoFields() {
    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 = mock(ItemDefinition.class);
    final QName tPersonTypeRef = new QName("", TYPE_PERSON);
    when(tPerson.getName()).thenReturn(new Name(TYPE_PERSON));
    when(tPerson.getTypeRef()).thenReturn(tPersonTypeRef);
    when(tPerson.getItemComponent()).thenReturn(emptyList());
    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(tPersonTypeRef);
    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(1);
    final OutputClause outputClause = outputClauses.get(0);
    assertEquals(DEFAULT_OUTPUT_NAME, outputClause.getName());
    assertEquals(tPersonTypeRef, outputClause.getTypeRef());
}
Also used : InformationItemPrimary(org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) DMNGraphUtils(org.kie.workbench.common.dmn.client.graph.DMNGraphUtils) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) Test(org.junit.Test)

Example 22 with InformationItemPrimary

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

the class DMNDocumentationDRDsFactoryTest method testCreate.

@Test
public void testCreate() {
    final String nodeUUID1 = "1111-1111-1111-1111";
    final String nodeUUID2 = "2222-2222-2222-2222";
    final Node<View, Edge> node1 = new NodeImpl<>(nodeUUID1);
    final Node<View, Edge> node2 = new NodeImpl<>(nodeUUID2);
    final View view1 = mock(View.class);
    final View view2 = mock(View.class);
    final HasExpression hasExpression1 = mock(HasExpression.class);
    final List<Node<View, Edge>> nodes = asList(node1, node2);
    final Decision drgElement1 = new Decision();
    final InputData drgElement2 = new InputData();
    final String name1 = "Decision-1";
    final String name2 = "Input-data-2";
    final String description1 = "Description...";
    final InformationItemPrimary variable1 = new InformationItemPrimary();
    final QName typeRef1 = BOOLEAN.asQName();
    final String image1 = "<image1>";
    final DMNExternalLink externalLink = new DMNExternalLink();
    final DocumentationLinksHolder linksHolder = new DocumentationLinksHolder();
    linksHolder.getValue().addLink(externalLink);
    drgElement2.setLinksHolder(linksHolder);
    node1.setContent(view1);
    node2.setContent(view2);
    when(view1.getDefinition()).thenReturn(drgElement1);
    when(view2.getDefinition()).thenReturn(drgElement2);
    when(expressionHelper.getOptionalHasExpression(node1)).thenReturn(Optional.ofNullable(hasExpression1));
    when(expressionHelper.getOptionalHasExpression(node2)).thenReturn(Optional.empty());
    when(expressionContainerGrid.getNodeUUID()).thenReturn(Optional.of(nodeUUID2));
    when(graph.nodes()).thenReturn(nodes);
    doReturn(image1).when(factory).getNodeImage(diagram, node1);
    doNothing().when(factory).setExpressionContainerGrid(any(), any());
    variable1.setTypeRef(typeRef1);
    drgElement1.setVariable(variable1);
    drgElement1.setDescription(new Description(description1));
    drgElement1.setName(new Name(name1));
    drgElement2.setName(new Name(name2));
    final List<DMNDocumentationDRD> drds = factory.create(diagram);
    final DMNDocumentationDRD documentationDRD1 = drds.get(0);
    final DMNDocumentationDRD documentationDRD2 = drds.get(1);
    assertEquals(2, drds.size());
    assertEquals(name1, documentationDRD1.getDrdName());
    assertEquals(BOOLEAN.getName(), documentationDRD1.getDrdType());
    assertEquals(description1, documentationDRD1.getDrdDescription());
    assertEquals(image1, documentationDRD1.getDrdBoxedExpressionImage());
    assertEquals(NONE, documentationDRD2.getDrdDescription());
    assertEquals(UNDEFINED.getName(), documentationDRD2.getDrdType());
    assertEquals(name2, documentationDRD2.getDrdName());
    assertEquals(NONE, documentationDRD2.getDrdBoxedExpressionImage());
    assertFalse(documentationDRD1.getHasExternalLinks());
    assertTrue(documentationDRD2.getHasExternalLinks());
    verify(factory).setExpressionContainerGrid(diagram, nodeUUID2);
}
Also used : InformationItemPrimary(org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) NodeImpl(org.kie.workbench.common.stunner.core.graph.impl.NodeImpl) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Node(org.kie.workbench.common.stunner.core.graph.Node) DocumentationLinksHolder(org.kie.workbench.common.dmn.api.property.dmn.DocumentationLinksHolder) ExpressionEditorView(org.kie.workbench.common.dmn.client.editors.expressions.ExpressionEditorView) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) Edge(org.kie.workbench.common.stunner.core.graph.Edge) DMNExternalLink(org.kie.workbench.common.dmn.api.property.dmn.DMNExternalLink) Test(org.junit.Test)

Example 23 with InformationItemPrimary

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

the class DecisionServiceParametersListWidgetTest method testAddDecisionNodeToGroup.

@Test
public void testAddDecisionNodeToGroup() {
    final ParameterGroup group = mock(ParameterGroup.class);
    final Node node = mock(Node.class);
    final Definition definition = mock(Definition.class);
    final Decision decision = mock(Decision.class);
    final InformationItemPrimary variable = mock(InformationItemPrimary.class);
    final String decisionName = "decision name";
    final String type = "type";
    final QName typeRef = mock(QName.class);
    when(definition.getDefinition()).thenReturn(decision);
    when(node.getContent()).thenReturn(definition);
    when(decision.getVariable()).thenReturn(variable);
    when(decision.getName()).thenReturn(new Name(decisionName));
    when(typeRef.getLocalPart()).thenReturn(type);
    when(variable.getTypeRef()).thenReturn(typeRef);
    widget.addDecisionNodeToGroup(group, node);
    verify(group).addParameter(decisionName, type);
}
Also used : InformationItemPrimary(org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) ParameterGroup(org.kie.workbench.common.dmn.client.widgets.decisionservice.parameters.parametergroup.ParameterGroup) Node(org.kie.workbench.common.stunner.core.graph.Node) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Example 24 with InformationItemPrimary

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

the class DecisionServiceConverterTest method testDMNFromWB.

@Test
public void testDMNFromWB() {
    final DecisionService wb = new DecisionService();
    final InformationItemPrimary informationItem = new InformationItemPrimary();
    wb.getId().setValue(DECISION_SERVICE_UUID);
    wb.getName().setValue(DECISION_SERVICE_NAME);
    wb.getDescription().setValue(DECISION_SERVICE_DESCRIPTION);
    wb.setVariable(informationItem);
    final Node<View<DecisionService>, ?> node = new NodeImpl<>(UUID.uuid());
    final View<DecisionService> view = new ViewImpl<>(wb, Bounds.create());
    node.setContent(view);
    final org.kie.dmn.model.api.DecisionService dmn = converter.dmnFromNode(node, componentWidthsConsumer);
    assertThat(dmn).isNotNull();
    assertThat(dmn.getId()).isNotNull();
    assertThat(dmn.getId()).isEqualTo(DECISION_SERVICE_UUID);
    assertThat(dmn.getName()).isNotNull();
    assertThat(dmn.getName()).isEqualTo(DECISION_SERVICE_NAME);
    assertThat(dmn.getDescription()).isNotNull();
    assertThat(dmn.getDescription()).isEqualTo(DECISION_SERVICE_DESCRIPTION);
    assertThat(dmn.getVariable()).isNotNull();
    assertThat(dmn.getVariable().getName()).isEqualTo(DECISION_SERVICE_NAME);
    verifyNoMoreInteractions(componentWidthsConsumer);
}
Also used : InformationItemPrimary(org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary) NodeImpl(org.kie.workbench.common.stunner.core.graph.impl.NodeImpl) ViewImpl(org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl) View(org.kie.workbench.common.stunner.core.graph.content.view.View) TDecisionService(org.kie.dmn.model.v1_2.TDecisionService) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) Test(org.junit.Test)

Example 25 with InformationItemPrimary

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

the class InformationItemPrimaryPropertyConverterTest method testWbFromDMNWhenDMNIsNull.

@Test
public void testWbFromDMNWhenDMNIsNull() {
    final InformationItem dmn = null;
    final InformationItemPrimary informationItemPrimary = InformationItemPrimaryPropertyConverter.wbFromDMN(dmn, dmn);
    assertNull(informationItemPrimary);
}
Also used : InformationItemPrimary(org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary) InformationItem(org.kie.dmn.model.api.InformationItem) TInformationItem(org.kie.dmn.model.v1_2.TInformationItem) Test(org.junit.Test)

Aggregations

InformationItemPrimary (org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary)39 Test (org.junit.Test)21 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)18 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)17 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)14 View (org.kie.workbench.common.stunner.core.graph.content.view.View)13 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)12 Node (org.kie.workbench.common.stunner.core.graph.Node)10 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)9 StylingSet (org.kie.workbench.common.dmn.api.property.styling.StylingSet)8 BindableAdapterUtils.getDefinitionId (org.kie.workbench.common.stunner.core.definition.adapter.binding.BindableAdapterUtils.getDefinitionId)8 InputData (org.kie.workbench.common.dmn.api.definition.model.InputData)7 GeneralRectangleDimensionsSet (org.kie.workbench.common.dmn.api.property.dimensions.GeneralRectangleDimensionsSet)6 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel)5 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)5 OutputClause (org.kie.workbench.common.dmn.api.definition.model.OutputClause)5 NodeImpl (org.kie.workbench.common.stunner.core.graph.impl.NodeImpl)5 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)4 DecisionService (org.kie.workbench.common.dmn.api.definition.model.DecisionService)4 FunctionDefinition (org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition)4