From 4e2efc811fd359eaf87f1bc1e43e78d54777a801 Mon Sep 17 00:00:00 2001 From: Simon Urli Date: Thu, 28 Nov 2024 17:21:04 +0100 Subject: [PATCH] [Misc] Move some deprecated class from model-api to legacy --- .../xwiki-platform-legacy-model-api/pom.xml | 7 ++ .../DefaultEntityReferenceValueProvider.java | 0 .../EntityReferenceValueProvider.java | 0 .../script/LegacyModelScriptService.java | 86 +++++++++++++++++++ .../main/resources/META-INF/components.txt | 2 + ...faultEntityReferenceValueProviderTest.java | 26 +++--- .../script/LegacyModelScriptServiceTest.java | 74 ++++++++++++++++ .../xwiki-platform-legacy-oldcore/pom.xml | 7 ++ .../CurrentEntityReferenceValueProvider.java | 0 ...rentMixedEntityReferenceValueProvider.java | 0 .../main/resources/META-INF/components.txt | 2 + .../xwiki-platform-model-api/pom.xml | 19 ++++ .../model/script/ModelScriptService.java | 51 +---------- .../main/resources/META-INF/components.txt | 1 - .../EntityReferenceConverterTest.java | 39 ++++----- .../model/script/ModelScriptServiceTest.java | 30 ------- .../java/com/xpn/xwiki/web/XWikiAction.java | 11 ++- .../main/resources/META-INF/components.txt | 2 - .../macro/useravatar/UserAvatarMacro.java | 8 -- .../macro/useravatar/IntegrationTests.java | 6 -- 20 files changed, 236 insertions(+), 135 deletions(-) rename xwiki-platform-core/{xwiki-platform-model/xwiki-platform-model-api => xwiki-platform-legacy/xwiki-platform-legacy-model-api}/src/main/java/org/xwiki/model/internal/reference/DefaultEntityReferenceValueProvider.java (100%) rename xwiki-platform-core/{xwiki-platform-model/xwiki-platform-model-api => xwiki-platform-legacy/xwiki-platform-legacy-model-api}/src/main/java/org/xwiki/model/reference/EntityReferenceValueProvider.java (100%) create mode 100644 xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-model-api/src/main/java/org/xwiki/model/script/LegacyModelScriptService.java rename xwiki-platform-core/{xwiki-platform-model/xwiki-platform-model-api => xwiki-platform-legacy/xwiki-platform-legacy-model-api}/src/test/java/org/xwiki/model/internal/reference/DefaultEntityReferenceValueProviderTest.java (69%) create mode 100644 xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-model-api/src/test/java/org/xwiki/model/script/LegacyModelScriptServiceTest.java rename xwiki-platform-core/{xwiki-platform-oldcore => xwiki-platform-legacy/xwiki-platform-legacy-oldcore}/src/main/java/com/xpn/xwiki/internal/model/reference/CurrentEntityReferenceValueProvider.java (100%) rename xwiki-platform-core/{xwiki-platform-oldcore => xwiki-platform-legacy/xwiki-platform-legacy-oldcore}/src/main/java/com/xpn/xwiki/internal/model/reference/CurrentMixedEntityReferenceValueProvider.java (100%) diff --git a/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-model-api/pom.xml b/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-model-api/pom.xml index ade47f1ca4c6..9e5d4ab3465e 100644 --- a/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-model-api/pom.xml +++ b/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-model-api/pom.xml @@ -48,6 +48,13 @@ ${commons.version} test + + org.xwiki.platform + xwiki-platform-model-api + ${project.version} + test-jar + test + org.xwiki.commons xwiki-commons-tool-test-jmock diff --git a/xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/src/main/java/org/xwiki/model/internal/reference/DefaultEntityReferenceValueProvider.java b/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-model-api/src/main/java/org/xwiki/model/internal/reference/DefaultEntityReferenceValueProvider.java similarity index 100% rename from xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/src/main/java/org/xwiki/model/internal/reference/DefaultEntityReferenceValueProvider.java rename to xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-model-api/src/main/java/org/xwiki/model/internal/reference/DefaultEntityReferenceValueProvider.java diff --git a/xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/src/main/java/org/xwiki/model/reference/EntityReferenceValueProvider.java b/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-model-api/src/main/java/org/xwiki/model/reference/EntityReferenceValueProvider.java similarity index 100% rename from xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/src/main/java/org/xwiki/model/reference/EntityReferenceValueProvider.java rename to xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-model-api/src/main/java/org/xwiki/model/reference/EntityReferenceValueProvider.java diff --git a/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-model-api/src/main/java/org/xwiki/model/script/LegacyModelScriptService.java b/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-model-api/src/main/java/org/xwiki/model/script/LegacyModelScriptService.java new file mode 100644 index 000000000000..4b8917fe0cd6 --- /dev/null +++ b/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-model-api/src/main/java/org/xwiki/model/script/LegacyModelScriptService.java @@ -0,0 +1,86 @@ +/* + * 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.model.script; + +import javax.inject.Named; +import javax.inject.Singleton; + +import org.xwiki.component.annotation.Component; +import org.xwiki.component.manager.ComponentLookupException; +import org.xwiki.model.EntityType; +import org.xwiki.model.reference.EntityReferenceValueProvider; + +/** + * Legacy version of {@link ModelScriptService}, holding deprecated methods. + * + * @version $Id$ + * @since 17.0.0RC1 + */ +@Deprecated(since = "17.0.0RC1") +@Component +@Named("model") +@Singleton +public class LegacyModelScriptService extends ModelScriptService +{ + /** + * Get the value configured for a specific entity type, like the space name or wiki name. This doesn't return a + * proper entity reference, but just the string value that should be used for that type of entity. + * + * @param type the target entity type; from Velocity it's enough to use a string with the uppercase name of the + * entity, like {@code 'SPACE'} + * @param hint the hint of the value provider to use (valid hints are for example "default", "current" and + * "currentmixed") + * @return the configured value for the requested entity type, for example "Main" for the default space or "WebHome" + * for the default space homepage + * @since 4.3M1 + * @deprecated since 7.2M1, use {@link #getEntityReference(EntityType, String)} + */ + @Deprecated + public String getEntityReferenceValue(EntityType type, String hint) + { + if (type == null) { + return null; + } + + try { + EntityReferenceValueProvider provider = + this.componentManager.getInstance(EntityReferenceValueProvider.class, hint); + return provider.getDefaultValue(type); + } catch (ComponentLookupException ex) { + return null; + } + } + + /** + * Get the current value for a specific entity type, like the current space or wiki name. This doesn't return a + * proper entity reference, but just the string value that should be used for that type of entity. + * + * @param type the target entity type; from Velocity it's enough to use a string with the uppercase name of the + * entity, like {@code 'SPACE'} + * @return the current value for the requested entity type + * @since 4.3M1 + * @deprecated since 7.4.1/8.0M1, use {@link #getEntityReference(EntityType)} + */ + @Deprecated + public String getEntityReferenceValue(EntityType type) + { + return getEntityReferenceValue(type, DEFAULT_RESOLVER_HINT); + } +} diff --git a/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-model-api/src/main/resources/META-INF/components.txt b/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-model-api/src/main/resources/META-INF/components.txt index 0c3153230533..cfa80a16eb67 100644 --- a/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-model-api/src/main/resources/META-INF/components.txt +++ b/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-model-api/src/main/resources/META-INF/components.txt @@ -1,3 +1,4 @@ +org.xwiki.model.internal.reference.DefaultEntityReferenceValueProvider org.xwiki.model.internal.reference.DeprecatedDefaultReferenceDocumentReferenceResolver org.xwiki.model.internal.reference.DeprecatedDefaultReferenceDocumentReferenceResolver2 org.xwiki.model.internal.reference.DeprecatedDefaultReferenceEntityReferenceResolver @@ -19,3 +20,4 @@ org.xwiki.model.internal.reference.DeprecatedLocalReferenceEntityReferenceSerial org.xwiki.model.internal.reference.DeprecatedLocalReferenceEntityReferenceSerializer2 org.xwiki.model.internal.reference.DeprecatedLocalStringEntityReferenceSerializer org.xwiki.model.internal.reference.DeprecatedRelativeStringEntityReferenceResolver +500:org.xwiki.model.script.LegacyModelScriptService diff --git a/xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/src/test/java/org/xwiki/model/internal/reference/DefaultEntityReferenceValueProviderTest.java b/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-model-api/src/test/java/org/xwiki/model/internal/reference/DefaultEntityReferenceValueProviderTest.java similarity index 69% rename from xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/src/test/java/org/xwiki/model/internal/reference/DefaultEntityReferenceValueProviderTest.java rename to xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-model-api/src/test/java/org/xwiki/model/internal/reference/DefaultEntityReferenceValueProviderTest.java index c967babe1279..a6739a0b5aaf 100644 --- a/xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/src/test/java/org/xwiki/model/internal/reference/DefaultEntityReferenceValueProviderTest.java +++ b/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-model-api/src/test/java/org/xwiki/model/internal/reference/DefaultEntityReferenceValueProviderTest.java @@ -49,22 +49,24 @@ public class DefaultEntityReferenceValueProviderTest implements TestConstants @BeforeEach public void beforeEach() { - when(this.configuration.getDefaultReferenceValue(EntityType.SPACE)).thenReturn(DEFAULT_SPACE); - when(this.configuration.getDefaultReferenceValue(EntityType.WIKI)).thenReturn(DEFAULT_WIKI); - when(this.configuration.getDefaultReferenceValue(EntityType.DOCUMENT)).thenReturn(DEFAULT_DOCUMENT); - when(this.configuration.getDefaultReferenceValue(EntityType.ATTACHMENT)).thenReturn(DEFAULT_ATTACHMENT); - when(this.configuration.getDefaultReferenceValue(EntityType.PAGE)).thenReturn(DEFAULT_PAGE); - when(this.configuration.getDefaultReferenceValue(EntityType.PAGE_ATTACHMENT)).thenReturn(DEFAULT_ATTACHMENT); + when(this.configuration.getDefaultReferenceValue(EntityType.SPACE)).thenReturn(TestConstants.DEFAULT_SPACE); + when(this.configuration.getDefaultReferenceValue(EntityType.WIKI)).thenReturn(TestConstants.DEFAULT_WIKI); + when(this.configuration.getDefaultReferenceValue(EntityType.DOCUMENT)).thenReturn(TestConstants.DEFAULT_DOCUMENT); + when(this.configuration.getDefaultReferenceValue(EntityType.ATTACHMENT)).thenReturn( + TestConstants.DEFAULT_ATTACHMENT); + when(this.configuration.getDefaultReferenceValue(EntityType.PAGE)).thenReturn(TestConstants.DEFAULT_PAGE); + when(this.configuration.getDefaultReferenceValue(EntityType.PAGE_ATTACHMENT)).thenReturn( + TestConstants.DEFAULT_ATTACHMENT); } @Test public void testGetDefaultValue() { - assertEquals(DEFAULT_WIKI, this.provider.getDefaultValue(EntityType.WIKI)); - assertEquals(DEFAULT_SPACE, this.provider.getDefaultValue(EntityType.SPACE)); - assertEquals(DEFAULT_DOCUMENT, this.provider.getDefaultValue(EntityType.DOCUMENT)); - assertEquals(DEFAULT_ATTACHMENT, this.provider.getDefaultValue(EntityType.ATTACHMENT)); - assertEquals(DEFAULT_PAGE, this.provider.getDefaultValue(EntityType.PAGE)); - assertEquals(DEFAULT_ATTACHMENT, this.provider.getDefaultValue(EntityType.PAGE_ATTACHMENT)); + assertEquals(TestConstants.DEFAULT_WIKI, this.provider.getDefaultValue(EntityType.WIKI)); + assertEquals(TestConstants.DEFAULT_SPACE, this.provider.getDefaultValue(EntityType.SPACE)); + assertEquals(TestConstants.DEFAULT_DOCUMENT, this.provider.getDefaultValue(EntityType.DOCUMENT)); + assertEquals(TestConstants.DEFAULT_ATTACHMENT, this.provider.getDefaultValue(EntityType.ATTACHMENT)); + assertEquals(TestConstants.DEFAULT_PAGE, this.provider.getDefaultValue(EntityType.PAGE)); + assertEquals(TestConstants.DEFAULT_ATTACHMENT, this.provider.getDefaultValue(EntityType.PAGE_ATTACHMENT)); } } diff --git a/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-model-api/src/test/java/org/xwiki/model/script/LegacyModelScriptServiceTest.java b/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-model-api/src/test/java/org/xwiki/model/script/LegacyModelScriptServiceTest.java new file mode 100644 index 000000000000..b3ade6f04c7b --- /dev/null +++ b/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-model-api/src/test/java/org/xwiki/model/script/LegacyModelScriptServiceTest.java @@ -0,0 +1,74 @@ +/* + * 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.model.script; + +import javax.inject.Named; + +import org.junit.jupiter.api.Test; +import org.mockito.Mock; +import org.xwiki.component.manager.ComponentLookupException; +import org.xwiki.component.manager.ComponentManager; +import org.xwiki.model.EntityType; +import org.xwiki.model.reference.EntityReferenceValueProvider; +import org.xwiki.test.junit5.mockito.ComponentTest; +import org.xwiki.test.junit5.mockito.InjectMockComponents; +import org.xwiki.test.junit5.mockito.MockComponent; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.when; + +@ComponentTest +class LegacyModelScriptServiceTest +{ + @InjectMockComponents + private LegacyModelScriptService service; + + @MockComponent + @Named("context") + private ComponentManager componentManager; + + @Mock + private EntityReferenceValueProvider valueProvider; + + @Test + void getEntityReferenceValue() throws Exception + { + when(this.componentManager.getInstance(EntityReferenceValueProvider.class, "current")) + .thenReturn(this.valueProvider); + when(this.valueProvider.getDefaultValue(EntityType.WIKI)).thenReturn("somewiki"); + + assertEquals("somewiki", this.service.getEntityReferenceValue(EntityType.WIKI)); + } + + @Test + void getEntityReferenceValueWithInvalidHint() throws Exception + { + when(this.componentManager.getInstance(EntityReferenceValueProvider.class, "invalid")) + .thenThrow(new ComponentLookupException("error")); + + assertNull(this.service.getEntityReferenceValue(EntityType.WIKI, "invalid")); + } + + @Test + void getEntityReferenceValueWithNullType() throws Exception + { + assertNull(this.service.getEntityReferenceValue(null)); + } +} \ No newline at end of file diff --git a/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-oldcore/pom.xml b/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-oldcore/pom.xml index f7ba0c61debf..4a2c5bc0ad8e 100644 --- a/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-oldcore/pom.xml +++ b/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-oldcore/pom.xml @@ -70,6 +70,12 @@ + + + org.xwiki.platform + xwiki-platform-legacy-model-api + ${project.version} + @@ -78,6 +84,7 @@ ${rendering.version} + diff --git a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/internal/model/reference/CurrentEntityReferenceValueProvider.java b/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-oldcore/src/main/java/com/xpn/xwiki/internal/model/reference/CurrentEntityReferenceValueProvider.java similarity index 100% rename from xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/internal/model/reference/CurrentEntityReferenceValueProvider.java rename to xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-oldcore/src/main/java/com/xpn/xwiki/internal/model/reference/CurrentEntityReferenceValueProvider.java diff --git a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/internal/model/reference/CurrentMixedEntityReferenceValueProvider.java b/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-oldcore/src/main/java/com/xpn/xwiki/internal/model/reference/CurrentMixedEntityReferenceValueProvider.java similarity index 100% rename from xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/internal/model/reference/CurrentMixedEntityReferenceValueProvider.java rename to xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-oldcore/src/main/java/com/xpn/xwiki/internal/model/reference/CurrentMixedEntityReferenceValueProvider.java diff --git a/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-oldcore/src/main/resources/META-INF/components.txt b/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-oldcore/src/main/resources/META-INF/components.txt index ed454e703dc1..e866e284fb01 100644 --- a/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-oldcore/src/main/resources/META-INF/components.txt +++ b/xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-oldcore/src/main/resources/META-INF/components.txt @@ -1,5 +1,7 @@ org.xwiki.legacy.internal.oldcore.notification.LegacyNotificationDispatcher com.xpn.xwiki.internal.mandatory.SheetClassDocumentInitializer +com.xpn.xwiki.internal.model.reference.CurrentEntityReferenceValueProvider +com.xpn.xwiki.internal.model.reference.CurrentMixedEntityReferenceValueProvider com.xpn.xwiki.internal.model.reference.DeprecatedCompactStringEntityReferenceSerializer com.xpn.xwiki.internal.model.reference.DeprecatedCompactWikiStringEntityReferenceSerializer com.xpn.xwiki.internal.model.reference.DeprecatedCurrentMixedReferenceDocumentReferenceResolver diff --git a/xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/pom.xml b/xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/pom.xml index 5a8231ad9e26..a0a1e88a2e0e 100644 --- a/xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/pom.xml +++ b/xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/pom.xml @@ -35,6 +35,8 @@ 0.79 org.xwiki.platform:xwiki-platform-model + + true @@ -99,6 +101,23 @@ + + org.apache.maven.plugins + maven-jar-plugin + + + test-jar + + test-jar + + + + **/TestConstants.class + + + + + diff --git a/xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/src/main/java/org/xwiki/model/script/ModelScriptService.java b/xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/src/main/java/org/xwiki/model/script/ModelScriptService.java index 2484c8fa1c46..c96506fce677 100644 --- a/xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/src/main/java/org/xwiki/model/script/ModelScriptService.java +++ b/xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/src/main/java/org/xwiki/model/script/ModelScriptService.java @@ -42,7 +42,6 @@ import org.xwiki.model.reference.EntityReferenceResolver; import org.xwiki.model.reference.EntityReferenceSerializer; import org.xwiki.model.reference.EntityReferenceTree; -import org.xwiki.model.reference.EntityReferenceValueProvider; import org.xwiki.model.reference.ObjectPropertyReference; import org.xwiki.model.reference.ObjectReference; import org.xwiki.model.reference.PageAttachmentReference; @@ -68,7 +67,7 @@ public class ModelScriptService implements ScriptService /** * The default hint used when resolving references. */ - private static final String DEFAULT_RESOLVER_HINT = "current"; + protected static final String DEFAULT_RESOLVER_HINT = "current"; /** * The default hint used when serializing references. @@ -85,7 +84,8 @@ public class ModelScriptService implements ScriptService * Used to dynamically look up component implementations based on a given hint. */ @Inject - private ComponentManager componentManager; + @Named("context") + protected ComponentManager componentManager; @Inject private EntityReferenceSerializer defaultSerializer; @@ -830,51 +830,6 @@ public String serialize(EntityReference reference, String hint, Object... parame return result; } - /** - * Get the current value for a specific entity type, like the current space or wiki name. This doesn't return a - * proper entity reference, but just the string value that should be used for that type of entity. - * - * @param type the target entity type; from Velocity it's enough to use a string with the uppercase name of the - * entity, like {@code 'SPACE'} - * @return the current value for the requested entity type - * @since 4.3M1 - * @deprecated since 7.4.1/8.0M1, use {@link #getEntityReference(EntityType)} - */ - @Deprecated - public String getEntityReferenceValue(EntityType type) - { - return getEntityReferenceValue(type, DEFAULT_RESOLVER_HINT); - } - - /** - * Get the value configured for a specific entity type, like the space name or wiki name. This doesn't return a - * proper entity reference, but just the string value that should be used for that type of entity. - * - * @param type the target entity type; from Velocity it's enough to use a string with the uppercase name of the - * entity, like {@code 'SPACE'} - * @param hint the hint of the value provider to use (valid hints are for example "default", "current" and - * "currentmixed") - * @return the configured value for the requested entity type, for example "Main" for the default space or "WebHome" - * for the default space homepage - * @since 4.3M1 - * @deprecated since 7.2M1, use {@link #getEntityReference(EntityType, String)} - */ - @Deprecated - public String getEntityReferenceValue(EntityType type, String hint) - { - if (type == null) { - return null; - } - - try { - EntityReferenceValueProvider provider = - this.componentManager.getInstance(EntityReferenceValueProvider.class, hint); - return provider.getDefaultValue(type); - } catch (ComponentLookupException ex) { - return null; - } - } - /** * Get the current reference configured for a specific entity type, like the space reference or wiki reference. This * doesn't return a full entity reference, but just the part that should be used for that type of entity. diff --git a/xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/src/main/resources/META-INF/components.txt b/xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/src/main/resources/META-INF/components.txt index 79582ca00ba8..bec038b62ca6 100644 --- a/xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/src/main/resources/META-INF/components.txt +++ b/xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/src/main/resources/META-INF/components.txt @@ -2,7 +2,6 @@ org.xwiki.model.internal.DefaultModelConfiguration org.xwiki.model.internal.DefaultModelContext org.xwiki.model.internal.reference.DefaultDocumentReferenceProvider org.xwiki.model.internal.reference.DefaultEntityReferenceProvider -org.xwiki.model.internal.reference.DefaultEntityReferenceValueProvider org.xwiki.model.internal.reference.DefaultPageReferenceProvider org.xwiki.model.internal.reference.DefaultReferenceAttachmentReferenceResolver org.xwiki.model.internal.reference.DefaultReferenceEntityReferenceResolver diff --git a/xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/src/test/java/org/xwiki/model/internal/reference/converter/EntityReferenceConverterTest.java b/xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/src/test/java/org/xwiki/model/internal/reference/converter/EntityReferenceConverterTest.java index 3fcb0605265d..b2ddbc075157 100644 --- a/xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/src/test/java/org/xwiki/model/internal/reference/converter/EntityReferenceConverterTest.java +++ b/xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/src/test/java/org/xwiki/model/internal/reference/converter/EntityReferenceConverterTest.java @@ -19,18 +19,18 @@ */ package org.xwiki.model.internal.reference.converter; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import javax.inject.Inject; + +import org.junit.jupiter.api.Test; import org.xwiki.model.EntityType; import org.xwiki.model.reference.EntityReference; import org.xwiki.properties.ConverterManager; -import org.xwiki.properties.converter.Converter; import org.xwiki.test.annotation.AllComponents; -import org.xwiki.test.mockito.MockitoComponentMockingRule; +import org.xwiki.test.junit5.mockito.ComponentTest; +import org.xwiki.test.junit5.mockito.InjectMockComponents; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; /** * Validate {@link EntityReferenceConverter} component. @@ -38,22 +38,17 @@ * @version $Id$ */ @AllComponents -public class EntityReferenceConverterTest +@ComponentTest +class EntityReferenceConverterTest { - @Rule - public MockitoComponentMockingRule> mocker = - new MockitoComponentMockingRule<>(EntityReferenceConverter.class); + @InjectMockComponents + private EntityReferenceConverter entityReferenceConverter; + @Inject private ConverterManager converterManager; - @Before - public void setUp() throws Exception - { - this.converterManager = this.mocker.getInstance(ConverterManager.class); - } - @Test - public void convertDocumentFromString() + void convertDocumentFromString() { EntityReference reference; @@ -72,7 +67,7 @@ public void convertDocumentFromString() } @Test - public void convertSpaceFromString() + void convertSpaceFromString() { EntityReference reference; @@ -84,20 +79,20 @@ public void convertSpaceFromString() } @Test - public void convertWikiFromString() + void convertWikiFromString() { EntityReference reference = new EntityReference("dev", EntityType.WIKI); assertEquals(reference, this.converterManager.convert(EntityReference.class, "wiki:dev")); } @Test - public void convertFromNull() + void convertFromNull() { assertNull(this.converterManager.convert(EntityReference.class, null)); } @Test - public void convertToString() + void convertToString() { EntityReference reference; diff --git a/xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/src/test/java/org/xwiki/model/script/ModelScriptServiceTest.java b/xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/src/test/java/org/xwiki/model/script/ModelScriptServiceTest.java index 9fc8b17d0e60..6191ca9c09d3 100644 --- a/xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/src/test/java/org/xwiki/model/script/ModelScriptServiceTest.java +++ b/xwiki-platform-core/xwiki-platform-model/xwiki-platform-model-api/src/test/java/org/xwiki/model/script/ModelScriptServiceTest.java @@ -34,7 +34,6 @@ import org.xwiki.model.reference.DocumentReferenceResolver; import org.xwiki.model.reference.EntityReference; import org.xwiki.model.reference.EntityReferenceResolver; -import org.xwiki.model.reference.EntityReferenceValueProvider; import org.xwiki.model.reference.ObjectPropertyReference; import org.xwiki.model.reference.ObjectReference; import org.xwiki.model.reference.PageReference; @@ -68,8 +67,6 @@ public class ModelScriptServiceTest private EntityReferenceResolver stringEntityReferenceResolver; - private EntityReferenceValueProvider valueProvider; - private Logger logger; @SuppressWarnings("unchecked") @@ -96,8 +93,6 @@ public void beforeEach() throws ComponentLookupException this.stringEntityReferenceResolver = mock(EntityReferenceResolver.class); when(this.componentManager.getInstance(EntityReferenceResolver.TYPE_STRING, "current")) .thenReturn(this.stringEntityReferenceResolver); - - this.valueProvider = mock(EntityReferenceValueProvider.class); } @Test @@ -234,31 +229,6 @@ public void createDocumentReferenceFromPageNameAndSpaceReference() documentReference.getLastSpaceReference())); } - @Test - public void getEntityReferenceValue() throws Exception - { - when(this.componentManager.getInstance(EntityReferenceValueProvider.class, "current")) - .thenReturn(this.valueProvider); - when(this.valueProvider.getDefaultValue(EntityType.WIKI)).thenReturn("somewiki"); - - assertEquals("somewiki", this.service.getEntityReferenceValue(EntityType.WIKI)); - } - - @Test - public void getEntityReferenceValueWithInvalidHint() throws Exception - { - when(this.componentManager.getInstance(EntityReferenceValueProvider.class, "invalid")) - .thenThrow(new ComponentLookupException("error")); - - assertNull(this.service.getEntityReferenceValue(EntityType.WIKI, "invalid")); - } - - @Test - public void getEntityReferenceValueWithNullType() throws Exception - { - assertNull(this.service.getEntityReferenceValue(null)); - } - @Test public void createWikiReference() { diff --git a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/web/XWikiAction.java b/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/web/XWikiAction.java index 0ac205527341..6e12fd6e05bd 100644 --- a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/web/XWikiAction.java +++ b/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/web/XWikiAction.java @@ -67,7 +67,6 @@ import org.xwiki.model.reference.EntityReference; import org.xwiki.model.reference.EntityReferenceProvider; import org.xwiki.model.reference.EntityReferenceSerializer; -import org.xwiki.model.reference.EntityReferenceValueProvider; import org.xwiki.model.reference.SpaceReference; import org.xwiki.model.validation.EntityNameValidationConfiguration; import org.xwiki.model.validation.EntityNameValidationManager; @@ -464,11 +463,11 @@ public void execute(XWikiContext context) throws Exception // Set the main home page in the main space of the main wiki as the current requested entity // since we cannot set the non existing one as it would generate errors obviously... - EntityReferenceValueProvider valueProvider = - Utils.getComponent(EntityReferenceValueProvider.class); - xwiki.setPhonyDocument(new DocumentReference(valueProvider.getDefaultValue(EntityType.WIKI), - valueProvider.getDefaultValue(EntityType.SPACE), - valueProvider.getDefaultValue(EntityType.DOCUMENT)), context, vcontext); + EntityReferenceProvider entityReferenceProvider = + Utils.getComponent(EntityReferenceProvider.class); + DocumentReference phonyDoc = + (DocumentReference) entityReferenceProvider.getDefaultReference(EntityType.DOCUMENT); + xwiki.setPhonyDocument(phonyDoc, context); // Parse the error template Utils.parseTemplate(context.getWiki().Param("xwiki.wiki_exception", "wikidoesnotexist"), diff --git a/xwiki-platform-core/xwiki-platform-oldcore/src/main/resources/META-INF/components.txt b/xwiki-platform-core/xwiki-platform-oldcore/src/main/resources/META-INF/components.txt index 1bfe14c8c955..bc309b8e482c 100644 --- a/xwiki-platform-core/xwiki-platform-oldcore/src/main/resources/META-INF/components.txt +++ b/xwiki-platform-core/xwiki-platform-oldcore/src/main/resources/META-INF/components.txt @@ -77,13 +77,11 @@ com.xpn.xwiki.internal.model.reference.CompactWikiStringEntityReferenceSerialize com.xpn.xwiki.internal.model.reference.CurrentAttachmentReferenceResolver com.xpn.xwiki.internal.model.reference.CurrentDocumentReferenceProvider com.xpn.xwiki.internal.model.reference.CurrentEntityReferenceProvider -com.xpn.xwiki.internal.model.reference.CurrentEntityReferenceValueProvider com.xpn.xwiki.internal.model.reference.CurrentEntityUserAndGroupDocumentReferenceResolver com.xpn.xwiki.internal.model.reference.CurrentEntityUserAndGroupEntityReferenceResolver com.xpn.xwiki.internal.model.reference.CurrentGetDocumentDocumentReferenceResolver com.xpn.xwiki.internal.model.reference.CurrentGetPagePageReferenceResolver com.xpn.xwiki.internal.model.reference.CurrentMixedEntityReferenceProvider -com.xpn.xwiki.internal.model.reference.CurrentMixedEntityReferenceValueProvider com.xpn.xwiki.internal.model.reference.CurrentMixedReferenceEntityReferenceResolver com.xpn.xwiki.internal.model.reference.CurrentMixedReferenceDocumentReferenceResolver com.xpn.xwiki.internal.model.reference.CurrentMixedStringDocumentReferenceResolver diff --git a/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-useravatar/src/main/java/org/xwiki/rendering/internal/macro/useravatar/UserAvatarMacro.java b/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-useravatar/src/main/java/org/xwiki/rendering/internal/macro/useravatar/UserAvatarMacro.java index f9d38509b3e0..7629aba8d99d 100644 --- a/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-useravatar/src/main/java/org/xwiki/rendering/internal/macro/useravatar/UserAvatarMacro.java +++ b/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-useravatar/src/main/java/org/xwiki/rendering/internal/macro/useravatar/UserAvatarMacro.java @@ -39,7 +39,6 @@ import org.xwiki.model.reference.DocumentReferenceResolver; import org.xwiki.model.reference.EntityReference; import org.xwiki.model.reference.EntityReferenceSerializer; -import org.xwiki.model.reference.EntityReferenceValueProvider; import org.xwiki.rendering.block.Block; import org.xwiki.rendering.block.GroupBlock; import org.xwiki.rendering.block.ImageBlock; @@ -99,13 +98,6 @@ public class UserAvatarMacro extends AbstractMacro @Named("compactwiki") private EntityReferenceSerializer compactWikiEntityReferenceSerializer; - /** - * Used to find out the current Wiki name. - */ - @Inject - @Named("current") - private EntityReferenceValueProvider currentEntityReferenceValueProvider; - /** * Logging framework. */ diff --git a/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-useravatar/src/test/java/org/xwiki/rendering/macro/useravatar/IntegrationTests.java b/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-useravatar/src/test/java/org/xwiki/rendering/macro/useravatar/IntegrationTests.java index 40342adc3a9b..5b221450555c 100644 --- a/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-useravatar/src/test/java/org/xwiki/rendering/macro/useravatar/IntegrationTests.java +++ b/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-useravatar/src/test/java/org/xwiki/rendering/macro/useravatar/IntegrationTests.java @@ -27,7 +27,6 @@ import org.xwiki.model.reference.DocumentReferenceResolver; import org.xwiki.model.reference.EntityReference; import org.xwiki.model.reference.EntityReferenceSerializer; -import org.xwiki.model.reference.EntityReferenceValueProvider; import org.xwiki.rendering.test.integration.Initialized; import org.xwiki.rendering.test.integration.Scope; import org.xwiki.rendering.test.integration.junit5.RenderingTest; @@ -108,10 +107,5 @@ public void initialize(MockitoComponentManager componentManager) throws Exceptio .thenReturn("XWiki.UserWithExceptionRetrievingAvatarFile@mockAvatar.png"); when(ers.serialize(userWithExceptionRetrievingAvatarFileReference)) .thenReturn("XWiki.UserWithExceptionRetrievingAvatarFile"); - - // Entity Reference Serializer Mock - EntityReferenceValueProvider ervp = - componentManager.registerMockComponent(EntityReferenceValueProvider.class, "current"); - when(ervp.getDefaultValue(EntityType.WIKI)).thenReturn("wiki"); } }