Package com.darkhonor.rage.model

Examples of com.darkhonor.rage.model.Course


        System.out.println("getAllCoursesByName");
        assertTrue(instance.isOpen());
        List<Course> courses = instance.getAllCoursesByName();
        assertNotNull(courses);
        assertEquals(2, courses.size());
        Course course1 = courses.get(0);
        assertEquals("CS110", course1.getName());
        Course course2 = courses.get(1);
        assertEquals("CS364", course2.getName());
    }
View Full Code Here


    {
        System.out.println("update - No change to Instructors or Sections");
        assertTrue(instance.isOpen());
        // Verify the original course
        System.out.println("Original: ");
        Course original = createExistingCourse();

        // Update the Name and Course Director fields
        System.out.println("Updated Course: ");
        original.setName("CS192P");
        System.out.println("- Setting Course Director");
        Instructor courseDirector = new Instructor("David", "Roberts", "David.Roberts");
        courseDirector.setDomainAccount(courseDirector.getWebID());
        courseDirector.setId(new Long(5L));
        System.out.println("  -- CD: " + courseDirector.getDomainAccount());
        original.setCourseDirector(courseDirector);

        Course result = instance.update(original);

        // Verify the result
        assertEquals(new Long(1L), result.getId());
        assertEquals("CS192P", result.getName());
        assertNotNull(result.getCourseDirector());
        assertEquals(courseDirector, 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("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 testUpdateNoChangeCD()
    {
        System.out.println("update - No change to Course Director, Instructors, " +
                "or Sections");
        Course course = createExistingCourse();
        course.setName("CS192P");
        assertTrue(instance.isOpen());
        Course result = instance.update(course);
        assertEquals(new Long(1L), result.getId());
        assertEquals("CS192P", 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("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 testUpdateNewCourseDirector()
    {
        System.out.println("update - New Instructor as Course Director");
        Course course = createExistingCourse();
        course.setName("CS192P");
        Instructor courseDirector = new Instructor("James", "Kirk", "James.Kirk");
        courseDirector.setId(50L);
        courseDirector.setDomainAccount(courseDirector.getWebID());
        course.setCourseDirector(courseDirector);

        Course result = instance.update(course);
        // Verify the result
        assertEquals(new Long(1L), result.getId());
        assertEquals("CS192P", result.getName());
        assertNotNull(result.getCourseDirector());
        assertEquals(courseDirector, 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("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 testUpdateRemoveInstructor()
    {
        System.out.println("update - Instructor Removed");
        Course course = createExistingCourse();
        assertEquals(2, course.getInstructors().size());
        Instructor oldIns = new Instructor("Sarah", "O'Reilly", "Sarah.OReilly");
        oldIns.setId(new Long(6L));
        oldIns.setDomainAccount(oldIns.getWebID());
        course.removeInstructor(oldIns);
       
        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(1, result.getInstructors().size());
        Instructor ins1 = result.getInstructor(0);
        assertEquals("David.Roberts", ins1.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();
        CriteriaQuery<Section> cqSection = cb.createQuery(Section.class);
View Full Code Here

     * any access to calling methods.
     */
    public void initialize()
    {
        persistDatabaseVersion(new Double(2.1));
        Course course1 = createTestCourse();
        Course course2 = createSecondCourse();

        Category category1 = createPersistedCategory(1L, "Array");
        Category category2 = createPersistedCategory(2L, "Loop");
        Category category3 = createPersistedCategory(3L, "Iteration");
        // Create some specific TestCases to start with that can be used for testing
View Full Code Here

     */
    private Course createTestCourse()
    {
        EntityManager em = emf.createEntityManager();
        EntityTransaction tx = em.getTransaction();
        Course course = new Course("CS110");
        course.setId(1L);
        tx.begin();
        em.persist(course);
        tx.commit();
        // Create 2 Sections, 2 Students per Section, and 2 Instructors
        Student student1 = createPersistedStudent(1L, "John", "Doe", "C13John.Doe",
                new Integer(2013));
        Student student2 = createPersistedStudent(2L, "Mary", "Johnson", "C13Mary.Johnson",
                new Integer(2013));
        Student student3 = createPersistedStudent(3L, "Bob", "Reimer", "C13Robert.Reimer",
                new Integer(2013));
        Student student4 = createPersistedStudent(4L, "Andrew", "Callow",
                "C13Andrew.Callow", new Integer(2013));

        Section section1 = new Section("M1A");
        section1.setId(new Long(1L));
        Section section2 = new Section("M2B");
        section2.setId(new Long(2L));
        section1.setCourse(course);
        section2.setCourse(course);
       
        Instructor instructor1 = createPersistedInstructor(5L, "David", "Roberts",
                "David.Roberts");
        Instructor instructor2 = createPersistedInstructor(6L, "Sarah", "O'Reilly",
                "Sarah.OReilly");

        // Set the Instructors for Sections 1 & 2
        section1.setInstructor(instructor1);
        section2.setInstructor(instructor2);

        // Add Instructors to Course
        course.addInstructor(instructor1);
        course.addInstructor(instructor2);

        // Add Students 1 & 2 to Section 1
        section1.addStudent(student1);
        student1.addSection(section1);
        section1.addStudent(student2);
        student2.addSection(section1);

        course.addSection(section1);
        course.addSection(section2);

        // Add Students 3 & 4 to Section 2
        section2.addStudent(student3);
        student3.addSection(section2);
        section2.addStudent(student4);
        student4.addSection(section2);

        tx.begin();
        em.persist(section1);
        em.persist(section2);
        em.merge(instructor1);
        em.merge(instructor2);
        em.merge(student1);
        em.merge(student2);
        em.merge(student3);
        em.merge(student4);
        em.merge(course);
        tx.commit();

        LOGGER.info("Saved Course (" + course + ") to database with " +
                course.getSections().size() + " sections and " +
                course.getInstructors().size() + " instructors");
        em.close();
        return course;
    }
View Full Code Here

    private Course createSecondCourse()
    {
        EntityManager em = emf.createEntityManager();
        EntityTransaction tx = em.getTransaction();
        // Create Second Course
        Course course = new Course("CS364");
        course.setId(2L);
        tx.begin();
        em.persist(course);
        tx.commit();
        // Create 2 Sections, 2 Students per Section, and 2 Instructors
        Student student1 = createPersistedStudent(7L, "John", "Doe", "C11John.Doe",
                new Integer(2011));
        Student student2 = createPersistedStudent(8L, "Mary", "Johnson",
                "C11Mary.Johnson", new Integer(2011));
        Student student3 = createPersistedStudent(3L, "Bob", "Reimer",
                "C13Robert.Reimer", new Integer(2013));
        Student student4 = createPersistedStudent(4L, "Andrew", "Callow",
                "C13Andrew.Callow", new Integer(2013));
        Student student5 = createPersistedStudent(9L, "Kerry", "Beevers",
                "C11Kerry.Beevers", new Integer(2011));

        Instructor instructor1 = createPersistedInstructor(5L, "David", "Roberts",
                "David.Roberts");

        Section section1 = new Section("T5A");
        section1.setId(new Long(3L));
        Section section2 = new Section("T6A");
        section2.setId(new Long(4L));
        section1.setCourse(course);
        section2.setCourse(course);

        // Set the Instructors for Sections 1 & 2
        section1.setInstructor(instructor1);
        section2.setInstructor(instructor1);

        // Add Instructors to Course
        course.addInstructor(instructor1);

        // Add Students 1 & 2 to Section 1
        section1.addStudent(student1);
        student1.addSection(section1);
        section1.addStudent(student2);
        student2.addSection(section1);

        course.addSection(section1);
        course.addSection(section2);

        // Add Students 3 & 4 to Section 2
        section2.addStudent(student3);
        student3.addSection(section2);
        section2.addStudent(student4);
        student4.addSection(section2);
        section2.addStudent(student5);
        student5.addSection(section2);

        tx.begin();
        em.persist(section1);
        em.persist(section2);
        em.merge(instructor1);
        em.merge(student1);
        em.merge(student2);
        em.merge(student3);
        em.merge(student4);
        em.merge(student5);
        em.merge(course);
        tx.commit();

        LOGGER.info("Saved Course (" + course + ") to database with " +
                course.getSections().size() + " sections and " +
                course.getInstructors().size() + " instructors");
        em.close();
        return course;
    }
View Full Code Here

            LOGGER.warn("Section already in database: " + section);
        } catch (NoResultException ex)
        {
            section = new Section(name);
            section.setId(id);
            Course dbCourse = em.find(Course.class, course.getId());
            section.setCourse(dbCourse);
            dbCourse.addSection(section);
            EntityTransaction tx = em.getTransaction();
            tx.begin();
            em.persist(section);
            em.merge(dbCourse);
            tx.commit();
View Full Code Here

     */
    private Course createPersistedCourse(Long id, String name)
    {
        EntityManager em = emf.createEntityManager();
        EntityTransaction tx = em.getTransaction();
        Course course = new Course(name);
        course.setId(id);

        tx.begin();
        em.persist(course);
        tx.commit();

        LOGGER.info("Saved Course (" + course + ") to database with " +
                course.getSections().size() + " sections and " +
                course.getInstructors().size() + " instructors");
        em.close();
        return course;
    }
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.