use of org.kie.workbench.common.dmn.api.definition.model.NamedElement in project kie-wb-common by kiegroup.
the class DMNMarshallerStandalone method getImportPrefix.
private static Optional<String> getImportPrefix(final Definitions definitions, final DMNElement dmnElement) {
if (!(dmnElement instanceof NamedElement)) {
return Optional.empty();
}
final NamedElement namedElement = (NamedElement) dmnElement;
final Optional<String> name = Optional.ofNullable(namedElement.getName().getValue());
return definitions.getImport().stream().filter(anImport -> {
final String importName = anImport.getName().getValue();
return name.map(n -> n.startsWith(importName + ".")).orElse(false);
}).map(anImport -> {
final String importNamespace = anImport.getNamespace();
return getNsContextsByNamespace(definitions, importNamespace);
}).findFirst();
}
use of org.kie.workbench.common.dmn.api.definition.model.NamedElement in project kie-wb-common by kiegroup.
the class InformationItemPrimaryPropertyConverterTest method testDmnFromWBWhenWBIsNotNull.
@Test
public void testDmnFromWBWhenWBIsNotNull() {
final String expectedId = "id";
final String expectedName = "name";
final Id id = new Id(expectedId);
final Name name = new Name(expectedName);
final String qNameNamespaceURI = "qName namespaceURI";
final String qNameLocalPart = "qName local part";
final String qNamePrefix = "qName prefix";
final InformationItemPrimary wb = mock(InformationItemPrimary.class);
final QName qName = mock(QName.class);
final javax.xml.namespace.QName expectedQName = new javax.xml.namespace.QName(qNameNamespaceURI, qNameLocalPart, qNamePrefix);
final NamedElement parentElement = mock(NamedElement.class);
when(wb.getId()).thenReturn(id);
when(wb.getName()).thenReturn(name);
when(wb.getTypeRef()).thenReturn(qName);
when(wb.getParent()).thenReturn(parentElement);
when(parentElement.getName()).thenReturn(name);
when(qName.getNamespaceURI()).thenReturn(qNameNamespaceURI);
when(qName.getLocalPart()).thenReturn(qNameLocalPart);
when(qName.getPrefix()).thenReturn(qNamePrefix);
final TInformationItem informationItem = InformationItemPrimaryPropertyConverter.dmnFromWB(wb, wb);
final String actualId = informationItem.getId();
final String actualName = informationItem.getName();
final javax.xml.namespace.QName actualQName = informationItem.getTypeRef();
assertEquals(expectedId, actualId);
assertEquals(expectedName, actualName);
assertEquals(expectedQName, actualQName);
}
use of org.kie.workbench.common.dmn.api.definition.model.NamedElement in project kie-wb-common by kiegroup.
the class DefaultValueUtilitiesTest method testUpdateNewNodeNameWhenNomeIsAlreadySet.
@Test
public void testUpdateNewNodeNameWhenNomeIsAlreadySet() {
final String existingName = "existingName";
final NamedElement dec = mock(NamedElement.class);
final Name name = new Name();
name.setValue(existingName);
when(dec.getName()).thenReturn(name);
DefaultValueUtilities.updateNewNodeName(graph, dec);
assertEquals(existingName, dec.getName().getValue());
}
use of org.kie.workbench.common.dmn.api.definition.model.NamedElement in project kie-wb-common by kiegroup.
the class NodeTextSetterTest method testGetName.
@Test
public void testGetName() {
final NamedElement named = mock(NamedElement.class);
final Node node = mock(Node.class);
final Name name = mock(Name.class);
final String nodeName = "node name";
when(name.getValue()).thenReturn(nodeName);
when(named.getName()).thenReturn(name);
doReturn(Optional.of(named)).when(nodeTextSetter).getNamedElement(node);
final String actualName = nodeTextSetter.getName(node);
assertEquals(nodeName, actualName);
}
use of org.kie.workbench.common.dmn.api.definition.model.NamedElement in project kie-wb-common by kiegroup.
the class NodeTextSetterTest method testGetNamedElement.
@Test
public void testGetNamedElement() {
final Node node = mock(Node.class);
final View content = mock(View.class);
final NamedElement namedElement = mock(NamedElement.class);
when(node.getContent()).thenReturn(content);
when(content.getDefinition()).thenReturn(namedElement);
final Optional<NamedElement> actualNamed = nodeTextSetter.getNamedElement(node);
assertTrue(actualNamed.isPresent());
assertEquals(namedElement, actualNamed.get());
}
Aggregations