use of org.kie.workbench.common.dmn.api.definition.model.DRGElement in project kie-wb-common by kiegroup.
the class DMNMarshallerImportsService method getDRGElements.
public void getDRGElements(final String dmnXml, final ServiceCallback<List<DRGElement>> callback) {
final DMN12UnmarshallCallback jsCallback = dmn12 -> {
final JSITDefinitions dmnDefinitions = Js.uncheckedCast(JsUtils.getUnwrappedElement(dmn12));
callback.onSuccess(modelToStunnerConverter.makeNodes(dmnDefinitions, new HashMap<>(), false, (a, b) -> {
/* Nothing. */
}).stream().map(e -> getDRGElement(e.getNode())).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList()));
};
MainJs.unmarshall(dmnXml, "", jsCallback);
}
use of org.kie.workbench.common.dmn.api.definition.model.DRGElement in project kie-wb-common by kiegroup.
the class DMNIncludedModelHandlerTest method testDestroy.
@Test
public void testDestroy() {
final Decision drgElement1 = makeDecision("model1.tUUID", "string", true);
final Decision drgElement2 = makeDecision("model1.imported person", "model1.tPerson", true);
final InputData drgElement3 = makeInputData("local person", "model1.tPerson", false);
final InputData drgElement4 = makeInputData("regular DRG Element", "boolean", false);
final List<DRGElement> drgElements = asList(drgElement1, drgElement2, drgElement3, drgElement4);
doNothing().when(handler).deleteDRGElement(any());
when(dmnGraphUtils.getModelDRGElements()).thenReturn(drgElements);
handler.destroy("model1");
verify(handler).deleteDRGElement(drgElement1);
verify(handler).deleteDRGElement(drgElement2);
}
use of org.kie.workbench.common.dmn.api.definition.model.DRGElement in project kie-wb-common by kiegroup.
the class DMNIncludedModelHandlerTest method testUpdateDRGElementName.
@Test
public void testUpdateDRGElementName() {
final DRGElement drgElement = mock(DRGElement.class);
final AbstractCanvasHandler canvasHandler = mock(AbstractCanvasHandler.class);
final String newName = "new name";
when(dmnGraphUtils.getCanvasHandler()).thenReturn(canvasHandler);
doReturn(compositeCommand).when(handler).buildUpdateCommand(drgElement, newName);
handler.updateDRGElementName(drgElement, newName);
verify(sessionCommandManager).execute(canvasHandler, compositeCommand);
}
use of org.kie.workbench.common.dmn.api.definition.model.DRGElement in project kie-wb-common by kiegroup.
the class DMNIncludedModelHandlerTest method testGetNode.
@Test
public void testGetNode() {
final DRGElement drgElement = mock(DRGElement.class);
final AbstractCanvasHandler canvasHandler = mock(AbstractCanvasHandler.class);
final Diagram diagram = mock(Diagram.class);
final Graph graph = mock(Graph.class);
final Node node1 = mock(Node.class);
final Node node2 = mock(Node.class);
final Node node3 = mock(Node.class);
final Definition definition1 = mock(Definition.class);
final Definition definition2 = mock(Definition.class);
final Definition definition3 = mock(Definition.class);
when(definition1.getDefinition()).thenReturn(new Object());
when(definition2.getDefinition()).thenReturn(drgElement);
when(definition3.getDefinition()).thenReturn(new Object());
when(node1.getContent()).thenReturn(definition1);
when(node2.getContent()).thenReturn(definition2);
when(node3.getContent()).thenReturn(definition3);
when(canvasHandler.getDiagram()).thenReturn(diagram);
when(diagram.getGraph()).thenReturn(graph);
when(graph.nodes()).thenReturn(asList(node1, node2, node3));
when(dmnGraphUtils.getCanvasHandler()).thenReturn(canvasHandler);
final Node actualNode = handler.getNode(drgElement);
assertEquals(node2, actualNode);
}
use of org.kie.workbench.common.dmn.api.definition.model.DRGElement in project kie-wb-common by kiegroup.
the class DMNMarshallerTest method testWithIncludedModelsWhenNodeAlreadyHasImports.
@Test
public void testWithIncludedModelsWhenNodeAlreadyHasImports() {
final DMNMarshaller dmnMarshaller = spy(new DMNMarshaller());
final Node node = mock(Node.class);
final Definition nodeDefinition = mock(Definition.class);
final DRGElement drgElement = mock(DRGElement.class);
final Definitions definitionsStunnerPojo = mock(Definitions.class);
final Import import1 = mock(Import.class);
final Import import2 = mock(Import.class);
final List<Import> diagramImports = new ArrayList<>(asList(import1, import2));
final DMNDiagram nodeDiagram = mock(DMNDiagram.class);
final Definitions nodeDiagramDefinitions = mock(Definitions.class);
final List<Import> nodeDiagramImports = new ArrayList<>(asList(import1, import2));
when(node.getContent()).thenReturn(nodeDefinition);
when(nodeDefinition.getDefinition()).thenReturn(drgElement);
when(definitionsStunnerPojo.getImport()).thenReturn(diagramImports);
when(drgElement.getParent()).thenReturn(nodeDiagram);
when(nodeDiagram.getDefinitions()).thenReturn(nodeDiagramDefinitions);
when(nodeDiagramDefinitions.getImport()).thenReturn(nodeDiagramImports);
dmnMarshaller.withIncludedModels(node, definitionsStunnerPojo);
assertEquals(2, nodeDiagramImports.size());
assertTrue(nodeDiagramImports.contains(import1));
assertTrue(nodeDiagramImports.contains(import2));
}
Aggregations