From aaaa2f3403c58ae09bd04e485875c9910175d1c9 Mon Sep 17 00:00:00 2001 From: Jose Castro Date: Tue, 6 Aug 2024 10:38:49 -0600 Subject: [PATCH 1/2] fixes #27978 chore(Language Variables) : Register the new Locale Variable Upgrade Task as a Data Task --- ...306MigrateLegacyLanguageVariablesTest.java | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/dotcms-integration/src/test/java/com/dotmarketing/startup/runonce/Task240306MigrateLegacyLanguageVariablesTest.java b/dotcms-integration/src/test/java/com/dotmarketing/startup/runonce/Task240306MigrateLegacyLanguageVariablesTest.java index feef75934de1..2630367c9276 100644 --- a/dotcms-integration/src/test/java/com/dotmarketing/startup/runonce/Task240306MigrateLegacyLanguageVariablesTest.java +++ b/dotcms-integration/src/test/java/com/dotmarketing/startup/runonce/Task240306MigrateLegacyLanguageVariablesTest.java @@ -20,8 +20,7 @@ import org.junit.BeforeClass; import org.junit.Test; -import java.io.IOException; -import java.net.URISyntaxException; +import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.Map; @@ -56,14 +55,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 + * + * + * @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", @@ -80,10 +83,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 List expectedLanguages = new ArrayList<>(); 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 migrationSummary = dataTask.getMigrationSummary(); migrationSummary.ifPresent(this::cleanup); @@ -152,11 +161,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 List expectedLanguages = new ArrayList<>(); 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 migrationSummary = dataTaskFirstInstance.getMigrationSummary(); migrationSummary.ifPresent(this::cleanup); From a28f3e1a27a5430ab0651f39ed0a95d17da09fa5 Mon Sep 17 00:00:00 2001 From: Jose Castro Date: Tue, 6 Aug 2024 12:48:57 -0600 Subject: [PATCH 2/2] Attempting to fix IT --- .../Task240306MigrateLegacyLanguageVariablesTest.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/dotcms-integration/src/test/java/com/dotmarketing/startup/runonce/Task240306MigrateLegacyLanguageVariablesTest.java b/dotcms-integration/src/test/java/com/dotmarketing/startup/runonce/Task240306MigrateLegacyLanguageVariablesTest.java index 2630367c9276..06042333c71f 100644 --- a/dotcms-integration/src/test/java/com/dotmarketing/startup/runonce/Task240306MigrateLegacyLanguageVariablesTest.java +++ b/dotcms-integration/src/test/java/com/dotmarketing/startup/runonce/Task240306MigrateLegacyLanguageVariablesTest.java @@ -20,12 +20,13 @@ import org.junit.BeforeClass; import org.junit.Test; -import java.util.ArrayList; +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; @@ -85,7 +86,7 @@ public void testExecuteUpgrade() throws DotDataException { // There are other ITs that create random languages. So let's check ONLY for our // expected languages - final List expectedLanguages = new ArrayList<>(); + final Set expectedLanguages = new HashSet<>(); summary.success().forEach((language, addedKeys) -> { final String isoCode = language.getIsoCode(); if (expectedResults.containsKey(isoCode)) { @@ -164,7 +165,7 @@ public void testDataTaskIdempotency() throws DotDataException { // There are other ITs that create random languages. So let's check ONLY for our // expected languages - final List expectedLanguages = new ArrayList<>(); + final Set expectedLanguages = new HashSet<>(); secondTaskSummary.success().forEach((language, addedKeys) -> { final String isoCode = language.getIsoCode(); if (expectedResults.containsKey(isoCode)) {