Clover Coverage Report - KS LUM Impl 1.2-M6-SNAPSHOT
Coverage timestamp: Sun Sep 11 2011 07:23:28 EDT
34   200   9   6.8
0   80   0.26   5
5     1.8  
1    
 
  TestLoDaoImpl       Line # 37 34 0% 9 4 89.7% 0.8974359
 
  (4)
 
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.lo.dao.impl;
17   
18    import static org.junit.Assert.assertEquals;
19    import static org.junit.Assert.assertNotNull;
20    import static org.junit.Assert.assertTrue;
21    import static org.junit.Assert.fail;
22   
23    import java.util.Arrays;
24    import java.util.List;
25   
26    import org.junit.Before;
27    import org.junit.Test;
28    import org.kuali.student.common.exceptions.DoesNotExistException;
29    import org.kuali.student.common.test.spring.AbstractTransactionalDaoTest;
30    import org.kuali.student.common.test.spring.Dao;
31    import org.kuali.student.common.test.spring.PersistenceFileLocation;
32    import org.kuali.student.lum.lo.dao.LoDao;
33    import org.kuali.student.lum.lo.entity.Lo;
34    import org.kuali.student.lum.lo.entity.LoRepository;
35   
36    @PersistenceFileLocation("classpath:META-INF/lo-persistence.xml")
 
37    public class TestLoDaoImpl extends AbstractTransactionalDaoTest {
38    @Dao(value = "org.kuali.student.lum.lo.dao.impl.LoDaoImpl", testSqlFile = "classpath:ks-lo.sql")
39    public LoDao dao;
40   
 
41  4 toggle @Before
42    public void addLosToRepository() throws DoesNotExistException {
43    // set the hierarchy's root Lo; constraint violation if we do it in ks-lo.sql
44  4 LoRepository repository = dao.fetch(LoRepository.class, "kuali.loRepository.key.singleUse");
45  4 Lo lo = dao.fetch(Lo.class, "81abea67-3bcc-4088-8348-e265f3670145");
46  4 repository.setRootLo(lo);
47    }
48   
 
49  1 toggle @Test
50    public void testGetLo()
51    {
52  1 Lo lo = null;
53  1 try {
54  1 lo = dao.fetch(Lo.class, "81abea67-3bcc-4088-8348-e265f3670145");
55    } catch (DoesNotExistException dnee) {
56  0 fail("Unable to find existing Learning Objective");
57    }
58  1 assertNotNull(lo);
59  1 assertEquals("Edit Wiki Message Structure", lo.getName());
60  1 assertEquals("singleUse", lo.getLoRepository().getName());
61  1 try {
62  1 lo = dao.fetch(Lo.class, "91a91860-d796-4a17-976b-a6165b1a0b05");
63    } catch (DoesNotExistException dnee) {
64  0 fail("Unable to find existing Learning Objective");
65    }
66  1 assertNotNull(lo);
67  1 assertEquals("Destroy Wiki", lo.getDescr().getPlain());
68    }
69   
 
70  1 toggle @Test
71    public void testGetRelatedLosByLoId()
72    {
73  1 String loId = "81abea67-3bcc-4088-8348-e265f3670145";
74  1 List<Lo> relatedLos = null;
75  1 try {
76  1 relatedLos = dao.getRelatedLosByLoId(loId, "kuali.lo.relation.type.includes");
77    } catch (DoesNotExistException dnee) {
78  0 fail("Unable to find existing Lo's related to Lo with ID == " + loId);
79    }
80  1 assertNotNull(relatedLos);
81  1 assertEquals(2, relatedLos.size());
82  1 assertTrue(relatedLos.get(0).getId().equals("e0b456b2-62cb-4bd3-8867-a0d59fd8f2cf") || relatedLos.get(1).getId().equals("e0b456b2-62cb-4bd3-8867-a0d59fd8f2cf"));
83    }
84   
 
85  1 toggle @Test
86    public void testGetLosByRelatedLoId()
87    {
88  1 String relatedLoId = "abd8ae21-34e9-4858-a714-b04134f55d68";
89  1 List<Lo> relatedLos = null;
90  1 try {
91  1 relatedLos = dao.getLosByRelatedLoId(relatedLoId, "kuali.lo.relation.type.includes");
92    } catch (DoesNotExistException dnee) {
93  0 fail("Unable to find existing Lo's related to Lo with ID == " + relatedLoId);
94    }
95  1 assertNotNull(relatedLos);
96  1 assertEquals(2, relatedLos.size());
97  1 assertTrue(relatedLos.get(0).getId().equals("e0b456b2-62cb-4bd3-8867-a0d59fd8f2cf") || relatedLos.get(1).getId().equals("e0b456b2-62cb-4bd3-8867-a0d59fd8f2cf"));
98    }
99   
 
100  1 toggle @Test
101    public void getLoByIdList() {
102  1 List<Lo> los = dao.getLoByIdList(Arrays.asList("81abea67-3bcc-4088-8348-e265f3670145", "e0b456b2-62cb-4bd3-8867-a0d59fd8f2cf", "dd0658d2-fdc9-48fa-9578-67a2ce53bf8a"));
103  1 assertNotNull(los);
104  1 assertEquals(3, los.size());
105    }
106   
107    /*
108    @Test
109    public void testGetLosByLoCategory() {
110    Set<String> loNames = new TreeSet<String>(Arrays.asList("Edit Wiki Message Structure", "Navigate Wiki", "Install Wiki Engine"));
111    List<Lo> los= dao.getLosByLoCategory("054CAA88-C21D-4496-8287-36A311A11D68");
112    assertNotNull(los);
113    assertEquals(5, los.size());
114    assertTrue(loNames.contains(los.get(0).getName()));
115    assertTrue(loNames.contains(los.get(1).getName()));
116    assertTrue(loNames.contains(los.get(2).getName()));
117   
118    // LoCategory associated w/ a LoHierarchy that has only one LO in it
119    los= dao.getLosByLoCategory("7114D2A4-F66D-4D3A-9D41-A7AA4299C797");
120    assertNotNull(los);
121    assertEquals(1, los.size());
122   
123    // Bogus LoCategory
124    los= dao.getLosByLoCategory("Not a valid UUID");
125    assertNotNull(los);
126    assertEquals(0, los.size());
127    }
128   
129    @Test
130    public void testAddLoCategoryToLo() {
131    String loId = "7BCD7C0E-3E6B-4527-AC55-254C58CECC22";
132    String loCatId = "054CAA88-C21D-4496-8287-36A311A11D68";
133    LoCategory loCategory = null;
134    try {
135    loCategory = dao.fetch(LoCategory.class, loCatId);
136    } catch (DoesNotExistException e) {
137    fail("DoesNotExistException when retrieving Lo w/ ID == " + loId);
138    }
139    assertFalse(dao.getLoCategoriesForLo(loId).contains(loCategory));
140    assertEquals("loHierarchy.fsu", loCategory.getLoHierarchy().getId());
141    assertTrue(dao.addLoCategoryToLo(loCatId, loId));
142    // confirm Category's hierarchy was switched.
143    try {
144    loCategory = dao.fetch(LoCategory.class, loCatId);
145    } catch (DoesNotExistException e) {
146    fail("DoesNotExistException when retrieving Lo w/ ID == " + loId);
147    }
148    assertTrue(dao.getLoCategoriesForLo(loId).contains(loCategory));
149    assertEquals("loHierarchy.kualiproject.common", loCategory.getLoHierarchy().getId());
150    }
151   
152    @Test
153    public void testRemoveLoCategoryFromLo() throws DoesNotExistException {
154    String loId = "E0B456B2-62CB-4BD3-8867-A0D59FD8F2CF";
155    String loCatId = "054CAA88-C21D-4496-8287-36A311A11D68";
156    LoCategory loCategory = null;
157    loCategory = dao.fetch(LoCategory.class, loCatId);
158    assertTrue(dao.getLoCategoriesForLo(loId).contains(loCategory));
159    assertEquals("loHierarchy.fsu", loCategory.getLoHierarchy().getId());
160    assertTrue(dao.removeLoCategoryFromLo(loCatId, loId));
161    // confirm Category's hierarchy was switched.
162    try {
163    loCategory = dao.fetch(LoCategory.class, loCatId);
164    } catch (DoesNotExistException e) {
165    fail("DoesNotExistException when retrieving Lo w/ ID == " + loId);
166    }
167    assertFalse(dao.getLoCategoriesForLo(loId).contains(loCategory));
168    assertNull(loCategory.getLoHierarchy());
169    }
170   
171    @Test
172    public void testDeleteLoCategory() throws DoesNotExistException, DependentObjectsExistException {
173    String nonEmptyCategoryId = "054CAA88-C21D-4496-8287-36A311A11D68";
174    String emptyCategoryId = "F2F02922-4E77-4144-AA07-8C2C956370DC";
175   
176    assertFalse(dao.getLosByLoCategory(nonEmptyCategoryId).isEmpty());
177    try {
178    dao.deleteLoCategory(nonEmptyCategoryId);
179    fail("Deleting LoCategory with associated Learning Objective(s) should have thrown DependentObjectsExistException");
180    } catch (DependentObjectsExistException doee) {}
181    // now delete one that has no associated Lo's
182    assertTrue(dao.deleteLoCategory(emptyCategoryId));
183    }
184   
185    @Test
186    public void testDeleteLo() throws DoesNotExistException, DependentObjectsExistException {
187    assertEquals(1, dao.getRelatedLosByLoId("91A91860-D796-4A17-976B-A6165B1A0B05", "kuali.lo.relation.type.includes").size());
188    try {
189    dao.deleteLo("91A91860-D796-4A17-976B-A6165B1A0B05");
190    fail("LoDao.deleteLo() should have thrown DependentObjectsExistException");
191    } catch (DependentObjectsExistException doee) {}
192    dao.deleteLo("FDE6421E-64B4-41AF-BAC5-269005101C2A");
193    try {
194    assertTrue(dao.deleteLo("91A91860-D796-4A17-976B-A6165B1A0B05"));
195    } catch (DependentObjectsExistException doee) {
196    fail("DependentObjectsExistException was thrown when deleting Lo with no children");
197    }
198    }
199    */
200    }