Package com.darkhonor.rage.model

Examples of com.darkhonor.rage.model.Course


        CriteriaBuilder cb = em.getCriteriaBuilder();
        // Get the Course from the database for the GradedEvent creation
        List<Course> courses = instance.getAllCoursesByName();
        System.out.println("Number of Courses (Expecting 2): " + courses.size());
        assertEquals(2, courses.size());
        Course course = createExistingCourse();

        // Validate Original Data was saved to database
        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: " + course.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());

        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());

        System.out.println("Removing Course 1");
        course.setId(null);
        instance.delete(course);

        // Validate GradedEvent for second course has not been deleted, but first
        // has
        courses = instance.getAllCoursesByName();
View Full Code Here


    public void testDeleteClosedConnection()
    {
        System.out.println("delete - Closed Connection");
        assertTrue(instance.isOpen());
        instance.closeConnection();
        Course course = createExistingCourse();
        instance.delete(course);
    }
View Full Code Here

    @Test(expected=NullPointerException.class)
    public void testDeleteNullCourse()
    {
        System.out.println("delete - Null Course");
        assertTrue(instance.isOpen());
        Course course = null;
        instance.delete(course);
    }
View Full Code Here

    @Test(expected=NullPointerException.class)
    public void testDeleteNullCourseName()
    {
        System.out.println("delete - Null Course Name");
        assertTrue(instance.isOpen());
        Course course = new Course();
        course.setId(new Long(1L));
        instance.delete(course);
    }
View Full Code Here

        CriteriaBuilder cb = em.getCriteriaBuilder();
        // Get the Course from the database for the GradedEvent creation
        List<Course> courses = instance.getAllCoursesByName();
        System.out.println("Number of Courses (Expecting 2): " + courses.size());
        assertEquals(2, courses.size());
        Course course1 = createExistingCourse();

        // Validate Original Data was saved to database
        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());

        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());

        System.out.println("Removing Course 2");
        Long id = new Long(2L);
        instance.delete(id);

        // Validate GradedEvent for second course has not been deleted, but first
        // has
        courses = instance.getAllCoursesByName();
        System.out.println("(Post) Number of Courses (Expecting 1): " + courses.size());
        assertEquals(1, courses.size());
        System.out.println("(Post) Expecting remaining course (CS110): " +
                courses.get(0).getName());
        assertEquals("CS110", courses.get(0).getName());

        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 3): "
                + events.size());
        assertEquals(3, events.size());

        instructors = instructorQuery.getResultList();
        System.out.println("(Post) Number of Instructors in DB (Expecting 2): "
                + instructors.size());
        assertEquals(2, instructors.size());

        Query query = em.createNativeQuery("SELECT * FROM Course_Instructor");
        List courseInsResult = query.getResultList();
        System.out.println("(Post) Number of Linked Instructor/Courses (Expecting 2): "
                + courseInsResult.size());
        assertEquals(2, courseInsResult.size());

        sections = sectionQuery.getResultList();
        System.out.println("(Post) Number of Sections in DB (Expecting 2): "
                + sections.size());
        assertEquals(2, sections.size());

        students = studentQuery.getResultList();
        System.out.println("(Post) Number of Students in DB (Expecting 7): "
                + students.size());
        assertEquals(7, students.size());

        em.close();
        Course deletedCourse = instance.find(id);
        assertNull(deletedCourse);
    }
View Full Code Here

        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();
    }
View Full Code Here

   
    @Test
    public void testUpdateInstructorsNewInstructor()
    {
        System.out.println("update - New Instructor added");
        Course course = createExistingCourse();
        assertEquals(2, course.getInstructors().size());
       
        Instructor newIns = new Instructor("John", "Smith", "John.Smith");
        newIns.setId(new Long(42L));
        newIns.setDomainAccount(newIns.getWebID());
        course.addInstructor(newIns);

        assertTrue(instance.isOpen());
        Course result = instance.update(course);
        assertEquals(new Long(1L), result.getId());
        assertEquals("CS110", result.getName());
        assertNull(result.getCourseDirector());
        assertNotNull(result.getInstructors());
        assertEquals(3, result.getInstructors().size());
        Instructor ins1 = result.getInstructor(0);
        assertEquals("David.Roberts", ins1.getDomainAccount());
        Instructor ins2 = result.getInstructor(1);
        assertEquals("Sarah.OReilly", ins2.getDomainAccount());
        Instructor ins3 = result.getInstructor(2);
        assertEquals("John.Smith", ins3.getDomainAccount());
        assertNotNull(result.getSections());
        assertEquals(2, result.getSections().size());
        for (int i = 0; i < result.getSections().size(); i++)
        {
            Section section = result.getSection(i);
            System.out.println("- Section: " + section + ", Id: " + section.getId());
        }
        assertTrue(result.getSection(0).getName().equals("M1A") ||
                result.getSection(0).getName().equals("M2B"));
        assertTrue(result.getSection(1).getName().equals("M1A") ||
                result.getSection(1).getName().equals("M2B"));


        // Verify the data in the database
        EntityManager em = testDb.getConnection();
        CriteriaBuilder cb = em.getCriteriaBuilder();
View Full Code Here

    @Test
    public void testUpdateClearInstructors()
    {
        System.out.println("update - Clear Instructors");
        Course course = createExistingCourse();
        course.clearInstructors();
       
        assertTrue(instance.isOpen());
        Course result = instance.update(course);
        assertEquals(new Long(1L), result.getId());
        assertEquals("CS110", result.getName());
        assertNull(result.getCourseDirector());
        assertNotNull(result.getInstructors());
        assertEquals(0, result.getInstructors().size());
        assertNotNull(result.getSections());
        assertEquals(2, result.getSections().size());
        for (int i = 0; i < result.getSections().size(); i++)
        {
            Section section = result.getSection(i);
            System.out.println("- Section: " + section + ", Id: " + section.getId());
        }
        assertTrue(result.getSection(0).getName().equals("M1A") ||
                result.getSection(0).getName().equals("M2B"));
        assertTrue(result.getSection(1).getName().equals("M1A") ||
                result.getSection(1).getName().equals("M2B"));

        // Verify the data in the database
        EntityManager em = testDb.getConnection();
        CriteriaBuilder cb = em.getCriteriaBuilder();
        CriteriaQuery<Section> cqSection = cb.createQuery(Section.class);
View Full Code Here

    @Test
    public void testUpdateSections()
    {
        System.out.println("update - Sections Updated");
        Course course = createExistingCourse();

        course.getSection(0).setName("M3A");

        assertTrue(instance.isOpen());
        Course result = instance.update(course);
        assertEquals(new Long(1L), result.getId());
        assertEquals("CS110", result.getName());
        assertNull(result.getCourseDirector());
        assertNotNull(result.getInstructors());
        assertEquals(2, result.getInstructors().size());
        Instructor ins1 = result.getInstructor(0);
        assertEquals("David.Roberts", ins1.getDomainAccount());
        Instructor ins2 = result.getInstructor(1);
        assertEquals("Sarah.OReilly", ins2.getDomainAccount());
        assertNotNull(result.getSections());
        assertEquals(2, result.getSections().size());
        for (int i = 0; i < result.getSections().size(); i++)
        {
            Section section = result.getSection(i);
            System.out.println("- Section: " + section + ", Id: " + section.getId());
        }
        assertTrue(result.getSection(0).getName().equals("M3A") ||
                result.getSection(0).getName().equals("M2B"));
        assertTrue(result.getSection(1).getName().equals("M3A") ||
                result.getSection(1).getName().equals("M2B"));

        // Verify the data in the database
        EntityManager em = testDb.getConnection();
        CriteriaBuilder cb = em.getCriteriaBuilder();
        CriteriaQuery<Section> cqSection = cb.createQuery(Section.class);
View Full Code Here

    @Test
    public void testUpdateSectionRemoved()
    {
        System.out.println("update - Section Removed");
        Course course = createExistingCourse();

        Section removedSect = new Section("M2B");
        removedSect.setId(new Long(2L));
        removedSect.setCourse(course);
        course.removeSection(removedSect);

        assertTrue(instance.isOpen());
        Course result = instance.update(course);
        assertEquals(new Long(1L), result.getId());
        assertEquals("CS110", result.getName());
        assertNull(result.getCourseDirector());
        assertNotNull(result.getInstructors());
        assertEquals(2, result.getInstructors().size());
        Instructor ins1 = result.getInstructor(0);
        assertEquals("David.Roberts", ins1.getDomainAccount());
        Instructor ins2 = result.getInstructor(1);
        assertEquals("Sarah.OReilly", ins2.getDomainAccount());
        assertNotNull(result.getSections());
        assertEquals(1, result.getSections().size());
        for (int i = 0; i < result.getSections().size(); i++)
        {
            Section section = result.getSection(i);
            System.out.println("- Section: " + section + ", Id: " + section.getId());
        }
        Section sec1 = result.getSection(0);
        assertEquals("M1A", sec1.getName());

        // Verify the data in the database
        EntityManager em = testDb.getConnection();
        CriteriaBuilder cb = em.getCriteriaBuilder();
View Full Code Here

TOP

Related Classes of com.darkhonor.rage.model.Course

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.