@Test public void testGetImportXML() throws java.io.IOException { final String xml1 = "<some xml/>"; final String xml2 = "<some other xml/>"; final Metadata metadata = mock(Metadata.class); final Import import1 = mock(Import.class); final Path path1 = makePath("../file1.dmn"); final Path path2 = makePath("../file2.dmn"); final InputStream inputStream1 = mock(InputStream.class); final InputStream inputStream2 = mock(InputStream.class); final InputStreamReader inputStreamReader1 = mock(InputStreamReader.class); final InputStreamReader inputStreamReader2 = mock(InputStreamReader.class); final List<Path> paths = asList(path1, path2); when(pathsHelper.getDMNModelsPaths(any())).thenReturn(paths); when(dmnIOHelper.isAsString(inputStream1)).thenReturn(xml1); when(dmnIOHelper.isAsString(inputStream2)).thenReturn(xml2); doReturn(Optional.of(inputStream1)).when(helper).loadPath(path1); doReturn(Optional.of(inputStream2)).when(helper).loadPath(path2); doReturn(inputStreamReader1).when(helper).toInputStreamReader(inputStream1); doReturn(inputStreamReader2).when(helper).toInputStreamReader(inputStream2); final StringReader stringReader1 = mock(StringReader.class); final StringReader stringReader2 = mock(StringReader.class); final Definitions definitions1 = mock(Definitions.class); final Definitions definitions2 = mock(Definitions.class); doReturn(stringReader1).when(helper).toStringReader(xml1); doReturn(stringReader2).when(helper).toStringReader(xml2); when(marshaller.unmarshal(stringReader1)).thenReturn(definitions1); when(marshaller.unmarshal(stringReader2)).thenReturn(definitions2); when(import1.getNamespace()).thenReturn(": when(definitions1.getNamespace()).thenReturn(": when(definitions2.getNamespace()).thenReturn(": final List<Import> imports = Collections.singletonList(import1); final Map<Import, String> importXML = helper.getImportXML(metadata, imports); assertEquals(1, importXML.size()); assertEquals(xml1, importXML.get(import1)); }
@Override public Map<Import, String> getImportXML(final Metadata metadata, final List<Import> imports) { final Map<Import, String> importXML = new HashMap<>(); if (imports.size() > 0) { for (final String xml : getOtherDMNDiagramsXML(metadata)) { try (final StringReader sr = toStringReader(xml)) { final Definitions definitions = marshaller.unmarshal(sr); findImportByDefinitions(definitions, imports).ifPresent(anImport -> { importXML.put(anImport, xml); }); } } } return importXML; }
DMNMarshallerImportsHelperStandaloneImpl implements DMNMarshallerImportsHelperStandalone { @Override public Map<Import, String> getImportXML(final Metadata metadata, final List<Import> imports) { final Map<Import, String> importXML = new HashMap<>(); if (imports.size() > 0) { for (final String xml : getOtherDMNDiagramsXML(metadata)) { try (final StringReader sr = toStringReader(xml)) { final Definitions definitions = marshaller.unmarshal(sr); findImportByDefinitions(definitions, imports).ifPresent(anImport -> { importXML.put(anImport, xml); }); } } } return importXML; } }
DMNMarshallerImportsHelperStandaloneImpl implements DMNMarshallerImportsHelperStandalone { @Override public Map<Import, String> getImportXML(final Metadata metadata, final List<Import> imports) { final Map<Import, String> importXML = new HashMap<>(); if (imports.size() > 0) { for (final String xml : getOtherDMNDiagramsXML(metadata)) { try (final StringReader sr = toStringReader(xml)) { final Definitions definitions = marshaller.unmarshal(sr); findImportByDefinitions(definitions, imports).ifPresent(anImport -> { importXML.put(anImport, xml); }); } } } return importXML; } DMNMarshallerImportsHelperStandaloneImpl(); @Inject  DMNMarshallerImportsHelperStandaloneImpl(final DMNPathsHelper pathsHelper,
                                                    final WorkspaceProjectService projectService,
                                                    final DMNMarshaller marshaller,
                                                    final DMNIOHelper dmnIOHelper,
                                                    final PMMLIncludedDocumentFactory pmmlDocumentFactory,
                                                    final @Named("ioStrategy") IOService ioService); }
DMNMarshallerImportsHelperStandaloneImpl implements DMNMarshallerImportsHelperStandalone { @Override public Map<Import, String> getImportXML(final Metadata metadata, final List<Import> imports) { final Map<Import, String> importXML = new HashMap<>(); if (imports.size() > 0) { for (final String xml : getOtherDMNDiagramsXML(metadata)) { try (final StringReader sr = toStringReader(xml)) { final Definitions definitions = marshaller.unmarshal(sr); findImportByDefinitions(definitions, imports).ifPresent(anImport -> { importXML.put(anImport, xml); }); } } } return importXML; } DMNMarshallerImportsHelperStandaloneImpl(); @Inject  DMNMarshallerImportsHelperStandaloneImpl(final DMNPathsHelper pathsHelper,
                                                    final WorkspaceProjectService projectService,
                                                    final DMNMarshaller marshaller,
                                                    final DMNIOHelper dmnIOHelper,
                                                    final PMMLIncludedDocumentFactory pmmlDocumentFactory,
                                                    final @Named("ioStrategy") IOService ioService); @Override Map<Import, Definitions> getImportDefinitions(final Metadata metadata,
                                                         final List<Import> imports); @Override Map<Import, PMMLDocumentMetadata> getPMMLDocuments(final Metadata metadata,
                                                              final List<Import> imports); @Override Map<Import, String> getImportXML(final Metadata metadata,
                                            final List<Import> imports); @Override Path getDMNModelPath(final Metadata metadata,
                                final String modelNamespace,
                                final String modelName); @Override List<DRGElement> getImportedDRGElements(final Map<Import, Definitions> importDefinitions); @Override List<ItemDefinition> getImportedItemDefinitions(final Map<Import, Definitions> importDefinitions); @Override List<ItemDefinition> getImportedItemDefinitionsByNamespace(final WorkspaceProject workspaceProject,
                                                                      final String modelName,
                                                                      final String namespace); @Override Optional<InputStream> loadPath(final Path path); }
DMNMarshallerImportsHelperStandaloneImpl implements DMNMarshallerImportsHelperStandalone { @Override public Map<Import, String> getImportXML(final Metadata metadata, final List<Import> imports) { final Map<Import, String> importXML = new HashMap<>(); if (imports.size() > 0) { for (final String xml : getOtherDMNDiagramsXML(metadata)) { try (final StringReader sr = toStringReader(xml)) { final Definitions definitions = marshaller.unmarshal(sr); findImportByDefinitions(definitions, imports).ifPresent(anImport -> { importXML.put(anImport, xml); }); } } } return importXML; } DMNMarshallerImportsHelperStandaloneImpl(); @Inject  DMNMarshallerImportsHelperStandaloneImpl(final DMNPathsHelper pathsHelper,
                                                    final WorkspaceProjectService projectService,
                                                    final DMNMarshaller marshaller,
                                                    final DMNIOHelper dmnIOHelper,
                                                    final PMMLIncludedDocumentFactory pmmlDocumentFactory,
                                                    final @Named("ioStrategy") IOService ioService); @Override Map<Import, Definitions> getImportDefinitions(final Metadata metadata,
                                                         final List<Import> imports); @Override Map<Import, PMMLDocumentMetadata> getPMMLDocuments(final Metadata metadata,
                                                              final List<Import> imports); @Override Map<Import, String> getImportXML(final Metadata metadata,
                                            final List<Import> imports); @Override Path getDMNModelPath(final Metadata metadata,
                                final String modelNamespace,
                                final String modelName); @Override List<DRGElement> getImportedDRGElements(final Map<Import, Definitions> importDefinitions); @Override List<ItemDefinition> getImportedItemDefinitions(final Map<Import, Definitions> importDefinitions); @Override List<ItemDefinition> getImportedItemDefinitionsByNamespace(final WorkspaceProject workspaceProject,
                                                                      final String modelName,
                                                                      final String namespace); @Override Optional<InputStream> loadPath(final Path path); static final QName NAMESPACE; }