@Test public void testGetDmnElementRefWithNamespaceWhenImportHasAnOddName() { final Decision drgElement = mock(Decision.class); final View<? extends DMNElement> view = new ViewImpl<>(drgElement, null); final Name drgElementName = mock(Name.class); final Name importName = mock(Name.class); final Id id = mock(Id.class); final org.kie.workbench.common.dmn.api.definition.model.Definitions definitions = mock(org.kie.workbench.common.dmn.api.definition.model.Definitions.class); final Import anImport = mock(Import.class); final List<Import> imports = singletonList(anImport); final String includedModelName = "d.i.v.i."; final String defaultNamespace = ": final String namespaceName = "include1"; final String importNamespace = ": final Map<String, String> nsContext = new HashMap<>(); when(importName.getValue()).thenReturn(includedModelName); when(anImport.getName()).thenReturn(importName); when(anImport.getNamespace()).thenReturn(importNamespace); 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); nsContext.put(namespaceName, importNamespace); when(definitions.getImport()).thenReturn(imports); when(definitions.getNsContext()).thenReturn(nsContext); final QName actual = getDmnElementRef(definitions, view, defaultNamespace); assertEquals(defaultNamespace, actual.getNamespaceURI()); assertEquals("include1:0000-1111-2222", actual.getLocalPart()); assertEquals("", actual.getPrefix()); }
static QName getDmnElementRef(final Definitions definitions, final View<? extends DMNElement> v, final String namespaceURI) { final DMNElement dmnElement = v.getDefinition(); final String dmnElementId = dmnElement.getId().getValue(); return getImportPrefix(definitions, dmnElement) .map(prefix -> new QName(namespaceURI, prefix + ":" + dmnElementId, XMLConstants.DEFAULT_NS_PREFIX)) .orElse(new QName(namespaceURI, dmnElementId, XMLConstants.DEFAULT_NS_PREFIX)); }
WrapperUtils { static QName getDmnElementRef(final Definitions definitions, final View<? extends DMNElement> v, final String namespaceURI) { final DMNElement dmnElement = v.getDefinition(); final String dmnElementId = dmnElement.getId().getValue(); return getImportPrefix(definitions, dmnElement) .map(prefix -> new QName(namespaceURI, prefix + ":" + dmnElementId, XMLConstants.DEFAULT_NS_PREFIX)) .orElse(new QName(namespaceURI, dmnElementId, XMLConstants.DEFAULT_NS_PREFIX)); } }
WrapperUtils { static QName getDmnElementRef(final Definitions definitions, final View<? extends DMNElement> v, final String namespaceURI) { final DMNElement dmnElement = v.getDefinition(); final String dmnElementId = dmnElement.getId().getValue(); return getImportPrefix(definitions, dmnElement) .map(prefix -> new QName(namespaceURI, prefix + ":" + dmnElementId, XMLConstants.DEFAULT_NS_PREFIX)) .orElse(new QName(namespaceURI, dmnElementId, XMLConstants.DEFAULT_NS_PREFIX)); }  }
WrapperUtils { static QName getDmnElementRef(final Definitions definitions, final View<? extends DMNElement> v, final String namespaceURI) { final DMNElement dmnElement = v.getDefinition(); final String dmnElementId = dmnElement.getId().getValue(); return getImportPrefix(definitions, dmnElement) .map(prefix -> new QName(namespaceURI, prefix + ":" + dmnElementId, XMLConstants.DEFAULT_NS_PREFIX)) .orElse(new QName(namespaceURI, dmnElementId, XMLConstants.DEFAULT_NS_PREFIX)); }  static JSITAssociation getWrappedJSITAssociation(final JSITAssociation toWrap); static JSITTextAnnotation getWrappedJSITTextAnnotation(final JSITTextAnnotation toWrap); static JSIDMNStyle getWrappedJSIDMNStyle(final JSIDMNStyle toWrap); static JSITDecisionTable getWrappedJSITDecisionTable(final JSITDecisionTable toWrap,
                                                                final String prefix,
                                                                final String localPart); static JSITFunctionDefinition getWrappedJSITFunctionDefinition(final JSITFunctionDefinition toWrap,
                                                                          final String prefix,
                                                                          final String localPart); static JSITInvocation getWrappedJSITInvocation(final JSITInvocation toWrap,
                                                          final String prefix,
                                                          final String localPart); static JSITList getWrappedJSITList(final JSITList toWrap,
                                              final String prefix,
                                              final String localPart); static JSITRelation getWrappedJSITRelation(final JSITRelation toWrap,
                                                      final String prefix,
                                                      final String localPart); static JSITContext getWrappedJSITContext(final JSITContext toWrap,
                                                    final String prefix,
                                                    final String localPart); static JSITLiteralExpression getWrappedJSITLiteralExpression(final JSITLiteralExpression toWrap,
                                                                        final String prefix,
                                                                        final String localPart); static JSIDMNEdge getWrappedJSIDMNEdge(final JSIDMNEdge toWrap); static JSIDMNShape getWrappedJSIDMNShape(final JSIDMNDiagram diagram,
                                                    final List<String> dmnDiagramElementIds,
                                                    final Definitions definitionsStunnerPojo,
                                                    final View<? extends DMNElement> v,
                                                    final String namespaceURI); static JSITAttachment getWrappedJSITAttachment(final JSITAttachment attachment); static JSITComponentsWidthsExtension getWrappedJSITComponentsWidthsExtension(final JSITComponentsWidthsExtension componentsWidthsExtension); static JSITDRGElement getWrappedJSITDRGElement(final JSITDRGElement toWrap,
                                                          final String prefix,
                                                          final String localPart); static void updateJSIName(final JSIName toUpdate,
                                     final String prefix,
                                     final String localPart); }
WrapperUtils { static QName getDmnElementRef(final Definitions definitions, final View<? extends DMNElement> v, final String namespaceURI) { final DMNElement dmnElement = v.getDefinition(); final String dmnElementId = dmnElement.getId().getValue(); return getImportPrefix(definitions, dmnElement) .map(prefix -> new QName(namespaceURI, prefix + ":" + dmnElementId, XMLConstants.DEFAULT_NS_PREFIX)) .orElse(new QName(namespaceURI, dmnElementId, XMLConstants.DEFAULT_NS_PREFIX)); }  static JSITAssociation getWrappedJSITAssociation(final JSITAssociation toWrap); static JSITTextAnnotation getWrappedJSITTextAnnotation(final JSITTextAnnotation toWrap); static JSIDMNStyle getWrappedJSIDMNStyle(final JSIDMNStyle toWrap); static JSITDecisionTable getWrappedJSITDecisionTable(final JSITDecisionTable toWrap,
                                                                final String prefix,
                                                                final String localPart); static JSITFunctionDefinition getWrappedJSITFunctionDefinition(final JSITFunctionDefinition toWrap,
                                                                          final String prefix,
                                                                          final String localPart); static JSITInvocation getWrappedJSITInvocation(final JSITInvocation toWrap,
                                                          final String prefix,
                                                          final String localPart); static JSITList getWrappedJSITList(final JSITList toWrap,
                                              final String prefix,
                                              final String localPart); static JSITRelation getWrappedJSITRelation(final JSITRelation toWrap,
                                                      final String prefix,
                                                      final String localPart); static JSITContext getWrappedJSITContext(final JSITContext toWrap,
                                                    final String prefix,
                                                    final String localPart); static JSITLiteralExpression getWrappedJSITLiteralExpression(final JSITLiteralExpression toWrap,
                                                                        final String prefix,
                                                                        final String localPart); static JSIDMNEdge getWrappedJSIDMNEdge(final JSIDMNEdge toWrap); static JSIDMNShape getWrappedJSIDMNShape(final JSIDMNDiagram diagram,
                                                    final List<String> dmnDiagramElementIds,
                                                    final Definitions definitionsStunnerPojo,
                                                    final View<? extends DMNElement> v,
                                                    final String namespaceURI); static JSITAttachment getWrappedJSITAttachment(final JSITAttachment attachment); static JSITComponentsWidthsExtension getWrappedJSITComponentsWidthsExtension(final JSITComponentsWidthsExtension componentsWidthsExtension); static JSITDRGElement getWrappedJSITDRGElement(final JSITDRGElement toWrap,
                                                          final String prefix,
                                                          final String localPart); static void updateJSIName(final JSIName toUpdate,
                                     final String prefix,
                                     final String localPart);  }