1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.query.internal

File HiddenSpaceFilterTest.java

 

Code metrics

0
17
12
1
151
98
12
0.71
1.42
12
1

Classes

Class Line # Actions
HiddenSpaceFilterTest 41 17 0% 12 0
1.0100%
 

Contributing tests

This file is covered by 10 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 org.xwiki.query.internal;
21   
22    import org.jmock.Expectations;
23    import org.junit.Before;
24    import org.junit.Test;
25    import org.slf4j.Logger;
26    import org.xwiki.component.util.ReflectionUtils;
27    import org.xwiki.configuration.ConfigurationSource;
28    import org.xwiki.query.Query;
29    import org.xwiki.query.QueryFilter;
30    import org.xwiki.test.jmock.AbstractMockingComponentTestCase;
31    import org.xwiki.test.jmock.annotation.MockingRequirement;
32   
33    import static org.junit.Assert.assertEquals;
34   
35    /**
36    * Tests for {@link HiddenDocumentFilter}
37    *
38    * @version $Id: 0a6ae074c9013a81c92d8a812ca5e943951a95cd $
39    */
40    @MockingRequirement(HiddenSpaceFilter.class)
 
41    public class HiddenSpaceFilterTest extends AbstractMockingComponentTestCase
42    {
43    private QueryFilter filter;
44   
45    private ConfigurationSource userConfiguration;
46   
 
47  10 toggle @Before
48    public void configure() throws Exception
49    {
50  10 this.userConfiguration = getComponentManager().getInstance(ConfigurationSource.class, "user");
51  10 getMockery().checking(new Expectations()
52    {
 
53  10 toggle {
54  10 ignoring(any(Logger.class)).method("debug");
55    // We need to set this expectation here because this call is made during the filter component
56    // initialization
57  10 oneOf(userConfiguration).getProperty("displayHiddenDocuments", Integer.class);
58  10 will(returnValue(0));
59    }
60    });
61   
62  10 this.filter = getComponentManager().getInstance(QueryFilter.class, "hidden/space");
63    }
64   
 
65  1 toggle @Test
66    public void filterHQLStatementWithDoNotDisplayHiddenDocumentsInTheUserPreferences() throws Exception
67    {
68  1 assertEquals("select space.reference from XWikiSpace space where space.hidden <> true and (1=1)",
69    filter.filterStatement("select space.reference from XWikiSpace space where 1=1", Query.HQL));
70    }
71   
 
72  1 toggle @Test
73    public void filterHQLStatementWithDisplayHiddenDocumentsInTheUserPreferences() throws Exception
74    {
75    // We need to do it that way since the expectation must be set in #configure() and the expectation sets the
76    // isActive property to true
77  1 ReflectionUtils.setFieldValue(this.filter, "isActive", false);
78   
79    // Insertions of distinct
80  1 assertEquals("select space.reference from XWikiSpace space where 1=1",
81    filter.filterStatement("select space.reference from XWikiSpace space where 1=1", Query.HQL));
82    }
83   
 
84  1 toggle @Test
85    public void filterIncorrectHQLStatement() throws Exception
86    {
87    // Insertions of distinct
88  1 assertEquals("select space.reference from XWikiSpace mydoc where 1=1",
89    filter.filterStatement("select space.reference from XWikiSpace mydoc where 1=1", Query.HQL));
90    }
91   
 
92  1 toggle @Test
93    public void filterXWQLStatement() throws Exception
94    {
95  1 assertEquals("select space.reference from XWikiSpace space where 1=1",
96    filter.filterStatement("select space.reference from XWikiSpace space where 1=1", Query.XWQL));
97    }
98   
 
99  1 toggle @Test
100    public void filterHQLStatementWithWhereAndOrderBy()
101    {
102    // Insertions of distinct
103  1 assertEquals("select space.name from XWikiSpace space where space.hidden <> true and "
104    + "(1=1) order by space.name",
105    filter.filterStatement("select space.name from XWikiSpace space where 1=1 order by space.name", Query.HQL));
106    }
107   
 
108  1 toggle @Test
109    public void filterHQLStatementWithWhereAndGroupBy()
110    {
111    // Insertions of distinct
112  1 assertEquals("select space.name from XWikiSpace space where space.hidden <> true and "
113    + "(1=1) group by space.name",
114    filter.filterStatement("select space.name from XWikiSpace space where 1=1 group by space.name", Query.HQL));
115    }
116   
 
117  1 toggle @Test
118    public void filterHQLStatementWithWhereAndOrderByAndGroupBy()
119    {
120    // Insertions of distinct
121  1 assertEquals("select space.name from XWikiSpace space where space.hidden <> true and "
122    + "(1=1) order by space.name group by space.name",
123    filter.filterStatement("select space.name from XWikiSpace space where 1=1 order by space.name group by "
124    + "space.name", Query.HQL));
125    }
126   
 
127  1 toggle @Test
128    public void filterHQLStatementWithoutWhere()
129    {
130    // Insertions of distinct
131  1 assertEquals("select space.name from XWikiSpace space where space.hidden <> true",
132    filter.filterStatement("select space.name from XWikiSpace space", Query.HQL));
133    }
134   
 
135  1 toggle @Test
136    public void filterHQLStatementWithoutWhereWithOrderBy()
137    {
138    // Insertions of distinct
139  1 assertEquals("select space.name from XWikiSpace space where space.hidden <> true order by " + "space.name asc",
140    filter.filterStatement("select space.name from XWikiSpace space order by space.name asc", Query.HQL));
141    }
142   
 
143  1 toggle @Test
144    public void filterHQLStatementWithoutWhereWithGroupBy()
145    {
146    // Insertions of distinct
147  1 assertEquals("select space.web, space.name from XWikiSpace space where space.hidden <> true "
148    + "group by space.web",
149    filter.filterStatement("select space.web, space.name from XWikiSpace space group by space.web", Query.HQL));
150    }
151    }