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 AbstractDMNDiagramFactory method updateName.
private void updateName(final Node<Definition<DMNDiagram>, ?> diagramNode, final String name) {
final DMNDiagram dmnDiagram = (DMNDiagram) DefinitionUtils.getElementDefinition(diagramNode);
final Definitions dmnDefinitions = dmnDiagram.getDefinitions();
final Name dmnName = dmnDefinitions.getName();
if (StringUtils.isEmpty(dmnName.getValue())) {
dmnName.setValue(name);
}
}
use of org.kie.workbench.common.dmn.api.definition.model.Definitions in project kie-wb-common by kiegroup.
the class AbstractDMNDiagramFactory method updateDefaultNameSpaces.
private void updateDefaultNameSpaces(final Node<Definition<DMNDiagram>, ?> diagramNode) {
final DMNDiagram dmnDiagram = (DMNDiagram) DefinitionUtils.getElementDefinition(diagramNode);
final Definitions dmnDefinitions = dmnDiagram.getDefinitions();
Stream.of(DMNModelInstrumentedBase.Namespace.values()).filter(namespace -> !dmnDefinitions.getNsContext().containsValue(namespace.getUri())).forEach(namespace -> {
if (!namespace.getPrefix().equalsIgnoreCase(DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix())) {
dmnDefinitions.getNsContext().put(namespace.getPrefix(), namespace.getUri());
}
});
String defaultNamespace = !StringUtils.isEmpty(dmnDefinitions.getNamespace().getValue()) ? dmnDefinitions.getNamespace().getValue() : DMNModelInstrumentedBase.Namespace.DEFAULT.getUri() + UUID.uuid();
dmnDefinitions.setNamespace(new Text(defaultNamespace));
dmnDefinitions.getNsContext().putIfAbsent(DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix(), defaultNamespace);
}
use of org.kie.workbench.common.dmn.api.definition.model.Definitions in project kie-wb-common by kiegroup.
the class DMNDiagramFactoryImplTest method testModelName.
@Test
@SuppressWarnings("unchecked")
public void testModelName() {
final Diagram diagram = factory.build(NAME, metadata, graph);
// We can safely get the first object on the iterator as we know the graph only contains one node
final Node<View, Edge> root = (Node<View, Edge>) diagram.getGraph().nodes().iterator().next();
final DMNDiagram dmnDiagram = (DMNDiagram) DefinitionUtils.getElementDefinition(root);
final Definitions dmnDefinitions = dmnDiagram.getDefinitions();
assertEquals(NAME, dmnDefinitions.getName().getValue());
}
use of org.kie.workbench.common.dmn.api.definition.model.Definitions in project kie-wb-common by kiegroup.
the class DMNDiagramFactoryImplTest method testModelNameWithNonEmptyExistingName.
@Test
@SuppressWarnings("unchecked")
public void testModelNameWithNonEmptyExistingName() {
final Node<View, Edge> existingRoot = (Node<View, Edge>) graph.nodes().iterator().next();
final DMNDiagram existingDMNDiagram = (DMNDiagram) DefinitionUtils.getElementDefinition(existingRoot);
final Definitions existingDMNDefinitions = existingDMNDiagram.getDefinitions();
existingDMNDefinitions.getName().setValue(EXISTING_NAME);
final Diagram newDiagram = factory.build(NAME, metadata, graph);
final Node<View, Edge> newRoot = (Node<View, Edge>) newDiagram.getGraph().nodes().iterator().next();
final DMNDiagram newDMNDiagram = (DMNDiagram) DefinitionUtils.getElementDefinition(newRoot);
final Definitions newDMNDefinitions = newDMNDiagram.getDefinitions();
assertEquals(EXISTING_NAME, newDMNDefinitions.getName().getValue());
}
Aggregations