Clover Coverage Report - Kuali Student 1.2-M4-SNAPSHOT (Aggregated)
Coverage timestamp: Wed Jul 20 2011 11:14:35 EDT
75   186   9   8.33
0   133   0.12   9
9     1  
1    
 
  TestLuDaoImpl       Line # 44 75 0% 9 0 100% 1.0
 
  (8)
 
1    /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10    * software distributed under the License is distributed on an "AS IS"
11    * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12    * or implied. See the License for the specific language governing
13    * permissions and limitations under the License.
14    */
15   
16    package org.kuali.student.lum.lu.dao.impl;
17   
18    import static org.junit.Assert.assertEquals;
19    import static org.junit.Assert.assertNotNull;
20   
21    import java.text.SimpleDateFormat;
22    import java.util.ArrayList;
23    import java.util.Arrays;
24    import java.util.List;
25   
26    import javax.persistence.Query;
27   
28    import org.junit.Test;
29    import org.kuali.student.common.dao.impl.AbstractSearchableCrudDaoImpl;
30    import org.kuali.student.common.exceptions.DoesNotExistException;
31    import org.kuali.student.common.test.spring.AbstractTransactionalDaoTest;
32    import org.kuali.student.common.test.spring.Dao;
33    import org.kuali.student.common.test.spring.PersistenceFileLocation;
34    import org.kuali.student.common.versionmanagement.dto.VersionDisplayInfo;
35    import org.kuali.student.lum.lu.dao.LuDao;
36    import org.kuali.student.lum.lu.entity.CluLoRelationType;
37    import org.kuali.student.lum.lu.entity.CluSet;
38    import org.kuali.student.lum.lu.entity.Lui;
39    import org.kuali.student.lum.lu.entity.MembershipQuery;
40    import org.kuali.student.lum.lu.entity.SearchParameter;
41    import org.kuali.student.lum.lu.entity.SearchParameterValue;
42   
43    @PersistenceFileLocation("classpath:META-INF/lu-persistence.xml")
 
44    public class TestLuDaoImpl extends AbstractTransactionalDaoTest {
45    @Dao(value = "org.kuali.student.lum.lu.dao.impl.LuDaoImpl", testSqlFile = "classpath:ks-lu.sql")
46    public LuDao dao;
47   
48    private static final SimpleDateFormat DF = new SimpleDateFormat("yyyyMMdd");
49   
 
50  1 toggle @Test
51    public void testJPQL(){
52   
53  1 Query query = ((AbstractSearchableCrudDaoImpl)dao).getEm().createQuery(
54    "SELECT clu.id, clu.officialIdentifier.code, rel.loId " +
55    "FROM CluLoRelation rel " +
56    "JOIN rel.clu clu " +
57    "LEFT JOIN clu.adminOrgs adminOrg " );
58   
59  1 query.getResultList();
60    }
61   
 
62  1 toggle @Test
63    public void testGetLuLuRelationTypeInfo(){
64  1 List<Lui> luis = dao.getLuisByRelationType("LUI-3", "luLuType.type1");
65  1 assertEquals(1, luis.size());
66  1 assertEquals("LUI-1", luis.get(0).getId());
67    }
68   
 
69  1 toggle @Test
70    public void testGetCluLoRelationTypeInfo() throws DoesNotExistException{
71  1 CluLoRelationType relType = dao.fetch(CluLoRelationType.class, "kuali.lu.lo.relation.type.includes");
72  1 assertEquals("Default Clu-Lo relation type", relType.getDescr());
73    }
74   
 
75  1 toggle @Test
76    public void testCreateCluLoRelation() throws Exception {
77    }
78   
 
79  1 toggle @Test
80    public void testCreateMembershipQuery_Simple() throws Exception {
81  1 MembershipQuery mq = new MembershipQuery();
82  1 mq.setSearchTypeKey("searchKey1");
83  1 mq = dao.create(mq);
84   
85  1 mq = dao.fetch(MembershipQuery.class, mq.getId());
86   
87  1 assertEquals("searchKey1", mq.getSearchTypeKey());
88  1 assertNotNull(mq.getSearchParameters());
89  1 assertEquals(0, mq.getSearchParameters().size());
90    }
91   
 
92  1 toggle @Test
93    public void testCreateMembershipQuery_Complex() throws Exception {
94  1 MembershipQuery mq = createMembershipQuery();
95  1 mq = dao.fetch(MembershipQuery.class, mq.getId());
96   
97  1 assertEquals("searchKey1", mq.getSearchTypeKey());
98  1 assertEquals(1, mq.getSearchParameters().size());
99  1 assertEquals("key-1", mq.getSearchParameters().get(0).getKey());
100  1 assertEquals(2, mq.getSearchParameters().get(0).getValues().size());
101  1 assertEquals("value-1", mq.getSearchParameters().get(0).getValues().get(0).getValue());
102  1 assertEquals("value-2", mq.getSearchParameters().get(0).getValues().get(1).getValue());
103    }
104   
 
105  1 toggle @Test
106    public void testCreateClu() throws Exception {
107  1 CluSet cluSet = new CluSet();
108  1 MembershipQuery mq = createMembershipQuery();
109  1 cluSet.setMembershipQuery(mq);
110  1 cluSet = dao.create(cluSet);
111   
112  1 assertEquals("searchKey1", cluSet.getMembershipQuery().getSearchTypeKey());
113  1 assertNotNull(cluSet.getMembershipQuery().getSearchParameters());
114  1 assertEquals(1, cluSet.getMembershipQuery().getSearchParameters().size());
115  1 assertEquals("key-1", cluSet.getMembershipQuery().getSearchParameters().get(0).getKey());
116  1 assertEquals(2, cluSet.getMembershipQuery().getSearchParameters().get(0).getValues().size());
117  1 assertEquals("value-1", cluSet.getMembershipQuery().getSearchParameters().get(0).getValues().get(0).getValue());
118  1 assertEquals("value-2", cluSet.getMembershipQuery().getSearchParameters().get(0).getValues().get(1).getValue());
119    }
120   
 
121  1 toggle @Test
122    public void testVersionQueries() throws Exception{
123  1 List<VersionDisplayInfo> versions;
124  1 versions = dao.getVersions("CLU-VERSIONTEST-IND", "foo.com");
125  1 assertEquals(6,versions.size());
126   
127  1 VersionDisplayInfo versionDisplay;
128  1 versionDisplay = dao.getCurrentCluVersionInfo("CLU-VERSIONTEST-IND", "foo.com");
129  1 assertEquals("CLU-VERSIONTEST-V4", versionDisplay.getId());
130   
131  1 versionDisplay = dao.getCurrentVersionOnDate("CLU-VERSIONTEST-IND", "foo.com", DF.parse("20100110"));
132  1 assertEquals("CLU-VERSIONTEST-V0", versionDisplay.getId());
133   
134  1 versionDisplay = dao.getCurrentVersionOnDate("CLU-VERSIONTEST-IND", "foo.com", DF.parse("20110210"));
135  1 assertEquals("CLU-VERSIONTEST-V4", versionDisplay.getId());
136   
137  1 versionDisplay = dao.getFirstVersion("CLU-VERSIONTEST-IND", "foo.com");
138  1 assertEquals("CLU-VERSIONTEST-V0", versionDisplay.getId());
139   
140  1 versionDisplay = dao.getLatestVersion("CLU-VERSIONTEST-IND", "foo.com");
141  1 assertEquals("CLU-VERSIONTEST-V5", versionDisplay.getId());
142   
143  1 versionDisplay = dao.getVersionBySequenceNumber("CLU-VERSIONTEST-IND", "foo.com", Long.valueOf(3));
144  1 assertEquals("CLU-VERSIONTEST-V3", versionDisplay.getId());
145   
146  1 versions = dao.getVersionsInDateRange("CLU-VERSIONTEST-IND", "foo.com", DF.parse("20100210"), DF.parse("20100410"));
147  1 assertEquals(3, versions.size());
148   
149  1 versions = dao.getVersionsInDateRange("CLU-VERSIONTEST-IND", "foo.com", DF.parse("20100210"), DF.parse("20100310"));
150  1 assertEquals(2, versions.size());
151   
152  1 versions = dao.getVersionsInDateRange("CLU-VERSIONTEST-IND", "foo.com", DF.parse("20100310"), DF.parse("20100310"));
153  1 assertEquals(1, versions.size());
154   
155  1 versions = dao.getVersionsInDateRange("CLU-VERSIONTEST-IND", "foo.com", DF.parse("20100310"), DF.parse("20100410"));
156  1 assertEquals(2, versions.size());
157   
158  1 versions = dao.getVersionsInDateRange("CLU-VERSIONTEST-IND", "foo.com", DF.parse("20090310"), DF.parse("20090410"));
159  1 assertEquals(0, versions.size());
160   
161    }
162   
 
163  2 toggle private MembershipQuery createMembershipQuery() {
164  2 List<SearchParameterValue> list1 = new ArrayList<SearchParameterValue>();
165  2 SearchParameterValue v1 = new SearchParameterValue();
166  2 v1.setValue("value-1");
167  2 list1.add(v1);
168  2 SearchParameterValue v2 = new SearchParameterValue();
169  2 v2.setValue("value-2");
170  2 list1.add(v2);
171   
172  2 SearchParameter sp = new SearchParameter();
173  2 sp.setKey("key-1");
174  2 sp.setValues(list1);
175   
176  2 List<SearchParameter> list2 = Arrays.asList(new SearchParameter[] {sp});
177   
178  2 MembershipQuery mq = new MembershipQuery();
179  2 mq.setSearchTypeKey("searchKey1");
180  2 mq.setSearchParameters(list2);
181  2 mq = dao.create(mq);
182   
183  2 return mq;
184    }
185   
186    }