1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.jpa;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.junit.Test;
20 import org.kuali.rice.core.framework.persistence.jpa.criteria.Criteria;
21 import org.kuali.rice.core.framework.persistence.jpa.criteria.QueryByCriteria.QueryByCriteriaType;
22 import org.kuali.rice.krad.test.document.bo.Account;
23 import org.kuali.test.KRADTestCase;
24
25 import static org.junit.Assert.assertTrue;
26
27
28
29
30
31
32 public class ReportQueryByCriteriaTest extends KRADTestCase {
33
34 @Test
35 public void testCriteriaToReportQuery_emptySelect() throws Exception {
36 Criteria criteria = new Criteria(Account.class.getName().substring(Account.class.getPackage().getName().length()+1), "a");
37
38 String query = criteria.toQuery(QueryByCriteriaType.SELECT, new String[0]);
39 assertTrue(StringUtils.equalsIgnoreCase(query, "select a from Account as a"));
40 }
41
42 @Test
43 public void testCriteriaToReportQuery_singleFieldSelect() throws Exception {
44 Criteria criteria = new Criteria(Account.class.getName().substring(Account.class.getPackage().getName().length()+1), "a");
45
46 String[] attr = new String[1];
47 attr[0] = "number";
48
49 String query = criteria.toQuery(QueryByCriteriaType.SELECT, attr);
50 assertTrue(StringUtils.equalsIgnoreCase(query, "select a.number from Account as a"));
51 }
52
53 @Test
54 public void testCriteriaToReportQuery_multipleFieldSelect() throws Exception {
55 Criteria criteria = new Criteria(Account.class.getName().substring(Account.class.getPackage().getName().length()+1), "a");
56
57 String[] attr = new String[3];
58 attr[0] = "number";
59 attr[1] = "name";
60 attr[2] = "amId";
61
62 String query = criteria.toQuery(QueryByCriteriaType.SELECT, attr);
63 assertTrue(StringUtils.equalsIgnoreCase(query, "select a.number, a.name, a.amId from Account as a"));
64 }
65
66 }