1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.internal.store.hibernate.query

File HqlQueryUtilsTest.java

 

Code metrics

0
12
1
1
59
26
1
0.08
12
1
1

Classes

Class Line # Actions
HqlQueryUtilsTest 32 12 0% 1 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

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.store.hibernate.query;
21   
22    import org.junit.Test;
23   
24    import static org.junit.Assert.assertFalse;
25    import static org.junit.Assert.assertTrue;
26   
27    /**
28    * Validate {@link HqlQueryUtils}.
29    *
30    * @version $Id: 1a0ec141e0b3bdd299f4fbd08a1409e3265ff6cf $
31    */
 
32    public class HqlQueryUtilsTest
33    {
 
34  1 toggle @Test
35    public void isSafe()
36    {
37    // allowed
38   
39  1 assertTrue(HqlQueryUtils.isSafe("select name from XWikiDocument"));
40  1 assertTrue(HqlQueryUtils.isSafe("select doc.name, space.name from XWikiDocument doc, XWikiSpace space"));
41  1 assertTrue(HqlQueryUtils
42    .isSafe("select doc.name, space.name from XWikiDocument doc, XWikiSpace space, OtherTable as ot"));
43  1 assertTrue(HqlQueryUtils.isSafe("select count(name) from XWikiDocument"));
44  1 assertTrue(HqlQueryUtils.isSafe("select count(doc.name) from XWikiDocument doc"));
45  1 assertTrue(HqlQueryUtils
46    .isSafe("select doc.fullName from XWikiDocument as doc, com.xpn.xwiki.objects.StringProperty as str"));
47   
48  1 assertTrue(HqlQueryUtils.isSafe("select count(*) from XWikiSpace"));
49   
50    // not allowed
51   
52  1 assertFalse(HqlQueryUtils.isSafe("select name from OtherTable"));
53  1 assertFalse(HqlQueryUtils.isSafe("select doc.* from XWikiDocument doc, XWikiSpace space"));
54  1 assertFalse(HqlQueryUtils.isSafe("select * from XWikiDocument doc"));
55  1 assertFalse(HqlQueryUtils
56    .isSafe("select doc.name, ot.field from XWikiDocument doc, XWikiSpace space, OtherTable as ot"));
57  1 assertFalse(HqlQueryUtils.isSafe("select count(*) from OtherTable"));
58    }
59    }