Skip to content

Commit

Permalink
XWIKI-22440: Wrong hrel links for REST attachments, objects...
Browse files Browse the repository at this point in the history
* fix wrong since
* fix two mistakes
* add unit tests
  • Loading branch information
tmortagne committed Sep 16, 2024
1 parent 65e121d commit 577a3e1
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,10 @@ public static List<String> getSpacesFromSpaceId(String spaceId)
* @return the spaces
* @since 16.8.0RC1
* @since 16.4.4
* @since 15.10.13
*/
public static List<String> getSpaces(EntityReference entityReference)
{
EntityReference spaceReference = entityReference.extractFirstReference(EntityType.SPACE);
EntityReference spaceReference = entityReference.extractReference(EntityType.SPACE);

List<String> spaces = new ArrayList<>();
for(EntityReference ref = spaceReference; ref != null && ref.getType() == EntityType.SPACE;
Expand All @@ -175,7 +174,6 @@ public static List<String> 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<String> getSpacesURLElements(EntityReference entityReference)
{
Expand All @@ -187,7 +185,6 @@ public static List<String> 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<String> getSpacesURLElements(List<String> spaces)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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"))));
}
}

0 comments on commit 577a3e1

Please sign in to comment.