Skip to content

Commit

Permalink
Merge pull request #48 from aservo/upgrade-jira-version
Browse files Browse the repository at this point in the history
Upgrade Jira version to 9.12.5 (LTS), adjust tests
  • Loading branch information
pathob authored Mar 19, 2024
2 parents ddf75e7 + 60ac02d commit b1f2423
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 37 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
</developers>

<properties>
<jira.version>8.15.0</jira.version>
<jira.data.version>8.12.1</jira.data.version>
<jira.version>9.12.5</jira.version>
<jira.data.version>9.12.5</jira.data.version>
<!-- other properties -->
<atlassian.ajp.port>8209</atlassian.ajp.port>
<atlassian.amps.version>8.0.2</atlassian.amps.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,33 @@
import com.atlassian.jira.config.properties.ApplicationProperties;
import com.atlassian.jira.config.properties.LnFDefaultColorProvider;
import com.atlassian.jira.config.properties.LogoProvider;
import com.atlassian.jira.config.properties.UiSettingsStateManager;
import com.atlassian.jira.config.util.JiraHome;
import com.atlassian.jira.lookandfeel.LogoChoice;
import com.atlassian.jira.lookandfeel.LookAndFeelConstants;
import com.atlassian.jira.lookandfeel.LookAndFeelProperties;
import com.atlassian.jira.lookandfeel.upload.UploadService;
import com.atlassian.jira.security.JiraAuthenticationContext;
import com.atlassian.sal.api.pluginsettings.PluginSettings;
import com.atlassian.sal.api.pluginsettings.PluginSettingsFactory;
import de.aservo.confapi.commons.exception.InternalServerErrorException;
import de.aservo.confapi.commons.model.SettingsBrandingColorSchemeBean;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.MockedStatic;
import org.mockito.junit.jupiter.MockitoExtension;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.util.Map;

import static de.aservo.confapi.jira.model.util.SettingsColourSchemeBeanUtilTest.getDummyBaseColourScheme;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.*;

@ExtendWith(MockitoExtension.class)
Expand Down Expand Up @@ -77,49 +83,63 @@ void testSetColourScheme() {
assertEquals(schemeBean.getTopBar(), colourScheme.getTopBar());
}

//InternalServerErrorException -> FileNotFoundException is expected because no logofile is present in the filesystem at test time
@Test
void testGetLogo() {
assertThrows(InternalServerErrorException.class, () -> {
settingsBrandingService.getLogo();
});
void testGetLogo() throws URISyntaxException {
final URL logoUrl = getClass().getResource("/images/" + LookAndFeelConstants.JIRA_SCALED_LOGO_FILENAME);
assert logoUrl != null;
final File imagesDirectory = new File(logoUrl.toURI()).getParentFile();

doReturn(imagesDirectory).when(uploadService).getLogoDirectory();
assertNotNull(settingsBrandingService.getLogo());
}

@Test
void testSetLogo() {
InputStream is = new ByteArrayInputStream("".getBytes());

try (MockedStatic<ComponentAccessor> componentAccessorMockedStatic = mockStatic(ComponentAccessor.class)) {
componentAccessorMockedStatic.when(() -> ComponentAccessor.getComponent(LnFDefaultColorProvider.class)).thenReturn(mock(LnFDefaultColorProvider.class));
componentAccessorMockedStatic.when(() -> ComponentAccessor.getComponent(LogoProvider.class)).thenReturn(mock(LogoProvider.class));
componentAccessorMockedStatic.when(() -> ComponentAccessor.getComponent(EventPublisher.class)).thenReturn(mock(EventPublisher.class));

settingsBrandingService.setLogo(is);
void testSetLogo() throws IOException {
final File logoDirectory = new File("target/logos");
Files.createDirectories(logoDirectory.toPath());
doReturn(logoDirectory).when(uploadService).getLogoDirectory();

try (InputStream is = getClass().getClassLoader().getResourceAsStream("images/" + LookAndFeelConstants.JIRA_SCALED_LOGO_FILENAME)) {
try (MockedStatic<ComponentAccessor> componentAccessorMockedStatic = mockStatic(ComponentAccessor.class)) {
componentAccessorMockedStatic.when(() -> ComponentAccessor.getComponent(LnFDefaultColorProvider.class)).thenReturn(mock(LnFDefaultColorProvider.class));
componentAccessorMockedStatic.when(() -> ComponentAccessor.getComponent(LogoProvider.class)).thenReturn(mock(LogoProvider.class));
componentAccessorMockedStatic.when(() -> ComponentAccessor.getComponent(EventPublisher.class)).thenReturn(mock(EventPublisher.class));
componentAccessorMockedStatic.when(() -> ComponentAccessor.getComponent(UiSettingsStateManager.class)).thenReturn(mock(UiSettingsStateManager.class));

settingsBrandingService.setLogo(is);
}

verify(lookAndFeelProperties).setLogoChoice(LogoChoice.UPLOAD);
}

verify(lookAndFeelProperties).setLogoChoice(LogoChoice.UPLOAD);
}

//InternalServerErrorException -> FileNotFoundException is expected because no logofile is present in the filesystem at test time
@Test
void testGetFavicon() {
assertThrows(InternalServerErrorException.class, () -> {
settingsBrandingService.getFavicon();
});
void testGetFavicon() throws URISyntaxException {
final URL faviconUrl = getClass().getResource("/images/" + LookAndFeelConstants.JIRA_SCALED_FAVICON_FILENAME);
assert faviconUrl != null;
final File imagesDirectory = new File(faviconUrl.toURI()).getParentFile();

doReturn(imagesDirectory).when(uploadService).getLogoDirectory();
assertNotNull(settingsBrandingService.getFavicon());
}

@Test
void testSetFavicon() {
final InputStream is = new ByteArrayInputStream("".getBytes());

try (MockedStatic<ComponentAccessor> componentAccessorMockedStatic = mockStatic(ComponentAccessor.class)) {
componentAccessorMockedStatic.when(() -> ComponentAccessor.getComponent(LnFDefaultColorProvider.class)).thenReturn(mock(LnFDefaultColorProvider.class));
componentAccessorMockedStatic.when(() -> ComponentAccessor.getComponent(LogoProvider.class)).thenReturn(mock(LogoProvider.class));
componentAccessorMockedStatic.when(() -> ComponentAccessor.getComponent(EventPublisher.class)).thenReturn(mock(EventPublisher.class));

settingsBrandingService.setFavicon(is);
void testSetFavicon() throws IOException {
final File logoDirectory = new File("target/logos");
Files.createDirectories(logoDirectory.toPath());
doReturn(logoDirectory).when(uploadService).getLogoDirectory();

try (InputStream is = getClass().getClassLoader().getResourceAsStream("images/" + LookAndFeelConstants.JIRA_SCALED_FAVICON_FILENAME)) {
try (MockedStatic<ComponentAccessor> componentAccessorMockedStatic = mockStatic(ComponentAccessor.class)) {
componentAccessorMockedStatic.when(() -> ComponentAccessor.getComponent(LnFDefaultColorProvider.class)).thenReturn(mock(LnFDefaultColorProvider.class));
componentAccessorMockedStatic.when(() -> ComponentAccessor.getComponent(LogoProvider.class)).thenReturn(mock(LogoProvider.class));
componentAccessorMockedStatic.when(() -> ComponentAccessor.getComponent(EventPublisher.class)).thenReturn(mock(EventPublisher.class));
componentAccessorMockedStatic.when(() -> ComponentAccessor.getComponent(UiSettingsStateManager.class)).thenReturn(mock(UiSettingsStateManager.class));

settingsBrandingService.setFavicon(is);
}

verify(lookAndFeelProperties).setFaviconChoice(LogoChoice.UPLOAD);
}

verify(lookAndFeelProperties).setFaviconChoice(LogoChoice.UPLOAD);
}
}
22 changes: 22 additions & 0 deletions src/test/resources/generated-test-resources.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
How generated test resources.zip has been generated
---------------------------------------------------

The whole steps don't have to be repeated when 'upgrading' the home zip,
they are just documented for reproducibility.

1. Start Jira with `./mvnw clean package jira:run` and login with 'admin:admin'
2. Change baseurl to localhost if necessary
3. Close health checks and other dialogs
4. Create user:
```
username: user
fullname: user
email: [email protected]
password: user
```
with access to Jira Service Management and Jira Software (includes Jira Core)
5. Shut down using `[Ctrl]+[D]`
6. Save home ZIP with `./mvnw jira:create-home-zip` and copy
`./target/jira/generated-test-resources.zip` to `src/test/resources/`

7. ...
Binary file modified src/test/resources/generated-test-resources.zip
Binary file not shown.
Binary file added src/test/resources/images/jira-favicon-scaled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/test/resources/images/jira-logo-scaled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b1f2423

Please sign in to comment.