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

File CountDocumentFilterTest.java

 

Code metrics

0
34
19
1
202
146
19
0.56
1.79
19
1

Classes

Class Line # Actions
CountDocumentFilterTest 39 34 0% 19 0
1.0100%
 

Contributing tests

This file is covered by 18 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 static org.junit.Assert.assertEquals;
23   
24    import java.util.Arrays;
25    import java.util.List;
26   
27    import org.apache.commons.collections.ListUtils;
28    import org.junit.Before;
29    import org.junit.Rule;
30    import org.junit.Test;
31    import org.xwiki.query.Query;
32    import org.xwiki.test.mockito.MockitoComponentMockingRule;
33   
34    /**
35    * Tests for {@link CountDocumentFilter}
36    *
37    * @version $Id: de947aaa28e2cf4398766a7d31d353f4a485dc5d $
38    */
 
39    public class CountDocumentFilterTest
40    {
41    @Rule
42    public MockitoComponentMockingRule<CountDocumentFilter> mocker = new MockitoComponentMockingRule(CountDocumentFilter.class);
43   
44    private CountDocumentFilter filter;
45   
 
46  18 toggle @Before
47    public void configure() throws Exception
48    {
49  18 this.filter = mocker.getComponentUnderTest();
50    }
51   
 
52  1 toggle @Test
53    public void filterSelectStatement() throws Exception
54    {
55  1 assertEquals("select count(doc.fullName) from XWikiDocument doc",
56    filter.filterStatement("select doc.fullName from XWikiDocument doc", Query.HQL));
57    }
58   
 
59  1 toggle @Test
60    public void filterSelectStatementWithWhitespace() throws Exception
61    {
62  1 assertEquals("select count(doc.fullName) from XWikiDocument as doc",
63    filter.filterStatement(" select doc.fullName from XWikiDocument as doc ", Query.HQL));
64    }
65   
 
66  1 toggle @Test
67    public void filterSelectDistinctStatement() throws Exception
68    {
69  1 assertEquals("select count(distinct doc.fullName) from XWikiDocument doc",
70    filter.filterStatement("select distinct doc.fullName from XWikiDocument doc", Query.HQL));
71    }
72   
 
73  1 toggle @Test
74    public void filterSelectWithAsStatement() throws Exception
75    {
76  1 assertEquals("select count(doc.fullName) from XWikiDocument as doc",
77    filter.filterStatement("select doc.fullName from XWikiDocument as doc", Query.HQL));
78    }
79   
 
80  1 toggle @Test
81    public void filterSelectStatementWithMismatchingDocAlias() throws Exception
82    {
83  1 assertEquals("select mydoc.fullName from XWikiDocument mydoc",
84    filter.filterStatement("select mydoc.fullName from XWikiDocument mydoc", Query.HQL));
85    }
86   
 
87  1 toggle @Test
88    public void filterStatementWhenStatementAlreadyContainsCount() throws Exception
89    {
90  1 assertEquals("select count(distinct doc.fullName) from XWikiDocument doc",
91    filter.filterStatement("select count(distinct doc.fullName) from XWikiDocument doc", Query.HQL));
92    }
93   
 
94  1 toggle @Test
95    public void filterStatementWhenStatementContainsOrderBy() throws Exception
96    {
97  1 assertEquals("select count(doc.fullName) from XWikiDocument doc ",
98    filter.filterStatement("select doc.fullName from XWikiDocument doc order by doc.name", Query.HQL));
99    }
100   
 
101  1 toggle @Test
102    public void filterStatementWhenStatementContainsOrderByAndGroupBy() throws Exception
103    {
104  1 assertEquals("select count(doc.fullName) from XWikiDocument doc group by doc.web",
105    filter.filterStatement("select doc.fullName from XWikiDocument doc order by doc.name group by doc.web",
106    Query.HQL)
107    );
108    }
109   
 
110  1 toggle @Test
111    public void filterStatementWhenStatementContainsDistinct() throws Exception
112    {
113  1 assertEquals("select count(distinct doc.fullName) from XWikiDocument doc",
114    filter.filterStatement("select distinct doc.fullName from XWikiDocument doc", Query.HQL));
115    }
116   
 
117  1 toggle @Test
118    public void filterStatementWhenStatementContainsMultipleColumns() throws Exception
119    {
120  1 assertEquals("select count(doc.fullName) from XWikiDocument doc group by doc.web",
121    filter.filterStatement(
122    "select doc.fullName, doc.name, doc.space from XWikiDocument doc order by doc.name group by doc.web",
123    Query.HQL)
124    );
125    }
126   
 
127  1 toggle @Test
128    public void getSelectColumns()
129    {
130  1 String[] columns = { "doc.fullName", "doc.name", "doc.space" };
131  1 List<String> result =
132    filter.getSelectColumns("select doc.fullName, doc.name, doc.space from XWikiDocument doc");
133   
134  1 assertEquals(Arrays.asList(columns), result);
135    }
136   
 
137  1 toggle @Test
138    public void getSelectColumnsWithAdditionalSpaces()
139    {
140  1 String[] columns = { "doc.fullName", "doc.name", "doc.space" };
141  1 List<String> result =
142    filter.getSelectColumns("select doc.fullName , doc.name , doc.space from XWikiDocument doc");
143   
144  1 assertEquals(Arrays.asList(columns), result);
145    }
146   
 
147  1 toggle @Test
148    public void getSelectColumnsWithDistinct()
149    {
150  1 String[] columns = { "distinct doc.fullName" };
151  1 List<String> result = filter.getSelectColumns("select distinct doc.fullName from XWikiDocument doc");
152   
153  1 assertEquals(Arrays.asList(columns), result);
154    }
155   
 
156  1 toggle @Test
157    public void getOrderByColumns() throws Exception
158    {
159  1 String[] columns = { "doc.name" };
160  1 List<String> result = filter.getOrderByColumns("select doc.fullName from XWikiDocument doc order by doc.name");
161   
162  1 assertEquals(Arrays.asList(columns), result);
163    }
164   
 
165  1 toggle @Test
166    public void getOrderByColumnsWithoutOrderBy() throws Exception
167    {
168  1 List<String> result = filter.getOrderByColumns("select doc.fullName from XWikiDocument doc");
169   
170  1 assertEquals(ListUtils.EMPTY_LIST, result);
171    }
172   
 
173  1 toggle @Test
174    public void getOrderByColumnsWithMultipleColumns() throws Exception
175    {
176  1 String[] columns = { "doc.name", "doc.web" };
177  1 List<String> result = filter.getOrderByColumns(
178    "select doc.fullName from XWikiDocument doc order by doc.name, doc.web");
179   
180  1 assertEquals(Arrays.asList(columns), result);
181    }
182   
 
183  1 toggle @Test
184    public void getOrderByColumnsWithGroupBy() throws Exception
185    {
186  1 String[] columns = { "doc.name", "doc.web" };
187  1 List<String> result = filter.getOrderByColumns(
188    "select doc.fullName from XWikiDocument doc order by doc.name, doc.web group by doc.web");
189   
190  1 assertEquals(Arrays.asList(columns), result);
191    }
192   
 
193  1 toggle @Test
194    public void getOrderByColumnsWithAdditionalSpaces() throws Exception
195    {
196  1 String[] columns = { "doc.name", "doc.web" };
197  1 List<String> result = filter.getOrderByColumns(
198    "select doc.fullName from XWikiDocument doc order by doc.name , doc.web group by doc.web");
199   
200  1 assertEquals(Arrays.asList(columns), result);
201    }
202    }