1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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 |
|
@link |
37 |
|
|
38 |
|
@version |
39 |
|
|
40 |
|
@MockingRequirement(HiddenSpaceFilter.class) |
|
|
| 100% |
Uncovered Elements: 0 (29) |
Complexity: 12 |
Complexity Density: 0.71 |
|
41 |
|
public class HiddenSpaceFilterTest extends AbstractMockingComponentTestCase |
42 |
|
{ |
43 |
|
private QueryFilter filter; |
44 |
|
|
45 |
|
private ConfigurationSource userConfiguration; |
46 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
47 |
10 |
@Before... |
48 |
|
public void configure() throws Exception |
49 |
|
{ |
50 |
10 |
this.userConfiguration = getComponentManager().getInstance(ConfigurationSource.class, "user"); |
51 |
10 |
getMockery().checking(new Expectations() |
52 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
53 |
10 |
{... |
54 |
10 |
ignoring(any(Logger.class)).method("debug"); |
55 |
|
|
56 |
|
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
65 |
1 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
72 |
1 |
@Test... |
73 |
|
public void filterHQLStatementWithDisplayHiddenDocumentsInTheUserPreferences() throws Exception |
74 |
|
{ |
75 |
|
|
76 |
|
|
77 |
1 |
ReflectionUtils.setFieldValue(this.filter, "isActive", false); |
78 |
|
|
79 |
|
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
84 |
1 |
@Test... |
85 |
|
public void filterIncorrectHQLStatement() throws Exception |
86 |
|
{ |
87 |
|
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
92 |
1 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
99 |
1 |
@Test... |
100 |
|
public void filterHQLStatementWithWhereAndOrderBy() |
101 |
|
{ |
102 |
|
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
108 |
1 |
@Test... |
109 |
|
public void filterHQLStatementWithWhereAndGroupBy() |
110 |
|
{ |
111 |
|
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
117 |
1 |
@Test... |
118 |
|
public void filterHQLStatementWithWhereAndOrderByAndGroupBy() |
119 |
|
{ |
120 |
|
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
127 |
1 |
@Test... |
128 |
|
public void filterHQLStatementWithoutWhere() |
129 |
|
{ |
130 |
|
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
135 |
1 |
@Test... |
136 |
|
public void filterHQLStatementWithoutWhereWithOrderBy() |
137 |
|
{ |
138 |
|
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
143 |
1 |
@Test... |
144 |
|
public void filterHQLStatementWithoutWhereWithGroupBy() |
145 |
|
{ |
146 |
|
|
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 |
|
} |