Package com.darkhonor.rage.model

Examples of com.darkhonor.rage.model.Course


    private void persistSectionInstructor(Section section, Instructor instructor)
    {
        EntityManager em = emf.createEntityManager();
        EntityTransaction tx = em.getTransaction();
        Section dbSection = em.find(Section.class, section.getId());
        Course dbCourse = em.find(Course.class, section.getCourse().getId());
        Instructor dbInstructor = em.find(Instructor.class, instructor.getId());
        dbSection.setInstructor(dbInstructor);
        dbInstructor.addSection(dbSection);
        if (dbCourse.getInstructors().contains(dbInstructor))
        {
            LOGGER.warn("Instructor already in the course");
        } else
        {
            dbCourse.addInstructor(dbInstructor);
        }
        tx.begin();
        em.merge(dbSection);
        em.merge(dbInstructor);
        em.merge(dbCourse);
View Full Code Here


     */
    @Test
    public void testCreate()
    {
        System.out.println("create");
        Course testCourse = createTestCourse();
        Long newId = instance.create(testCourse);
        assertNotNull(newId);
        assertEquals(new Long(15L), newId);


        EntityManager em = testDb.getConnection();
        List<Course> courses = instance.getAllCoursesByName();
        System.out.println("Number of Courses (Expecting 1): " + courses.size());
        if (courses.size() > 1)
        {
            for (int i = 0; i < courses.size(); i++)
            {
                Course crs = (Course) courses.get(i);
                System.out.println("Course " + i + ": " + crs.getName()
                        + " (ID: " + crs.getId() + ")");
            }
        }
        assertEquals(3, courses.size());
        Course course = (Course) courses.get(0);
        System.out.println("Course (Expecting CS110): " + course.getName());
        assertEquals("CS110", course.getName());
        // Instructors are Eagerly loaded.  Sections are lazily loaded
        System.out.println("Number of Instructors in Course (Expecting 2): "
                + course.getInstructors().size());
        assertEquals(2, course.getInstructors().size());
        System.out.println("Number of Sections in Course (Expecting 2): "
                + course.getSections().size());
        assertEquals(2, course.getSections().size());

        Query query = em.createQuery("SELECT ins FROM Instructor ins");
        List instructors = query.getResultList();
        System.out.println("Number of Instructors in DB (Expecting 4): "
                + instructors.size());
View Full Code Here

    @Test
    public void testCreateNullId()
    {
        System.out.println("create - null Id");
        Course testCourse = createTestCourse();
        Long newId = instance.create(testCourse);
        assertNotNull(newId);

        EntityManager em = testDb.getConnection();
        List<Course> courses = instance.getAllCoursesByName();
        System.out.println("Number of Courses (Expecting 1): " + courses.size());
        if (courses.size() > 1)
        {
            for (int i = 0; i < courses.size(); i++)
            {
                Course crs = (Course) courses.get(i);
                System.out.println("Course " + i + ": " + crs.getName()
                        + " (ID: " + crs.getId() + ")");
            }
        }
        assertEquals(3, courses.size());
        Query query = em.createQuery("SELECT ins FROM Instructor ins");
View Full Code Here

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

    @Test(expected=IllegalArgumentException.class)
    public void testCreateNegativeId()
    {
        System.out.println("create - Negative Id");
        assertTrue(instance.isOpen());
        Course course = createTestCourse();
        course.setId(new Long(-5L));
        Long newId = instance.create(course);
    }
View Full Code Here

    @Test(expected=IllegalArgumentException.class)
    public void testCreateNullName()
    {
        System.out.println("create - Null Name");
        assertTrue(instance.isOpen());
        Course course = createTestCourse();
        course.setName(null);
        Long newId = instance.create(course);
    }
View Full Code Here

    @Test(expected=IllegalArgumentException.class)
    public void testCreateBlankName()
    {
        System.out.println("create - Blank Name");
        assertTrue(instance.isOpen());
        Course course = createTestCourse();
        course.setName("");
        Long newId = instance.create(course);
    }
View Full Code Here

    {
        System.out.println("create - Closed Connection");
        assertTrue(instance.isOpen());
        instance.closeConnection();
        assertFalse(instance.isOpen());
        Course course = createTestCourse();
        Long newId = instance.create(course);
    }
View Full Code Here

    @Test(expected = IllegalArgumentException.class)
    public void testCreateDuplicateCourse()
    {
        System.out.println("create - Duplicate Course");
        assertTrue(instance.isOpen());
        Course course = createExistingCourse();
        Long newId = instance.create(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);
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.