List<Course> courses = instance.getAllCoursesByName();
System.out.println("Number of Courses in DB (Expecting 2): " +
courses.size());
assertEquals(2, courses.size());
Course course1 = courses.get(0);
System.out.println("Course 1 (Expecting CS110): " + course1.getName());
assertEquals("CS110", course1.getName());
CriteriaQuery<Section> cqSection = cb.createQuery(Section.class);
Root<Section> sectionRoot = cqSection.from(Section.class);
TypedQuery<Section> sectionQuery = em.createQuery(cqSection);
List<Section> sections = sectionQuery.getResultList();
System.out.println("Number of Sections in DB (Expecting 4): "
+ sections.size());
System.out.println("Sections in Course: " + course1.getSections().size());
// Validate Original Data was saved to database
CriteriaQuery<Question> cqQuestion = cb.createQuery(Question.class);
Root<Question> questionRoot = cqQuestion.from(Question.class);
TypedQuery<Question> questionQuery = em.createQuery(cqQuestion);
List<Question> questions = questionQuery.getResultList();
System.out.println("Number of Questions in DB (Expecting 3): "
+ questions.size());
assertEquals(3, questions.size());
CriteriaQuery<GradedEvent> cqGradedEvent = cb.createQuery(GradedEvent.class);
Root<GradedEvent> gradedEventRoot = cqGradedEvent.from(GradedEvent.class);
TypedQuery<GradedEvent> gradedEventQuery = em.createQuery(cqGradedEvent);
List<GradedEvent> events = gradedEventQuery.getResultList();
System.out.println("Number of GradedEvents in DB (Expecting 4): "
+ events.size());
assertEquals(4, events.size());
CriteriaQuery<Instructor> cqInstructor = cb.createQuery(Instructor.class);
Root<Instructor> instructorRoot = cqInstructor.from(Instructor.class);
TypedQuery<Instructor> instructorQuery = em.createQuery(cqInstructor);
List<Instructor> instructors = instructorQuery.getResultList();
System.out.println("Number of Instructors in DB (Expecting 2): "
+ instructors.size());
assertEquals(2, instructors.size());
Query query = em.createNativeQuery("SELECT * FROM Course_Instructor WHERE "
+ "course_id = " + course1.getId());
List courseInsResult = query.getResultList();
System.out.println("Number of Instructors for " + course1.getName() +
" (Expecting 2 / 2): "
+ courseInsResult.size() + " / " + course1.getInstructors().size());
assertEquals(2, courseInsResult.size());
assertEquals(2, course1.getInstructors().size());
query = em.createNativeQuery("SELECT * FROM Section_Course WHERE " +
"course_id = " + course1.getId());
List sectionCrsResult = query.getResultList();
System.out.println("Number of Sections in " + course1.getName() +
" (Expecting 2 / 2): " + sectionCrsResult.size() + " / " +
course1.getSections().size());
assertEquals(2, sectionCrsResult.size());
assertEquals(2, course1.getSections().size());
CriteriaQuery<Student> cqStudent = cb.createQuery(Student.class);
Root<Student> studentRoot = cqStudent.from(Student.class);
TypedQuery<Student> studentQuery = em.createQuery(cqStudent);
List<Student> students = studentQuery.getResultList();
System.out.println("Number of Students in DB (Expecting 7): "
+ students.size());
assertEquals(7, students.size());
// Clear the first Course: CS110
System.out.println("Clearing Course 1: " + course1.getName() + " (" +
course1.getId() + ")");
instance.clearCourse(course1);
// GradedEvent data remains, but enrollment and Instructors have been
// cleared
courses = instance.getAllCoursesByName();
System.out.println("(Post) Number of Courses (Expecting 2): " + courses.size());
assertEquals(2, courses.size());
questions = questionQuery.getResultList();
System.out.println("(Post) Number of Questions in DB (Expecting 3): "
+ questions.size());
assertEquals(3, questions.size());
events = gradedEventQuery.getResultList();
System.out.println("(Post) Number of GradedEvents in DB (Expecting 4): "
+ events.size());
assertEquals(4, events.size());
instructors = instructorQuery.getResultList();
System.out.println("(Post) Number of Instructors in DB (Expecting 2): "
+ instructors.size());
assertEquals(2, instructors.size());
query = em.createNativeQuery("SELECT * FROM Course_Instructor WHERE "
+ "course_id = " + course1.getId());
courseInsResult = query.getResultList();
System.out.println("(Post) Number of Instructors for " + course1.getName() +
" (Expecting 0): "
+ courseInsResult.size());
assertEquals(0, courseInsResult.size());
students = studentQuery.getResultList();
System.out.println("(Post) Number of Students in DB (Expecting 7): "
+ students.size());
assertEquals(7, students.size());
sections = sectionQuery.getResultList();
System.out.println("(Post) Number of Sections in DB (Expecting 2): "
+ sections.size());
assertEquals(2, sections.size());
query = em.createNativeQuery("SELECT * FROM Section_Course WHERE " +
"course_id = " + course1.getId());
sectionCrsResult = query.getResultList();
System.out.println("(Post) Number of Sections in " + course1.getName() +
" (Expecting 0): " + sectionCrsResult.size());
assertEquals(0, sectionCrsResult.size());
em.close();
}