| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /* | ||
| * 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.like.script; | ||
|
|
||
| import java.lang.annotation.Documented; | ||
| import java.lang.annotation.Inherited; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| import org.xwiki.like.internal.DefaultLikeConfiguration; | ||
| import org.xwiki.like.internal.DefaultLikeManager; | ||
| import org.xwiki.like.internal.LikeConfigurationSource; | ||
| import org.xwiki.ratings.internal.DefaultRatingsConfiguration; | ||
| import org.xwiki.ratings.internal.DefaultRatingsManagerFactory; | ||
| import org.xwiki.ratings.internal.RatingsConfigurationSource; | ||
| import org.xwiki.test.annotation.ComponentList; | ||
|
|
||
| import static java.lang.annotation.ElementType.ANNOTATION_TYPE; | ||
| import static java.lang.annotation.ElementType.METHOD; | ||
| import static java.lang.annotation.ElementType.TYPE; | ||
| import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
|
||
| /** | ||
| * Pack of default Component implementations that are needed for {@link LikeScriptService}. | ||
| * | ||
| * @version $Id$ | ||
| * @since 13.9RC1 | ||
| * @since 13.4.4 | ||
| */ | ||
| @Documented | ||
| @Retention(RUNTIME) | ||
| @Target({ TYPE, METHOD, ANNOTATION_TYPE }) | ||
| @ComponentList({ | ||
| LikeScriptService.class, | ||
| DefaultLikeManager.class, | ||
| DefaultRatingsManagerFactory.class, | ||
| DefaultLikeConfiguration.class, | ||
| LikeConfigurationSource.class, | ||
| // Ratings dependencies. | ||
| DefaultRatingsConfiguration.class, | ||
| RatingsConfigurationSource.class, | ||
| }) | ||
| @Inherited | ||
| public @interface LikeScriptServiceComponentList | ||
| { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| /* | ||
| * 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.user; | ||
|
|
||
| import java.lang.annotation.Documented; | ||
| import java.lang.annotation.Inherited; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| import org.xwiki.configuration.internal.DocumentsConfigurationSource; | ||
| import org.xwiki.configuration.internal.SpacesConfigurationSource; | ||
| import org.xwiki.test.annotation.ComponentList; | ||
| import org.xwiki.user.internal.AllGuestConfigurationSource; | ||
| import org.xwiki.user.internal.AllSuperAdminConfigurationSource; | ||
| import org.xwiki.user.internal.ConfiguredStringUserReferenceSerializer; | ||
| import org.xwiki.user.internal.DefaultConfiguredStringUserReferenceResolver; | ||
| import org.xwiki.user.internal.DefaultUserConfiguration; | ||
| import org.xwiki.user.internal.DefaultUserManager; | ||
| import org.xwiki.user.internal.GuestConfigurationSource; | ||
| import org.xwiki.user.internal.SecureAllUserPropertiesResolver; | ||
| import org.xwiki.user.internal.SecureUserPropertiesResolver; | ||
| import org.xwiki.user.internal.SuperAdminConfigurationSource; | ||
| import org.xwiki.user.internal.document.CurrentUserReferenceResolver; | ||
| import org.xwiki.user.internal.document.DocumentDocumentReferenceUserReferenceResolver; | ||
| import org.xwiki.user.internal.document.DocumentDocumentReferenceUserReferenceSerializer; | ||
| import org.xwiki.user.internal.document.NormalUserConfigurationSourceAuthorization; | ||
| import org.xwiki.user.internal.document.NormalUserPreferencesConfigurationSource; | ||
| import org.xwiki.user.internal.document.SecureUserDocumentUserPropertiesResolver; | ||
| import org.xwiki.user.internal.document.UserPreferencesConfigurationSource; | ||
| import org.xwiki.user.internal.group.DefaultGroupManager; | ||
| import org.xwiki.user.internal.group.GroupsCache; | ||
| import org.xwiki.user.internal.group.MembersCache; | ||
|
|
||
| import static java.lang.annotation.ElementType.ANNOTATION_TYPE; | ||
| import static java.lang.annotation.ElementType.METHOD; | ||
| import static java.lang.annotation.ElementType.TYPE; | ||
| import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
|
||
| /** | ||
| * Pack of default Components that are needed for the User API. | ||
| * | ||
| * @version $Id$ | ||
| * @since 13.9RC1 | ||
| * @since 13.4.4 | ||
| */ | ||
| @Documented | ||
| @Retention(RUNTIME) | ||
| @Target({ TYPE, METHOD, ANNOTATION_TYPE }) | ||
| @ComponentList({ | ||
| // UserReferenceSerializer | ||
| DocumentDocumentReferenceUserReferenceSerializer.class, | ||
| CurrentUserReferenceResolver.class, | ||
| DocumentDocumentReferenceUserReferenceResolver.class, | ||
| ConfiguredStringUserReferenceSerializer.class, | ||
| // User Script Service | ||
| SecureUserPropertiesResolver.class, | ||
| SuperAdminConfigurationSource.class, | ||
| GuestConfigurationSource.class, | ||
| SecureAllUserPropertiesResolver.class, | ||
| AllSuperAdminConfigurationSource.class, | ||
| DocumentsConfigurationSource.class, | ||
| AllGuestConfigurationSource.class, | ||
| DefaultUserManager.class, | ||
| DefaultConfiguredStringUserReferenceResolver.class, | ||
| SecureUserDocumentUserPropertiesResolver.class, | ||
| UserPreferencesConfigurationSource.class, | ||
| NormalUserPreferencesConfigurationSource.class, | ||
| NormalUserConfigurationSourceAuthorization.class, | ||
| // User Configuration | ||
| DefaultUserConfiguration.class, | ||
| // Group Script Service | ||
| DefaultGroupManager.class, | ||
| GroupsCache.class, | ||
| MembersCache.class, | ||
| SpacesConfigurationSource.class | ||
| }) | ||
| @Inherited | ||
| public @interface DefaultUserComponentList | ||
| { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| /* | ||
| * 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.web; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import org.apache.velocity.tools.generic.MathTool; | ||
| import org.apache.velocity.tools.generic.NumberTool; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.mockito.ArgumentCaptor; | ||
| import org.mockito.Mock; | ||
| import org.xwiki.model.reference.DocumentReference; | ||
| import org.xwiki.query.QueryException; | ||
| import org.xwiki.query.internal.ScriptQuery; | ||
| import org.xwiki.query.script.QueryManagerScriptService; | ||
| import org.xwiki.script.service.ScriptService; | ||
| import org.xwiki.template.TemplateManager; | ||
| import org.xwiki.test.annotation.ComponentList; | ||
| import org.xwiki.test.page.PageTest; | ||
| import org.xwiki.velocity.tools.EscapeTool; | ||
| import org.xwiki.velocity.tools.JSONTool; | ||
|
|
||
| import com.xpn.xwiki.doc.XWikiDeletedDocument; | ||
| import com.xpn.xwiki.doc.XWikiDeletedDocumentContent; | ||
| import com.xpn.xwiki.doc.XWikiDocument; | ||
| import com.xpn.xwiki.internal.store.StoreConfiguration; | ||
| import com.xpn.xwiki.store.XWikiRecycleBinStoreInterface; | ||
|
|
||
| import static java.util.Arrays.asList; | ||
| import static java.util.Collections.singletonList; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.ArgumentMatchers.anyInt; | ||
| import static org.mockito.ArgumentMatchers.anyList; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| /** | ||
| * Test the {@code getdeleteddocuments.vm} template. Assert that the returned results are well-formed. | ||
| * | ||
| * @version $Id$ | ||
| * @since 13.9RC1 | ||
| * @since 13.4.4 | ||
| */ | ||
| @ComponentList({ | ||
| StoreConfiguration.class | ||
| }) | ||
| class GetdeleteddocumentsPageTest extends PageTest | ||
| { | ||
| private static final String GETDELETEDDOCUMENTS = "getdeleteddocuments.vm"; | ||
|
|
||
| @Mock | ||
| private QueryManagerScriptService queryService; | ||
|
|
||
| @Mock | ||
| private ScriptQuery query; | ||
|
|
||
| @Mock | ||
| private XWikiRecycleBinStoreInterface recycleBinStore; | ||
|
|
||
| private TemplateManager templateManager; | ||
|
|
||
| @BeforeEach | ||
| void setUp() throws Exception | ||
| { | ||
| this.templateManager = this.oldcore.getMocker().getInstance(TemplateManager.class); | ||
| this.oldcore.getMocker().registerComponent(ScriptService.class, "query", this.queryService); | ||
|
|
||
| this.oldcore.getMocker().registerComponent(ScriptService.class, "query", this.queryService); | ||
|
|
||
| this.xwiki.setRecycleBinStore(this.recycleBinStore); | ||
|
|
||
| registerVelocityTool("mathtool", new MathTool()); | ||
| registerVelocityTool("escapetool", new EscapeTool()); | ||
| registerVelocityTool("numbertool", new NumberTool()); | ||
| } | ||
|
|
||
| @Test | ||
| void getDeletedDocumentsObfuscatedResultsAreFiltered() throws Exception | ||
| { | ||
| defaultQueryMocks(); | ||
|
|
||
| when(this.query.execute()).thenReturn(asList("1", "2"), singletonList(2)); | ||
|
|
||
| when(this.recycleBinStore.getDeletedDocument(1L, this.context, true)) | ||
| .thenReturn(new XWikiDeletedDocument("fullName1", null, null, null, null, null)); | ||
| XWikiDeletedDocumentContent xWikiDeletedDocumentContent = mock(XWikiDeletedDocumentContent.class); | ||
| when(xWikiDeletedDocumentContent.getXWikiDocument(null)).thenReturn( | ||
| new XWikiDocument(new DocumentReference("xwiki", "XWiki", "fullName2"))); | ||
| when(this.recycleBinStore.getDeletedDocument(2L, this.context, true)) | ||
| .thenReturn(new XWikiDeletedDocument("fullName2", null, null, null, null, xWikiDeletedDocumentContent)); | ||
|
|
||
| when(this.xwiki.getRightService().hasAccessLevel("admin", "XWiki.XWikiGuest", "fullName2", this.context)) | ||
| .thenReturn(true); | ||
|
|
||
| Map<String, Object> results = getJsonResultMap(); | ||
|
|
||
| List<Map<String, Object>> rows = (List<Map<String, Object>>) results.get("rows"); | ||
| assertEquals(1, rows.size()); | ||
| assertTrue((Boolean) rows.get(0).get("doc_viewable")); | ||
| assertEquals("fullName2", rows.get(0).get("doc_name")); | ||
| verify(this.queryService).hql("SELECT ddoc.id FROM XWikiDeletedDocument as ddoc WHERE 1=1 "); | ||
| verify(this.queryService).hql("SELECT COUNT(ddoc.id) FROM XWikiDeletedDocument as ddoc WHERE 1=1"); | ||
| } | ||
|
|
||
| @Test | ||
| void getDeletedDocumentsOfuscatedResultsAreNotFiltered() throws Exception | ||
| { | ||
| this.request.put("limit", "1"); | ||
|
|
||
| defaultQueryMocks(); | ||
|
|
||
| when(this.query.execute()).thenReturn(asList("1"), singletonList(2)); | ||
|
|
||
| when(this.recycleBinStore.getDeletedDocument(1L, this.context, true)) | ||
| .thenReturn(new XWikiDeletedDocument("fullName1", null, null, null, null, null)); | ||
|
|
||
| when(this.xwiki.getRightService().hasAccessLevel("admin", "XWiki.XWikiGuest", "fullName2", this.context)) | ||
| .thenReturn(true); | ||
|
|
||
| Map<String, Object> results = getJsonResultMap(); | ||
|
|
||
| List<Map<String, Object>> rows = (List<Map<String, Object>>) results.get("rows"); | ||
| assertEquals(1, rows.size()); | ||
| assertFalse((Boolean) rows.get(0).get("doc_viewable")); | ||
| verify(this.queryService).hql("SELECT ddoc.id FROM XWikiDeletedDocument as ddoc WHERE 1=1 "); | ||
| verify(this.queryService).hql("SELECT COUNT(ddoc.id) FROM XWikiDeletedDocument as ddoc WHERE 1=1"); | ||
| } | ||
|
|
||
| private void defaultQueryMocks() throws QueryException | ||
| { | ||
| when(this.queryService.hql(any())).thenReturn(this.query, this.query); | ||
| when(this.query.setLimit(anyInt())).thenReturn(this.query); | ||
| when(this.query.setOffset(anyInt())).thenReturn(this.query); | ||
| when(this.query.bindValues(anyList())).thenReturn(this.query, this.query); | ||
| when(this.query.setWiki(any())).thenReturn(this.query, this.query); | ||
| } | ||
|
|
||
| private Map<String, Object> getJsonResultMap() throws Exception | ||
| { | ||
| JSONTool jsonTool = mock(JSONTool.class); | ||
| registerVelocityTool("jsontool", jsonTool); | ||
|
|
||
| this.templateManager.render(GETDELETEDDOCUMENTS); | ||
|
|
||
| ArgumentCaptor<Object> argument = ArgumentCaptor.forClass(Object.class); | ||
| verify(jsonTool).serialize(argument.capture()); | ||
|
|
||
| return (Map<String, Object>) argument.getValue(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| /* | ||
| * 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.web; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import org.apache.velocity.tools.generic.MathTool; | ||
| import org.apache.velocity.tools.generic.NumberTool; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.mockito.ArgumentCaptor; | ||
| import org.mockito.Mock; | ||
| import org.xwiki.model.script.ModelScriptService; | ||
| import org.xwiki.query.internal.ScriptQuery; | ||
| import org.xwiki.query.script.QueryManagerScriptService; | ||
| import org.xwiki.script.service.ScriptService; | ||
| import org.xwiki.template.TemplateManager; | ||
| import org.xwiki.test.annotation.ComponentList; | ||
| import org.xwiki.test.page.PageTest; | ||
| import org.xwiki.velocity.internal.XWikiDateTool; | ||
| import org.xwiki.velocity.tools.EscapeTool; | ||
| import org.xwiki.velocity.tools.JSONTool; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.ArgumentMatchers.anyInt; | ||
| import static org.mockito.ArgumentMatchers.anyString; | ||
| import static org.mockito.ArgumentMatchers.eq; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| /** | ||
| * Test the {@code getdocuments.vm} template. Assert that the returned results are well-formed. | ||
| * | ||
| * @version $Id$ | ||
| * @since 13.9RC1 | ||
| * @since 13.4.4 | ||
| */ | ||
| @ComponentList({ | ||
| XWikiDateTool.class, | ||
| ModelScriptService.class, | ||
| }) | ||
| class GetdocumentsPageTest extends PageTest | ||
| { | ||
| private static final String GETDOCUMENTS = "getdocuments.vm"; | ||
|
|
||
| @Mock | ||
| private QueryManagerScriptService queryService; | ||
|
|
||
| @Mock | ||
| private ScriptQuery query; | ||
|
|
||
| private TemplateManager templateManager; | ||
|
|
||
| @BeforeEach | ||
| void setUp() throws Exception | ||
| { | ||
| this.templateManager = this.oldcore.getMocker().getInstance(TemplateManager.class); | ||
| this.oldcore.getMocker().registerComponent(ScriptService.class, "query", this.queryService); | ||
|
|
||
| registerVelocityTool("jsontool", new JSONTool()); | ||
| registerVelocityTool("mathtool", new MathTool()); | ||
| registerVelocityTool("escapetool", new EscapeTool()); | ||
| registerVelocityTool("numbertool", new NumberTool()); | ||
| } | ||
|
|
||
| @Test | ||
| void removeObuscatedResultsWhenTotalrowsLowerThanLimit() throws Exception | ||
| { | ||
| when(this.oldcore.getMockRightService().hasAccessLevel(eq("view"), any(), any(), any())) | ||
| .thenReturn(false, true); | ||
| this.request.put("limit", "2"); | ||
| when(this.queryService.hql(anyString())).thenReturn(this.query); | ||
| when(this.query.setLimit(anyInt())).thenReturn(this.query); | ||
| when(this.query.setOffset(anyInt())).thenReturn(this.query); | ||
| when(this.query.bindValues(any(Map.class))).thenReturn(this.query); | ||
| when(this.query.bindValues(any(List.class))).thenReturn(this.query); | ||
| when(this.query.count()).thenReturn(3L); | ||
| when(this.query.execute()).thenReturn(Arrays.asList("XWiki.NotViewable", "XWiki.Viewable")); | ||
|
|
||
| Map<String, Object> result = getJsonResultMap(); | ||
|
|
||
| List<Map<String, Object>> rows = (List<Map<String, Object>>) result.get("rows"); | ||
| assertEquals(2, rows.size()); | ||
| assertEquals(2, result.get("returnedrows")); | ||
| Map<String, Object> obfuscated = rows.get(0); | ||
| assertFalse((boolean) obfuscated.get("doc_viewable")); | ||
| assertEquals("obfuscated", obfuscated.get("doc_fullName")); | ||
|
|
||
| Map<String, Object> viewable = rows.get(1); | ||
| assertTrue((boolean) viewable.get("doc_viewable")); | ||
| assertEquals("xwiki:XWiki.Viewable", viewable.get("doc_fullName")); | ||
| } | ||
|
|
||
| @Test | ||
| void nonViewableResultsAreObfuscated() throws Exception | ||
| { | ||
| when(this.oldcore.getMockRightService().hasAccessLevel(eq("view"), any(), any(), any())).thenReturn(false, | ||
| true); | ||
| this.request.put("limit", "2"); | ||
| when(this.queryService.hql(anyString())).thenReturn(this.query); | ||
| when(this.query.setLimit(anyInt())).thenReturn(this.query); | ||
| when(this.query.setOffset(anyInt())).thenReturn(this.query); | ||
| when(this.query.bindValues(any(Map.class))).thenReturn(this.query); | ||
| when(this.query.bindValues(any(List.class))).thenReturn(this.query); | ||
| when(this.query.count()).thenReturn(2L); | ||
| when(this.query.execute()).thenReturn(Arrays.asList("XWiki.NotViewable", "XWiki.Viewable")); | ||
|
|
||
| Map<String, Object> result = getJsonResultMap(); | ||
|
|
||
| List<Map<String, Object>> rows = (List<Map<String, Object>>) result.get("rows"); | ||
| assertEquals(1, rows.size()); | ||
| assertEquals(1, result.get("returnedrows")); | ||
|
|
||
| Map<String, Object> viewable = rows.get(0); | ||
| assertTrue((boolean) viewable.get("doc_viewable")); | ||
| assertEquals("xwiki:XWiki.Viewable", viewable.get("doc_fullName")); | ||
| } | ||
|
|
||
| private Map<String, Object> getJsonResultMap() throws Exception | ||
| { | ||
| JSONTool jsonTool = mock(JSONTool.class); | ||
| registerVelocityTool("jsontool", jsonTool); | ||
|
|
||
| this.templateManager.render(GETDOCUMENTS); | ||
|
|
||
| ArgumentCaptor<Object> argument = ArgumentCaptor.forClass(Object.class); | ||
| verify(jsonTool).serialize(argument.capture()); | ||
|
|
||
| return (Map<String, Object>) argument.getValue(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,195 @@ | ||
| /* | ||
| * 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.web; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.apache.velocity.tools.generic.MathTool; | ||
| import org.apache.velocity.tools.generic.NumberTool; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.mockito.ArgumentCaptor; | ||
| import org.xwiki.model.internal.reference.converter.EntityReferenceConverter; | ||
| import org.xwiki.model.reference.DocumentReference; | ||
| import org.xwiki.model.script.ModelScriptService; | ||
| import org.xwiki.rendering.syntax.Syntax; | ||
| import org.xwiki.script.service.ScriptService; | ||
| import org.xwiki.template.TemplateManager; | ||
| import org.xwiki.test.annotation.ComponentList; | ||
| import org.xwiki.test.page.PageTest; | ||
| import org.xwiki.user.DefaultUserComponentList; | ||
| import org.xwiki.user.internal.group.AbstractGroupCache.GroupCacheEntry; | ||
| import org.xwiki.user.internal.group.MembersCache; | ||
| import org.xwiki.user.script.GroupScriptService; | ||
| import org.xwiki.user.script.UserScriptService; | ||
| import org.xwiki.velocity.tools.EscapeTool; | ||
| import org.xwiki.velocity.tools.JSONTool; | ||
|
|
||
| import com.xpn.xwiki.doc.XWikiDocument; | ||
| import com.xpn.xwiki.plugin.rightsmanager.RightsManagerPlugin; | ||
| import com.xpn.xwiki.user.api.XWikiGroupService; | ||
|
|
||
| import static java.util.Arrays.asList; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| /** | ||
| * Test the {@code getgroupmembers.vm} template. Assert that the returned results are well-formed. | ||
| * | ||
| * @version $Id$ | ||
| * @since 13.9RC1 | ||
| * @since 13.4.4 | ||
| */ | ||
| @ComponentList({ | ||
| ModelScriptService.class, | ||
| EntityReferenceConverter.class, | ||
| UserScriptService.class, | ||
| GroupScriptService.class | ||
| }) | ||
| @DefaultUserComponentList | ||
| class GetgroupmembersPageTest extends PageTest | ||
| { | ||
| private static final String GETGROUPMEMBERS = "getgroupmembers.vm"; | ||
|
|
||
| private TemplateManager templateManager; | ||
|
|
||
| private XWikiGroupService groupService; | ||
|
|
||
| private MembersCache membersCache; | ||
|
|
||
| @BeforeEach | ||
| void setUp() throws Exception | ||
| { | ||
| setOutputSyntax(Syntax.PLAIN_1_0); | ||
|
|
||
| this.templateManager = this.oldcore.getMocker().getInstance(TemplateManager.class); | ||
|
|
||
| // Enable the Rights Manager plugin. | ||
| this.oldcore.getSpyXWiki().getPluginManager().addPlugin("rightsmanager", RightsManagerPlugin.class.getName(), | ||
| this.oldcore.getXWikiContext()); | ||
|
|
||
| this.groupService = this.context.getWiki().getGroupService(this.context); | ||
|
|
||
| // Override the members cache component with a mock. | ||
| this.membersCache = this.componentManager.registerMockComponent(MembersCache.class); | ||
|
|
||
| // Make sure User and Group script services load properly. | ||
| this.componentManager.getInstance(ScriptService.class, "user"); | ||
| this.componentManager.getInstance(ScriptService.class, "user.group"); | ||
|
|
||
| registerVelocityTool("numbertool", new NumberTool()); | ||
| registerVelocityTool("mathtool", new MathTool()); | ||
| registerVelocityTool("stringutils", new StringUtils()); | ||
| registerVelocityTool("stringtool", new StringUtils()); | ||
| registerVelocityTool("escapetool", new EscapeTool()); | ||
| } | ||
|
|
||
| @Test | ||
| void removeObuscatedResultsWhenTotalrowsLowerThanLimit() throws Exception | ||
| { | ||
| this.request.put("limit", "10"); | ||
| this.request.put("offset", "1"); | ||
|
|
||
| DocumentReference groupDocumentReference = new DocumentReference("xwiki", "XWiki", "group"); | ||
|
|
||
| XWikiDocument groupDoc = this.xwiki.getDocument(groupDocumentReference, this.context); | ||
| this.context.setDoc(groupDoc); | ||
|
|
||
| this.xwiki.createUser("U1", Collections.emptyMap(), this.context); | ||
| this.xwiki.createUser("U2", Collections.emptyMap(), this.context); | ||
|
|
||
| when(this.xwiki.getRightService().hasAccessLevel("view", "XWiki.XWikiGuest", "U2", this.context)) | ||
| .thenAnswer(invocationOnMock -> false); | ||
|
|
||
| GroupCacheEntry groupCacheEntry = mock(GroupCacheEntry.class); | ||
| when(this.membersCache.getCacheEntry(groupDocumentReference, true)).thenReturn(groupCacheEntry); | ||
| when(groupCacheEntry.getAll()).thenReturn(Arrays.asList( | ||
| new DocumentReference("xwiki", "XWiki", "U1"), | ||
| new DocumentReference("xwiki", "XWiki", "U2") | ||
| )); | ||
|
|
||
| when(this.groupService.getAllMatchedMembersNamesForGroup("XWiki.group", null, 10, 0, true, this.context)) | ||
| .thenReturn(asList( | ||
| "U1", | ||
| "U2")); | ||
| Map<String, Object> results = getJsonResultMap(); | ||
| List<Map<String, Object>> rows = (List<Map<String, Object>>) results.get("rows"); | ||
| assertEquals(1, rows.size()); | ||
| assertEquals("U1", rows.get(0).get("doc_fullName")); | ||
| } | ||
|
|
||
| @Test | ||
| void nonViewableResultsAreObfuscated() throws Exception | ||
| { | ||
| this.request.put("limit", "2"); | ||
| this.request.put("offset", "1"); | ||
|
|
||
| DocumentReference groupDocumentReference = new DocumentReference("xwiki", "XWiki", "group"); | ||
|
|
||
| XWikiDocument groupDoc = this.xwiki.getDocument(groupDocumentReference, this.context); | ||
| this.context.setDoc(groupDoc); | ||
|
|
||
| this.xwiki.createUser("U1", Collections.emptyMap(), this.context); | ||
| this.xwiki.createUser("U2", Collections.emptyMap(), this.context); | ||
|
|
||
| when(this.xwiki.getRightService().hasAccessLevel("view", "XWiki.XWikiGuest", "U2", this.context)) | ||
| .thenAnswer(invocationOnMock -> false); | ||
|
|
||
| GroupCacheEntry groupCacheEntry = mock(GroupCacheEntry.class); | ||
| when(this.membersCache.getCacheEntry(groupDocumentReference, true)).thenReturn(groupCacheEntry); | ||
| when(groupCacheEntry.getAll()).thenReturn(Arrays.asList( | ||
| new DocumentReference("xwiki", "XWiki", "U1"), | ||
| new DocumentReference("xwiki", "XWiki", "U2"), | ||
| new DocumentReference("xwiki", "XWiki", "U3") | ||
| )); | ||
|
|
||
| when(this.groupService.getAllMatchedMembersNamesForGroup("XWiki.group", null, 2, 0, true, this.context)) | ||
| .thenReturn(asList( | ||
| "U1", | ||
| "U2")); | ||
| Map<String, Object> results = getJsonResultMap(); | ||
| List<Map<String, Object>> rows = (List<Map<String, Object>>) results.get("rows"); | ||
| assertEquals(2, rows.size()); | ||
| assertEquals("U1", rows.get(0).get("doc_fullName")); | ||
| assertTrue((Boolean) rows.get(0).get("doc_viewable")); | ||
| assertFalse((Boolean) rows.get(1).get("doc_viewable")); | ||
| } | ||
|
|
||
| private Map<String, Object> getJsonResultMap() throws Exception | ||
| { | ||
| JSONTool jsonTool = mock(JSONTool.class); | ||
| registerVelocityTool("jsontool", jsonTool); | ||
|
|
||
| this.templateManager.render(GETGROUPMEMBERS); | ||
|
|
||
| ArgumentCaptor<Object> argument = ArgumentCaptor.forClass(Object.class); | ||
| verify(jsonTool).serialize(argument.capture()); | ||
|
|
||
| return (Map<String, Object>) argument.getValue(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| /* | ||
| * 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.web; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import org.apache.velocity.tools.generic.MathTool; | ||
| import org.apache.velocity.tools.generic.NumberTool; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.mockito.ArgumentCaptor; | ||
| import org.xwiki.model.reference.DocumentReference; | ||
| import org.xwiki.security.authorization.ContextualAuthorizationManager; | ||
| import org.xwiki.security.authorization.Right; | ||
| import org.xwiki.security.script.SecurityScriptServiceComponentList; | ||
| import org.xwiki.template.TemplateManager; | ||
| import org.xwiki.test.page.PageTest; | ||
| import org.xwiki.velocity.tools.JSONTool; | ||
|
|
||
| import com.xpn.xwiki.doc.XWikiDocument; | ||
| import com.xpn.xwiki.plugin.rightsmanager.RightsManagerPlugin; | ||
| import com.xpn.xwiki.user.api.XWikiGroupService; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.ArgumentMatchers.eq; | ||
| import static org.mockito.Mockito.doReturn; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| /** | ||
| * Test the {@code getgroups.vm} template. Assert that the returned results are well-formed. | ||
| * | ||
| * @version $Id$ | ||
| * @since 13.9RC1 | ||
| * @since 13.4.4 | ||
| */ | ||
| @SecurityScriptServiceComponentList | ||
| class GetgroupsPageTest extends PageTest | ||
| { | ||
| private static final String GETGROUPS = "getgroups.vm"; | ||
|
|
||
| private TemplateManager templateManager; | ||
|
|
||
| private XWikiGroupService groupService; | ||
|
|
||
| private ContextualAuthorizationManager contextualAuthorizationManager; | ||
|
|
||
| @BeforeEach | ||
| void setUp() throws Exception | ||
| { | ||
| this.templateManager = this.oldcore.getMocker().getInstance(TemplateManager.class); | ||
|
|
||
| // Enable the Rights Manager plugin. | ||
| this.oldcore.getSpyXWiki().getPluginManager().addPlugin("rightsmanager", RightsManagerPlugin.class.getName(), | ||
| this.oldcore.getXWikiContext()); | ||
|
|
||
| this.groupService = this.context.getWiki().getGroupService(this.context); | ||
|
|
||
| this.contextualAuthorizationManager = this.componentManager.getInstance(ContextualAuthorizationManager.class); | ||
|
|
||
| registerVelocityTool("numbertool", new NumberTool()); | ||
| registerVelocityTool("mathtool", new MathTool()); | ||
| } | ||
|
|
||
| @Test | ||
| void removeObuscatedResultsWhenTotalrowsLowerThanLimit() throws Exception | ||
| { | ||
| this.request.put("wiki", "local"); | ||
| this.request.put("limit", "10"); | ||
| this.request.put("offset", "1"); | ||
|
|
||
| DocumentReference group1DocumentReference = new DocumentReference("xwiki", "XWiki", "G1"); | ||
| DocumentReference group2DocumentReference = new DocumentReference("xwiki", "XWiki", "G2"); | ||
| when(this.contextualAuthorizationManager.hasAccess(Right.VIEW, group2DocumentReference)).thenReturn(false); | ||
| XWikiDocument group1 = this.xwiki.getDocument(group1DocumentReference, this.context); | ||
| XWikiDocument group2 = this.xwiki.getDocument(group2DocumentReference, this.context); | ||
|
|
||
|
|
||
| doReturn(Arrays.asList(group1, group2)) | ||
| .when(this.groupService) | ||
| .getAllMatchedGroups(eq(null), eq(true), eq(10), eq(0), any(), eq(this.context)); | ||
| when(this.groupService.countAllMatchedGroups(any(), eq(this.context))).thenReturn(2); | ||
|
|
||
| Map<String, Object> results = getJsonResultMap(); | ||
| List<Map<String, Object>> rows = (List<Map<String, Object>>) results.get("rows"); | ||
| assertEquals(1, rows.size()); | ||
| assertEquals("XWiki.G1", rows.get(0).get("doc_fullName")); | ||
| } | ||
|
|
||
| @Test | ||
| void nonViewableResultsAreObfuscated() throws Exception | ||
| { | ||
| this.request.put("wiki", "local"); | ||
| this.request.put("limit", "2"); | ||
| this.request.put("offset", "1"); | ||
|
|
||
| DocumentReference group1DocumentReference = new DocumentReference("xwiki", "XWiki", "G1"); | ||
| DocumentReference group2DocumentReference = new DocumentReference("xwiki", "XWiki", "G2"); | ||
| when(this.contextualAuthorizationManager.hasAccess(Right.VIEW, group2DocumentReference)).thenReturn(false); | ||
| XWikiDocument group1 = this.xwiki.getDocument(group1DocumentReference, this.context); | ||
| XWikiDocument group2 = this.xwiki.getDocument(group2DocumentReference, this.context); | ||
|
|
||
|
|
||
| doReturn(Arrays.asList(group1, group2)) | ||
| .when(this.groupService) | ||
| .getAllMatchedGroups(eq(null), eq(true), eq(2), eq(0), any(), eq(this.context)); | ||
| when(this.groupService.countAllMatchedGroups(any(), eq(this.context))).thenReturn(10); | ||
|
|
||
| Map<String, Object> results = getJsonResultMap(); | ||
| List<Map<String, Object>> rows = (List<Map<String, Object>>) results.get("rows"); | ||
| assertEquals(2, rows.size()); | ||
| assertEquals("XWiki.G1", rows.get(0).get("doc_fullName")); | ||
| assertTrue((Boolean) rows.get(0).get("doc_viewable")); | ||
| assertEquals("obfuscated", rows.get(1).get("doc_fullName")); | ||
| assertFalse((Boolean) rows.get(1).get("doc_viewable")); | ||
| } | ||
|
|
||
| private Map<String, Object> getJsonResultMap() throws Exception | ||
| { | ||
| JSONTool jsonTool = mock(JSONTool.class); | ||
| registerVelocityTool("jsontool", jsonTool); | ||
|
|
||
| this.templateManager.render(GETGROUPS); | ||
|
|
||
| ArgumentCaptor<Object> argument = ArgumentCaptor.forClass(Object.class); | ||
| verify(jsonTool).serialize(argument.capture()); | ||
|
|
||
| return (Map<String, Object>) argument.getValue(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| /* | ||
| * 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.web; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import org.apache.velocity.tools.generic.MathTool; | ||
| import org.apache.velocity.tools.generic.NumberTool; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.mockito.ArgumentCaptor; | ||
| import org.xwiki.model.reference.DocumentReference; | ||
| import org.xwiki.security.authorization.ContextualAuthorizationManager; | ||
| import org.xwiki.security.authorization.Right; | ||
| import org.xwiki.security.script.SecurityScriptServiceComponentList; | ||
| import org.xwiki.template.TemplateManager; | ||
| import org.xwiki.test.page.PageTest; | ||
| import org.xwiki.velocity.tools.JSONTool; | ||
|
|
||
| import com.xpn.xwiki.doc.XWikiDocument; | ||
| import com.xpn.xwiki.plugin.rightsmanager.RightsManagerPlugin; | ||
| import com.xpn.xwiki.user.api.XWikiGroupService; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.ArgumentMatchers.eq; | ||
| import static org.mockito.Mockito.doReturn; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| /** | ||
| * Test the {@code getusers.vm} template. Assert that the returned results are well-formed. | ||
| * | ||
| * @version $Id$ | ||
| * @since 13.9RC1 | ||
| * @since 13.4.4 | ||
| */ | ||
| @SecurityScriptServiceComponentList | ||
| class GetusersPageTest extends PageTest | ||
| { | ||
| private static final String GETUSERS = "getusers.vm"; | ||
|
|
||
| private TemplateManager templateManager; | ||
|
|
||
| private XWikiGroupService groupService; | ||
|
|
||
| private ContextualAuthorizationManager contextualAuthorizationManager; | ||
|
|
||
| @BeforeEach | ||
| void setUp() throws Exception | ||
| { | ||
| this.templateManager = this.oldcore.getMocker().getInstance(TemplateManager.class); | ||
|
|
||
| // Enable the Rights Manager plugin. | ||
| this.oldcore.getSpyXWiki().getPluginManager().addPlugin("rightsmanager", RightsManagerPlugin.class.getName(), | ||
| this.oldcore.getXWikiContext()); | ||
|
|
||
| this.groupService = this.context.getWiki().getGroupService(this.context); | ||
|
|
||
| this.contextualAuthorizationManager = this.componentManager.getInstance(ContextualAuthorizationManager.class); | ||
|
|
||
| registerVelocityTool("numbertool", new NumberTool()); | ||
| registerVelocityTool("mathtool", new MathTool()); | ||
| } | ||
|
|
||
| @Test | ||
| void removeObuscatedResultsWhenTotalrowsLowerThanLimit() throws Exception | ||
| { | ||
| this.request.put("wiki", "local"); | ||
| this.request.put("limit", "10"); | ||
| this.request.put("offset", "1"); | ||
|
|
||
| DocumentReference user1DocumentReference = new DocumentReference("xwiki", "XWiki", "U1"); | ||
| DocumentReference user2DocumentReference = new DocumentReference("xwiki", "XWiki", "U2"); | ||
| when(this.contextualAuthorizationManager.hasAccess(Right.VIEW, user2DocumentReference)).thenReturn(false); | ||
| XWikiDocument user1 = this.xwiki.getDocument(user1DocumentReference, this.context); | ||
| XWikiDocument user2 = this.xwiki.getDocument(user2DocumentReference, this.context); | ||
|
|
||
|
|
||
| doReturn(Arrays.asList(user1, user2)) | ||
| .when(this.groupService) | ||
| .getAllMatchedUsers(eq(null), eq(true), eq(10), eq(0), any(), eq(this.context)); | ||
| when(this.groupService.countAllMatchedUsers(any(), eq(this.context))).thenReturn(2); | ||
|
|
||
| Map<String, Object> results = getJsonResultMap(); | ||
| List<Map<String, Object>> rows = (List<Map<String, Object>>) results.get("rows"); | ||
| assertEquals(1, rows.size()); | ||
| assertEquals("XWiki.U1", rows.get(0).get("doc_fullName")); | ||
| } | ||
|
|
||
| @Test | ||
| void nonViewableResultsAreObfuscated() throws Exception | ||
| { | ||
| this.request.put("wiki", "local"); | ||
| this.request.put("limit", "2"); | ||
| this.request.put("offset", "1"); | ||
|
|
||
| DocumentReference user1DocumentReference = new DocumentReference("xwiki", "XWiki", "U1"); | ||
| DocumentReference user2DocumentReference = new DocumentReference("xwiki", "XWiki", "U2"); | ||
| when(this.contextualAuthorizationManager.hasAccess(Right.VIEW, user2DocumentReference)).thenReturn(false); | ||
| XWikiDocument user1 = this.xwiki.getDocument(user1DocumentReference, this.context); | ||
| XWikiDocument user2 = this.xwiki.getDocument(user2DocumentReference, this.context); | ||
|
|
||
|
|
||
| doReturn(Arrays.asList(user1, user2)) | ||
| .when(this.groupService) | ||
| .getAllMatchedUsers(eq(null), eq(true), eq(2), eq(0), any(), eq(this.context)); | ||
| when(this.groupService.countAllMatchedUsers(any(), eq(this.context))).thenReturn(10); | ||
|
|
||
| Map<String, Object> results = getJsonResultMap(); | ||
| List<Map<String, Object>> rows = (List<Map<String, Object>>) results.get("rows"); | ||
| assertEquals(2, rows.size()); | ||
| assertEquals("XWiki.U1", rows.get(0).get("doc_fullName")); | ||
| assertTrue((Boolean) rows.get(0).get("doc_viewable")); | ||
| assertEquals("obfuscated", rows.get(1).get("doc_fullName")); | ||
| assertFalse((Boolean) rows.get(1).get("doc_viewable")); | ||
| } | ||
|
|
||
| private Map<String, Object> getJsonResultMap() throws Exception | ||
| { | ||
| JSONTool jsonTool = mock(JSONTool.class); | ||
| registerVelocityTool("jsontool", jsonTool); | ||
|
|
||
| this.templateManager.render(GETUSERS); | ||
|
|
||
| ArgumentCaptor<Object> argument = ArgumentCaptor.forClass(Object.class); | ||
| verify(jsonTool).serialize(argument.capture()); | ||
|
|
||
| return (Map<String, Object>) argument.getValue(); | ||
| } | ||
| } |