@Test public void testAddNewOutcomeEvaluationForAssignmentFeedback() { Student student = studentDao.getStudentById(1000000L); AssignmentRecord r = student.getRecord().getSbgGrades().get(0); AssignmentFeedback f = r.getFeedback().get(0); Assert.assertEquals(2, f.getGrades().size()); OutcomeEvaluation grade = new OutcomeEvaluation(); Outcome o = new Outcome(); o.setId(100002L); // Should be 'Pipeline outputs between various programs' grade.setOutcome(o); grade.setComment("Woops"); f.getGrades().add(grade); studentDao.createOrUpdateStudent(student); Student student2 = studentDao.getStudentById(1000000L); AssignmentRecord r2 = student2.getRecord().getSbgGrades().get(0); AssignmentFeedback f2 = r2.getFeedback().get(0); Assert.assertEquals(3, f2.getGrades().size()); OutcomeEvaluation eval = f2.getGrades().get(0); Assert.assertEquals("Woops", eval.getComment()); Assert.assertEquals( "Pipeline outputs between various programs", eval.getOutcome().getDescription()); Assert.assertEquals(Long.valueOf(100002L), eval.getOutcome().getId()); }
@Test public void testCreateOrUpdateStudentGrades() { // Build the grade list. List<GPA> grades = new ArrayList<GPA>(); // We leave the correctness of the GET to other unit tests. GPA gpa = new GPA(); gpa.setTerm(Term.SPRING); gpa.setYear(2017); gpa.setGpa(2.75); grades.add(gpa); gpa = new GPA(); gpa.setTerm(Term.SUMMER); gpa.setYear(2015); gpa.setGpa(2.0); grades.add(gpa); Student student = studentDao.getStudentById(1000000L); student.getRecord().setGrades(grades); studentDao.createOrUpdateStudent(student); // We check that the grades were indeed saved. grades = studentDao.getStudentById(1000000L).getRecord().getGrades(); Assert.assertEquals(2, grades.size()); Assert.assertEquals(Term.SUMMER, grades.get(0).getTerm()); Assert.assertEquals(2015, grades.get(0).getYear()); Assert.assertEquals(2.0, grades.get(0).getGpa(), 0.0); Assert.assertEquals(Term.SPRING, grades.get(1).getTerm()); Assert.assertEquals(2017, grades.get(1).getYear()); Assert.assertEquals(2.75, grades.get(1).getGpa(), 0.0); }
@Test public void testCreateOrUpdateStudentAddMajorsAndMinors() { // Grab a test fixture student. Student student = studentDao.getStudentById(1000001L); // Add a major and some minors. Major major = new Major(); major.setCollegeOrSchool("Science"); major.setDegree("BS"); major.setDiscipline("Biology"); student.getMajors().add(major); student.getMinors().add("Physics"); student.getMinors().add("Chemistry"); studentDao.createOrUpdateStudent(student); // Now re-grab and check. student = studentDao.getStudentById(1000001L); Assert.assertEquals(1, student.getMajors().size()); Assert.assertEquals(2, student.getMinors().size()); Assert.assertEquals("Biology", student.getMajors().get(0).getDiscipline()); Assert.assertEquals("Physics", student.getMinors().get(0)); Assert.assertEquals("Chemistry", student.getMinors().get(1)); }
@Test public void testFindByName() { StudentDao dao = Mockito.mock(StudentDao.class); StudentService service = new StudentService(dao); service.findByName("alice"); verify(dao, times(1)).findByName("alice"); when(dao.findByName("alice")).thenReturn(Arrays.asList(new Student[] {})); service.findByName("alice"); assertThat(service.findByName("alice").size(), equalTo(0)); }
@Test public void testCreatOrUpdateStudentFoodPreference() { Student student = studentDao.getStudentById(1000000L); List<String> foodPreference = new ArrayList<String>(); foodPreference.add("vegetarian"); foodPreference.add("glutenfree"); student.setFoodPreference(foodPreference); studentDao.createOrUpdateStudent(student); student = studentDao.getStudentById(1000000L); Assert.assertEquals(foodPreference.get(0), student.getFoodPreference().get(0)); Assert.assertEquals(foodPreference.get(1), student.getFoodPreference().get(1)); }
@Test public void testGetStudentsByCumulativeGpaAndTransfer() { List<Student> students = studentDao.getStudents( null, null, true, null, null, 3.5, 4.0, null, null, null, null, null, 0, 10); Assert.assertEquals(2, students.size()); Assert.assertEquals(Long.valueOf(1000008), students.get(0).getId()); Assert.assertEquals(Long.valueOf(1000009), students.get(1).getId()); students = studentDao.getStudents( null, null, true, null, null, 4.0, null, null, null, null, null, null, 0, 10); Assert.assertEquals(0, students.size()); }
@Test public void testGetStudentsByTermGpaAndTransfer() { List<Student> students = studentDao.getStudents( null, null, true, null, null, null, null, 3.7, 4.0, Term.FALL, 2012, null, 0, 10); Assert.assertEquals(2, students.size()); Assert.assertEquals("Ferguson", students.get(0).getLastName()); Assert.assertEquals("McBean", students.get(1).getLastName()); students = studentDao.getStudents( null, null, true, null, null, null, null, 4.0, 4.0, Term.FALL, 2012, null, 0, 10); Assert.assertEquals(0, students.size()); }
@Test public void testGetStudentById() { // Grab a test fixture student. Student student = studentDao.getStudentById(1000000L); Assert.assertEquals(Long.valueOf(1000000L), student.getId()); Assert.assertEquals("Berners-Lee", student.getLastName()); Assert.assertEquals("Tim", student.getFirstName()); Assert.assertTrue(student.isActive()); Assert.assertEquals(Integer.valueOf(2016), student.getExpectedGraduationYear()); // The text fixture data has some empty values. Assert.assertNull(student.getMiddleName()); Assert.assertNull(student.getEntryYear()); Assert.assertEquals(0, student.getMajors().size()); Assert.assertEquals(0, student.getMinors().size()); Assert.assertEquals(0, student.getRecord().getGrades().size()); // Grant and event data do not come along for the ride. try { student.getGrants().size(); // If this doesn't bork, something is wrong. Assert.fail("getGrants should not succeed, but did."); } catch (LazyInitializationException lazyInitializationException) { // This is what should happen; carry on. } try { student.getAttendance().size(); // If this doesn't bork, something is wrong. Assert.fail("getAttendance should not succeed, but did."); } catch (LazyInitializationException lazyInitializationException) { // This is what should happen; carry on. } }
private void populateLaboratoryFields(Laboratory laboratory) throws DaoEntityNotFoundException { Hour from = hourDao.getHourByValue(laboratory.getFrom().getValue()); Hour to = hourDao.getHourByValue(laboratory.getTo().getValue()); Professor professor = professorDao.getProfessorByPnc(laboratory.getProfessor().getPnc()); Room room = roomDao.getRoomByName(laboratory.getRoom().getName()); Day day = dayDao.getDayByValue(laboratory.getDay().getValue()); Section section = sectionDao.getSectionByName(laboratory.getSection().getName()); Group group = groupDao.getGroupByName(laboratory.getGroup().getName()); Subgroup subgroup = subgroupDao.getSubgroupByName(laboratory.getSubgroup().getName()); Year year = yearDao.getYearByValue(laboratory.getYear().getValue()); Semester semester = semesterDao.getSemesterByValue(laboratory.getSemester().getValue()); WeeklyOccurrence weeklyOccurrence = weeklyOccurrenceDao.getWeeklyOccurrenceByName(laboratory.getWeeklyOccurrence().getName()); List<Student> students = studentDao.getStudents(section, year, semester, group, subgroup); laboratory.setFrom(from); laboratory.setTo(to); laboratory.setProfessor(professor); laboratory.setRoom(room); laboratory.setDay(day); laboratory.setSection(section); laboratory.setGroup(group); laboratory.setSubgroup(subgroup); laboratory.setYear(year); laboratory.setSemester(semester); laboratory.setWeeklyOccurrence(weeklyOccurrence); laboratory.setStudents(students); }
@Override public void updateLaboratory(LaboratoryDto laboratoryDto) throws ServiceEntityNotFoundException { try { Laboratory laboratory = laboratoryDao.getLaboratoryById(laboratoryDto.getId()); boolean studentsNeedUpdate = studentsNeedUpdate(laboratory, laboratoryDto); updateLaboratoryFields(laboratory, laboratoryDto); laboratoryDao.updateLaboratory(laboratory); if (studentsNeedUpdate) { laboratory.getStudents().clear(); List<Student> students = studentDao.getStudents( laboratory.getSection(), laboratory.getYear(), laboratory.getSemester(), laboratory.getGroup(), laboratory.getSubgroup()); laboratory.setStudents(students); } } catch (DaoEntityNotFoundException e) { LOGGER.debug("DaoEntityNotFoundException"); throw new ServiceEntityNotFoundException(e); } }
@Test public void testGetStudentAttendanceByIdForStudentWithNoEvents() { // We get a non-null but empty list for a student without events. List<Event> events = studentDao.getStudentAttendanceById(1000003L); Assert.assertNotNull(events); Assert.assertEquals(0, events.size()); }
@Test public void testGetStudentsByTermGpaMaxAndMin() { List<Student> students = studentDao.getStudents( null, null, null, null, null, null, null, 3.7, 3.7, Term.FALL, 2012, null, 0, 10); Assert.assertEquals(1, students.size()); Assert.assertEquals("McBean", students.get(0).getLastName()); }
@Test public void testGetStudentByTermGpaMaximumOnly() { List<Student> students = studentDao.getStudents( null, null, null, null, null, null, null, null, 3.9, Term.FALL, 2012, null, 0, 10); Assert.assertEquals(2, students.size()); Assert.assertEquals("Turd", students.get(0).getFirstName()); Assert.assertEquals("Trevor", students.get(1).getFirstName()); }
@Test public void testGetStudentByGpaBothMinimumAndMaximum() { List<Student> students = studentDao.getStudents( null, null, null, null, null, 3.39, 3.91, null, null, null, null, null, 0, 10); Assert.assertEquals(2, students.size()); Assert.assertEquals(Long.valueOf(1000008), students.get(0).getId()); Assert.assertEquals(Long.valueOf(1000009), students.get(1).getId()); }
@Test public void testGetStudentByGpaWithOnlyMaximum() { List<Student> students = studentDao.getStudents( null, null, null, null, null, null, 3.0, null, null, null, null, null, 0, 10); Assert.assertEquals(2, students.size()); Assert.assertEquals(Long.valueOf(1000005), students.get(0).getId()); Assert.assertEquals(Long.valueOf(1000006), students.get(1).getId()); }
@Test public void testGetStudentsByEnrolledCourse() { List<Student> students = studentDao.getStudents( null, null, null, null, null, null, null, null, null, null, null, 100001L, 0, 10); Assert.assertEquals(2, students.size()); Assert.assertEquals(Long.valueOf(1000000L), students.get(0).getId()); Assert.assertEquals(Long.valueOf(1000001L), students.get(1).getId()); }
public static void main(String[] args) { StudentDao studentDao = new StudentDaoImpl(); // print all students for (Student student : studentDao.getAllStudents()) { System.out.println( "Student: [RollNo : " + student.getRollNo() + ", Name : " + student.getName() + " ]"); } // update student Student student = studentDao.getAllStudents().get(0); student.setName("Michael"); studentDao.updateStudent(student); // get the student studentDao.getStudent(0); System.out.println( "Student: [RollNo : " + student.getRollNo() + ", Name : " + student.getName() + " ]"); }
@Test public void testUpdatingAssignmentFeedback() { Student student = studentDao.getStudentById(1000000L); Assert.assertEquals(1, student.getRecord().getSbgGrades().size()); AssignmentRecord r = student.getRecord().getSbgGrades().get(0); AssignmentFeedback f = r.getFeedback().get(0); OutcomeEvaluation eval = f.getGrades().get(0); Assert.assertEquals("Good job!", eval.getComment()); Assert.assertEquals(Long.valueOf(100001L), eval.getId()); eval.setComment("Bad job!"); studentDao.createOrUpdateStudent(student); Student student2 = studentDao.getStudentById(1000000L); AssignmentRecord r2 = student2.getRecord().getSbgGrades().get(0); AssignmentFeedback f2 = r2.getFeedback().get(0); OutcomeEvaluation eval2 = f2.getGrades().get(0); Assert.assertEquals("Bad job!", eval2.getComment()); Assert.assertEquals(Long.valueOf(100001L), eval2.getId()); }
@Test public void testGetStudentsByLastName() { // When without commas and not all-digits, the student query is hits on // "last name starts with query," case insensitive. List<Student> students = studentDao.getStudents( "cer", null, null, null, null, null, null, null, null, null, null, null, 0, 10); Assert.assertEquals(1, students.size()); Assert.assertEquals(Long.valueOf(1000001L), students.get(0).getId()); students = studentDao.getStudents( "k", null, null, null, null, null, null, null, null, null, null, null, 0, 10); Assert.assertEquals(2, students.size()); // Search results are sorted by last name, first name. Assert.assertEquals(Long.valueOf(1000004L), students.get(0).getId()); Assert.assertEquals(Long.valueOf(1000002L), students.get(1).getId()); }
@Test public void testGetStudentsBySpecificExpectedGraduationYear() { List<Student> students = studentDao.getStudents( null, null, null, 2015, 2015, null, null, null, null, null, null, null, 0, 10); Assert.assertEquals(2, students.size()); // Search results are sorted by last name, first name. Assert.assertEquals(Long.valueOf(1000001L), students.get(0).getId()); Assert.assertEquals(Long.valueOf(1000002L), students.get(1).getId()); }
@Test public void testGetInactiveStudents() { List<Student> students = studentDao.getStudents( null, Boolean.FALSE, null, null, null, null, null, null, null, null, null, null, 0, 10); Assert.assertEquals(2, students.size()); // Search results are sorted by last name, first name. Assert.assertEquals(Long.valueOf(1000001L), students.get(0).getId()); Assert.assertEquals(Long.valueOf(1000003L), students.get(1).getId()); }
@Test public void testGetStudentAttendanceById() { // Verify that the text fixture event attendance comes out correctly. for (long l = 1000000L; l < 1000003L; l++) { List<Event> events = studentDao.getStudentAttendanceById(l); Assert.assertEquals(1, events.size()); Assert.assertEquals(Long.valueOf(1000000L), events.get(0).getId()); Assert.assertEquals("Summit", events.get(0).getTitle()); Assert.assertEquals("The big one", events.get(0).getDescription()); } }
@Test public void testGetStudentByIdMajorsAndMinors() { // One of the test fixture students has majors and minors. Student student = studentDao.getStudentById(1000002L); Assert.assertEquals(2, student.getMajors().size()); Assert.assertEquals(1, student.getMinors().size()); // Majors and minors are manually ordered. Assert.assertEquals("Computer Science", student.getMajors().get(0).getDiscipline()); Assert.assertEquals("Mathematics", student.getMajors().get(1).getDiscipline()); Assert.assertEquals("Music", student.getMinors().get(0)); }
/* * Tests for SBG Student records */ @Test public void testCheckStudentSBGGradeRecord() { Student student = studentDao.getStudentById(1000000L); Assert.assertEquals(1, student.getRecord().getSbgGrades().size()); AssignmentRecord r = student.getRecord().getSbgGrades().get(0); Assert.assertEquals(Long.valueOf(100001L), r.getId()); Assert.assertEquals(1, r.getFeedback().size()); AssignmentFeedback f = r.getFeedback().get(0); Assert.assertEquals(Long.valueOf(100001L), f.getAssignment().getId()); Assert.assertEquals(2, f.getGrades().size()); Assert.assertEquals("Good job!", f.getGrades().get(0).getComment()); Assert.assertEquals("Needs work...", f.getGrades().get(1).getComment()); }
@Test public void testGetMatchingDisciplines() { // "ic" should match both Mathematics and Music. List<String> results = studentDao.getMatchingDisciplines("ic", 0, 50); Assert.assertEquals(2, results.size()); Assert.assertEquals("Mathematics", results.get(0)); Assert.assertEquals("Music", results.get(1)); // "comp" should match only Computer Science. results = studentDao.getMatchingDisciplines("comp", 0, 50); Assert.assertEquals(1, results.size()); Assert.assertEquals("Computer Science", results.get(0)); // "us" should match only Music. results = studentDao.getMatchingDisciplines("us", 0, 50); Assert.assertEquals(1, results.size()); Assert.assertEquals("Music", results.get(0)); // "cucaracha" should match nothing. results = studentDao.getMatchingDisciplines("cucaracha", 0, 50); Assert.assertEquals(0, results.size()); }
@Test public void testGetMatchingDegrees() { // "b" should match both BA and BS. List<String> results = studentDao.getMatchingDegrees("b", 0, 50); Assert.assertEquals(2, results.size()); Assert.assertEquals("BA", results.get(0)); Assert.assertEquals("BS", results.get(1)); // "s" should match only BS. results = studentDao.getMatchingDegrees("s", 0, 50); Assert.assertEquals(1, results.size()); Assert.assertEquals("BS", results.get(0)); // "a" should match only BA. results = studentDao.getMatchingDegrees("a", 0, 50); Assert.assertEquals(1, results.size()); Assert.assertEquals("BA", results.get(0)); // "bazinga" should match nothing. results = studentDao.getMatchingDegrees("bazinga", 0, 50); Assert.assertEquals(0, results.size()); }
@Test public void testGetMatchingCollegesOrSchools() { // "en" should match both science and engineering. List<String> results = studentDao.getMatchingCollegesOrSchools("en", 0, 50); Assert.assertEquals(2, results.size()); Assert.assertEquals("Engineering", results.get(0)); Assert.assertEquals("Science", results.get(1)); // "sc" should match only science. results = studentDao.getMatchingCollegesOrSchools("sc", 0, 50); Assert.assertEquals(1, results.size()); Assert.assertEquals("Science", results.get(0)); // "eer" should match only engineering. results = studentDao.getMatchingCollegesOrSchools("eer", 0, 50); Assert.assertEquals(1, results.size()); Assert.assertEquals("Engineering", results.get(0)); // "zatoichi" should match nothing. results = studentDao.getMatchingCollegesOrSchools("zatoichi", 0, 50); Assert.assertEquals(0, results.size()); }
@Test public void testGetStudentByIdGrades() { // One of the test fixture students has grades. List<GPA> grades = studentDao.getStudentById(1000002L).getRecord().getGrades(); Assert.assertEquals(2, grades.size()); // We expect grades to be sorted by year then term. Assert.assertEquals(Term.FALL, grades.get(0).getTerm()); Assert.assertEquals(2015, grades.get(0).getYear()); Assert.assertEquals(3.8, grades.get(0).getGpa(), 0.0); Assert.assertEquals(Term.SPRING, grades.get(1).getTerm()); Assert.assertEquals(2016, grades.get(1).getYear()); Assert.assertEquals(3.5, grades.get(1).getGpa(), 0.0); }
@Test public void testGetTransferStudents() { List<Student> students = studentDao.getStudents( null, null, Boolean.TRUE, null, null, null, null, null, null, null, null, null, 0, 10); Assert.assertEquals(7, students.size()); // Search results are sorted by last name, first name. Assert.assertEquals(Long.valueOf(1000000L), students.get(0).getId()); Assert.assertEquals(Long.valueOf(1000005L), students.get(1).getId()); Assert.assertEquals(Long.valueOf(1000004L), students.get(2).getId()); Assert.assertEquals(Long.valueOf(1000002L), students.get(3).getId()); Assert.assertEquals(Long.valueOf(1000006L), students.get(4).getId()); Assert.assertEquals(Long.valueOf(1000008L), students.get(5).getId()); Assert.assertEquals(Long.valueOf(1000009L), students.get(6).getId()); }
private static void testDatabase() { Student student = (Student) studentDao.list("stud1").toArray()[0]; System.out.println("last name: " + student.getLastName()); System.out.println("group name: " + student.getGroup().getName()); for (Student student1 : student.getGroup().getStudentList()) { System.out.println("students in group: " + student1.getFirstName()); } System.out.println("curator last name: " + student.getGroup().getCurator().getLastName()); for (GroupLection groupLection : student.getGroup().getCurator().getGroupLectionList()) { System.out.println("group lection time: " + groupLection.getDate()); } LossStudent lossStudent = (LossStudent) lossStudentDao.list().toArray()[0]; System.out.println( lossStudent.getDate() + " " + lossStudent.getStudent().getLastName() + " " + lossStudent.getLection().getName()); }