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