Skip to content
Snippets Groups Projects
Commit 215fd856 authored by Simon Urli's avatar Simon Urli
Browse files

XWIKI-22368: UIExtensionClass imported properties removed after editing and rolling back

  * Change condition of the test to make it more reliable

(cherry picked from commit 22a10a1b)
parent 9e14276f
No related branches found
No related tags found
No related merge requests found
...@@ -36,50 +36,45 @@ public class MandatoryDocInitializedTest extends AbstractTest ...@@ -36,50 +36,45 @@ public class MandatoryDocInitializedTest extends AbstractTest
{ {
private static final String GROOVY_CODE = private static final String GROOVY_CODE =
""" """
{{groovy}} {{groovy}}
import com.xpn.xwiki.doc.MandatoryDocumentInitializer; import com.xpn.xwiki.doc.MandatoryDocumentInitializer;
import java.time.temporal.ChronoUnit; import java.text.SimpleDateFormat;
import java.text.SimpleDateFormat; import java.lang.management.ManagementFactory;
// define the pages that shouldn't be created during the build. // define the pages that shouldn't be created during the build.
def allowedExceptions = ["XWiki.XWikiServerXwiki"]; def allowedExceptions = ["XWiki.XWikiServerXwiki"];
// Get creation date at build time. def dateFormat = new SimpleDateFormat("dd/MM/YYYY HH:mm");
def adminRef = services.model.resolveDocument("XWiki.Admin"); def rb = ManagementFactory.getRuntimeMXBean();
def adminDoc = xwiki.getDocument(adminRef); def startedSince = new Date(rb.getStartTime());
def adminCreationDate = adminDoc.getCreationDate();
def adminCreationDateDay = adminDoc.getCreationDate().toInstant().truncatedTo(ChronoUnit.DAYS);
def allowedExceptionsRef = [];
for (exception in allowedExceptions) {
allowedExceptionsRef.add(services.model.resolveDocument(exception));
}
def componentManager = services.component.getContextComponentManager(); def allowedExceptionsRef = [];
def documentInitializersList = componentManager.getInstanceList(MandatoryDocumentInitializer.class); for (exception in allowedExceptions) {
allowedExceptionsRef.add(services.model.resolveDocument(exception));
}
def componentManager = services.component.getContextComponentManager();
def documentInitializersList = componentManager.getInstanceList(MandatoryDocumentInitializer.class);
def dateFormat = new SimpleDateFormat("dd/MM/YYYY"); def foundErrors = [];
def foundErrors = []; for (initializer in documentInitializersList) {
for (initializer in documentInitializersList) { def ref = initializer.getDocumentReference();
def ref = initializer.getDocumentReference(); if (!allowedExceptionsRef.contains(ref)) {
if (!allowedExceptionsRef.contains(ref)) { def classDoc = xwiki.getDocument(ref);
def classDoc = xwiki.getDocument(ref); def creationDate = classDoc.getCreationDate();
def creationDate = classDoc.getCreationDate(); if (creationDate.after(startedSince)) {
def creationDateDay = classDoc.getCreationDate().toInstant().truncatedTo(ChronoUnit.DAYS); foundErrors.add(ref.toString() + " ("+dateFormat.format(creationDate)+")");
if (!creationDateDay.equals(adminCreationDateDay)) { }
foundErrors.add(ref.toString() + " ("+dateFormat.format(creationDateDay.toDate())+")");
} }
} }
}
if (foundErrors.size() > 0) {
if (foundErrors.size() > 0) { println "Instance started at " + dateFormat.format(startedSince);
def adminDateFormat = dateFormat.format(adminCreationDateDay.toDate()); println foundErrors.size() + " page found created after:\\n";
println foundErrors.size() + " page found created after the build ("+adminDateFormat+"):\\n";
for (error in foundErrors) { for (error in foundErrors) {
println " * " + error; println " * " + error;
} }
} }
{{/groovy}} {{/groovy}}
"""; """;
@Test @Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment