diff --git a/xwiki-platform-core/xwiki-platform-rest/xwiki-platform-rest-server/src/main/java/org/xwiki/rest/internal/Utils.java b/xwiki-platform-core/xwiki-platform-rest/xwiki-platform-rest-server/src/main/java/org/xwiki/rest/internal/Utils.java index 8b2053065b52..2eeefb2c0165 100644 --- a/xwiki-platform-core/xwiki-platform-rest/xwiki-platform-rest-server/src/main/java/org/xwiki/rest/internal/Utils.java +++ b/xwiki-platform-core/xwiki-platform-rest/xwiki-platform-rest-server/src/main/java/org/xwiki/rest/internal/Utils.java @@ -154,11 +154,10 @@ public static List getSpacesFromSpaceId(String spaceId) * @return the spaces * @since 16.8.0RC1 * @since 16.4.4 - * @since 15.10.13 */ public static List getSpaces(EntityReference entityReference) { - EntityReference spaceReference = entityReference.extractFirstReference(EntityType.SPACE); + EntityReference spaceReference = entityReference.extractReference(EntityType.SPACE); List spaces = new ArrayList<>(); for(EntityReference ref = spaceReference; ref != null && ref.getType() == EntityType.SPACE; @@ -175,7 +174,6 @@ public static List getSpaces(EntityReference entityReference) * @return the value to pass to the URL factory for the space * @since 16.8.0RC1 * @since 16.4.4 - * @since 15.10.13 */ public static List getSpacesURLElements(EntityReference entityReference) { @@ -187,7 +185,6 @@ public static List getSpacesURLElements(EntityReference entityReference) * @return the value to pass to the URL factory for the space * @since 16.8.0RC1 * @since 16.4.4 - * @since 15.10.13 */ public static List getSpacesURLElements(List spaces) { diff --git a/xwiki-platform-core/xwiki-platform-rest/xwiki-platform-rest-server/src/main/java/org/xwiki/rest/internal/resources/spaces/SpacesResourceImpl.java b/xwiki-platform-core/xwiki-platform-rest/xwiki-platform-rest-server/src/main/java/org/xwiki/rest/internal/resources/spaces/SpacesResourceImpl.java index d4a07a3c1641..2baf53edfc15 100644 --- a/xwiki-platform-core/xwiki-platform-rest/xwiki-platform-rest-server/src/main/java/org/xwiki/rest/internal/resources/spaces/SpacesResourceImpl.java +++ b/xwiki-platform-core/xwiki-platform-rest/xwiki-platform-rest-server/src/main/java/org/xwiki/rest/internal/resources/spaces/SpacesResourceImpl.java @@ -64,7 +64,7 @@ public Spaces getSpaces(String wikiName, Integer start, Integer number) home = Utils.getXWikiApi(componentManager).getDocument(homeId); } spaces.getSpaces().add(DomainObjectFactory.createSpace(objectFactory, uriInfo.getBaseUri(), - wikiName, Utils.getSpacesURLElements(spaceList), home)); + wikiName, spaceList, home)); } } } catch (Exception e) { diff --git a/xwiki-platform-core/xwiki-platform-rest/xwiki-platform-rest-server/src/test/java/org/xwiki/rest/internal/UtilsTest.java b/xwiki-platform-core/xwiki-platform-rest/xwiki-platform-rest-server/src/test/java/org/xwiki/rest/internal/UtilsTest.java new file mode 100644 index 000000000000..75dbd0e1d6e2 --- /dev/null +++ b/xwiki-platform-core/xwiki-platform-rest/xwiki-platform-rest-server/src/test/java/org/xwiki/rest/internal/UtilsTest.java @@ -0,0 +1,52 @@ +/* + * 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.rest.internal; + +import java.util.List; + +import org.junit.jupiter.api.Test; +import org.xwiki.model.reference.DocumentReference; +import org.xwiki.model.reference.SpaceReference; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * Validate {@link Utils}. + * + * @version $Id$ + */ +class UtilsTest +{ + @Test + void getSpacesURLElements() + { + assertEquals(List.of("space1", "spaces", "space2"), + Utils.getSpacesURLElements(new DocumentReference("wiki", List.of("space1", "space2"), "document"))); + + assertEquals(List.of("space1"), + Utils.getSpacesURLElements(new DocumentReference("wiki", List.of("space1"), "document"))); + + assertEquals(List.of("space1", "spaces", "space2"), + Utils.getSpacesURLElements(new SpaceReference("wiki", List.of("space1", "space2")))); + + assertEquals(List.of("space1"), + Utils.getSpacesURLElements(new SpaceReference("wiki", List.of("space1")))); + } +}