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));
}
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));
}
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());
}
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);
}
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);
}
Aggregations