Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,7 @@ public String executeWiki(String wikiContent, Syntax wikiSyntax) throws Exceptio
/**
* @since 16.4.0RC1
* @since 15.10.11
* @since 14.10.22
*/
public String executeWikiPlain(String wikiContent, Syntax wikiSyntax) throws Exception
{
Expand All @@ -1229,6 +1230,7 @@ public String executeWikiPlain(String wikiContent, Syntax wikiSyntax) throws Exc
/**
* @since 16.4.0RC1
* @since 15.10.11
* @since 14.10.22
*/
public String executeWiki(String wikiContent, Syntax wikiSyntax, Map<String, String> queryParameters)
throws Exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,44 +35,55 @@
public class MandatoryDocInitializedTest extends AbstractTest
{
private static final String GROOVY_CODE = "{{groovy}}\n"
+ " import com.xpn.xwiki.doc.MandatoryDocumentInitializer;\n"
+ " import java.text.SimpleDateFormat;\n"
+ " import java.lang.management.ManagementFactory;\n"
+ " \n"
+ " // define the pages that shouldn't be created during the build.\n"
+ " def allowedExceptions = [\"XWiki.XWikiServerXwiki\"];\n"
+ " \n"
+ " def dateFormat = new SimpleDateFormat(\"dd/MM/YYYY HH:mm\");\n"
+ " def rb = ManagementFactory.getRuntimeMXBean();\n"
+ " def startedSince = new Date(rb.getStartTime());\n"
+ " \n"
+ " def allowedExceptionsRef = [];\n"
+ " for (exception in allowedExceptions) {\n"
+ " allowedExceptionsRef.add(services.model.resolveDocument(exception));\n"
+ " }\n"
+ " def componentManager = services.component.getContextComponentManager();\n"
+ " def documentInitializersList = componentManager.getInstanceList(MandatoryDocumentInitializer.class);\n"
+ " \n"
+ " def foundErrors = [];\n"
+ " for (initializer in documentInitializersList) {\n"
+ " def ref = initializer.getDocumentReference();\n"
+ " if (!allowedExceptionsRef.contains(ref)) {\n"
+ " def classDoc = xwiki.getDocument(ref);\n"
+ " def creationDate = classDoc.getCreationDate();\n"
+ " if (creationDate.after(startedSince)) {\n"
+ " foundErrors.add(ref.toString() + \" (\"+dateFormat.format(creationDate)+\")\");\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ " \n"
+ " if (foundErrors.size() > 0) {\n"
+ " println \"Instance started at \" + dateFormat.format(startedSince);\n"
+ " println foundErrors.size() + \" page found created after:\\n\";\n"
+ " for (error in foundErrors) {\n"
+ " println \" * \" + error;\n"
+ " }\n"
+ " }\n"
+ " {{/groovy}}";
+ "import com.xpn.xwiki.doc.MandatoryDocumentInitializer;\n"
+ "import java.text.SimpleDateFormat;\n"
+ "import java.lang.management.ManagementFactory;\n"
+ "\n"
+ "// define the pages that should be created at startup\n"
+ "def startupPages = [\"XWiki.XWikiServerXwiki\"];\n"
+ "\n"
+ "def dateFormat = new SimpleDateFormat(\"dd/MM/YYYY HH:mm:ss\");\n"
+ "def rb = ManagementFactory.getRuntimeMXBean();\n"
+ "def startedSince = new Date(rb.getStartTime());\n"
+ "\n"
+ "def startupPageRef = [];\n"
+ "for (startupPage in startupPages) {\n"
+ " startupPageRef.add(services.model.resolveDocument(startupPage));\n"
+ "}\n"
+ "\n"
+ "def componentManager = services.component.getContextComponentManager();\n"
+ "def documentInitializersList = componentManager.getInstanceList(MandatoryDocumentInitializer.class);\n"
+ "\n"
+ "def foundErrorsCreatedAfter = [];\n"
+ "def foundErrorsCreatedBefore = [];\n"
+ "for (initializer in documentInitializersList) {\n"
+ " def ref = initializer.getDocumentReference();\n"
+ " def classDoc = xwiki.getDocument(ref);\n"
+ " def creationDate = classDoc.getCreationDate();\n"
+ " def shouldBeBefore = (!startupPageRef.contains(ref));\n"
+ " if (shouldBeBefore && creationDate.after(startedSince)) {\n"
+ " foundErrorsCreatedAfter.add(ref.toString() + \" (\"+dateFormat.format(creationDate)+\")\");\n"
+ " } else if (!shouldBeBefore && creationDate.before(startedSince)) {\n"
+ " foundErrorsCreatedBefore.add(ref.toString() + \" (\"+dateFormat.format(creationDate)+\")\");\n"
+ " }\n"
+ "}\n"
+ "\n"
+ "if (foundErrorsCreatedAfter.size() > 0) {\n"
+ " println \"Instance started at \" + dateFormat.format(startedSince);\n"
+ " println foundErrorsCreatedAfter.size() + \" page found created after:\\n\";\n"
+ " for (error in foundErrorsCreatedAfter) {\n"
+ " println \" * \" + error;\n"
+ " }\n"
+ "}\n"
+ "if (foundErrorsCreatedBefore.size() > 0) {\n"
+ " println \"Instance started at \" + dateFormat.format(startedSince);\n"
+ " println foundErrorsCreatedBefore.size() + \" page found created before while they should be created at "
+ "startup:\\n\";\n"
+ " for (error in foundErrorsCreatedBefore) {\n"
+ " println \" * \" + error;\n"
+ " }\n"
+ "}\n"
+ "{{/groovy}}";

@Test
public void docsAreInitialized() throws Exception
Expand Down