Search in sources :

Example 31 with DRGElement

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

the class DMNMarshallerTest method testWithIncludedModelsWhenNodeParentIsDefinitions.

@Test
public void testWithIncludedModelsWhenNodeParentIsDefinitions() {
    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 Definitions nodeDiagramDefinitions = mock(Definitions.class);
    final List<Import> nodeDiagramImports = new ArrayList<>();
    when(node.getContent()).thenReturn(nodeDefinition);
    when(nodeDefinition.getDefinition()).thenReturn(drgElement);
    when(definitionsStunnerPojo.getImport()).thenReturn(diagramImports);
    when(drgElement.getParent()).thenReturn(nodeDiagramDefinitions);
    when(nodeDiagramDefinitions.getImport()).thenReturn(nodeDiagramImports);
    dmnMarshaller.withIncludedModels(node, definitionsStunnerPojo);
    assertEquals(2, nodeDiagramImports.size());
    assertTrue(nodeDiagramImports.contains(import1));
    assertTrue(nodeDiagramImports.contains(import2));
}
Also used : Import(org.kie.workbench.common.dmn.api.definition.model.Import) Node(org.kie.workbench.common.stunner.core.graph.Node) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) ArrayList(java.util.ArrayList) JSITDRGElement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDRGElement) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) Test(org.junit.Test)

Example 32 with DRGElement

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

the class DMNElementsSynchronizerTest method testSynchronizeBaseDRGProperties.

@Test
public void testSynchronizeBaseDRGProperties() {
    final DRGElement from = mock(DRGElement.class);
    final DRGElement to = mock(DRGElement.class);
    final Description description = mock(Description.class);
    final DocumentationLinksHolder linksHolder = mock(DocumentationLinksHolder.class);
    final Name name = mock(Name.class);
    when(from.getDescription()).thenReturn(description);
    when(from.getLinksHolder()).thenReturn(linksHolder);
    when(from.getName()).thenReturn(name);
    synchronizer.synchronizeBaseDRGProperties(from, to);
    verify(to).setDescription(description);
    verify(to).setName(name);
    verify(to).setLinksHolder(linksHolder);
}
Also used : Description(org.kie.workbench.common.dmn.api.property.dmn.Description) DocumentationLinksHolder(org.kie.workbench.common.dmn.api.property.dmn.DocumentationLinksHolder) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Example 33 with DRGElement

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

the class DMNElementsSynchronizerTest method testGetElementsWithContentId.

@Test
public void testGetElementsWithContentId() {
    final Node node1 = mock(Node.class);
    final Node node2 = mock(Node.class);
    final Node node3 = mock(Node.class);
    final DRGElement contentDefinition1 = mock(DRGElement.class);
    final DRGElement contentDefinition3 = mock(DRGElement.class);
    final String theId = "the id";
    final String anotherId = "another id";
    final List<Node> nodes = Arrays.asList(node1, node2, node3);
    when(dmnDiagramsSession.getAllNodes()).thenReturn(nodes);
    when(contentDefinition1.getContentDefinitionId()).thenReturn(theId);
    when(contentDefinition3.getContentDefinitionId()).thenReturn(anotherId);
    doReturn(contentDefinition1).when(synchronizer).getDRGElementFromContentDefinition(node1);
    doReturn(contentDefinition3).when(synchronizer).getDRGElementFromContentDefinition(node3);
    doReturn(true).when(synchronizer).definitionContainsDRGElement(node1);
    doReturn(false).when(synchronizer).definitionContainsDRGElement(node2);
    doReturn(true).when(synchronizer).definitionContainsDRGElement(node3);
    final List<Node> elements = synchronizer.getElementsWithContentId(theId);
    verify(synchronizer).definitionContainsDRGElement(node1);
    verify(synchronizer).definitionContainsDRGElement(node2);
    verify(synchronizer).definitionContainsDRGElement(node3);
    verify(synchronizer).getDRGElementFromContentDefinition(node1);
    verify(synchronizer, never()).getDRGElementFromContentDefinition(node2);
    verify(synchronizer).getDRGElementFromContentDefinition(node3);
    assertEquals(1, elements.size());
    assertTrue(elements.contains(node1));
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) Test(org.junit.Test)

Example 34 with DRGElement

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

the class DMNElementsSynchronizerTest method testSynchronizeElementsFrom.

@Test
public void testSynchronizeElementsFrom() {
    final Node node1 = mock(Node.class);
    final Node node2 = mock(Node.class);
    final Node node3 = mock(Node.class);
    final List<Node> nodes = Arrays.asList(node1, node2, node3);
    final DRGElement drgElement = mock(DRGElement.class);
    final String contentDefinitionId = "id";
    final DRGElement drgElement1 = mock(DRGElement.class);
    final DRGElement drgElement2 = mock(DRGElement.class);
    final DRGElement drgElement3 = mock(DRGElement.class);
    when(drgElement.getContentDefinitionId()).thenReturn(contentDefinitionId);
    doNothing().when(synchronizer).updateText(any(DRGElement.class), any(Node.class));
    doReturn(nodes).when(synchronizer).getElementsWithContentId(contentDefinitionId);
    doReturn(drgElement1).when(synchronizer).getDRGElementFromContentDefinition(node1);
    doReturn(drgElement2).when(synchronizer).getDRGElementFromContentDefinition(node2);
    doReturn(drgElement3).when(synchronizer).getDRGElementFromContentDefinition(node3);
    doNothing().when(synchronizer).synchronizeBaseDRGProperties(any(DRGElement.class), any(DRGElement.class));
    doNothing().when(synchronizer).synchronizeSpecializedProperties(any(DRGElement.class), any(DRGElement.class));
    synchronizer.synchronizeElementsFrom(drgElement);
    verify(synchronizer).getElementsWithContentId(contentDefinitionId);
    verify(synchronizer).updateText(drgElement, node1);
    verify(synchronizer).updateText(drgElement, node2);
    verify(synchronizer).updateText(drgElement, node3);
    verify(synchronizer).synchronizeBaseDRGProperties(drgElement, drgElement1);
    verify(synchronizer).synchronizeBaseDRGProperties(drgElement, drgElement2);
    verify(synchronizer).synchronizeBaseDRGProperties(drgElement, drgElement3);
    verify(synchronizer).synchronizeSpecializedProperties(drgElement, drgElement1);
    verify(synchronizer).synchronizeSpecializedProperties(drgElement, drgElement2);
    verify(synchronizer).synchronizeSpecializedProperties(drgElement, drgElement3);
    verify(refreshDecisionComponentsEvent).fire(any(RefreshDecisionComponents.class));
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) RefreshDecisionComponents(org.kie.workbench.common.dmn.client.docks.navigator.events.RefreshDecisionComponents) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) Test(org.junit.Test)

Example 35 with DRGElement

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

the class HrefBuilderTest method testGetHrefForImportedDRGElement.

@Test
public void testGetHrefForImportedDRGElement() {
    final DRGElement drgElement = mock(DRGElement.class);
    final Name drgElementName = mock(Name.class);
    final Name importName = mock(Name.class);
    final Id id = mock(Id.class);
    final Definitions definitions = mock(Definitions.class);
    final Import anImport = mock(Import.class);
    final List<Import> imports = singletonList(anImport);
    final String includedModelName = "includedModel";
    when(importName.getValue()).thenReturn(includedModelName);
    when(anImport.getName()).thenReturn(importName);
    when(anImport.getNamespace()).thenReturn("https://github.com/kiegroup/dmn/something");
    when(id.getValue()).thenReturn("0000-1111-2222");
    when(drgElementName.getValue()).thenReturn(includedModelName + ".Decision");
    when(drgElement.getId()).thenReturn(id);
    when(drgElement.getName()).thenReturn(drgElementName);
    when(drgElement.getParent()).thenReturn(definitions);
    when(definitions.getImport()).thenReturn(imports);
    final String actual = HrefBuilder.getHref(drgElement);
    final String expected = "https://github.com/kiegroup/dmn/something#0000-1111-2222";
    assertEquals(expected, actual);
}
Also used : Import(org.kie.workbench.common.dmn.api.definition.model.Import) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Aggregations

DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)72 Test (org.junit.Test)45 Node (org.kie.workbench.common.stunner.core.graph.Node)27 ArrayList (java.util.ArrayList)25 Edge (org.kie.workbench.common.stunner.core.graph.Edge)17 View (org.kie.workbench.common.stunner.core.graph.content.view.View)17 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)16 List (java.util.List)15 Definitions (org.kie.workbench.common.dmn.api.definition.model.Definitions)15 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)15 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)15 InputData (org.kie.workbench.common.dmn.api.definition.model.InputData)14 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)13 DecisionService (org.kie.workbench.common.dmn.api.definition.model.DecisionService)10 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel)9 Import (org.kie.workbench.common.dmn.api.definition.model.Import)9 KnowledgeSource (org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource)8 KnowledgeRequirement (org.kie.workbench.common.dmn.api.definition.model.KnowledgeRequirement)7 JSITDefinitions (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions)7 Optional (java.util.Optional)6