Skip to content
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

fixes #27978 chore(Language Variables) : Register the new Locale Variable Upgrade Task as a Data Task #29469

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
import org.junit.BeforeClass;
import org.junit.Test;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Random;
import java.util.Set;

import static com.liferay.util.StringPool.BLANK;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -56,14 +56,18 @@ public static void prepare() throws Exception {
}

/**
* Given scenario: we copy the messages directory to the expected location and run the upgrade task
* Expected result: the upgrade task should run without errors and the expected results should be ingested into the system
* @throws DotDataException
* @throws IOException
* @throws URISyntaxException
* <ul>
* <li><b>Method to test:
* </b>{@link Task240306MigrateLegacyLanguageVariables#executeUpgrade()}</li>
* <li><b>Given Scenario: </b>Run the Data Task as it would when dotCMS is being updated
* .</li>
* <li><b>Expected Result: </b>Running the Data Task should not cause any errors.</li>
* </ul>
*
* @throws DotDataException An error occurred when interacting with the database.
*/
@Test
public void testExecuteUpgrade() throws DotDataException, IOException, URISyntaxException {
public void testExecuteUpgrade() throws DotDataException {
final Task240306MigrateLegacyLanguageVariables dataTask = new Task240306MigrateLegacyLanguageVariables();
assertTrue("This Data Task must always run", dataTask.forceRun());
assertTrue("The migration summary object should not exist before running the task",
Expand All @@ -80,10 +84,16 @@ public void testExecuteUpgrade() throws DotDataException, IOException, URISyntax
// Verify the languages we were not able to find
assertTrue(locales.contains(Locale.SIMPLIFIED_CHINESE));

// There are other ITs that create random languages. So let's check ONLY for our
// expected languages
final Set<String> expectedLanguages = new HashSet<>();
summary.success().forEach((language, addedKeys) -> {
final String isoCode = language.getIsoCode();
assertTrue("ISO Code not expected: " + isoCode, expectedResults.containsKey(isoCode));
if (expectedResults.containsKey(isoCode)) {
expectedLanguages.add(isoCode);
}
});
assertEquals("The expected languages must be present", expectedResults.size(), expectedLanguages.size());
} finally {
final Optional<ImmutableMigrationSummary> migrationSummary = dataTask.getMigrationSummary();
migrationSummary.ifPresent(this::cleanup);
Expand Down Expand Up @@ -152,11 +162,18 @@ public void testDataTaskIdempotency() throws DotDataException {
assertTrue("There must be at least 5 successfully processed Locales in the second run",
secondTaskSummary.success().size() >= 5);
assertEquals("There must be no errors in the second run", 0, secondTaskSummary.fails().size());

// There are other ITs that create random languages. So let's check ONLY for our
// expected languages
final Set<String> expectedLanguages = new HashSet<>();
secondTaskSummary.success().forEach((language, addedKeys) -> {
final String isoCode = language.getIsoCode();
assertTrue("ISO Code not expected: " + isoCode, expectedResults.containsKey(isoCode));
if (expectedResults.containsKey(isoCode)) {
expectedLanguages.add(isoCode);
}
assertEquals("No entries should've been updated", 0, addedKeys.size());
});
assertEquals("The expected languages must be present", expectedResults.size(), expectedLanguages.size());
} finally {
final Optional<ImmutableMigrationSummary> migrationSummary = dataTaskFirstInstance.getMigrationSummary();
migrationSummary.ifPresent(this::cleanup);
Expand Down