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.test.spring.AbstractTransactionalDaoTest; 29 import org.kuali.student.common.test.spring.Dao; 30 import org.kuali.student.common.test.spring.PersistenceFileLocation; 31 import org.kuali.student.core.exceptions.DoesNotExistException; 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 @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 LoRepository repository = dao.fetch(LoRepository.class, "kuali.loRepository.key.singleUse"); 45 Lo lo = dao.fetch(Lo.class, "81abea67-3bcc-4088-8348-e265f3670145"); 46 repository.setRootLo(lo); 47 } 48 49 @Test 50 public void testGetLo() 51 { 52 Lo lo = null; 53 try { 54 lo = dao.fetch(Lo.class, "81abea67-3bcc-4088-8348-e265f3670145"); 55 } catch (DoesNotExistException dnee) { 56 fail("Unable to find existing Learning Objective"); 57 } 58 assertNotNull(lo); 59 assertEquals("Edit Wiki Message Structure", lo.getName()); 60 assertEquals("singleUse", lo.getLoRepository().getName()); 61 try { 62 lo = dao.fetch(Lo.class, "91a91860-d796-4a17-976b-a6165b1a0b05"); 63 } catch (DoesNotExistException dnee) { 64 fail("Unable to find existing Learning Objective"); 65 } 66 assertNotNull(lo); 67 assertEquals("Destroy Wiki", lo.getDescr().getPlain()); 68 } 69 70 @Test 71 public void testGetRelatedLosByLoId() 72 { 73 String loId = "81abea67-3bcc-4088-8348-e265f3670145"; 74 List<Lo> relatedLos = null; 75 try { 76 relatedLos = dao.getRelatedLosByLoId(loId, "kuali.lo.relation.type.includes"); 77 } catch (DoesNotExistException dnee) { 78 fail("Unable to find existing Lo's related to Lo with ID == " + loId); 79 } 80 assertNotNull(relatedLos); 81 assertEquals(2, relatedLos.size()); 82 assertTrue(relatedLos.get(0).getId().equals("e0b456b2-62cb-4bd3-8867-a0d59fd8f2cf") || relatedLos.get(1).getId().equals("e0b456b2-62cb-4bd3-8867-a0d59fd8f2cf")); 83 } 84 85 @Test 86 public void testGetLosByRelatedLoId() 87 { 88 String relatedLoId = "abd8ae21-34e9-4858-a714-b04134f55d68"; 89 List<Lo> relatedLos = null; 90 try { 91 relatedLos = dao.getLosByRelatedLoId(relatedLoId, "kuali.lo.relation.type.includes"); 92 } catch (DoesNotExistException dnee) { 93 fail("Unable to find existing Lo's related to Lo with ID == " + relatedLoId); 94 } 95 assertNotNull(relatedLos); 96 assertEquals(2, relatedLos.size()); 97 assertTrue(relatedLos.get(0).getId().equals("e0b456b2-62cb-4bd3-8867-a0d59fd8f2cf") || relatedLos.get(1).getId().equals("e0b456b2-62cb-4bd3-8867-a0d59fd8f2cf")); 98 } 99 100 @Test 101 public void getLoByIdList() { 102 List<Lo> los = dao.getLoByIdList(Arrays.asList("81abea67-3bcc-4088-8348-e265f3670145", "e0b456b2-62cb-4bd3-8867-a0d59fd8f2cf", "dd0658d2-fdc9-48fa-9578-67a2ce53bf8a")); 103 assertNotNull(los); 104 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 }