Package se.gu.fire.data

Examples of se.gu.fire.data.SubmissionManager


    public TestBean(EntityManager entMan) {
        this.entMan = entMan;

        assignMan = new AssignmentManager();
        subMan = new SubmissionManager();
        userMan = new UserManager();
        groupMan = new GroupManager();
        comMan = new CommentManager();
        passMan = new PasswordManager();
        fileMan = new StoredFileManager();
View Full Code Here


        // Create the managers
        AssignmentManager am = new AssignmentManager();
        am.setEntityManager(em);

        SubmissionManager sm = new SubmissionManager();
        sm.setEntityManager(em);

        UserManager um = new UserManager();
        um.setEntityManager(em);

        GroupManager gm = new GroupManager();
        gm.setEntityManager(em);

        CommentManager cm = new CommentManager();
        cm.setEntityManager(em);

        // Fix assignment
        Assignment assign = new Assignment.Builder()
                .title("Ratnum labb")
                .information("Programmera RatNum labben ordentligt annars kommer Christopher.")
                .finalDeadline(new Date(Calendar.getInstance().getTime().getTime()+15000))
                .firstDeadline(new Date(Calendar.getInstance().getTime().getTime()+10000))
                .build();
           
        em.getTransaction().begin();
        am.create(assign);
        em.getTransaction().commit();


        // Fix users
        FireUser u = TestUtil.createRandomUser();
       
        em.getTransaction().begin();
        um.create(u);
        em.getTransaction().commit();


        FireUser u2 = TestUtil.createRandomUser();
       
        em.getTransaction().begin();
        um.create(u2);
        em.getTransaction().commit();

        // Student group
        StudentGroup group = new StudentGroup();
        em.getTransaction().begin();
        group.addGroupMember(u);
        gm.create(group);
        em.getTransaction().commit();

        assertEquals(SubmissionStatus.NotSubmitted, sm.getAssignmentStatus(assign, group));


        // Test adding submission and a file
        byte[] text = "Java, Lava\nNava".getBytes();
       
        Submission sub = new Submission.Builder()
                .assignment(assign)
                .submittingGroup(group)
                .grader(u2)
                .build();
       
        em.getTransaction().begin();
        sm.create(sub);
        em.getTransaction().commit();
        assertEquals(SubmissionStatus.New, sm.getAssignmentStatus(assign, group));

        Comment com = new Comment(u2, "Total katastrof! Bara Christopher kan rädda dig nu");

        sub.addComments(com);
        sub.addFile(new StoredFile("Hacker.java", text, "text/plain"));
        Submission sub2 = sm.read(sub.getId());

        assertEquals(sub, sub2);

        // Test setSubmissionStatus()
        sub.setSubmissionStatus(SubmissionStatus.Rejected);
        em.getTransaction().begin();
        sm.update(sub);
        em.getTransaction().commit();

        assertEquals(SubmissionStatus.Rejected, sm.getAssignmentStatus(assign, group));

        // Ensure comment exits
        assertTrue(sub2.getComments().size() > 0);

        // Ensure files exists
        List<StoredFile> files = sm.getSubmissionFiles(sub);
        assertTrue(files.size() > 0);

        sub = sm.read(sub.getId());
        assertEquals(SubmissionStatus.Rejected, sub.getSubmissionStatus());

        // Test getAllByGroup()
        Submission subAgain = new Submission.Builder()
                .assignment(assign)
                .submittingGroup(group)
                .grader(u2)
                .build();

        em.getTransaction().begin();
        sm.create(subAgain);
        em.getTransaction().commit();
        List<Submission> allGroupSub = sm.getAllByGroup(group);
        assertNotNull(allGroupSub);
        assertTrue(allGroupSub.size() >= 2);

        // Test getALlByGroup(Assignment, Group)
        allGroupSub = sm.getAllByGroup(assign, group);
        assertNotNull(allGroupSub);
        assertTrue(allGroupSub.size() >= 2);

        // Test submission with no grader doesn't give NPE
        subAgain = new Submission.Builder()
                .assignment(assign)
                .submittingGroup(group)
                .build();

        em.getTransaction().begin();
        sm.create(subAgain);
        em.getTransaction().commit();
       
        List<Submission> assignedSub = sm.getAllForGrader(assign, u2);
        assertNotNull(assignedSub);
        assertTrue(assignedSub.size() >= 2);

        // Test for isPassed
        subAgain.setSubmissionStatus(SubmissionStatus.Accepted);

        em.getTransaction().begin();
        sm.update(subAgain);
        em.getTransaction().commit();
       
        assertTrue(sm.isPassed(assign, group));     
        assertEquals(SubmissionStatus.Accepted, sm.getAssignmentStatus(assign, group));

        // Testa att group inte klarat kursen
        //assertFalse(am.isCompletedCourse(group));

    }
View Full Code Here

TOP

Related Classes of se.gu.fire.data.SubmissionManager

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.