| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.kuali.student.core.atp; |
| 17 |
|
|
| 18 |
|
import static org.junit.Assert.assertEquals; |
| 19 |
|
import static org.junit.Assert.assertTrue; |
| 20 |
|
import static org.junit.Assert.fail; |
| 21 |
|
|
| 22 |
|
import java.text.ParseException; |
| 23 |
|
import java.text.SimpleDateFormat; |
| 24 |
|
import java.util.Calendar; |
| 25 |
|
import java.util.Date; |
| 26 |
|
import java.util.List; |
| 27 |
|
|
| 28 |
|
import org.apache.log4j.Logger; |
| 29 |
|
import org.junit.Test; |
| 30 |
|
import org.kuali.student.common.test.spring.AbstractServiceTest; |
| 31 |
|
import org.kuali.student.common.test.spring.Client; |
| 32 |
|
import org.kuali.student.common.test.spring.Dao; |
| 33 |
|
import org.kuali.student.common.test.spring.Daos; |
| 34 |
|
import org.kuali.student.common.test.spring.PersistenceFileLocation; |
| 35 |
|
import org.kuali.student.core.atp.dto.AtpInfo; |
| 36 |
|
import org.kuali.student.core.atp.dto.AtpTypeInfo; |
| 37 |
|
import org.kuali.student.core.atp.dto.DateRangeInfo; |
| 38 |
|
import org.kuali.student.core.atp.dto.DateRangeTypeInfo; |
| 39 |
|
import org.kuali.student.core.atp.dto.MilestoneInfo; |
| 40 |
|
import org.kuali.student.core.atp.dto.MilestoneTypeInfo; |
| 41 |
|
import org.kuali.student.core.atp.service.AtpService; |
| 42 |
|
import org.kuali.student.core.dto.RichTextInfo; |
| 43 |
|
import org.kuali.student.core.exceptions.DoesNotExistException; |
| 44 |
|
import org.kuali.student.core.exceptions.InvalidParameterException; |
| 45 |
|
import org.kuali.student.core.exceptions.MissingParameterException; |
| 46 |
|
import org.kuali.student.core.exceptions.OperationFailedException; |
| 47 |
|
import org.kuali.student.core.exceptions.VersionMismatchException; |
| 48 |
|
|
| 49 |
|
@Daos( { @Dao(value = "org.kuali.student.core.atp.dao.impl.AtpDaoImpl", testDataFile = "classpath:atp-test-beans.xml") }) |
| 50 |
|
@PersistenceFileLocation("classpath:META-INF/atp-persistence.xml") |
|
|
|
| 82% |
Uncovered Elements: 22 (122) |
Complexity: 15 |
Complexity Density: 0.12 |
|
| 51 |
|
public class TestAtpService extends AbstractServiceTest { |
| 52 |
|
final Logger LOG = Logger.getLogger(TestAtpService.class); |
| 53 |
|
|
| 54 |
|
@Client(value = "org.kuali.student.core.atp.service.impl.AtpServiceImpl") |
| 55 |
|
public AtpService client; |
| 56 |
|
|
| 57 |
|
public static final String atpType_fallSemester = "atp.atpType.fallSemester"; |
| 58 |
|
public static final String milestoneType_lastDateToDrop = "atp.milestoneType.lastDateToDrop"; |
| 59 |
|
public static final String dateRangeType_finals = "atp.dateRangeType.finals"; |
| 60 |
|
public static final String atpAttribute_notes = "atp.attribute.notes"; |
| 61 |
|
public static final String dateRangeAttribute_notes = "atp.dateRangeAttribute.notes"; |
| 62 |
|
public static final String milestoneAttribute_notes = "atp.milestoneAttribute.notes"; |
| 63 |
|
public static final String atp_fall2008Semester = "atp.fall2008Semester"; |
| 64 |
|
public static final String milestone_lastDateToDropFall2008 = "atp.milestone.lastDateToDropFall2008"; |
| 65 |
|
public static final String dateRange_finalsFall2008 = "atp.dateRange.finalsFall2008"; |
| 66 |
|
|
| 67 |
|
public static final String atp_2009FallSemester = "atp.2009FallSemester"; |
| 68 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (31) |
Complexity: 1 |
Complexity Density: 0.03 |
1
PASS
|
|
| 69 |
1
|
@Test... |
| 70 |
|
public void TestFinds() throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, ParseException{ |
| 71 |
|
|
| 72 |
1
|
Calendar cal = Calendar.getInstance(); |
| 73 |
1
|
cal.set(2009, 9, 1); |
| 74 |
|
|
| 75 |
1
|
Calendar startCal = Calendar.getInstance(); |
| 76 |
1
|
startCal.set(2008, 1, 1); |
| 77 |
|
|
| 78 |
1
|
Calendar endCal = Calendar.getInstance(); |
| 79 |
1
|
endCal.set(2010, 1, 1); |
| 80 |
|
|
| 81 |
1
|
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd"); |
| 82 |
|
|
| 83 |
1
|
List<AtpTypeInfo> atpTypes = client.getAtpTypes(); |
| 84 |
1
|
assertEquals(2,atpTypes.size()); |
| 85 |
|
|
| 86 |
1
|
List<AtpInfo> atpsByAtpType = client.getAtpsByAtpType(atpType_fallSemester); |
| 87 |
1
|
assertEquals(1,atpsByAtpType.size()); |
| 88 |
1
|
assertEquals(atp_2009FallSemester,atpsByAtpType.get(0).getId()); |
| 89 |
|
|
| 90 |
1
|
List<AtpInfo> atpsByDate = client.getAtpsByDate(cal.getTime()); |
| 91 |
1
|
assertEquals(1,atpsByDate.size()); |
| 92 |
1
|
assertEquals(atp_2009FallSemester,atpsByDate.get(0).getId()); |
| 93 |
|
|
| 94 |
1
|
List<AtpInfo> atpsByDates = client.getAtpsByDates(startCal.getTime(), endCal.getTime()); |
| 95 |
1
|
assertEquals(2,atpsByDates.size()); |
| 96 |
|
|
| 97 |
1
|
List<DateRangeInfo> dateRangesByAtp = client.getDateRangesByAtp(atp_2009FallSemester); |
| 98 |
1
|
assertEquals(1,dateRangesByAtp.size()); |
| 99 |
|
|
| 100 |
1
|
List<DateRangeInfo> dateRangesByDate = client.getDateRangesByDate(df.parse("20091205")); |
| 101 |
1
|
assertEquals(1,dateRangesByDate.size()); |
| 102 |
|
|
| 103 |
1
|
List<DateRangeTypeInfo> dateRangeTypesForAtpType = client.getDateRangeTypesForAtpType(atpType_fallSemester); |
| 104 |
1
|
assertEquals(1,dateRangeTypesForAtpType.size()); |
| 105 |
|
|
| 106 |
1
|
List<MilestoneInfo> milestonesByAtp = client.getMilestonesByAtp(atp_2009FallSemester); |
| 107 |
1
|
assertEquals(1,milestonesByAtp.size()); |
| 108 |
|
|
| 109 |
1
|
List<MilestoneInfo> milestonesByDates = client.getMilestonesByDates(startCal.getTime(), endCal.getTime()); |
| 110 |
1
|
assertEquals(1,milestonesByDates.size()); |
| 111 |
|
|
| 112 |
1
|
List<MilestoneInfo> milestonesByDatesAndType = client.getMilestonesByDatesAndType(milestoneType_lastDateToDrop, startCal.getTime(), endCal.getTime()); |
| 113 |
1
|
assertEquals(1,milestonesByDatesAndType.size()); |
| 114 |
|
|
| 115 |
1
|
List<MilestoneTypeInfo> milestoneTypesForAtpType = client.getMilestoneTypesForAtpType(atpType_fallSemester); |
| 116 |
1
|
assertEquals(1,milestoneTypesForAtpType.size()); |
| 117 |
|
} |
| 118 |
|
|
|
|
|
| 75.3% |
Uncovered Elements: 22 (89) |
Complexity: 14 |
Complexity Density: 0.16 |
1
PASS
|
|
| 119 |
1
|
@Test... |
| 120 |
|
public void TestCreateUpdateDelete(){ |
| 121 |
|
|
| 122 |
1
|
AtpInfo atpInfo = new AtpInfo(); |
| 123 |
1
|
atpInfo.setDesc(new RichTextInfo()); |
| 124 |
1
|
atpInfo.getDesc().setFormatted("Atp for fall 2008 semester"); |
| 125 |
1
|
atpInfo.getDesc().setPlain("Atp for fall 2008 semester"); |
| 126 |
1
|
atpInfo.setName("Fall 2008 Semester"); |
| 127 |
1
|
atpInfo.setStartDate(new Date()); |
| 128 |
1
|
atpInfo.setEndDate(new Date()); |
| 129 |
|
|
| 130 |
1
|
Date stDate = atpInfo.getStartDate(); |
| 131 |
1
|
Date enDate = atpInfo.getEndDate(); |
| 132 |
|
|
| 133 |
1
|
atpInfo.setState("new"); |
| 134 |
|
|
| 135 |
1
|
atpInfo.getAttributes().put(atpAttribute_notes, "Notes for the Fall 2008 Semester"); |
| 136 |
|
|
| 137 |
1
|
AtpInfo createdAtp=null; |
| 138 |
1
|
try { |
| 139 |
1
|
createdAtp = client.createAtp(atpType_fallSemester, atp_fall2008Semester, atpInfo); |
| 140 |
|
} catch (Exception e) { |
| 141 |
0
|
LOG.error(e); |
| 142 |
0
|
fail(); |
| 143 |
|
} |
| 144 |
|
|
| 145 |
1
|
assertTrue(stDate.equals(createdAtp.getStartDate())); |
| 146 |
1
|
assertTrue(enDate.equals(createdAtp.getEndDate())); |
| 147 |
|
|
| 148 |
|
|
| 149 |
1
|
DateRangeInfo dateRangeInfo=new DateRangeInfo(); |
| 150 |
1
|
dateRangeInfo.setDesc(new RichTextInfo()); |
| 151 |
1
|
dateRangeInfo.getDesc().setFormatted("Date Range for fall 2008 semester finals"); |
| 152 |
1
|
dateRangeInfo.setName("Finals Fall 2008 Semester"); |
| 153 |
1
|
dateRangeInfo.setStartDate(new Date()); |
| 154 |
1
|
dateRangeInfo.setEndDate(new Date()); |
| 155 |
1
|
dateRangeInfo.setState("new"); |
| 156 |
1
|
dateRangeInfo.setAtpId(atp_fall2008Semester); |
| 157 |
1
|
dateRangeInfo.setType(dateRangeType_finals); |
| 158 |
|
|
| 159 |
1
|
dateRangeInfo.getAttributes().put(dateRangeAttribute_notes, "Notes for the Finals date range Fall 2008 Semester"); |
| 160 |
|
|
| 161 |
1
|
DateRangeInfo createdDateRange=null; |
| 162 |
1
|
try { |
| 163 |
1
|
createdDateRange = client.addDateRange(atp_fall2008Semester, dateRange_finalsFall2008, dateRangeInfo); |
| 164 |
|
} catch (Exception e) { |
| 165 |
0
|
LOG.error(e); |
| 166 |
0
|
fail(); |
| 167 |
|
} |
| 168 |
|
|
| 169 |
|
|
| 170 |
1
|
MilestoneInfo milestoneInfo=new MilestoneInfo(); |
| 171 |
1
|
milestoneInfo.setDesc(new RichTextInfo()); |
| 172 |
1
|
milestoneInfo.getDesc().setFormatted("Milestone for fall 2008 semester last day to drop"); |
| 173 |
1
|
milestoneInfo.setName("Last Day to Drop Fall 2008 Semester"); |
| 174 |
1
|
milestoneInfo.setMilestoneDate(new Date()); |
| 175 |
1
|
milestoneInfo.setState("new"); |
| 176 |
1
|
milestoneInfo.setAtpId(atp_fall2008Semester); |
| 177 |
1
|
milestoneInfo.setType(milestoneType_lastDateToDrop); |
| 178 |
|
|
| 179 |
1
|
milestoneInfo.getAttributes().put(milestoneAttribute_notes, "Notes for the Last Day to Drop Fall 2008 Semester"); |
| 180 |
|
|
| 181 |
1
|
MilestoneInfo createdMilestone=null; |
| 182 |
1
|
try { |
| 183 |
1
|
createdMilestone = client.addMilestone(atp_fall2008Semester, milestone_lastDateToDropFall2008, milestoneInfo); |
| 184 |
|
} catch (Exception e) { |
| 185 |
0
|
LOG.error(e); |
| 186 |
0
|
fail(); |
| 187 |
|
} |
| 188 |
|
|
| 189 |
|
|
| 190 |
|
|
| 191 |
|
|
| 192 |
1
|
createdAtp.getDesc().setFormatted("Updated Atp for the Fall 2008 Semester"); |
| 193 |
1
|
try { |
| 194 |
1
|
assertEquals("0",createdAtp.getMetaInfo().getVersionInd()); |
| 195 |
1
|
AtpInfo updatedAtp = client.updateAtp(atp_fall2008Semester, createdAtp); |
| 196 |
1
|
assertEquals("1",updatedAtp.getMetaInfo().getVersionInd()); |
| 197 |
1
|
assertEquals("Updated Atp for the Fall 2008 Semester", updatedAtp.getDesc().getFormatted()); |
| 198 |
|
} catch (Exception e) { |
| 199 |
0
|
LOG.error(e); |
| 200 |
0
|
fail(); |
| 201 |
|
} |
| 202 |
|
|
| 203 |
|
|
| 204 |
1
|
try { |
| 205 |
1
|
client.updateAtp(atp_fall2008Semester, createdAtp); |
| 206 |
0
|
fail("AtpService.updateAtp() should have thrown VersionMismatchException"); |
| 207 |
|
} catch (VersionMismatchException vme) { |
| 208 |
|
|
| 209 |
|
} catch (Exception e) { |
| 210 |
0
|
LOG.error(e); |
| 211 |
0
|
fail(); |
| 212 |
|
} |
| 213 |
|
|
| 214 |
|
|
| 215 |
1
|
createdDateRange.getDesc().setFormatted("Updated DateRange for the Finals date range Fall 2008 Semester"); |
| 216 |
1
|
try { |
| 217 |
1
|
assertEquals("0",createdDateRange.getMetaInfo().getVersionInd()); |
| 218 |
1
|
DateRangeInfo updatedDateRange = client.updateDateRange(dateRange_finalsFall2008, createdDateRange); |
| 219 |
1
|
assertEquals("1",updatedDateRange.getMetaInfo().getVersionInd()); |
| 220 |
1
|
assertEquals("Updated DateRange for the Finals date range Fall 2008 Semester", updatedDateRange.getDesc().getFormatted()); |
| 221 |
|
} catch (Exception e) { |
| 222 |
0
|
LOG.error(e); |
| 223 |
0
|
fail(); |
| 224 |
|
} |
| 225 |
|
|
| 226 |
|
|
| 227 |
1
|
try { |
| 228 |
1
|
client.updateDateRange(dateRange_finalsFall2008, createdDateRange); |
| 229 |
0
|
fail("AtpService.updateDateRange() should have thrown VersionMismatchException"); |
| 230 |
|
} catch (VersionMismatchException vme) { |
| 231 |
|
|
| 232 |
|
} catch (Exception e) { |
| 233 |
0
|
LOG.error(e); |
| 234 |
0
|
fail(); |
| 235 |
|
} |
| 236 |
|
|
| 237 |
|
|
| 238 |
1
|
createdMilestone.getDesc().setFormatted("Updated Milestone for fall 2008 semester last day to drop"); |
| 239 |
1
|
try { |
| 240 |
1
|
assertEquals("0",createdMilestone.getMetaInfo().getVersionInd()); |
| 241 |
1
|
MilestoneInfo updatedMilestone = client.updateMilestone(milestone_lastDateToDropFall2008, createdMilestone); |
| 242 |
1
|
assertEquals("1",updatedMilestone.getMetaInfo().getVersionInd()); |
| 243 |
1
|
assertEquals("Updated Milestone for fall 2008 semester last day to drop", updatedMilestone.getDesc().getFormatted()); |
| 244 |
|
} catch (Exception e) { |
| 245 |
0
|
LOG.error(e); |
| 246 |
|
} |
| 247 |
|
|
| 248 |
|
|
| 249 |
1
|
try { |
| 250 |
1
|
client.updateMilestone(milestone_lastDateToDropFall2008, createdMilestone); |
| 251 |
0
|
fail("AtpService.updateDateRange() should have thrown VersionMismatchException"); |
| 252 |
|
} catch (VersionMismatchException vme) { |
| 253 |
|
|
| 254 |
|
} catch (Exception e) { |
| 255 |
0
|
LOG.error(e); |
| 256 |
0
|
fail(); |
| 257 |
|
} |
| 258 |
|
|
| 259 |
|
|
| 260 |
1
|
try { |
| 261 |
1
|
client.deleteAtp(atp_fall2008Semester); |
| 262 |
|
} catch (Exception e) { |
| 263 |
0
|
LOG.error(e); |
| 264 |
0
|
fail(); |
| 265 |
|
} |
| 266 |
|
} |
| 267 |
|
} |