1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.lum.lu.dao.impl;
17
18 import org.junit.Test;
19 import org.kuali.student.common.test.spring.AbstractTransactionalDaoTest;
20 import org.kuali.student.common.test.spring.Dao;
21 import org.kuali.student.common.test.spring.PersistenceFileLocation;
22 import org.kuali.student.r1.common.dao.impl.AbstractCrudDaoImpl;
23 import org.kuali.student.r2.common.exceptions.DoesNotExistException;
24 import org.kuali.student.r2.common.util.date.DateFormatters;
25 import org.kuali.student.r2.core.versionmanagement.dto.VersionDisplayInfo;
26 import org.kuali.student.r2.lum.lu.dao.LuDao;
27 import org.kuali.student.r2.lum.lu.entity.CluLoRelationType;
28 import org.kuali.student.r2.lum.lu.entity.CluSet;
29 import org.kuali.student.r2.lum.lu.entity.MembershipQuery;
30 import org.kuali.student.r2.lum.lu.entity.SearchParameter;
31 import org.kuali.student.r2.lum.lu.entity.SearchParameterValue;
32
33 import javax.persistence.Query;
34 import java.util.ArrayList;
35 import java.util.Arrays;
36 import java.util.List;
37
38 import static org.junit.Assert.assertEquals;
39 import static org.junit.Assert.assertNotNull;
40
41
42
43 @PersistenceFileLocation("classpath:META-INF/lu-persistence.xml")
44 public class TestLuDaoImpl extends AbstractTransactionalDaoTest {
45 @Dao(value = "org.kuali.student.r2.lum.lu.dao.impl.LuDaoImpl", testSqlFile = "classpath:ks-lu.sql")
46 public LuDao dao;
47
48 @Test
49 public void testJPQL() {
50
51 Query query = ((AbstractCrudDaoImpl) dao).getEm().createQuery(
52 "SELECT clu.id, clu.officialIdentifier.code, rel.loId " +
53 "FROM CluLoRelation rel " +
54 "JOIN rel.clu clu " +
55 "LEFT JOIN clu.adminOrgs adminOrg ");
56
57 query.getResultList();
58 }
59
60
61
62
63
64
65
66
67
68 @Test
69 public void testGetCluLoRelationTypeInfo() throws DoesNotExistException {
70 CluLoRelationType relType = dao.fetch(CluLoRelationType.class, "kuali.lu.lo.relation.type.includes");
71 assertEquals("Default Clu-Lo relation type", relType.getDescr());
72 }
73
74 @Test
75 public void testCreateCluLoRelation() throws Exception {
76 }
77
78 @Test
79 public void testCreateMembershipQuery_Simple() throws Exception {
80 MembershipQuery mq = new MembershipQuery();
81 mq.setSearchTypeKey("searchKey1");
82 mq = dao.create(mq);
83
84 mq = dao.fetch(MembershipQuery.class, mq.getId());
85
86 assertEquals("searchKey1", mq.getSearchTypeKey());
87 assertNotNull(mq.getSearchParameters());
88 assertEquals(0, mq.getSearchParameters().size());
89 }
90
91 @Test
92 public void testCreateMembershipQuery_Complex() throws Exception {
93 MembershipQuery mq = createMembershipQuery();
94 mq = dao.fetch(MembershipQuery.class, mq.getId());
95
96 assertEquals("searchKey1", mq.getSearchTypeKey());
97 assertEquals(1, mq.getSearchParameters().size());
98 assertEquals("key-1", mq.getSearchParameters().get(0).getKey());
99 assertEquals(2, mq.getSearchParameters().get(0).getValues().size());
100 assertEquals("value-1", mq.getSearchParameters().get(0).getValues().get(0).getValue());
101 assertEquals("value-2", mq.getSearchParameters().get(0).getValues().get(1).getValue());
102 }
103
104 @Test
105 public void testCreateClu() throws Exception {
106 CluSet cluSet = new CluSet();
107 MembershipQuery mq = createMembershipQuery();
108 cluSet.setMembershipQuery(mq);
109 cluSet = dao.create(cluSet);
110
111 assertEquals("searchKey1", cluSet.getMembershipQuery().getSearchTypeKey());
112 assertNotNull(cluSet.getMembershipQuery().getSearchParameters());
113 assertEquals(1, cluSet.getMembershipQuery().getSearchParameters().size());
114 assertEquals("key-1", cluSet.getMembershipQuery().getSearchParameters().get(0).getKey());
115 assertEquals(2, cluSet.getMembershipQuery().getSearchParameters().get(0).getValues().size());
116 assertEquals("value-1", cluSet.getMembershipQuery().getSearchParameters().get(0).getValues().get(0).getValue());
117 assertEquals("value-2", cluSet.getMembershipQuery().getSearchParameters().get(0).getValues().get(1).getValue());
118 }
119
120 @Test
121 public void testVersionQueries() throws Exception {
122 List<VersionDisplayInfo> versions;
123 versions = dao.getVersions("CLU-VERSIONTEST-IND", "foo.com");
124 assertEquals(6, versions.size());
125
126 VersionDisplayInfo versionDisplay;
127 versionDisplay = dao.getCurrentCluVersionInfo("CLU-VERSIONTEST-IND", "foo.com");
128 assertEquals("CLU-VERSIONTEST-V4", versionDisplay.getId());
129
130 versionDisplay = dao.getCurrentVersionOnDate("CLU-VERSIONTEST-IND", "foo.com", DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20100110"));
131 assertEquals("CLU-VERSIONTEST-V0", versionDisplay.getId());
132
133 versionDisplay = dao.getCurrentVersionOnDate("CLU-VERSIONTEST-IND", "foo.com", DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20110210"));
134 assertEquals("CLU-VERSIONTEST-V4", versionDisplay.getId());
135
136 versionDisplay = dao.getFirstVersion("CLU-VERSIONTEST-IND", "foo.com");
137 assertEquals("CLU-VERSIONTEST-V0", versionDisplay.getId());
138
139 versionDisplay = dao.getLatestVersion("CLU-VERSIONTEST-IND", "foo.com");
140 assertEquals("CLU-VERSIONTEST-V5", versionDisplay.getId());
141
142 versionDisplay = dao.getVersionBySequenceNumber("CLU-VERSIONTEST-IND", "foo.com", Long.valueOf(3));
143 assertEquals("CLU-VERSIONTEST-V3", versionDisplay.getId());
144
145 versions = dao.getVersionsInDateRange("CLU-VERSIONTEST-IND", "foo.com", DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20100210"), DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20100410"));
146 assertEquals(3, versions.size());
147
148 versions = dao.getVersionsInDateRange("CLU-VERSIONTEST-IND", "foo.com", DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20100210"), DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20100310"));
149 assertEquals(2, versions.size());
150
151 versions = dao.getVersionsInDateRange("CLU-VERSIONTEST-IND", "foo.com", DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20100310"), DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20100310"));
152 assertEquals(1, versions.size());
153
154 versions = dao.getVersionsInDateRange("CLU-VERSIONTEST-IND", "foo.com", DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20100310"), DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20100410"));
155 assertEquals(2, versions.size());
156
157 versions = dao.getVersionsInDateRange("CLU-VERSIONTEST-IND", "foo.com", DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20090310"), DateFormatters.YEAR_MONTH_DAY_CONCAT_DATE_FORMATTER.parse("20090410"));
158 assertEquals(0, versions.size());
159
160 }
161
162 private MembershipQuery createMembershipQuery() {
163 List<SearchParameterValue> list1 = new ArrayList<SearchParameterValue>();
164 SearchParameterValue v1 = new SearchParameterValue();
165 v1.setValue("value-1");
166 list1.add(v1);
167 SearchParameterValue v2 = new SearchParameterValue();
168 v2.setValue("value-2");
169 list1.add(v2);
170
171 SearchParameter sp = new SearchParameter();
172 sp.setKey("key-1");
173 sp.setValues(list1);
174
175 List<SearchParameter> list2 = Arrays.asList(new SearchParameter[]{sp});
176
177 MembershipQuery mq = new MembershipQuery();
178 mq.setSearchTypeKey("searchKey1");
179 mq.setSearchParameters(list2);
180 mq = dao.create(mq);
181
182 return mq;
183 }
184
185 }