1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package com.xpn.xwiki.internal.objects.classes

File ViewableAllowedDBListValueFilterTest.java

 

Code metrics

0
16
4
1
95
58
4
0.25
4
4
1

Classes

Class Line # Actions
ViewableAllowedDBListValueFilterTest 45 16 0% 4 0
1.0100%
 

Contributing tests

This file is covered by 3 tests. .

Source view

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 com.xpn.xwiki.internal.objects.classes;
21   
22    import java.util.Arrays;
23    import java.util.List;
24   
25    import org.junit.Before;
26    import org.junit.Rule;
27    import org.junit.Test;
28    import org.xwiki.model.reference.DocumentReference;
29    import org.xwiki.model.reference.DocumentReferenceResolver;
30    import org.xwiki.query.Query;
31    import org.xwiki.query.QueryFilter;
32    import org.xwiki.security.authorization.ContextualAuthorizationManager;
33    import org.xwiki.security.authorization.Right;
34    import org.xwiki.test.mockito.MockitoComponentMockingRule;
35   
36    import static org.junit.Assert.*;
37    import static org.mockito.Mockito.*;
38   
39    /**
40    * Unit tests for {@link ViewableAllowedDBListValueFilter}.
41    *
42    * @version $Id: 9a85b3b2b793e40fdee38b848efa88f1d3d44192 $
43    * @since 9.8RC1
44    */
 
45    public class ViewableAllowedDBListValueFilterTest
46    {
47    @Rule
48    public MockitoComponentMockingRule<QueryFilter> mocker =
49    new MockitoComponentMockingRule<QueryFilter>(ViewableAllowedDBListValueFilter.class);
50   
51    private ContextualAuthorizationManager authorization;
52   
53    private DocumentReferenceResolver<String> documentReferenceResolver;
54   
 
55  3 toggle @Before
56    public void configure() throws Exception
57    {
58  3 this.authorization = this.mocker.getInstance(ContextualAuthorizationManager.class);
59  3 this.documentReferenceResolver = this.mocker.getInstance(DocumentReferenceResolver.TYPE_STRING, "current");
60   
61  3 DocumentReference aliceReference = new DocumentReference("wiki", "User", "alice");
62  3 when(this.documentReferenceResolver.resolve("alice")).thenReturn(aliceReference);
63  3 when(this.authorization.hasAccess(Right.VIEW, aliceReference)).thenReturn(false);
64   
65  3 DocumentReference bobReference = new DocumentReference("wiki", "User", "bob");
66  3 when(this.documentReferenceResolver.resolve("bob")).thenReturn(bobReference);
67  3 when(this.authorization.hasAccess(Right.VIEW, bobReference)).thenReturn(true);
68    }
69   
 
70  1 toggle @Test
71    public void filterStatement() throws Exception
72    {
73  1 String statement = "select doc.fullName from XWikiDocument doc";
74  1 assertEquals("The statement should not be filtered", statement,
75    this.mocker.getComponentUnderTest().filterStatement(statement, Query.HQL));
76    }
77   
 
78  1 toggle @Test
79    public void filterResultsStrings() throws Exception
80    {
81  1 assertEquals(Arrays.asList("bob"),
82    this.mocker.getComponentUnderTest().filterResults(Arrays.asList("alice", "bob")));
83    }
84   
 
85  1 toggle @Test
86    public void filterResultsArray() throws Exception
87    {
88  1 List<?> filteredResults = this.mocker.getComponentUnderTest()
89    .filterResults(Arrays.asList(new Object[] {"alice", 13}, new Object[] {"bob", 7}));
90  1 assertEquals(1, filteredResults.size());
91  1 Object[] result = (Object[]) filteredResults.get(0);
92  1 assertEquals(1, result.length);
93  1 assertEquals(7, result[0]);
94    }
95    }