2727import org .xwiki .model .reference .DocumentReference ;
2828import org .xwiki .model .reference .SpaceReference ;
2929import org .xwiki .model .validation .test .po .NameStrategiesAdministrationSectionPage ;
30+ import org .xwiki .rendering .syntax .Syntax ;
3031import org .xwiki .rest .model .jaxb .Objects ;
3132import org .xwiki .rest .model .jaxb .Page ;
3233import org .xwiki .test .docker .junit5 .TestReference ;
5051 * The strategy is configured with its own forbidden character (nothing is inherited from the standard flavor, which is
5152 * not installed here). The mapping is seeded directly through the REST API rather than through the administration's
5253 * "Add new character" UI, because that UI relies on the configuration document (with its list properties) shipped by
53- * the flavor, which is absent from this WAR. Seeding through REST also avoids triggering the name-strategy validation
54- * (only invoked on the UI create/save actions): the strategy caches its replacement map in a singleton initialized on
55- * first use, and it reads the seeded mapping when it is first initialized (on the first administration visit below).
54+ * the flavor, which is absent from this WAR. The {@code ReplaceCharacterEntityNameValidation} strategy caches its
55+ * replacement map in a singleton and only reloads it from {@code EntityNameValidationManager.resetStrategies()} (the
56+ * "Add new character" UI is the only production caller); the REST seed alone does not refresh it, so {@code beforeAll}
57+ * calls {@code resetStrategies()} explicitly once the mapping has been seeded.
5658 *
5759 * @version $Id$
5860 * @since 18.6.0RC1
@@ -73,10 +75,7 @@ void beforeAll(TestUtils setup) throws Exception
7375
7476 // Configure the Character Replacement strategy with a custom "@" -> "-" mapping directly through the REST API.
7577 // The administration's "Add new character" UI is not used because it requires the configuration document (with
76- // its list properties) shipped by the standard flavor, which is not installed in this test's WAR. Seeding
77- // through REST also avoids the name-strategy validation (only invoked on the UI create/save actions): the
78- // strategy caches its replacement map in a singleton initialized on first use, and it reads this seeded mapping
79- // when it is first initialized (on the first administration visit in the tests below).
78+ // its list properties) shipped by the standard flavor, which is not installed in this test's WAR.
8079 DocumentReference configReference =
8180 new DocumentReference ("xwiki" , List .of ("XWiki" , "EntityNameValidation" ), "Configuration" );
8281 Page configPage = setup .rest ().page (configReference );
@@ -92,6 +91,14 @@ void beforeAll(TestUtils setup) throws Exception
9291 configObject .withProperties (RestTestUtils .property ("replaceCharacters.replacementCharacters" , "-" ));
9392 objects .withObjectSummaries (configObject );
9493 setup .rest ().save (configPage );
94+
95+ // The ReplaceCharacterEntityNameValidation strategy caches its replacement map at component initialisation and
96+ // is only refreshed by EntityNameValidationManager.resetStrategies(). In this shared-instance test run the
97+ // singleton has already been initialised (with an empty map) by an earlier test, and neither the REST save
98+ // above nor the administration form save in the tests below refreshes it. Force the reload so the seeded
99+ // "@" -> "-" mapping is actually used.
100+ setup .executeWikiPlain ("{{velocity}}$services.modelvalidation.manager.resetStrategies(){{/velocity}}" ,
101+ Syntax .XWIKI_2_1 );
95102 }
96103
97104 /**
0 commit comments