Search in sources :

Example 11 with Submission

use of cn.edu.zjnu.acm.judge.domain.Submission in project judge by zjnu-acm.

the class JudgeServiceTest method check.

private void check(Checker c) throws IOException {
    String userId = initializer.userId;
    CompletableFuture<?> future;
    long id;
    try {
        String extension = getExtension(path);
        int language = findFirstLanguageByExtension(EXTENSION_MAP.get(extension));
        String source = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
        submissionService.remove(userId);
        future = submissionService.submit(language, source, userId, IP, initializer.problem);
        id = findOneByUserId(userId).getId();
    } catch (IOException ex) {
        throw new UncheckedIOException(ex);
    }
    initializer.submissions.add(id);
    Submission submission;
    try {
        submission = future.thenApply(__ -> submissionMapper.findOne(id)).get();
    } catch (InterruptedException | ExecutionException ex) {
        throw new AssertionError(ex);
    }
    assertNotNull(submission);
    int expectScore = c.getScore();
    String key = path.getParent().getFileName() + "/" + path.getFileName();
    if (specialKey.equals(key)) {
        expectScore = specialScore;
    }
    assertEquals(id + " " + path, expectScore, submission.getScore());
    String detail = submissionMapper.getSubmissionDetail(id);
    String[] details = detail.split(",");
    ArrayList<String> list = Lists.newArrayList();
    for (int i = 0; i < details.length; i += 4) {
        list.add(details[i]);
    }
    assertTrue(id + " " + path + " " + Arrays.toString(details), list.contains(Integer.toString(c.getStatus())));
}
Also used : Submission(cn.edu.zjnu.acm.judge.domain.Submission) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 12 with Submission

use of cn.edu.zjnu.acm.judge.domain.Submission in project judge by zjnu-acm.

the class ShowSourceControllerTest method testShowSource.

/**
 * Test of showSource method, of class ShowSourceController.
 *
 * @see ShowSourceController#showSource(HttpServletRequest, long, Integer,
 * Authentication)
 */
@Test
public void testShowSource() throws Exception {
    log.info("showSource");
    Submission submission = mockDataService.submission();
    long solutionId = submission.getId();
    Integer style = null;
    MvcResult result = mvc.perform(get("/showsource").with(user(submission.getUser())).param("solution_id", Long.toString(solutionId)).param("style", Objects.toString(style, ""))).andExpect(status().isOk()).andExpect(view().name("submissions/source")).andExpect(content().contentTypeCompatibleWith(MediaType.TEXT_HTML)).andReturn();
}
Also used : Submission(cn.edu.zjnu.acm.judge.domain.Submission) MvcResult(org.springframework.test.web.servlet.MvcResult) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 13 with Submission

use of cn.edu.zjnu.acm.judge.domain.Submission in project judge by zjnu-acm.

the class ShowSubmissionDetailsControllerTest method testShowSolutionDetails.

/**
 * Test of showSolutionDetails method, of class
 * ShowSubmissionDetailsController.
 *
 * @see
 * ShowSubmissionDetailsController#showSolutionDetails(HttpServletRequest,
 * long, Authentication)
 */
@Test
public void testShowSolutionDetails() throws Exception {
    log.info("showSolutionDetails");
    Submission submission = mockDataService.submission();
    long solutionId = submission.getId();
    MvcResult result = mvc.perform(get("/showsolutiondetails").with(user(submission.getUser())).param("solution_id", Long.toString(solutionId))).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(MediaType.TEXT_HTML)).andExpect(view().name("submissions/detail")).andReturn();
}
Also used : Submission(cn.edu.zjnu.acm.judge.domain.Submission) MvcResult(org.springframework.test.web.servlet.MvcResult) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Submission (cn.edu.zjnu.acm.judge.domain.Submission)13 GetMapping (org.springframework.web.bind.annotation.GetMapping)5 Test (org.junit.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 Problem (cn.edu.zjnu.acm.judge.domain.Problem)3 BusinessException (cn.edu.zjnu.acm.judge.exception.BusinessException)3 MvcResult (org.springframework.test.web.servlet.MvcResult)3 ScoreCount (cn.edu.zjnu.acm.judge.data.dto.ScoreCount)2 SubmissionQueryForm (cn.edu.zjnu.acm.judge.data.form.SubmissionQueryForm)2 MessageException (cn.edu.zjnu.acm.judge.exception.MessageException)2 Instant (java.time.Instant)2 ArrayList (java.util.ArrayList)2 RunRecord (cn.edu.zjnu.acm.judge.data.dto.RunRecord)1 SubmissionDetail (cn.edu.zjnu.acm.judge.data.dto.SubmissionDetail)1 BestSubmissionForm (cn.edu.zjnu.acm.judge.data.form.BestSubmissionForm)1 Contest (cn.edu.zjnu.acm.judge.domain.Contest)1 Language (cn.edu.zjnu.acm.judge.domain.Language)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 DecimalFormat (java.text.DecimalFormat)1