From d434fbf82d0844a4d07700ce6082f7f80b0ee085 Mon Sep 17 00:00:00 2001 From: Sergey Grigoriev Date: Wed, 5 Jun 2024 10:48:39 +0200 Subject: [PATCH] feat: migration to generic v4.10.0 --- pom.xml | 2 +- .../settings/CoverPageSettingsTest.java | 19 ++++++-------- .../exporter/settings/CssSettingsTest.java | 20 +++++++-------- .../FileNameTemplateSettingsTest.java | 25 +++++++------------ .../settings/HeaderFooterSettingsTest.java | 23 +++++++---------- .../settings/LocalizationSettingsTest.java | 1 - .../settings/StylePackageSettingsTest.java | 23 +++++++---------- 7 files changed, 44 insertions(+), 69 deletions(-) diff --git a/pom.xml b/pom.xml index 11750a2..39fb46e 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ ch.sbb.polarion.extensions ch.sbb.polarion.extension.generic.parent-pom - 4.9.1 + 4.10.0 ch.sbb.polarion.extension.pdf-exporter diff --git a/src/test/java/ch/sbb/polarion/extension/pdf/exporter/settings/CoverPageSettingsTest.java b/src/test/java/ch/sbb/polarion/extension/pdf/exporter/settings/CoverPageSettingsTest.java index 7af514e..8184a5b 100644 --- a/src/test/java/ch/sbb/polarion/extension/pdf/exporter/settings/CoverPageSettingsTest.java +++ b/src/test/java/ch/sbb/polarion/extension/pdf/exporter/settings/CoverPageSettingsTest.java @@ -1,5 +1,6 @@ package ch.sbb.polarion.extension.pdf.exporter.settings; +import ch.sbb.polarion.extension.generic.exception.ObjectNotFoundException; import ch.sbb.polarion.extension.generic.settings.GenericNamedSettings; import ch.sbb.polarion.extension.generic.settings.SettingId; import ch.sbb.polarion.extension.generic.settings.SettingsService; @@ -53,10 +54,9 @@ void testDefaultCss() { } @Test - void testLoadDefaultWhenSettingDoesNotExist() { + void testSettingDoesNotExist() { try (MockedStatic mockScopeUtils = mockStatic(ScopeUtils.class)) { SettingsService mockedSettingsService = mock(SettingsService.class); - when(mockedSettingsService.exists(any())).thenReturn(true); mockScopeUtils.when(() -> ScopeUtils.getFileContent(any())).thenCallRealMethod(); GenericNamedSettings coverPageSettings = new CoverPageSettings(mockedSettingsService, mockedPdfExporterPolarionService); @@ -66,7 +66,6 @@ void testLoadDefaultWhenSettingDoesNotExist() { ILocation mockProjectLocation = mock(ILocation.class); when(mockProjectLocation.append(anyString())).thenReturn(mockProjectLocation); mockScopeUtils.when(() -> ScopeUtils.getContextLocationByProject(projectName)).thenReturn(mockProjectLocation); - when(mockedSettingsService.read(eq(mockProjectLocation), any())).thenReturn(null); mockScopeUtils.when(() -> ScopeUtils.getScopeFromProject(projectName)).thenCallRealMethod(); mockScopeUtils.when(() -> ScopeUtils.getContextLocation("project/test_project/")).thenReturn(mockProjectLocation); @@ -74,14 +73,10 @@ void testLoadDefaultWhenSettingDoesNotExist() { when(mockDefaultLocation.append(anyString())).thenReturn(mockDefaultLocation); mockScopeUtils.when(ScopeUtils::getDefaultLocation).thenReturn(mockDefaultLocation); mockScopeUtils.when(() -> ScopeUtils.getContextLocation("")).thenReturn(mockDefaultLocation); - CoverPageModel coverPageModel = coverPageSettings.defaultValues(); - coverPageModel.setBundleTimestamp("default"); - when(mockedSettingsService.read(eq(mockDefaultLocation), any())).thenReturn(coverPageModel.serialize()); - CoverPageModel loadedModel = coverPageSettings.load(projectName, SettingId.fromName("Any setting name")); - assertEquals(coverPageModel.getTemplateHtml(), loadedModel.getTemplateHtml()); - assertEquals(coverPageModel.getTemplateCss(), loadedModel.getTemplateCss()); - assertEquals("default", loadedModel.getBundleTimestamp()); + assertThrows(ObjectNotFoundException.class, () -> { + CoverPageModel loadedModel = coverPageSettings.load(projectName, SettingId.fromName("Any setting name")); + }); } } @@ -109,8 +104,8 @@ void testLoadCustomWhenSettingExists() { customModel.setBundleTimestamp("custom"); when(mockedSettingsService.read(eq(mockProjectLocation), any())).thenReturn(customModel.serialize()); - CoverPageModel defaultProjectModel = CoverPageModel.builder().templateHtml("defaultHtml").templateCss("defaultCss").build(); - defaultProjectModel.setBundleTimestamp("default"); + when(mockedSettingsService.getLastRevision(mockProjectLocation)).thenReturn("345"); + when(mockedSettingsService.getPersistedSettingFileNames(mockProjectLocation)).thenReturn(List.of("Any setting name")); CoverPageModel loadedModel = coverPageSettings.load(projectName, SettingId.fromName("Any setting name")); assertEquals(customModel.getTemplateHtml(), loadedModel.getTemplateHtml()); diff --git a/src/test/java/ch/sbb/polarion/extension/pdf/exporter/settings/CssSettingsTest.java b/src/test/java/ch/sbb/polarion/extension/pdf/exporter/settings/CssSettingsTest.java index 217e7d3..af456b9 100644 --- a/src/test/java/ch/sbb/polarion/extension/pdf/exporter/settings/CssSettingsTest.java +++ b/src/test/java/ch/sbb/polarion/extension/pdf/exporter/settings/CssSettingsTest.java @@ -1,5 +1,6 @@ package ch.sbb.polarion.extension.pdf.exporter.settings; +import ch.sbb.polarion.extension.generic.exception.ObjectNotFoundException; import ch.sbb.polarion.extension.generic.settings.GenericNamedSettings; import ch.sbb.polarion.extension.generic.settings.SettingId; import ch.sbb.polarion.extension.generic.settings.SettingsService; @@ -13,8 +14,7 @@ import java.util.List; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) @@ -27,10 +27,9 @@ void testDefaultCss() { } @Test - void testLoadDefaultWhenSettingDoesNotExist() { + void testSettingDoesNotExist() { try (MockedStatic mockScopeUtils = mockStatic(ScopeUtils.class)) { SettingsService mockedSettingsService = mock(SettingsService.class); - when(mockedSettingsService.exists(any())).thenReturn(true); mockScopeUtils.when(() -> ScopeUtils.getFileContent(any())).thenCallRealMethod(); GenericNamedSettings cssSettings = new CssSettings(mockedSettingsService); @@ -40,7 +39,6 @@ void testLoadDefaultWhenSettingDoesNotExist() { ILocation mockProjectLocation = mock(ILocation.class); when(mockProjectLocation.append(anyString())).thenReturn(mockProjectLocation); mockScopeUtils.when(() -> ScopeUtils.getContextLocationByProject(projectName)).thenReturn(mockProjectLocation); - when(mockedSettingsService.read(eq(mockProjectLocation), any())).thenReturn(null); mockScopeUtils.when(() -> ScopeUtils.getScopeFromProject(projectName)).thenCallRealMethod(); mockScopeUtils.when(() -> ScopeUtils.getContextLocation("project/test_project/")).thenReturn(mockProjectLocation); @@ -48,13 +46,10 @@ void testLoadDefaultWhenSettingDoesNotExist() { when(mockDefaultLocation.append(anyString())).thenReturn(mockDefaultLocation); mockScopeUtils.when(ScopeUtils::getDefaultLocation).thenReturn(mockDefaultLocation); mockScopeUtils.when(() -> ScopeUtils.getContextLocation("")).thenReturn(mockDefaultLocation); - CssModel cssModel = cssSettings.defaultValues(); - cssModel.setBundleTimestamp("default"); - when(mockedSettingsService.read(eq(mockDefaultLocation), any())).thenReturn(cssModel.serialize()); - CssModel loadedModel = cssSettings.load(projectName, SettingId.fromName("Any setting name")); - assertEquals(cssModel.getCss(), loadedModel.getCss()); - assertEquals("default", loadedModel.getBundleTimestamp()); + assertThrows(ObjectNotFoundException.class, () -> { + CssModel loadedModel = cssSettings.load(projectName, SettingId.fromName("Any setting name")); + }); } } @@ -82,6 +77,9 @@ void testLoadCustomWhenSettingExists() { customProjectModel.setBundleTimestamp("custom"); when(mockedSettingsService.read(eq(mockProjectLocation), any())).thenReturn(customProjectModel.serialize()); + when(mockedSettingsService.getLastRevision(mockProjectLocation)).thenReturn("345"); + when(mockedSettingsService.getPersistedSettingFileNames(mockProjectLocation)).thenReturn(List.of("Any setting name")); + CssModel defaultProjectModel = CssModel.builder().css("defaultCss").build(); defaultProjectModel.setBundleTimestamp("default"); diff --git a/src/test/java/ch/sbb/polarion/extension/pdf/exporter/settings/FileNameTemplateSettingsTest.java b/src/test/java/ch/sbb/polarion/extension/pdf/exporter/settings/FileNameTemplateSettingsTest.java index 87be1ab..260885b 100644 --- a/src/test/java/ch/sbb/polarion/extension/pdf/exporter/settings/FileNameTemplateSettingsTest.java +++ b/src/test/java/ch/sbb/polarion/extension/pdf/exporter/settings/FileNameTemplateSettingsTest.java @@ -1,5 +1,6 @@ package ch.sbb.polarion.extension.pdf.exporter.settings; +import ch.sbb.polarion.extension.generic.exception.ObjectNotFoundException; import ch.sbb.polarion.extension.generic.settings.GenericNamedSettings; import ch.sbb.polarion.extension.generic.settings.SettingId; import ch.sbb.polarion.extension.generic.settings.SettingsService; @@ -14,6 +15,7 @@ import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.contains; import static org.mockito.Mockito.*; @@ -21,10 +23,9 @@ @ExtendWith(MockitoExtension.class) class FileNameTemplateSettingsTest { @Test - void testLoadDefaultWhenSettingDoesNotExist() { + void testSettingDoesNotExist() { try (MockedStatic mockScopeUtils = mockStatic(ScopeUtils.class)) { SettingsService mockedSettingsService = mock(SettingsService.class); - when(mockedSettingsService.exists(any())).thenReturn(true); mockScopeUtils.when(() -> ScopeUtils.getFileContent(any())).thenCallRealMethod(); FileNameTemplateSettings fileNameTemplateSettings = new FileNameTemplateSettings(mockedSettingsService); @@ -34,7 +35,6 @@ void testLoadDefaultWhenSettingDoesNotExist() { ILocation mockProjectLocation = mock(ILocation.class); when(mockProjectLocation.append(anyString())).thenReturn(mockProjectLocation); mockScopeUtils.when(() -> ScopeUtils.getContextLocationByProject(projectName)).thenReturn(mockProjectLocation); - when(mockedSettingsService.read(eq(mockProjectLocation), any())).thenReturn(null); mockScopeUtils.when(() -> ScopeUtils.getScopeFromProject(projectName)).thenCallRealMethod(); mockScopeUtils.when(() -> ScopeUtils.getContextLocation("project/test_project/")).thenReturn(mockProjectLocation); @@ -42,14 +42,10 @@ void testLoadDefaultWhenSettingDoesNotExist() { when(mockDefaultLocation.append(anyString())).thenReturn(mockDefaultLocation); mockScopeUtils.when(ScopeUtils::getDefaultLocation).thenReturn(mockDefaultLocation); mockScopeUtils.when(() -> ScopeUtils.getContextLocation("")).thenReturn(mockDefaultLocation); - FileNameTemplateModel model = fileNameTemplateSettings.defaultValues(); - model.setBundleTimestamp("default"); - when(mockedSettingsService.read(eq(mockDefaultLocation), any())).thenReturn(model.serialize()); - - FileNameTemplateModel loadedModel = fileNameTemplateSettings.load(projectName, SettingId.fromName("Any setting name")); - assertEquals(model.getDocumentNameTemplate(), loadedModel.getDocumentNameTemplate()); - assertEquals(model.getReportNameTemplate(), loadedModel.getReportNameTemplate()); - assertEquals("default", loadedModel.getBundleTimestamp()); + + assertThrows(ObjectNotFoundException.class, () -> { + FileNameTemplateModel loadedModel = fileNameTemplateSettings.load(projectName, SettingId.fromName("Any setting name")); + }); } } @@ -80,11 +76,8 @@ void testLoadCustomWhenSettingExists() { customProjectModel.setBundleTimestamp("custom"); when(mockedSettingsService.read(eq(mockProjectLocation), any())).thenReturn(customProjectModel.serialize()); - FileNameTemplateModel defaultProjectModel = FileNameTemplateModel.builder() - .documentNameTemplate("defaultDocumentNameTemplate") - .reportNameTemplate("defaultReportTemplate") - .build(); - defaultProjectModel.setBundleTimestamp("default"); + when(mockedSettingsService.getLastRevision(mockProjectLocation)).thenReturn("345"); + when(mockedSettingsService.getPersistedSettingFileNames(mockProjectLocation)).thenReturn(List.of("Any setting name")); FileNameTemplateModel loadedModel = exporterSettings.load(projectName, SettingId.fromName("Any setting name")); assertEquals("customDocumentNameTemplate", loadedModel.getDocumentNameTemplate()); diff --git a/src/test/java/ch/sbb/polarion/extension/pdf/exporter/settings/HeaderFooterSettingsTest.java b/src/test/java/ch/sbb/polarion/extension/pdf/exporter/settings/HeaderFooterSettingsTest.java index da8a91d..9f5b2c0 100644 --- a/src/test/java/ch/sbb/polarion/extension/pdf/exporter/settings/HeaderFooterSettingsTest.java +++ b/src/test/java/ch/sbb/polarion/extension/pdf/exporter/settings/HeaderFooterSettingsTest.java @@ -1,5 +1,6 @@ package ch.sbb.polarion.extension.pdf.exporter.settings; +import ch.sbb.polarion.extension.generic.exception.ObjectNotFoundException; import ch.sbb.polarion.extension.generic.settings.SettingId; import ch.sbb.polarion.extension.generic.settings.SettingsService; import ch.sbb.polarion.extension.generic.util.ScopeUtils; @@ -15,16 +16,16 @@ import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) class HeaderFooterSettingsTest { @Test - void testLoadDefaultWhenSettingDoesNotExist() { + void testSettingDoesNotExist() { try (MockedStatic mockScopeUtils = mockStatic(ScopeUtils.class)) { SettingsService mockedSettingsService = mock(SettingsService.class); - when(mockedSettingsService.exists(any())).thenReturn(true); mockScopeUtils.when(() -> ScopeUtils.getFileContent(any())).thenCallRealMethod(); HeaderFooterSettings headerFooterSettings = new HeaderFooterSettings(mockedSettingsService); @@ -34,7 +35,6 @@ void testLoadDefaultWhenSettingDoesNotExist() { ILocation mockProjectLocation = mock(ILocation.class); when(mockProjectLocation.append(anyString())).thenReturn(mockProjectLocation); mockScopeUtils.when(() -> ScopeUtils.getContextLocationByProject(projectName)).thenReturn(mockProjectLocation); - when(mockedSettingsService.read(eq(mockProjectLocation), any())).thenReturn(null); mockScopeUtils.when(() -> ScopeUtils.getScopeFromProject(projectName)).thenCallRealMethod(); mockScopeUtils.when(() -> ScopeUtils.getContextLocation("project/test_project/")).thenReturn(mockProjectLocation); @@ -42,18 +42,10 @@ void testLoadDefaultWhenSettingDoesNotExist() { when(mockDefaultLocation.append(anyString())).thenReturn(mockDefaultLocation); mockScopeUtils.when(ScopeUtils::getDefaultLocation).thenReturn(mockDefaultLocation); mockScopeUtils.when(() -> ScopeUtils.getContextLocation("")).thenReturn(mockDefaultLocation); - HeaderFooterModel model = headerFooterSettings.defaultValues(); - model.setBundleTimestamp("default"); - when(mockedSettingsService.read(eq(mockDefaultLocation), any())).thenReturn(model.serialize()); - HeaderFooterModel loadedModel = headerFooterSettings.load(projectName, SettingId.fromName("Any setting name")); - assertEquals(model.getHeaderLeft(), loadedModel.getHeaderLeft()); - assertEquals(model.getHeaderCenter(), loadedModel.getHeaderCenter()); - assertEquals(model.getHeaderRight(), loadedModel.getHeaderRight()); - assertEquals(model.getFooterLeft(), loadedModel.getFooterLeft()); - assertEquals(model.getFooterCenter(), loadedModel.getFooterCenter()); - assertEquals(model.getFooterRight(), loadedModel.getFooterRight()); - assertEquals("default", loadedModel.getBundleTimestamp()); + assertThrows(ObjectNotFoundException.class, () -> { + HeaderFooterModel loadedModel = headerFooterSettings.load(projectName, SettingId.fromName("Any setting name")); + }); } } @@ -81,6 +73,9 @@ void testLoadCustomWhenSettingExists() { customProjectModel.setBundleTimestamp("custom"); when(mockedSettingsService.read(eq(mockProjectLocation), any())).thenReturn(customProjectModel.serialize()); + when(mockedSettingsService.getLastRevision(mockProjectLocation)).thenReturn("345"); + when(mockedSettingsService.getPersistedSettingFileNames(mockProjectLocation)).thenReturn(List.of("Any setting name")); + HeaderFooterModel defaultProjectModel = getHeaderFooter("leftDefault", "centerDefault", "rightDefault", "leftDefault", "centerDefault", "rightDefault"); defaultProjectModel.setBundleTimestamp("default"); diff --git a/src/test/java/ch/sbb/polarion/extension/pdf/exporter/settings/LocalizationSettingsTest.java b/src/test/java/ch/sbb/polarion/extension/pdf/exporter/settings/LocalizationSettingsTest.java index 90a1192..8157282 100644 --- a/src/test/java/ch/sbb/polarion/extension/pdf/exporter/settings/LocalizationSettingsTest.java +++ b/src/test/java/ch/sbb/polarion/extension/pdf/exporter/settings/LocalizationSettingsTest.java @@ -67,7 +67,6 @@ void testDefaultLocalizationLoad() { mockScopeUtils.when(() -> ScopeUtils.getContextLocationByProject(projectName)).thenReturn(mockProjectLocation); mockScopeUtils.when(ScopeUtils::getDefaultLocation).thenReturn(mockDefaultLocation); mockScopeUtils.when(() -> ScopeUtils.getContextLocation("")).thenReturn(mockDefaultLocation); - when(mockedSettingsService.exists(any())).thenReturn(true); mockScopeUtils.when(() -> ScopeUtils.getFileContent(any())).thenCallRealMethod(); LocalizationSettings localizationSettings = new LocalizationSettings(mockedSettingsService); diff --git a/src/test/java/ch/sbb/polarion/extension/pdf/exporter/settings/StylePackageSettingsTest.java b/src/test/java/ch/sbb/polarion/extension/pdf/exporter/settings/StylePackageSettingsTest.java index 20722d9..90187ec 100644 --- a/src/test/java/ch/sbb/polarion/extension/pdf/exporter/settings/StylePackageSettingsTest.java +++ b/src/test/java/ch/sbb/polarion/extension/pdf/exporter/settings/StylePackageSettingsTest.java @@ -1,5 +1,6 @@ package ch.sbb.polarion.extension.pdf.exporter.settings; +import ch.sbb.polarion.extension.generic.exception.ObjectNotFoundException; import ch.sbb.polarion.extension.generic.settings.GenericNamedSettings; import ch.sbb.polarion.extension.generic.settings.SettingId; import ch.sbb.polarion.extension.generic.settings.SettingsService; @@ -17,6 +18,7 @@ import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.contains; @@ -27,10 +29,9 @@ @ExtendWith(MockitoExtension.class) class StylePackageSettingsTest { @Test - void testLoadDefaultWhenSettingDoesNotExist() { + void testSettingDoesNotExist() { try (MockedStatic mockScopeUtils = mockStatic(ScopeUtils.class)) { SettingsService mockedSettingsService = mock(SettingsService.class); - when(mockedSettingsService.exists(any())).thenReturn(true); mockScopeUtils.when(() -> ScopeUtils.getFileContent(any())).thenCallRealMethod(); StylePackageSettings stylePackageSettings = new StylePackageSettings(mockedSettingsService); @@ -40,7 +41,6 @@ void testLoadDefaultWhenSettingDoesNotExist() { ILocation mockProjectLocation = mock(ILocation.class); when(mockProjectLocation.append(anyString())).thenReturn(mockProjectLocation); mockScopeUtils.when(() -> ScopeUtils.getContextLocationByProject(projectName)).thenReturn(mockProjectLocation); - when(mockedSettingsService.read(eq(mockProjectLocation), any())).thenReturn(null); mockScopeUtils.when(() -> ScopeUtils.getScopeFromProject(projectName)).thenCallRealMethod(); mockScopeUtils.when(() -> ScopeUtils.getContextLocation("project/test_project/")).thenReturn(mockProjectLocation); @@ -48,18 +48,10 @@ void testLoadDefaultWhenSettingDoesNotExist() { when(mockDefaultLocation.append(anyString())).thenReturn(mockDefaultLocation); mockScopeUtils.when(ScopeUtils::getDefaultLocation).thenReturn(mockDefaultLocation); mockScopeUtils.when(() -> ScopeUtils.getContextLocation("")).thenReturn(mockDefaultLocation); - StylePackageModel model = stylePackageSettings.defaultValues(); - model.setBundleTimestamp("default"); - when(mockedSettingsService.read(eq(mockDefaultLocation), any())).thenReturn(model.serialize()); - StylePackageModel loadedModel = stylePackageSettings.load(projectName, SettingId.fromName("Any setting name")); - assertEquals(model.getCss(), loadedModel.getCss()); - assertEquals(model.getCoverPage(), loadedModel.getCoverPage()); - assertEquals(model.getLanguage(), loadedModel.getLanguage()); - assertEquals(model.getOrientation(), loadedModel.getOrientation()); - assertEquals(model.getHeaderFooter(), loadedModel.getHeaderFooter()); - assertEquals(model.getPaperSize(), loadedModel.getPaperSize()); - assertEquals("default", loadedModel.getBundleTimestamp()); + assertThrows(ObjectNotFoundException.class, () -> { + StylePackageModel loadedModel = stylePackageSettings.load(projectName, SettingId.fromName("Any setting name")); + }); } } @@ -91,6 +83,9 @@ void testLoadCustomWhenSettingExists() { customProjectModel.setBundleTimestamp("custom"); when(mockedSettingsService.read(eq(mockProjectLocation), any())).thenReturn(customProjectModel.serialize()); + when(mockedSettingsService.getLastRevision(mockProjectLocation)).thenReturn("345"); + when(mockedSettingsService.getPersistedSettingFileNames(mockProjectLocation)).thenReturn(List.of("Any setting name")); + StylePackageModel loadedModel = stylePackageSettings.load(projectName, SettingId.fromName("Any setting name")); assertEquals("customCSS", loadedModel.getCss()); assertEquals("customCoverPage", loadedModel.getCoverPage());