1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.objects.classes; |
21 |
|
|
22 |
|
import org.junit.Before; |
23 |
|
import org.junit.Rule; |
24 |
|
import org.junit.Test; |
25 |
|
import org.mockito.invocation.InvocationOnMock; |
26 |
|
import org.mockito.stubbing.Answer; |
27 |
|
|
28 |
|
import com.xpn.xwiki.XWikiContext; |
29 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
30 |
|
import com.xpn.xwiki.test.MockitoOldcoreRule; |
31 |
|
import com.xpn.xwiki.test.reference.ReferenceComponentList; |
32 |
|
|
33 |
|
import static org.junit.Assert.assertEquals; |
34 |
|
import static org.mockito.ArgumentMatchers.any; |
35 |
|
import static org.mockito.Mockito.doAnswer; |
36 |
|
|
37 |
|
|
38 |
|
@link |
39 |
|
|
40 |
|
@version |
41 |
|
|
42 |
|
@ReferenceComponentList |
|
|
| 100% |
Uncovered Elements: 0 (166) |
Complexity: 15 |
Complexity Density: 0.1 |
|
43 |
|
public class DBTreeListClassTest |
44 |
|
{ |
45 |
|
@Rule |
46 |
|
public MockitoOldcoreRule oldcore = new MockitoOldcoreRule(); |
47 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
48 |
13 |
@Before... |
49 |
|
public void before() throws Exception |
50 |
|
{ |
51 |
13 |
doAnswer(new Answer<String>() |
52 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
53 |
53 |
@Override... |
54 |
|
public String answer(InvocationOnMock invocation) throws Throwable |
55 |
|
{ |
56 |
53 |
return invocation.getArgument(0); |
57 |
|
} |
58 |
|
}).when(this.oldcore.getSpyXWiki()).parseContent(any(), any(XWikiContext.class)); |
59 |
|
|
60 |
13 |
this.oldcore.getXWikiContext().setDoc(new XWikiDocument()); |
61 |
|
} |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
63 |
1 |
@Test... |
64 |
|
public void testGetQueryWhenNoSQLSCriptSpecified() |
65 |
|
{ |
66 |
1 |
DBTreeListClass dbtlc = new DBTreeListClass(); |
67 |
1 |
assertEquals("select doc.name from XWikiDocument doc where 1 = 0", |
68 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
69 |
|
} |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
71 |
1 |
@Test... |
72 |
|
public void testGetQueryWithSqlScriptSpecified() |
73 |
|
{ |
74 |
1 |
DBTreeListClass dbtlc = new DBTreeListClass(); |
75 |
1 |
assertEquals("", dbtlc.getSql()); |
76 |
1 |
String sql = "select doc.name, doc.title, doc.creator from XWikiDocument as doc"; |
77 |
1 |
dbtlc.setSql(sql); |
78 |
1 |
assertEquals(sql, dbtlc.getQuery(this.oldcore.getXWikiContext())); |
79 |
|
} |
80 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
81 |
1 |
@Test... |
82 |
|
public void testGetQueryWithClassSpecified() |
83 |
|
{ |
84 |
1 |
DBTreeListClass dbtlc = new DBTreeListClass(); |
85 |
1 |
dbtlc.setClassname("XWiki.XWikiUsers"); |
86 |
1 |
assertEquals( |
87 |
|
"select distinct doc.fullName, doc.fullName, doc.parent" + " from XWikiDocument as doc, BaseObject as obj" |
88 |
|
+ " where doc.fullName=obj.name and obj.className='XWiki.XWikiUsers'", |
89 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
90 |
|
} |
91 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
92 |
1 |
@Test... |
93 |
|
public void testGetQueryWithClassAndParentSpecified() |
94 |
|
{ |
95 |
1 |
DBTreeListClass dbtlc = new DBTreeListClass(); |
96 |
1 |
dbtlc.setClassname("XWiki.XWikiUsers"); |
97 |
1 |
dbtlc.setParentField("obj.id"); |
98 |
1 |
assertEquals( |
99 |
|
"select distinct doc.fullName, doc.fullName, obj.id" + " from XWikiDocument as doc, BaseObject as obj" |
100 |
|
+ " where doc.fullName=obj.name and obj.className='XWiki.XWikiUsers'", |
101 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
102 |
|
} |
103 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
104 |
1 |
@Test... |
105 |
|
public void testGetQueryWithIdSpecified() |
106 |
|
{ |
107 |
1 |
DBTreeListClass dbtlc = new DBTreeListClass(); |
108 |
1 |
dbtlc.setIdField("doc.name"); |
109 |
1 |
assertEquals("select distinct doc.name, doc.name, doc.parent from XWikiDocument as doc", |
110 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
111 |
1 |
dbtlc.setIdField("obj.className"); |
112 |
1 |
assertEquals("select distinct obj.className, obj.className, doc.parent" |
113 |
|
+ " from XWikiDocument as doc, BaseObject as obj" + " where doc.fullName=obj.name", |
114 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
115 |
1 |
dbtlc.setIdField("property"); |
116 |
1 |
assertEquals("select distinct doc.property, doc.property, doc.parent" + " from XWikiDocument as doc", |
117 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
118 |
|
} |
119 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
120 |
1 |
@Test... |
121 |
|
public void testGetQueryWithIdAndParentSpecified() |
122 |
|
{ |
123 |
1 |
DBTreeListClass dbtlc = new DBTreeListClass(); |
124 |
1 |
dbtlc.setIdField("doc.name"); |
125 |
1 |
dbtlc.setParentField("doc.name"); |
126 |
1 |
assertEquals("select distinct doc.name, doc.name, doc.name from XWikiDocument as doc", |
127 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
128 |
1 |
dbtlc.setParentField("obj.className"); |
129 |
1 |
assertEquals( |
130 |
|
"select distinct doc.name, doc.name, obj.className" |
131 |
|
+ " from XWikiDocument as doc, BaseObject as obj where doc.fullName=obj.name", |
132 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
133 |
1 |
dbtlc.setParentField("property"); |
134 |
1 |
assertEquals("select distinct doc.name, doc.name, doc.property from XWikiDocument as doc", |
135 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
136 |
|
|
137 |
1 |
dbtlc.setIdField("obj.className"); |
138 |
1 |
dbtlc.setParentField("doc.name"); |
139 |
1 |
assertEquals( |
140 |
|
"select distinct obj.className, obj.className, doc.name" |
141 |
|
+ " from XWikiDocument as doc, BaseObject as obj where doc.fullName=obj.name", |
142 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
143 |
1 |
dbtlc.setParentField("obj.className"); |
144 |
1 |
assertEquals("select distinct obj.className, obj.className, obj.className" + " from BaseObject as obj", |
145 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
146 |
1 |
dbtlc.setParentField("property"); |
147 |
1 |
assertEquals( |
148 |
|
"select distinct obj.className, obj.className, doc.property" |
149 |
|
+ " from XWikiDocument as doc, BaseObject as obj where doc.fullName=obj.name", |
150 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
151 |
|
|
152 |
1 |
dbtlc.setIdField("property"); |
153 |
1 |
dbtlc.setParentField("doc.name"); |
154 |
1 |
assertEquals("select distinct doc.property, doc.property, doc.name" + " from XWikiDocument as doc", |
155 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
156 |
1 |
dbtlc.setParentField("obj.className"); |
157 |
1 |
assertEquals( |
158 |
|
"select distinct doc.property, doc.property, obj.className" |
159 |
|
+ " from XWikiDocument as doc, BaseObject as obj where doc.fullName=obj.name", |
160 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
161 |
1 |
dbtlc.setParentField("property"); |
162 |
1 |
assertEquals("select distinct doc.property, doc.property, doc.property" + " from XWikiDocument as doc", |
163 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
164 |
1 |
dbtlc.setParentField("property2"); |
165 |
1 |
assertEquals("select distinct doc.property, doc.property, doc.property2" + " from XWikiDocument as doc", |
166 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
167 |
|
} |
168 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
169 |
1 |
@Test... |
170 |
|
public void testGetQueryWithValueSpecified() |
171 |
|
{ |
172 |
1 |
DBTreeListClass dbtlc = new DBTreeListClass(); |
173 |
1 |
dbtlc.setValueField("doc.name"); |
174 |
1 |
assertEquals("select distinct doc.name, doc.name, doc.parent from XWikiDocument as doc", |
175 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
176 |
|
} |
177 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
178 |
1 |
@Test... |
179 |
|
public void testGetQueryWithIdAndClassnameSpecified() |
180 |
|
{ |
181 |
1 |
DBTreeListClass dbtlc = new DBTreeListClass(); |
182 |
1 |
dbtlc.setClassname("XWiki.XWikiUsers"); |
183 |
1 |
dbtlc.setIdField("doc.name"); |
184 |
1 |
assertEquals( |
185 |
|
"select distinct doc.name, doc.name, doc.parent" + " from XWikiDocument as doc, BaseObject as obj" |
186 |
|
+ " where doc.fullName=obj.name and obj.className='XWiki.XWikiUsers'", |
187 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
188 |
1 |
dbtlc.setIdField("obj.className"); |
189 |
1 |
assertEquals( |
190 |
|
"select distinct obj.className, obj.className, doc.parent" + " from XWikiDocument as doc, BaseObject as obj" |
191 |
|
+ " where doc.fullName=obj.name and obj.className='XWiki.XWikiUsers'", |
192 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
193 |
1 |
dbtlc.setIdField("property"); |
194 |
1 |
assertEquals( |
195 |
|
"select distinct idprop.value, idprop.value, doc.parent" |
196 |
|
+ " from XWikiDocument as doc, BaseObject as obj, StringProperty as idprop" |
197 |
|
+ " where doc.fullName=obj.name and obj.className='XWiki.XWikiUsers'" |
198 |
|
+ " and obj.id=idprop.id.id and idprop.id.name='property'", |
199 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
200 |
|
} |
201 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (25) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
202 |
1 |
@Test... |
203 |
|
public void testGetQueryWithIdParentAndClassnameSpecified() |
204 |
|
{ |
205 |
1 |
DBTreeListClass dbtlc = new DBTreeListClass(); |
206 |
1 |
dbtlc.setClassname("XWiki.XWikiUsers"); |
207 |
1 |
dbtlc.setParentField("doc.name"); |
208 |
1 |
dbtlc.setIdField("doc.name"); |
209 |
1 |
assertEquals( |
210 |
|
"select distinct doc.name, doc.name, doc.name" + " from XWikiDocument as doc, BaseObject as obj" |
211 |
|
+ " where doc.fullName=obj.name and obj.className='XWiki.XWikiUsers'", |
212 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
213 |
1 |
dbtlc.setIdField("obj.className"); |
214 |
1 |
assertEquals( |
215 |
|
"select distinct obj.className, obj.className, doc.name" + " from XWikiDocument as doc, BaseObject as obj" |
216 |
|
+ " where doc.fullName=obj.name and obj.className='XWiki.XWikiUsers'", |
217 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
218 |
1 |
dbtlc.setIdField("property"); |
219 |
1 |
assertEquals( |
220 |
|
"select distinct idprop.value, idprop.value, doc.name" |
221 |
|
+ " from XWikiDocument as doc, BaseObject as obj, StringProperty as idprop" |
222 |
|
+ " where doc.fullName=obj.name and obj.className='XWiki.XWikiUsers'" |
223 |
|
+ " and obj.id=idprop.id.id and idprop.id.name='property'", |
224 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
225 |
|
|
226 |
1 |
dbtlc.setParentField("obj.className"); |
227 |
1 |
dbtlc.setIdField("doc.name"); |
228 |
1 |
assertEquals( |
229 |
|
"select distinct doc.name, doc.name, obj.className" + " from XWikiDocument as doc, BaseObject as obj" |
230 |
|
+ " where doc.fullName=obj.name and obj.className='XWiki.XWikiUsers'", |
231 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
232 |
1 |
dbtlc.setIdField("obj.className"); |
233 |
1 |
assertEquals( |
234 |
|
"select distinct obj.className, obj.className, obj.className" |
235 |
|
+ " from BaseObject as obj where obj.className='XWiki.XWikiUsers'", |
236 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
237 |
1 |
dbtlc.setIdField("property"); |
238 |
1 |
assertEquals( |
239 |
|
"select distinct idprop.value, idprop.value, obj.className" |
240 |
|
+ " from BaseObject as obj, StringProperty as idprop" + " where obj.className='XWiki.XWikiUsers'" |
241 |
|
+ " and obj.id=idprop.id.id and idprop.id.name='property'", |
242 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
243 |
|
|
244 |
1 |
dbtlc.setParentField("property"); |
245 |
1 |
dbtlc.setIdField("doc.name"); |
246 |
1 |
assertEquals( |
247 |
|
"select distinct doc.name, doc.name, parentprop.value" |
248 |
|
+ " from XWikiDocument as doc, BaseObject as obj, StringProperty as parentprop" |
249 |
|
+ " where doc.fullName=obj.name and obj.className='XWiki.XWikiUsers'" |
250 |
|
+ " and obj.id=parentprop.id.id and parentprop.id.name='property'", |
251 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
252 |
1 |
dbtlc.setIdField("obj.className"); |
253 |
1 |
assertEquals( |
254 |
|
"select distinct obj.className, obj.className, parentprop.value" |
255 |
|
+ " from BaseObject as obj, StringProperty as parentprop" + " where obj.className='XWiki.XWikiUsers'" |
256 |
|
+ " and obj.id=parentprop.id.id and parentprop.id.name='property'", |
257 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
258 |
1 |
dbtlc.setIdField("property"); |
259 |
1 |
assertEquals( |
260 |
|
"select distinct idprop.value, idprop.value, idprop.value" |
261 |
|
+ " from BaseObject as obj, StringProperty as idprop" + " where obj.className='XWiki.XWikiUsers'" |
262 |
|
+ " and obj.id=idprop.id.id and idprop.id.name='property'", |
263 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
264 |
1 |
dbtlc.setIdField("property2"); |
265 |
1 |
assertEquals( |
266 |
|
"select distinct idprop.value, idprop.value, parentprop.value" |
267 |
|
+ " from BaseObject as obj, StringProperty as idprop, StringProperty as parentprop" |
268 |
|
+ " where obj.className='XWiki.XWikiUsers'" + " and obj.id=idprop.id.id and idprop.id.name='property2'" |
269 |
|
+ " and obj.id=parentprop.id.id and parentprop.id.name='property'", |
270 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
271 |
|
} |
272 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (28) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
273 |
1 |
@Test... |
274 |
|
public void testGetQueryWithIdAndValueSpecified() |
275 |
|
{ |
276 |
1 |
DBTreeListClass dbtlc = new DBTreeListClass(); |
277 |
1 |
dbtlc.setIdField("doc.name"); |
278 |
1 |
dbtlc.setValueField("doc.name"); |
279 |
1 |
assertEquals("select distinct doc.name, doc.name, doc.parent" + " from XWikiDocument as doc", |
280 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
281 |
1 |
dbtlc.setValueField("doc.creator"); |
282 |
1 |
assertEquals("select distinct doc.name, doc.creator, doc.parent" + " from XWikiDocument as doc", |
283 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
284 |
1 |
dbtlc.setValueField("obj.className"); |
285 |
1 |
assertEquals( |
286 |
|
"select distinct doc.name, obj.className, doc.parent" |
287 |
|
+ " from XWikiDocument as doc, BaseObject as obj where doc.fullName=obj.name", |
288 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
289 |
1 |
dbtlc.setValueField("property"); |
290 |
1 |
assertEquals("select distinct doc.name, doc.property, doc.parent" + " from XWikiDocument as doc", |
291 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
292 |
|
|
293 |
1 |
dbtlc.setIdField("obj.className"); |
294 |
1 |
dbtlc.setValueField("doc.name"); |
295 |
1 |
assertEquals( |
296 |
|
"select distinct obj.className, doc.name, doc.parent" |
297 |
|
+ " from XWikiDocument as doc, BaseObject as obj where doc.fullName=obj.name", |
298 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
299 |
1 |
dbtlc.setValueField("obj.className"); |
300 |
1 |
assertEquals( |
301 |
|
"select distinct obj.className, obj.className, doc.parent" |
302 |
|
+ " from XWikiDocument as doc, BaseObject as obj where doc.fullName=obj.name", |
303 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
304 |
1 |
dbtlc.setValueField("obj.id"); |
305 |
1 |
assertEquals( |
306 |
|
"select distinct obj.className, obj.id, doc.parent" |
307 |
|
+ " from XWikiDocument as doc, BaseObject as obj where doc.fullName=obj.name", |
308 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
309 |
1 |
dbtlc.setValueField("property"); |
310 |
1 |
assertEquals( |
311 |
|
"select distinct obj.className, doc.property, doc.parent" |
312 |
|
+ " from XWikiDocument as doc, BaseObject as obj where doc.fullName=obj.name", |
313 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
314 |
|
|
315 |
1 |
dbtlc.setIdField("property"); |
316 |
1 |
dbtlc.setValueField("doc.name"); |
317 |
1 |
assertEquals("select distinct doc.property, doc.name, doc.parent" + " from XWikiDocument as doc", |
318 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
319 |
1 |
dbtlc.setValueField("obj.className"); |
320 |
1 |
assertEquals( |
321 |
|
"select distinct doc.property, obj.className, doc.parent" |
322 |
|
+ " from XWikiDocument as doc, BaseObject as obj where doc.fullName=obj.name", |
323 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
324 |
1 |
dbtlc.setValueField("property"); |
325 |
1 |
assertEquals("select distinct doc.property, doc.property, doc.parent" + " from XWikiDocument as doc", |
326 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
327 |
1 |
dbtlc.setValueField("otherProperty"); |
328 |
1 |
assertEquals("select distinct doc.property, doc.otherProperty, doc.parent" + " from XWikiDocument as doc", |
329 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
330 |
|
} |
331 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
332 |
1 |
@Test... |
333 |
|
public void testGetQueryWithIdValueAndParentSpecified() |
334 |
|
{ |
335 |
1 |
DBTreeListClass dbtlc = new DBTreeListClass(); |
336 |
1 |
dbtlc.setIdField("doc.name"); |
337 |
1 |
dbtlc.setValueField("doc.title"); |
338 |
1 |
dbtlc.setParentField("doc.space"); |
339 |
1 |
assertEquals("select distinct doc.name, doc.title, doc.space from XWikiDocument as doc", |
340 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
341 |
1 |
dbtlc.setValueField("obj.name"); |
342 |
1 |
assertEquals( |
343 |
|
"select distinct doc.name, obj.name, doc.space" |
344 |
|
+ " from XWikiDocument as doc, BaseObject as obj where doc.fullName=obj.name", |
345 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
346 |
1 |
dbtlc.setIdField("obj.className"); |
347 |
1 |
dbtlc.setParentField("obj.id"); |
348 |
1 |
assertEquals("select distinct obj.className, obj.name, obj.id from BaseObject as obj", |
349 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
350 |
|
} |
351 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
352 |
1 |
@Test... |
353 |
|
public void testGetQueryWithIdValueAndClassSpecified() |
354 |
|
{ |
355 |
1 |
DBTreeListClass dbtlc = new DBTreeListClass(); |
356 |
1 |
dbtlc.setClassname("XWiki.XWikiUsers"); |
357 |
1 |
dbtlc.setIdField("doc.name"); |
358 |
1 |
dbtlc.setValueField("doc.name"); |
359 |
1 |
assertEquals( |
360 |
|
"select distinct doc.name, doc.name, doc.parent" + " from XWikiDocument as doc, BaseObject as obj" |
361 |
|
+ " where doc.fullName=obj.name and obj.className='XWiki.XWikiUsers'", |
362 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
363 |
1 |
dbtlc.setValueField("obj.className"); |
364 |
1 |
assertEquals( |
365 |
|
"select distinct doc.name, obj.className, doc.parent" + " from XWikiDocument as doc, BaseObject as obj" |
366 |
|
+ " where doc.fullName=obj.name and obj.className='XWiki.XWikiUsers'", |
367 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
368 |
1 |
dbtlc.setValueField("property"); |
369 |
1 |
assertEquals( |
370 |
|
"select distinct doc.name, valueprop.value, doc.parent" |
371 |
|
+ " from XWikiDocument as doc, BaseObject as obj, StringProperty as valueprop" |
372 |
|
+ " where doc.fullName=obj.name and obj.className='XWiki.XWikiUsers'" |
373 |
|
+ " and obj.id=valueprop.id.id and valueprop.id.name='property'", |
374 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
375 |
1 |
dbtlc.setIdField("property"); |
376 |
1 |
assertEquals( |
377 |
|
"select distinct idprop.value, idprop.value, doc.parent" |
378 |
|
+ " from XWikiDocument as doc, BaseObject as obj, StringProperty as idprop" |
379 |
|
+ " where doc.fullName=obj.name and obj.className='XWiki.XWikiUsers'" |
380 |
|
+ " and obj.id=idprop.id.id and idprop.id.name='property'", |
381 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
382 |
1 |
dbtlc.setIdField("property2"); |
383 |
1 |
assertEquals( |
384 |
|
"select distinct idprop.value, valueprop.value, doc.parent" |
385 |
|
+ " from XWikiDocument as doc, BaseObject as obj," |
386 |
|
+ " StringProperty as idprop, StringProperty as valueprop" |
387 |
|
+ " where doc.fullName=obj.name and obj.className='XWiki.XWikiUsers'" |
388 |
|
+ " and obj.id=idprop.id.id and idprop.id.name='property2'" |
389 |
|
+ " and obj.id=valueprop.id.id and valueprop.id.name='property'", |
390 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
391 |
|
} |
392 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
393 |
1 |
@Test... |
394 |
|
public void testGetQueryWithIdValueParentAndClassSpecified() |
395 |
|
{ |
396 |
1 |
DBTreeListClass dbtlc = new DBTreeListClass(); |
397 |
1 |
dbtlc.setClassname("XWiki.XWikiUsers"); |
398 |
1 |
dbtlc.setIdField("doc.name"); |
399 |
1 |
dbtlc.setValueField("doc.name"); |
400 |
1 |
dbtlc.setParentField("doc.name"); |
401 |
1 |
assertEquals( |
402 |
|
"select distinct doc.name, doc.name, doc.name" + " from XWikiDocument as doc, BaseObject as obj" |
403 |
|
+ " where doc.fullName=obj.name and obj.className='XWiki.XWikiUsers'", |
404 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
405 |
1 |
dbtlc.setIdField("prop1"); |
406 |
1 |
dbtlc.setValueField("prop1"); |
407 |
1 |
dbtlc.setParentField("prop1"); |
408 |
1 |
assertEquals( |
409 |
|
"select distinct idprop.value, idprop.value, idprop.value" |
410 |
|
+ " from BaseObject as obj, StringProperty as idprop" + " where obj.className='XWiki.XWikiUsers'" |
411 |
|
+ " and obj.id=idprop.id.id and idprop.id.name='prop1'", |
412 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
413 |
1 |
dbtlc.setValueField("prop2"); |
414 |
1 |
assertEquals( |
415 |
|
"select distinct idprop.value, valueprop.value, idprop.value" |
416 |
|
+ " from BaseObject as obj, StringProperty as idprop, StringProperty as valueprop" |
417 |
|
+ " where obj.className='XWiki.XWikiUsers'" + " and obj.id=idprop.id.id and idprop.id.name='prop1'" |
418 |
|
+ " and obj.id=valueprop.id.id and valueprop.id.name='prop2'", |
419 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
420 |
1 |
dbtlc.setParentField("prop2"); |
421 |
1 |
assertEquals( |
422 |
|
"select distinct idprop.value, valueprop.value, valueprop.value" |
423 |
|
+ " from BaseObject as obj, StringProperty as idprop, StringProperty as valueprop" |
424 |
|
+ " where obj.className='XWiki.XWikiUsers'" + " and obj.id=idprop.id.id and idprop.id.name='prop1'" |
425 |
|
+ " and obj.id=valueprop.id.id and valueprop.id.name='prop2'", |
426 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
427 |
1 |
dbtlc.setParentField("prop3"); |
428 |
1 |
assertEquals( |
429 |
|
"select distinct idprop.value, valueprop.value, parentprop.value" |
430 |
|
+ " from BaseObject as obj, StringProperty as idprop," |
431 |
|
+ " StringProperty as valueprop, StringProperty as parentprop" |
432 |
|
+ " where obj.className='XWiki.XWikiUsers'" + " and obj.id=idprop.id.id and idprop.id.name='prop1'" |
433 |
|
+ " and obj.id=valueprop.id.id and valueprop.id.name='prop2'" |
434 |
|
+ " and obj.id=parentprop.id.id and parentprop.id.name='prop3'", |
435 |
|
dbtlc.getQuery(this.oldcore.getXWikiContext())); |
436 |
|
} |
437 |
|
} |