@Test public void testGetOtherDMNDiagramsDefinitions() { final Metadata metadata = mock(Metadata.class); final Path path1 = makePath("../file1.dmn"); final Path path2 = makePath("../file2.dmn"); final Path path3 = makePath("../file3.dmn"); final Path path4 = makePath("../file4.dmn"); final InputStream inputStream1 = mock(InputStream.class); final InputStream inputStream2 = mock(InputStream.class); final InputStream inputStream3 = mock(InputStream.class); final InputStreamReader inputStreamReader1 = mock(InputStreamReader.class); final InputStreamReader inputStreamReader2 = mock(InputStreamReader.class); final InputStreamReader inputStreamReader3 = mock(InputStreamReader.class); final Definitions definitions1 = mock(Definitions.class); final Definitions definitions2 = mock(Definitions.class); final Definitions definitions3 = mock(Definitions.class); final List<Path> paths = asList(path1, path2, path3, path4); when(pathsHelper.getDMNModelsPaths(any())).thenReturn(paths); when(metadata.getPath()).thenReturn(path2); doReturn(Optional.of(inputStream1)).when(helper).loadPath(path1); doReturn(Optional.of(inputStream2)).when(helper).loadPath(path2); doReturn(Optional.of(inputStream3)).when(helper).loadPath(path3); doReturn(inputStreamReader1).when(helper).toInputStreamReader(inputStream1); doReturn(inputStreamReader2).when(helper).toInputStreamReader(inputStream2); doReturn(inputStreamReader3).when(helper).toInputStreamReader(inputStream3); doReturn(Optional.empty()).when(helper).loadPath(path4); when(marshaller.unmarshal(inputStreamReader1)).thenReturn(definitions1); when(marshaller.unmarshal(inputStreamReader2)).thenReturn(definitions2); when(marshaller.unmarshal(inputStreamReader3)).thenReturn(definitions3); final List<Definitions> actualDefinitions = helper.getOtherDMNDiagramsDefinitions(metadata); final List<Definitions> expectedDefinitions = asList(definitions1, definitions3); assertEquals(expectedDefinitions, actualDefinitions); }
List<Definitions> getOtherDMNDiagramsDefinitions(final Metadata metadata) { final List<Path> diagramPaths = pathsHelper.getDMNModelsPaths(getProject(metadata)); return diagramPaths .stream() .filter(path -> !Objects.equals(metadata.getPath(), path)) .map(path -> loadPath(path).orElse(null)) .filter(Objects::nonNull) .map(this::toDefinitions) .filter(Objects::nonNull) .collect(Collectors.toList()); }
DMNMarshallerImportsHelperStandaloneImpl implements DMNMarshallerImportsHelperStandalone { List<Definitions> getOtherDMNDiagramsDefinitions(final Metadata metadata) { final List<Path> diagramPaths = pathsHelper.getDMNModelsPaths(getProject(metadata)); return diagramPaths .stream() .filter(path -> !Objects.equals(metadata.getPath(), path)) .map(path -> loadPath(path).orElse(null)) .filter(Objects::nonNull) .map(this::toDefinitions) .filter(Objects::nonNull) .collect(Collectors.toList()); } }
DMNMarshallerImportsHelperStandaloneImpl implements DMNMarshallerImportsHelperStandalone { List<Definitions> getOtherDMNDiagramsDefinitions(final Metadata metadata) { final List<Path> diagramPaths = pathsHelper.getDMNModelsPaths(getProject(metadata)); return diagramPaths .stream() .filter(path -> !Objects.equals(metadata.getPath(), path)) .map(path -> loadPath(path).orElse(null)) .filter(Objects::nonNull) .map(this::toDefinitions) .filter(Objects::nonNull) .collect(Collectors.toList()); } 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 { List<Definitions> getOtherDMNDiagramsDefinitions(final Metadata metadata) { final List<Path> diagramPaths = pathsHelper.getDMNModelsPaths(getProject(metadata)); return diagramPaths .stream() .filter(path -> !Objects.equals(metadata.getPath(), path)) .map(path -> loadPath(path).orElse(null)) .filter(Objects::nonNull) .map(this::toDefinitions) .filter(Objects::nonNull) .collect(Collectors.toList()); } 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 { List<Definitions> getOtherDMNDiagramsDefinitions(final Metadata metadata) { final List<Path> diagramPaths = pathsHelper.getDMNModelsPaths(getProject(metadata)); return diagramPaths .stream() .filter(path -> !Objects.equals(metadata.getPath(), path)) .map(path -> loadPath(path).orElse(null)) .filter(Objects::nonNull) .map(this::toDefinitions) .filter(Objects::nonNull) .collect(Collectors.toList()); } 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; }