Search in sources :

Example 41 with Decision

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

the class DMNGraphProcessorTest method testGetNodesWithDecisionServices.

@Test
public void testGetNodesWithDecisionServices() {
    final String childId1 = "id1";
    final String childId2 = "id2";
    final String dsId = "dsId";
    final String decisionNodeId = "decision1Node";
    final DMNGraphProcessor processor = spy(new DMNGraphProcessor());
    final Graph graph = mock(Graph.class);
    final Decision decision1 = mock(Decision.class);
    final Node decisionNode = createNode(decision1, decisionNodeId);
    final DecisionService ds = mock(DecisionService.class);
    final Node dsNode = createNode(ds, dsId);
    final Decision child1 = mock(Decision.class);
    final Node ch1 = createNode(child1, childId1);
    final Decision child2 = mock(Decision.class);
    final Node ch2 = createNode(child2, childId2);
    final List<Node> children = Arrays.asList(ch1, ch2);
    doReturn(children).when(processor).getChildNodes(dsNode);
    final List<Node> graphNodes = createGraphNodes(dsNode, decisionNode);
    when(graph.nodes()).thenReturn(graphNodes);
    final List<Node> nodes = (List<Node>) processor.getNodes(graph);
    assertEquals(2, nodes.size());
    assertTrue(nodes.contains(dsNode));
    assertTrue(nodes.contains(decisionNode));
    assertTrue(processor.isReplacedByAnotherNode(childId1));
    assertEquals(dsId, processor.getReplaceNodeId(childId1));
    assertTrue(processor.isReplacedByAnotherNode(childId2));
    assertEquals(dsId, processor.getReplaceNodeId(childId2));
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) Node(org.kie.workbench.common.stunner.core.graph.Node) List(java.util.List) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) Test(org.junit.Test)

Example 42 with Decision

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

the class StunnerConverterTest method testDecision.

@Test
public void testDecision() {
    final StylingSet decisionStylingSet = mock(StylingSet.class);
    final Decision decision = spy(new Decision());
    when(decision.getStylingSet()).thenReturn(decisionStylingSet);
    final JSITDecision jsitDecision = mock(JSITDecision.class);
    when(jsitDecision.getTYPE_NAME()).thenReturn(JSITDecision.TYPE);
    final JSIStyle style = mock(JSIStyle.class);
    final JSIDMNShape shape = mock(JSIDMNShape.class);
    final JSIDMNStyle dmnStyleOfDrgShape = mock(JSIDMNStyle.class);
    when(shape.getStyle()).thenReturn(style);
    doReturn(style).when(converter).getUnwrappedJSIStyle(style);
    doReturn(true).when(converter).isJSIDMNStyle(style);
    doReturn(dmnStyleOfDrgShape).when(converter).getJSIDmnStyle(style);
    final NodeEntry nodeEntry = mock(NodeEntry.class);
    when(nodeEntry.getDmnElement()).thenReturn(jsitDecision);
    when(nodeEntry.getId()).thenReturn("_id");
    when(nodeEntry.getDmnShape()).thenReturn(shape);
    final Element graphElement = mock(Element.class);
    final Node graphNode = mock(Node.class);
    final View content = mock(View.class);
    when(factoryManager.newElement(anyString(), anyString())).thenReturn(graphElement);
    when(graphElement.asNode()).thenReturn(graphNode);
    when(graphNode.getContent()).thenReturn(content);
    when(content.getDefinition()).thenReturn(decision);
    final JSIColor randomColor = mock(JSIColor.class);
    when(randomColor.getRed()).thenReturn(12);
    when(randomColor.getGreen()).thenReturn(34);
    when(randomColor.getBlue()).thenReturn(56);
    when(dmnStyleOfDrgShape.getFontColor()).thenReturn(randomColor);
    when(dmnStyleOfDrgShape.getStrokeColor()).thenReturn(randomColor);
    when(dmnStyleOfDrgShape.getFillColor()).thenReturn(randomColor);
    when(dmnStyleOfDrgShape.getFontSize()).thenReturn(11d);
    converter.make(nodeEntry);
    verify(decisionStylingSet).setFontSize(fontSizeArgumentCaptor.capture());
    Assertions.assertThat(fontSizeArgumentCaptor.getValue().getValue()).isEqualTo(11d);
    verify(decisionStylingSet).setBorderColour(borderColourArgumentCaptor.capture());
    Assertions.assertThat(borderColourArgumentCaptor.getValue().getValue()).isEqualTo("#0c2238");
    verify(decisionStylingSet).setBgColour(bgColourArgumentCaptor.capture());
    Assertions.assertThat(bgColourArgumentCaptor.getValue().getValue()).isEqualTo("#0c2238");
    verify(decisionStylingSet).setFontColour(fontColourArgumentCaptor.capture());
    Assertions.assertThat(fontColourArgumentCaptor.getValue().getValue()).isEqualTo("#0c2238");
}
Also used : JSIColor(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIColor) JSIStyle(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.di.JSIStyle) JSIDMNShape(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNShape) Element(org.kie.workbench.common.stunner.core.graph.Element) Node(org.kie.workbench.common.stunner.core.graph.Node) StylingSet(org.kie.workbench.common.dmn.api.property.styling.StylingSet) JSITDecision(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecision) JSIDMNStyle(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNStyle) View(org.kie.workbench.common.stunner.core.graph.content.view.View) JSITDecision(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecision) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) Test(org.junit.Test)

Example 43 with Decision

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

the class DefaultValueUtilitiesTest method testUpdateNewNodeName_DecisionService.

@Test
public void testUpdateNewNodeName_DecisionService() {
    // Add some existing nodes to ensure naming is not affected by existing content
    graph.addNode(makeMockNode(new BusinessKnowledgeModel()));
    graph.addNode(makeMockNode(new Decision()));
    graph.addNode(makeMockNode(new InputData()));
    graph.addNode(makeMockNode(new KnowledgeSource()));
    final DecisionService decisionService1 = new DecisionService();
    final DecisionService decisionService2 = new DecisionService();
    final DecisionService decisionService3 = new DecisionService();
    final DecisionService decisionService4 = new DecisionService();
    assertUpdateNewNodeName(decisionService1, decisionService2, (decisionService) -> decisionService.getName().getValue(), () -> DecisionService.class.getSimpleName() + "-1", () -> DecisionService.class.getSimpleName() + "-2");
    // Update existing names manually and add two more
    decisionService1.getName().setValue("decisionService");
    decisionService2.getName().setValue(DecisionService.class.getSimpleName() + "-5");
    assertUpdateNewNodeName(decisionService3, decisionService4, (decisionService) -> decisionService.getName().getValue(), () -> DecisionService.class.getSimpleName() + "-6", () -> DecisionService.class.getSimpleName() + "-7");
}
Also used : KnowledgeSource(org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) Test(org.junit.Test)

Example 44 with Decision

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

the class DefaultValueUtilitiesTest method testUpdateNewNodeName_InputData.

@Test
public void testUpdateNewNodeName_InputData() {
    // Add some existing nodes to ensure naming is not affected by existing content
    graph.addNode(makeMockNode(new BusinessKnowledgeModel()));
    graph.addNode(makeMockNode(new Decision()));
    graph.addNode(makeMockNode(new KnowledgeSource()));
    graph.addNode(makeMockNode(new TextAnnotation()));
    final InputData inputData1 = new InputData();
    final InputData inputData2 = new InputData();
    final InputData inputData3 = new InputData();
    final InputData inputData4 = new InputData();
    assertUpdateNewNodeName(inputData1, inputData2, (inputData) -> inputData.getName().getValue(), () -> InputData.class.getSimpleName() + "-1", () -> InputData.class.getSimpleName() + "-2");
    // Update existing names manually and add two more
    inputData1.getName().setValue("inputData");
    inputData2.getName().setValue(InputData.class.getSimpleName() + "-5");
    assertUpdateNewNodeName(inputData3, inputData4, (inputData) -> inputData.getName().getValue(), () -> InputData.class.getSimpleName() + "-6", () -> InputData.class.getSimpleName() + "-7");
}
Also used : KnowledgeSource(org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) TextAnnotation(org.kie.workbench.common.dmn.api.definition.model.TextAnnotation) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) Test(org.junit.Test)

Example 45 with Decision

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

the class DefaultValueUtilitiesTest method testUpdateNewNodeName_TextAnnotation.

@Test
public void testUpdateNewNodeName_TextAnnotation() {
    // Add some existing nodes to ensure naming is not affected by existing content
    graph.addNode(makeMockNode(new BusinessKnowledgeModel()));
    graph.addNode(makeMockNode(new Decision()));
    graph.addNode(makeMockNode(new InputData()));
    graph.addNode(makeMockNode(new KnowledgeSource()));
    final TextAnnotation textAnnotation1 = new TextAnnotation();
    final TextAnnotation textAnnotation2 = new TextAnnotation();
    final TextAnnotation textAnnotation3 = new TextAnnotation();
    final TextAnnotation textAnnotation4 = new TextAnnotation();
    assertUpdateNewNodeName(textAnnotation1, textAnnotation2, (textAnnotation) -> textAnnotation.getText().getValue(), () -> TextAnnotation.class.getSimpleName() + "-1", () -> TextAnnotation.class.getSimpleName() + "-2");
    // Update existing names manually and add two more
    textAnnotation1.getText().setValue("textAnnotation");
    textAnnotation2.getText().setValue(TextAnnotation.class.getSimpleName() + "-5");
    assertUpdateNewNodeName(textAnnotation3, textAnnotation4, (textAnnotation) -> textAnnotation.getText().getValue(), () -> TextAnnotation.class.getSimpleName() + "-6", () -> TextAnnotation.class.getSimpleName() + "-7");
}
Also used : KnowledgeSource(org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) TextAnnotation(org.kie.workbench.common.dmn.api.definition.model.TextAnnotation) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) Test(org.junit.Test)

Aggregations

Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)121 Test (org.junit.Test)79 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)39 View (org.kie.workbench.common.stunner.core.graph.content.view.View)38 InputData (org.kie.workbench.common.dmn.api.definition.model.InputData)37 Node (org.kie.workbench.common.stunner.core.graph.Node)28 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)23 Edge (org.kie.workbench.common.stunner.core.graph.Edge)23 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel)22 KnowledgeSource (org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource)21 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)21 ViewImpl (org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl)20 List (java.util.List)16 TDecision (org.kie.dmn.model.v1_2.TDecision)16 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)16 DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)16 TextAnnotation (org.kie.workbench.common.dmn.api.definition.model.TextAnnotation)16 ArrayList (java.util.ArrayList)15 Optional (java.util.Optional)15 DecisionService (org.kie.workbench.common.dmn.api.definition.model.DecisionService)15