|
| 1 | +/* |
| 2 | + * See the NOTICE file distributed with this work for additional |
| 3 | + * information regarding copyright ownership. |
| 4 | + * |
| 5 | + * This is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU Lesser General Public License as |
| 7 | + * published by the Free Software Foundation; either version 2.1 of |
| 8 | + * the License, or (at your option) any later version. |
| 9 | + * |
| 10 | + * This software is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | + * Lesser General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU Lesser General Public |
| 16 | + * License along with this software; if not, write to the Free |
| 17 | + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 18 | + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. |
| 19 | + */ |
| 20 | +package org.xwiki.like; |
| 21 | + |
| 22 | +import java.util.List; |
| 23 | + |
| 24 | +import javax.inject.Named; |
| 25 | + |
| 26 | +import org.junit.jupiter.api.Test; |
| 27 | +import org.xwiki.like.script.LikeScriptServiceComponentList; |
| 28 | +import org.xwiki.model.reference.DocumentReference; |
| 29 | +import org.xwiki.model.script.ModelScriptService; |
| 30 | +import org.xwiki.ratings.RatingsManager; |
| 31 | +import org.xwiki.ratings.internal.DefaultRating; |
| 32 | +import org.xwiki.rendering.syntax.Syntax; |
| 33 | +import org.xwiki.template.script.TemplateScriptService; |
| 34 | +import org.xwiki.test.annotation.ComponentList; |
| 35 | +import org.xwiki.test.junit5.mockito.MockComponent; |
| 36 | +import org.xwiki.test.page.PageTest; |
| 37 | +import org.xwiki.test.page.XWikiSyntax21ComponentList; |
| 38 | +import org.xwiki.user.UserReferenceComponentList; |
| 39 | + |
| 40 | +import com.xpn.xwiki.doc.XWikiDocument; |
| 41 | + |
| 42 | +import net.sf.json.JSONObject; |
| 43 | + |
| 44 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 45 | +import static org.mockito.ArgumentMatchers.any; |
| 46 | +import static org.mockito.ArgumentMatchers.anyBoolean; |
| 47 | +import static org.mockito.ArgumentMatchers.anyInt; |
| 48 | +import static org.mockito.ArgumentMatchers.anyMap; |
| 49 | +import static org.mockito.Mockito.when; |
| 50 | + |
| 51 | +/** |
| 52 | + * Test of {@code XWiki.Like.Code.LiveTableResultPage}. |
| 53 | + * |
| 54 | + * @version $Id$ |
| 55 | + * @since 15.1 |
| 56 | + * @since 14.10.6 |
| 57 | + */ |
| 58 | +@XWikiSyntax21ComponentList |
| 59 | +@LikeScriptServiceComponentList |
| 60 | +@UserReferenceComponentList |
| 61 | +@ComponentList({ |
| 62 | + TemplateScriptService.class, |
| 63 | + ModelScriptService.class |
| 64 | +}) |
| 65 | +class LiveTableResultPagePageTest extends PageTest |
| 66 | +{ |
| 67 | + private static final DocumentReference DOCUMENT_REFERENCE = |
| 68 | + new DocumentReference("xwiki", List.of("XWiki", "Like", "Code"), "LiveTableResultPage"); |
| 69 | + |
| 70 | + @MockComponent |
| 71 | + @Named("solr") |
| 72 | + private RatingsManager ratingsManager; |
| 73 | + |
| 74 | + @Test |
| 75 | + void likedPageWithADot() throws Exception |
| 76 | + { |
| 77 | + DocumentReference likedPageReference = new DocumentReference("xwiki", "Space", "With.ADot"); |
| 78 | + |
| 79 | + // Create an empty page to be returned as a liked page. |
| 80 | + XWikiDocument likedDocument = this.xwiki.getDocument(likedPageReference, this.context); |
| 81 | + this.xwiki.saveDocument(likedDocument, this.context); |
| 82 | + |
| 83 | + // The rating manager is mocked for now as the focus of the tests is currently not to test the likes indexing. |
| 84 | + when(this.ratingsManager.getRatings(anyMap(), anyInt(), anyInt(), any(RatingsManager.RatingQueryField.class), |
| 85 | + anyBoolean())).thenReturn(List.of(new DefaultRating("id1").setReference(likedPageReference))); |
| 86 | + |
| 87 | + setOutputSyntax(Syntax.PLAIN_1_0); |
| 88 | + this.context.setAction("get"); |
| 89 | + |
| 90 | + this.request.put("offset", "1"); |
| 91 | + this.request.put("reqNo", "1"); |
| 92 | + this.request.put("limit", "10"); |
| 93 | + |
| 94 | + JSONObject object = renderJSONPage(DOCUMENT_REFERENCE); |
| 95 | + |
| 96 | + assertEquals("xwiki:Space.With\\.ADot", object.getJSONArray("rows").getJSONObject(0).getString("doc_fullName")); |
| 97 | + } |
| 98 | +} |
0 commit comments