Search in sources :

Example 46 with Definitions

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

the class DecisionNavigatorItemFactoryTest method testGetOnRemove.

@Test
public void testGetOnRemove() {
    final DMNDiagramElement drgDiagramElement = new DMNDiagramElement();
    final DMNDiagramElement drd1DiagramElement = new DMNDiagramElement();
    final DMNDiagramElement drd2DiagramElement = new DMNDiagramElement();
    final DMNDiagramElement drgElement = mock(DMNDiagramElement.class);
    final Graph drgGraph = mock(Graph.class);
    final Diagram drgDiagram = mock(Diagram.class);
    final DecisionNavigatorItem item = mock(DecisionNavigatorItem.class);
    final Node node = mock(Node.class);
    final Definition definition = mock(Definition.class);
    final DMNDiagram dmnDiagram = mock(DMNDiagram.class);
    final Definitions dmnDefinitions = mock(Definitions.class);
    final List<DMNDiagramElement> diagramElements = new ArrayList<>(asList(drgDiagramElement, drd1DiagramElement, drd2DiagramElement));
    final Iterable nodes = singletonList(node);
    when(dmnDiagramsSession.getDRGDiagramElement()).thenReturn(drgElement);
    when(dmnDiagramsSession.getDRGDiagram()).thenReturn(drgDiagram);
    when(drgDiagram.getGraph()).thenReturn(drgGraph);
    when(drgGraph.nodes()).thenReturn(nodes);
    when(node.getContent()).thenReturn(definition);
    when(definition.getDefinition()).thenReturn(dmnDiagram);
    when(dmnDiagram.getDefinitions()).thenReturn(dmnDefinitions);
    when(dmnDefinitions.getDiagramElements()).thenReturn(diagramElements);
    factory.getOnRemove(drd1DiagramElement).accept(item);
    verify(dmnDiagramsSession).remove(drd1DiagramElement);
    verify(selectedEvent).fire(diagramSelectedArgumentCaptor.capture());
    assertEquals(drgElement, diagramSelectedArgumentCaptor.getValue().getDiagramElement());
    assertEquals(2, diagramElements.size());
    assertTrue(diagramElements.contains(drgDiagramElement));
    assertFalse(diagramElements.contains(drd1DiagramElement));
    assertTrue(diagramElements.contains(drd2DiagramElement));
}
Also used : DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Graph(org.kie.workbench.common.stunner.core.graph.Graph) DecisionNavigatorItem(org.kie.workbench.common.dmn.client.docks.navigator.DecisionNavigatorItem) Node(org.kie.workbench.common.stunner.core.graph.Node) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) ArrayList(java.util.ArrayList) DMNDiagramElement(org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Test(org.junit.Test)

Example 47 with Definitions

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

the class DMNMarshallerTest method testWithIncludedModelsWhenNodeParentIsDMNDiagram.

@Test
public void testWithIncludedModelsWhenNodeParentIsDMNDiagram() {
    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<>();
    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));
}
Also used : JSIDMNDiagram(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram) DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) 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 48 with Definitions

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

the class DefinitionsConverterTest method wbFromDMN.

@Test
public void wbFromDMN() {
    final Import anImport = new TImport();
    anImport.setImportType(DMNImportTypes.DMN.getDefaultNamespace());
    final org.kie.dmn.model.api.Definitions definitions = mock(org.kie.dmn.model.api.Definitions.class);
    final Map<Import, org.kie.dmn.model.api.Definitions> importDefinitions = new Maps.Builder<Import, org.kie.dmn.model.api.Definitions>().put(anImport, definitions).build();
    final Map<Import, PMMLDocumentMetadata> pmmlDocuments = new Maps.Builder<Import, PMMLDocumentMetadata>().build();
    when(definitions.getDrgElement()).thenReturn(asList(mock(DRGElement.class), mock(DRGElement.class)));
    when(definitions.getItemDefinition()).thenReturn(asList(mock(ItemDefinition.class), mock(ItemDefinition.class), mock(ItemDefinition.class)));
    when(apiDefinitions.getImport()).thenReturn(singletonList(anImport));
    final Definitions wb = DefinitionsConverter.wbFromDMN(apiDefinitions, importDefinitions, pmmlDocuments);
    final String defaultNs = wb.getNsContext().get(DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix());
    final String namespace = wb.getNamespace().getValue();
    final List<org.kie.workbench.common.dmn.api.definition.model.Import> imports = wb.getImport();
    assertEquals(defaultNs, namespace);
    assertEquals(1, imports.size());
    assertTrue(imports.get(0) instanceof ImportDMN);
    final ImportDMN importDMN = (ImportDMN) imports.get(0);
    assertEquals(2, importDMN.getDrgElementsCount());
    assertEquals(3, importDMN.getItemDefinitionsCount());
}
Also used : TImport(org.kie.dmn.model.v1_2.TImport) Import(org.kie.dmn.model.api.Import) ImportDMN(org.kie.workbench.common.dmn.api.definition.model.ImportDMN) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) TImport(org.kie.dmn.model.v1_2.TImport) Maps(org.kie.soup.commons.util.Maps) Test(org.junit.Test)

Example 49 with Definitions

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

the class DMNDiagramHelperTest method testGetItemDefinitionsByDiagram.

@Test
public void testGetItemDefinitionsByDiagram() {
    final Definitions definitions = mock(Definitions.class);
    final List<ItemDefinition> expectedItemDefinitions = asList(mock(ItemDefinition.class), mock(ItemDefinition.class));
    when(definitions.getItemDefinition()).thenReturn(expectedItemDefinitions);
    when(dmnDiagramUtils.getDefinitions(diagram)).thenReturn(definitions);
    final List<ItemDefinition> actualItemDefinitions = helper.getItemDefinitions(diagram);
    assertEquals(expectedItemDefinitions, actualItemDefinitions);
}
Also used : Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) Test(org.junit.Test)

Example 50 with Definitions

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

the class DMNDomainValidatorImplTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() throws IOException {
    this.definitions = new Definitions();
    this.validationMessages = new ArrayList<>();
    this.domainValidator = spy(new DMNDomainValidatorImpl(dmnMarshaller, dmnDiagramUtils, importsHelper, dmnIOHelper));
    doReturn(dmnValidator).when(domainValidator).getDMNValidator();
    domainValidator.setupValidator();
    when(dmnMarshaller.marshall(diagram)).thenReturn(DMN_XML);
    when(dmnDiagramUtils.getDefinitions(diagram)).thenReturn(definitions);
    when(dmnValidator.validateUsing(any())).thenReturn(dmnValidatorBuilder);
    when(dmnValidatorBuilder.usingImports(resolver)).thenReturn(dmnValidatorBuilder);
    when(dmnValidatorBuilder.theseModels(Mockito.<Reader>any())).thenReturn(validationMessages);
    when(diagram.getMetadata()).thenReturn(metadata);
}
Also used : Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) Before(org.junit.Before)

Aggregations

Definitions (org.kie.workbench.common.dmn.api.definition.model.Definitions)70 Test (org.junit.Test)41 ItemDefinition (org.kie.workbench.common.dmn.api.definition.model.ItemDefinition)24 Node (org.kie.workbench.common.stunner.core.graph.Node)23 DMNDiagram (org.kie.workbench.common.dmn.api.definition.model.DMNDiagram)22 DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)19 ArrayList (java.util.ArrayList)18 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)18 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)15 Import (org.kie.workbench.common.dmn.api.definition.model.Import)15 Diagram (org.kie.workbench.common.stunner.core.diagram.Diagram)14 View (org.kie.workbench.common.stunner.core.graph.content.view.View)14 List (java.util.List)13 Objects (java.util.Objects)12 Optional (java.util.Optional)12 PMMLDocumentMetadata (org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata)12 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)12 JSITDefinitions (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions)12 Edge (org.kie.workbench.common.stunner.core.graph.Edge)12 Map (java.util.Map)11