-
-
Notifications
You must be signed in to change notification settings - Fork 553
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
XWIKI-21207: Improve the evaluation of ConfigurableClass
* Stop evaluating pretty names (which seems like an old feature no longer used anywhere) * Introduce ConfigurableObjectEvaluator to safely evaluate heading and linkPrefix properties
- Loading branch information
Showing
9 changed files
with
276 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
xwiki-platform-core/xwiki-platform-administration/xwiki-platform-administration-api/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
* 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. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.xwiki.platform</groupId> | ||
<artifactId>xwiki-platform-administration</artifactId> | ||
<version>16.4.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>xwiki-platform-administration-api</artifactId> | ||
<name>XWiki Platform - Administration - API</name> | ||
<packaging>jar</packaging> | ||
<description>XWiki Platform - Administration - API</description> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.xwiki.platform</groupId> | ||
<artifactId>xwiki-platform-oldcore</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.xwiki.commons</groupId> | ||
<artifactId>xwiki-commons-component-api</artifactId> | ||
<version>${commons.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.xwiki.commons</groupId> | ||
<artifactId>xwiki-commons-tool-test-component</artifactId> | ||
<version>${commons.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
62 changes: 62 additions & 0 deletions
62
...istration-api/src/main/java/org/xwiki/administration/api/ConfigurableObjectEvaluator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* 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.administration.api; | ||
|
||
import java.util.Map; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
import javax.inject.Singleton; | ||
|
||
import org.xwiki.component.annotation.Component; | ||
import org.xwiki.evaluation.ObjectEvaluator; | ||
import org.xwiki.evaluation.ObjectEvaluatorException; | ||
import org.xwiki.evaluation.ObjectPropertyEvaluator; | ||
|
||
import com.xpn.xwiki.objects.BaseObject; | ||
|
||
/** | ||
* Evaluator for objects of class {@code XWiki.ConfigurableClass}. | ||
* Returns a Map storing the evaluated content for "heading" and "linkPrefix" properties. | ||
* | ||
* @version $Id$ | ||
* @since 15.10.9 | ||
* @since 16.3.0 | ||
*/ | ||
@Component | ||
@Singleton | ||
@Named(ConfigurableObjectEvaluator.ROLE_HINT) | ||
public class ConfigurableObjectEvaluator implements ObjectEvaluator | ||
{ | ||
/** | ||
* The role hint of this component. | ||
*/ | ||
public static final String ROLE_HINT = "XWiki.ConfigurableClass"; | ||
|
||
@Inject | ||
@Named("velocity") | ||
private ObjectPropertyEvaluator velocityPropertyEvaluator; | ||
|
||
@Override | ||
public Map<String, String> evaluate(BaseObject object) throws ObjectEvaluatorException | ||
{ | ||
return this.velocityPropertyEvaluator.evaluateProperties(object, "heading", "linkPrefix"); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...ministration/xwiki-platform-administration-api/src/main/resources/META-INF/components.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.xwiki.administration.api.ConfigurableObjectEvaluator |
80 changes: 80 additions & 0 deletions
80
...ation-api/src/test/java/org/xwiki/administration/api/ConfigurableObjectEvaluatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* 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.administration.api; | ||
|
||
import java.util.Map; | ||
|
||
import javax.inject.Named; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mock; | ||
import org.xwiki.evaluation.ObjectEvaluatorException; | ||
import org.xwiki.evaluation.ObjectPropertyEvaluator; | ||
import org.xwiki.test.junit5.mockito.ComponentTest; | ||
import org.xwiki.test.junit5.mockito.InjectMockComponents; | ||
import org.xwiki.test.junit5.mockito.MockComponent; | ||
|
||
import com.xpn.xwiki.objects.BaseObject; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
/** | ||
* Validate {@link ConfigurableObjectEvaluator}. | ||
* | ||
* @version $Id$ | ||
*/ | ||
@ComponentTest | ||
class ConfigurableObjectEvaluatorTest | ||
{ | ||
@InjectMockComponents | ||
private ConfigurableObjectEvaluator configurableObjectEvaluator; | ||
|
||
@MockComponent | ||
@Named("velocity") | ||
private ObjectPropertyEvaluator velocityObjectPropertyEvaluator; | ||
|
||
@Mock | ||
private BaseObject baseObject; | ||
|
||
@BeforeEach | ||
void setUp() throws ObjectEvaluatorException | ||
{ | ||
when(this.baseObject.getStringValue("heading")).thenReturn("unevaluated heading"); | ||
when(this.baseObject.getStringValue("linkPrefix")).thenReturn("unevaluated linkPrefix"); | ||
|
||
Map<String, String> evaluatedVelocityProperties = | ||
Map.of("heading", "evaluated heading", "linkPrefix", "evaluated linkPrefix"); | ||
|
||
when(this.velocityObjectPropertyEvaluator.evaluateProperties(this.baseObject, "heading", "linkPrefix")) | ||
.thenReturn(evaluatedVelocityProperties); | ||
} | ||
|
||
@Test | ||
void checkEvaluationThroughPropertyEvaluator() throws ObjectEvaluatorException | ||
{ | ||
Map<String, String> evaluationResults = this.configurableObjectEvaluator.evaluate(this.baseObject); | ||
verify(this.velocityObjectPropertyEvaluator).evaluateProperties(this.baseObject, "heading", "linkPrefix"); | ||
assertEquals("evaluated heading", evaluationResults.get("heading")); | ||
assertEquals("evaluated linkPrefix", evaluationResults.get("linkPrefix")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.