use of org.kie.workbench.common.dmn.api.definition.model.DMNDiagram in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionEnricherTest method setup.
@Before
public void setup() {
super.setup();
this.diagram = new DMNDiagram();
this.inputData1 = new InputData();
this.inputData2 = new InputData();
this.decision1 = new Decision();
}
use of org.kie.workbench.common.dmn.api.definition.model.DMNDiagram in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method connectTwoNodes.
@SuppressWarnings("unchecked")
private Diagram<Graph, Metadata> connectTwoNodes(final org.kie.workbench.common.stunner.core.graph.content.Bounds bounds, final String decisionNode1UUID, final String decisionNode2UUID, final String edgeUUID, final MagnetConnection edgeSourceConnection, final MagnetConnection edgeTargetConnection, final Consumer<MagnetConnection> sourceMagnetConsumer, final Consumer<MagnetConnection> targetMagnetConsumer) {
final DiagramImpl diagram = createDiagram();
final Graph<DefinitionSet, Node> graph = mock(Graph.class);
final Node<View, Edge> diagramNode = mock(Node.class);
final View diagramView = mock(View.class);
final DMNDiagram dmnDiagram = new DMNDiagram();
when(diagramNode.getContent()).thenReturn(diagramView);
when(diagramView.getDefinition()).thenReturn(dmnDiagram);
final Node<View, Edge> decisionNode1 = mock(Node.class);
final View decisionView1 = mock(View.class);
final Decision decision1 = new Decision();
decision1.getId().setValue(decisionNode1UUID);
when(decisionNode1.getContent()).thenReturn(decisionView1);
when(decisionView1.getDefinition()).thenReturn(decision1);
when(decisionView1.getBounds()).thenReturn(bounds);
final Node<View, Edge> decisionNode2 = mock(Node.class);
final View decisionView2 = mock(View.class);
final Decision decision2 = new Decision();
decision2.getId().setValue(decisionNode2UUID);
when(decisionNode2.getContent()).thenReturn(decisionView2);
when(decisionView2.getDefinition()).thenReturn(decision2);
when(decisionView2.getBounds()).thenReturn(bounds);
final Edge edge = mock(Edge.class);
final ViewConnector edgeView = mock(ViewConnector.class);
Optional edgeSourceConnectionOptional = Optional.empty();
if (edgeSourceConnection != null) {
edgeSourceConnectionOptional = Optional.of(edgeSourceConnection);
}
Optional edgeTargetConnectionOptional = Optional.empty();
if (edgeTargetConnection != null) {
edgeTargetConnectionOptional = Optional.of(edgeTargetConnection);
}
when(edge.getUUID()).thenReturn(edgeUUID);
when(edge.getContent()).thenReturn(edgeView);
when(edgeView.getSourceConnection()).thenReturn(edgeSourceConnectionOptional);
when(edgeView.getTargetConnection()).thenReturn(edgeTargetConnectionOptional);
when(edgeView.getControlPoints()).thenReturn(new ControlPoint[] {});
when(decisionNode1.getOutEdges()).thenReturn(Collections.singletonList(edge));
when(decisionNode2.getInEdges()).thenReturn(Collections.singletonList(edge));
when(edge.getSourceNode()).thenReturn(decisionNode1);
when(edge.getTargetNode()).thenReturn(decisionNode2);
sourceMagnetConsumer.accept(edgeSourceConnection);
targetMagnetConsumer.accept(edgeTargetConnection);
doReturn(asList(diagramNode, decisionNode1, decisionNode2)).when(graph).nodes();
diagram.setGraph(graph);
return diagram;
}
use of org.kie.workbench.common.dmn.api.definition.model.DMNDiagram in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method newDiagramDecisionWithExpression.
@SuppressWarnings("unchecked")
private Diagram<Graph, Metadata> newDiagramDecisionWithExpression(final Expression expression) {
final Diagram<Graph, Metadata> diagram = createDiagram();
final Graph<DefinitionSet, Node> graph = mock(Graph.class);
final Node<View, ?> diagramNode = mock(Node.class);
final View diagramView = mock(View.class);
final DMNDiagram dmnDiagram = new DMNDiagram();
doReturn(diagramView).when(diagramNode).getContent();
doReturn(dmnDiagram).when(diagramView).getDefinition();
final Node<View, ?> decisionNode = mock(Node.class);
final View decisionView = mock(View.class);
final Decision decision = new Decision();
doReturn(decisionView).when(decisionNode).getContent();
doReturn(decision).when(decisionView).getDefinition();
decision.setExpression(expression);
doReturn(asList(diagramNode, decisionNode)).when(graph).nodes();
((DiagramImpl) diagram).setGraph(graph);
return diagram;
}
use of org.kie.workbench.common.dmn.api.definition.model.DMNDiagram in project kie-wb-common by kiegroup.
the class DMNMarshallerService method registerDiagramInstance.
public void registerDiagramInstance(final Diagram diagram, final String title, final String shapeSetId) {
registerMetadata(diagram, title, shapeSetId);
final Node<?, ?> dmnDiagramRoot = DMNGraphUtils.findDMNDiagramRoot(diagram.getGraph());
final DMNDiagram definition = ((View<DMNDiagram>) dmnDiagramRoot.getContent()).getDefinition();
final DMNDiagramElement drgDiagram = DRGDiagramUtils.newDRGInstance();
final String diagramId = drgDiagram.getId().getValue();
final Map<String, Diagram> diagramsByDiagramElementId = new HashMap<>();
final Map<String, DMNDiagramElement> dmnDiagramsByDiagramElementId = new HashMap<>();
definition.getDefinitions().getDiagramElements().add(drgDiagram);
diagramsByDiagramElementId.put(diagramId, diagram);
dmnDiagramsByDiagramElementId.put(diagramId, drgDiagram);
dmnDiagramsSession.setState(getMetadata(), diagramsByDiagramElementId, dmnDiagramsByDiagramElementId);
}
use of org.kie.workbench.common.dmn.api.definition.model.DMNDiagram in project kie-wb-common by kiegroup.
the class DecisionNavigatorBaseItemFactoryTest method testMakeItem.
@Test
@SuppressWarnings("unchecked")
public void testMakeItem() {
final String itemUUID = "itemUUID";
final String childUUID = "childUUID";
final String graphUUID = "graphUUID";
final String label = "label";
final Command onClick = mock(Command.class);
final Node<Definition, Edge> diagramNode = mock(Node.class);
final Definition diagramDefinition = mock(Definition.class);
final DMNDiagram diagram = mock(DMNDiagram.class);
final DecisionNavigatorItem child = new DecisionNavigatorItemBuilder().withUUID(childUUID).build();
final List<DecisionNavigatorItem> nestedItems = singletonList(child);
when(node.getUUID()).thenReturn(itemUUID);
doReturn(label).when(factory).getLabel(node);
doReturn(onClick).when(factory).makeOnClickCommand(node);
doReturn(nestedItems).when(factory).makeNestedItems(node);
when(graph.nodes()).thenReturn(Collections.singletonList(diagramNode));
when(diagramNode.getContent()).thenReturn(diagramDefinition);
when(diagramDefinition.getDefinition()).thenReturn(diagram);
when(diagramNode.getUUID()).thenReturn(graphUUID);
final DecisionNavigatorItem item = factory.makeItem(node, ITEM);
assertEquals(itemUUID, item.getUUID());
assertEquals(label, item.getLabel());
assertTrue(item.getOnClick().isPresent());
assertEquals(onClick, item.getOnClick().get());
assertEquals(asTreeSet(child), item.getChildren());
assertEquals(itemUUID, child.getParentUUID());
}
Aggregations