ExportModelValidationServiceImpl implements ExportModelValidationService { @Override public Map<String, List<String>> checkMissingDatasets(DataTransferExportModel exportModel) { if (exportModel == null || exportModel.getPages().isEmpty()) { return Collections.emptyMap(); } Map<String, List<String>> deps = exportModel.getPages() .stream() .collect(Collectors.toMap(p -> p, p -> datasetsUsedInPage(p, exportModel))); deps.entrySet().removeIf(e -> e.getValue().isEmpty()); return deps; } ExportModelValidationServiceImpl(); @Inject  ExportModelValidationServiceImpl(PerspectivePluginServices perspectivePluginServices);   ExportModelValidationServiceImpl(PerspectivePluginServices perspectivePluginServices,
                                     DisplayerSettingsJSONMarshaller marshaller); @Override Map<String, List<String>> checkMissingDatasets(DataTransferExportModel exportModel);  }
@Test public void testTryingToExportPageWithMissingDataSet() { String page1 = "page1"; String ds1 = "ds1"; String json1 = "json1"; DataSetDef def = mock(DataSetDef.class); when(def.getUUID()).thenReturn(ds1); DisplayerSettings ds = registerDSMock(ds1); when(marshaller.fromJsonString(json1)).thenReturn(ds); LayoutTemplate ltForPage1 = createTemplate(json1); when(perspectivePluginServices.getLayoutTemplate(page1)).thenReturn(ltForPage1); DataTransferExportModel model = new DataTransferExportModel(Collections.emptyList(), Arrays.asList(page1), true); Map<String, List<String>> missingDataSets = dataTransferExportValidator.checkMissingDatasets(model); assertTrue(missingDataSets.containsKey(page1)); assertEquals(ds1, missingDataSets.get(page1).get(0)); }
@Test public void testSuccessExportWithAllDatasets() { String page1 = "page1"; String ds1 = "ds1"; String json1 = "json1"; DataSetDef def = mock(DataSetDef.class); when(def.getUUID()).thenReturn(ds1); DisplayerSettings ds = registerDSMock(ds1); when(marshaller.fromJsonString(json1)).thenReturn(ds); LayoutTemplate ltForPage1 = createTemplate(json1); when(perspectivePluginServices.getLayoutTemplate(page1)).thenReturn(ltForPage1); DataTransferExportModel model = new DataTransferExportModel(Arrays.asList(def), Arrays.asList(page1), true); Map<String, List<String>> missingDataSets = dataTransferExportValidator.checkMissingDatasets(model); assertTrue(missingDataSets.isEmpty()); assertFalse(missingDataSets.containsKey(page1)); }