-
Notifications
You must be signed in to change notification settings - Fork 483
fix(content): handle language-only locales without a country code #36405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jcastro-dotcms
wants to merge
10
commits into
main
Choose a base branch
from
issue-36106-language-only-locale-country-npe
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+272
−26
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
fdc1eb4
Default null country/countryCode to blank in LanguageViewStrategy.map…
jcastro-dotcms 0156e31
Defer Velocity health check probe until dotCMS startup completes
jcastro-dotcms 526c73b
Fix NPE building visitor Locale for language-only locales
jcastro-dotcms 7d06a61
Merge branch 'main' into issue-36106-language-only-locale-country-npe
jcastro-dotcms 2e8e989
Fix NPE building Push Publishing queue map for language-only locales
jcastro-dotcms 6d48400
Assert isoCode in LanguageViewStrategyTest null-country cases
jcastro-dotcms 56bc6fd
Fix VelocityHealthCheckTest broken by the startup-deferral guard
jcastro-dotcms a1299d2
Pushing fixes for unit test
jcastro-dotcms 1c698c5
Merge branch 'main' into issue-36106-language-only-locale-country-npe
jcastro-dotcms 0598579
Merge branch 'main' into issue-36106-language-only-locale-country-npe
jcastro-dotcms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
dotCMS/src/test/java/com/dotcms/publisher/business/PublishQueueElementTransformerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| package com.dotcms.publisher.business; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.mockito.Mockito.mockStatic; | ||
|
|
||
| import com.dotcms.publisher.util.PusheableAsset; | ||
| import com.dotmarketing.business.APILocator; | ||
| import com.dotmarketing.portlets.languagesmanager.business.LanguageAPI; | ||
| import com.dotmarketing.portlets.languagesmanager.model.Language; | ||
| import java.util.Map; | ||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.mockito.MockedStatic; | ||
| import org.mockito.Mockito; | ||
|
|
||
| /** | ||
| * Unit tests for {@link PublishQueueElementTransformer}. | ||
| * | ||
| * @author Jose Castro | ||
| * @since Jul 2, 2026 | ||
| */ | ||
| public class PublishQueueElementTransformerTest { | ||
|
|
||
| private MockedStatic<APILocator> apiLocatorMock; | ||
| private LanguageAPI languageAPI; | ||
|
|
||
| @Before | ||
| public void setUp() { | ||
| languageAPI = Mockito.mock(LanguageAPI.class); | ||
| apiLocatorMock = mockStatic(APILocator.class); | ||
| apiLocatorMock.when(APILocator::getLanguageAPI).thenReturn(languageAPI); | ||
| } | ||
|
|
||
| @After | ||
| public void tearDown() { | ||
| apiLocatorMock.close(); | ||
| } | ||
|
|
||
| /** | ||
| * Regression test for the Push Publishing queue view crashing on language-only locales. | ||
| * <p> | ||
| * {@code getMapForLanguage} used to build a {@code java.util.Map.of(...)} directly from | ||
| * {@code language.getCountryCode()}, which is legitimately null for a language-only locale | ||
| * (e.g. {@code es}, no country). {@code Map.of()} throws {@code NullPointerException} on any | ||
| * null value, the same failure mode as Guava's {@code ImmutableMap.Builder}. | ||
| */ | ||
| @Test | ||
| public void testGetMap_whenLanguageIsLanguageOnly_doesNotThrowAndDefaultsCountryToBlank() { | ||
| final Language language = new Language(1L, "es", null, "Spanish", null); | ||
| Mockito.when(languageAPI.getLanguage("1")).thenReturn(language); | ||
|
|
||
| final PublishQueueElementTransformer transformer = new PublishQueueElementTransformer(); | ||
| final Map<String, Object> result = transformer.getMap("1", PusheableAsset.LANGUAGE.getType()); | ||
|
|
||
| assertEquals("", result.get(PublishQueueElementTransformer.COUNTRY_CODE_KEY)); | ||
| assertEquals("es", result.get(PublishQueueElementTransformer.LANGUAGE_CODE_KEY)); | ||
| assertEquals("Spanish()", result.get(PublishQueueElementTransformer.TITLE_KEY)); | ||
| } | ||
|
|
||
| /** | ||
| * Non-regression check: a locale with both language and country must keep mapping the | ||
| * country code through unchanged. | ||
| */ | ||
| @Test | ||
| public void testGetMap_whenLanguageHasCountry_mapsCountryCode() { | ||
| final Language language = new Language(2L, "es", "CR", "Spanish", "Costa Rica"); | ||
| Mockito.when(languageAPI.getLanguage("2")).thenReturn(language); | ||
|
|
||
| final PublishQueueElementTransformer transformer = new PublishQueueElementTransformer(); | ||
| final Map<String, Object> result = transformer.getMap("2", PusheableAsset.LANGUAGE.getType()); | ||
|
|
||
| assertEquals("CR", result.get(PublishQueueElementTransformer.COUNTRY_CODE_KEY)); | ||
| assertEquals("Spanish(CR)", result.get(PublishQueueElementTransformer.TITLE_KEY)); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.