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.rice.krad.test.KRADTestCase;
24
25 import static org.junit.Assert.assertTrue;
26
27
28
29
30
31
32
33 public class ReportQueryByCriteriaTest extends KRADTestCase {
34
35 @Test
36
37
38
39 public void testCriteriaToReportQuery_emptySelect() throws Exception {
40 Criteria criteria = new Criteria(Account.class.getName().substring(Account.class.getPackage().getName().length()+1), "a");
41
42 String query = criteria.toQuery(QueryByCriteriaType.SELECT, new String[0]);
43 assertTrue(StringUtils.equalsIgnoreCase(query, "select a from Account as a"));
44 }
45
46 @Test
47
48
49
50
51 public void testCriteriaToReportQuery_singleFieldSelect() throws Exception {
52 Criteria criteria = new Criteria(Account.class.getName().substring(Account.class.getPackage().getName().length()+1), "a");
53
54 String[] attr = new String[1];
55 attr[0] = "number";
56
57 String query = criteria.toQuery(QueryByCriteriaType.SELECT, attr);
58 assertTrue(StringUtils.equalsIgnoreCase(query, "select a.number from Account as a"));
59 }
60
61 @Test
62
63
64
65 public void testCriteriaToReportQuery_multipleFieldSelect() throws Exception {
66 Criteria criteria = new Criteria(Account.class.getName().substring(Account.class.getPackage().getName().length()+1), "a");
67
68 String[] attr = new String[3];
69 attr[0] = "number";
70 attr[1] = "name";
71 attr[2] = "amId";
72
73 String query = criteria.toQuery(QueryByCriteriaType.SELECT, attr);
74 assertTrue(StringUtils.equalsIgnoreCase(query, "select a.number, a.name, a.amId from Account as a"));
75 }
76
77 }