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

XWIKI-22368: UIExtensionClass imported properties removed after editing and rolling back (#3306)

  * Provide a test to check that mandatory document initializers are
    properly declared for the demo package
  * Rename and improve the test
  * Put other missing modules

(cherry picked from commit 917d730e)
parent f5e29fb3
No related branches found
No related tags found
No related merge requests found
...@@ -88,24 +88,67 @@ ...@@ -88,24 +88,67 @@
<artifactId>xwiki-platform-annotation-io</artifactId> <artifactId>xwiki-platform-annotation-io</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<!-- WikiMacro classes are automatically generated. --> <!-- Modules containing mandatory document initializers -->
<dependency> <dependency>
<groupId>org.xwiki.platform</groupId> <groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-rendering-wikimacro-store</artifactId> <artifactId>xwiki-platform-rendering-wikimacro-store</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<!-- UIExtensionClass is automatically generated -->
<dependency> <dependency>
<groupId>org.xwiki.platform</groupId> <groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-uiextension-api</artifactId> <artifactId>xwiki-platform-uiextension-api</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<!-- PanelClass is automatically generated -->
<dependency> <dependency>
<groupId>org.xwiki.platform</groupId> <groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-panels-api</artifactId> <artifactId>xwiki-platform-panels-api</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-crypto-store-wiki</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-edit-default</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-feed-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-localization-source-wiki</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-attachment-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-attachment-validation-default</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-notifications-filters-watch</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-index-tree-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-security-authentication-default</artifactId>
<version>${project.version}</version>
</dependency>
<!-- Instance module has its own Hibernate mapping file --> <!-- Instance module has its own Hibernate mapping file -->
<dependency> <dependency>
<groupId>org.xwiki.platform</groupId> <groupId>org.xwiki.platform</groupId>
......
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.test.ui;
import org.junit.Test;
import org.xwiki.rendering.syntax.Syntax;
import static org.junit.Assert.assertEquals;
/**
* Check that all mandatory document initializers are properly declared in the demo package build and that the pages
* are not created at first start only. See also XWIKI-22368.
*
* @version $Id$
* @since 16.7.0RC1
*/
public class MandatoryDocInitializedTest extends AbstractTest
{
private static final String GROOVY_CODE =
"""
{{groovy}}
import com.xpn.xwiki.doc.MandatoryDocumentInitializer;
import java.time.temporal.ChronoUnit;
import java.text.SimpleDateFormat;
// define the pages that shouldn't be created during the build.
def allowedExceptions = ["XWiki.XWikiServerXwiki"];
// Get creation date at build time.
def adminRef = services.model.resolveDocument("XWiki.Admin");
def adminDoc = xwiki.getDocument(adminRef);
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 documentInitializersList = componentManager.getInstanceList(MandatoryDocumentInitializer.class);
def dateFormat = new SimpleDateFormat("dd/MM/YYYY");
def foundErrors = [];
for (initializer in documentInitializersList) {
def ref = initializer.getDocumentReference();
if (!allowedExceptionsRef.contains(ref)) {
def classDoc = xwiki.getDocument(ref);
def creationDate = classDoc.getCreationDate();
def creationDateDay = classDoc.getCreationDate().toInstant().truncatedTo(ChronoUnit.DAYS);
if (!creationDateDay.equals(adminCreationDateDay)) {
foundErrors.add(ref.toString() + " ("+dateFormat.format(creationDateDay.toDate())+")");
}
}
}
if (foundErrors.size() > 0) {
def adminDateFormat = dateFormat.format(adminCreationDateDay.toDate());
println foundErrors.size() + " page found created after the build ("+adminDateFormat+"):\\n";
for (error in foundErrors) {
println " * " + error;
}
}
{{/groovy}}
""";
@Test
public void docsAreInitialized() throws Exception
{
getUtil().loginAsAdmin();
String result = getUtil().executeWikiPlain(GROOVY_CODE, Syntax.XWIKI_2_1);
// Using equals on purpose to see the output in case of failure.
assertEquals("", result);
}
}
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