Skip to content

Commit

Permalink
feat: migration to generic v4.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
grigoriev committed Jun 5, 2024
1 parent 3fbd1cc commit d434fbf
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 69 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>ch.sbb.polarion.extensions</groupId>
<artifactId>ch.sbb.polarion.extension.generic.parent-pom</artifactId>
<version>4.9.1</version>
<version>4.10.0</version>
</parent>

<artifactId>ch.sbb.polarion.extension.pdf-exporter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -53,10 +54,9 @@ void testDefaultCss() {
}

@Test
void testLoadDefaultWhenSettingDoesNotExist() {
void testSettingDoesNotExist() {
try (MockedStatic<ScopeUtils> mockScopeUtils = mockStatic(ScopeUtils.class)) {
SettingsService mockedSettingsService = mock(SettingsService.class);
when(mockedSettingsService.exists(any())).thenReturn(true);
mockScopeUtils.when(() -> ScopeUtils.getFileContent(any())).thenCallRealMethod();

GenericNamedSettings<CoverPageModel> coverPageSettings = new CoverPageSettings(mockedSettingsService, mockedPdfExporterPolarionService);
Expand All @@ -66,22 +66,17 @@ 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);

ILocation mockDefaultLocation = mock(ILocation.class);
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"));
});
}
}

Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)
Expand All @@ -27,10 +27,9 @@ void testDefaultCss() {
}

@Test
void testLoadDefaultWhenSettingDoesNotExist() {
void testSettingDoesNotExist() {
try (MockedStatic<ScopeUtils> mockScopeUtils = mockStatic(ScopeUtils.class)) {
SettingsService mockedSettingsService = mock(SettingsService.class);
when(mockedSettingsService.exists(any())).thenReturn(true);
mockScopeUtils.when(() -> ScopeUtils.getFileContent(any())).thenCallRealMethod();

GenericNamedSettings<CssModel> cssSettings = new CssSettings(mockedSettingsService);
Expand All @@ -40,21 +39,17 @@ 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);

ILocation mockDefaultLocation = mock(ILocation.class);
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"));
});
}
}

Expand Down Expand Up @@ -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");

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,17 +15,17 @@
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.*;

@ExtendWith(MockitoExtension.class)
class FileNameTemplateSettingsTest {
@Test
void testLoadDefaultWhenSettingDoesNotExist() {
void testSettingDoesNotExist() {
try (MockedStatic<ScopeUtils> 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);
Expand All @@ -34,22 +35,17 @@ 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);

ILocation mockDefaultLocation = mock(ILocation.class);
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"));
});
}
}

Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<ScopeUtils> 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);
Expand All @@ -34,26 +35,17 @@ 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);

ILocation mockDefaultLocation = mock(ILocation.class);
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"));
});
}
}

Expand Down Expand Up @@ -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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit d434fbf

Please sign in to comment.