Search in sources :

Example 1 with Contest

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

the class ContestMapperTest method testFindOneByIdAndDisabledFalse.

/**
 * Test of findOneByIdAndNotDisabled method, of class ContestMapper.
 */
@Test
public void testFindOneByIdAndDisabledFalse() {
    log.info("findOneByIdAndDisabledFalse");
    long contestId = 0L;
    Contest expResult = null;
    Contest result = instance.findOneByIdAndNotDisabled(contestId);
    assertEquals(expResult, result);
}
Also used : Contest(cn.edu.zjnu.acm.judge.domain.Contest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with Contest

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

the class ContestControllerTest method testSave.

/**
 * Test of save method, of class ContestController.
 *
 * @see ContestController#save(Contest)
 */
@Test
public void testSave() throws Exception {
    log.info("save");
    Contest contest = mockDataService.contest(false);
    MvcResult result = mvc.perform(post("/api/contests.json").content(objectMapper.writeValueAsString(contest)).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)).andReturn();
}
Also used : Contest(cn.edu.zjnu.acm.judge.domain.Contest) MvcResult(org.springframework.test.web.servlet.MvcResult) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with Contest

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

the class ContestControllerTest method testUpdate.

/**
 * Test of update method, of class ContestController.
 *
 * @see ContestController#update(long, Contest)
 */
@Test
public void testUpdate() throws Exception {
    log.info("update");
    long id = mockDataService.contest().getId();
    Contest request = new Contest();
    MvcResult result = mvc.perform(patch("/api/contests/{id}.json", id).content(objectMapper.writeValueAsString(request)).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isNoContent()).andReturn();
}
Also used : Contest(cn.edu.zjnu.acm.judge.domain.Contest) MvcResult(org.springframework.test.web.servlet.MvcResult) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with Contest

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

the class SubmissionService method canView.

public boolean canView(HttpServletRequest request, Submission submission) {
    if (UserDetailsServiceImpl.isAdminLoginned(request)) {
        return true;
    }
    // TODO cast to Authentication
    if (UserDetailsServiceImpl.isUser((Authentication) request.getUserPrincipal(), submission.getUser())) {
        return true;
    }
    boolean sourceBrowser = UserDetailsServiceImpl.isSourceBrowser(request);
    if (sourceBrowser) {
        Long contestId = submission.getContest();
        if (contestId == null) {
            return true;
        }
        Contest contest = contestMapper.findOne(contestId);
        return contest == null || contest.isEnded();
    }
    return false;
}
Also used : Contest(cn.edu.zjnu.acm.judge.domain.Contest)

Example 5 with Contest

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

the class SubmissionService method contestSubmit.

public CompletableFuture<?> contestSubmit(int languageId, String source, String userId, String ip, long contestId, long problemNum) {
    check(languageId, source, userId);
    Contest contest = contestService.findOneByIdAndNotDisabled(contestId);
    // contest not started yet, can't submit the problem.
    if (!contest.isStarted()) {
        throw new BusinessException(BusinessCode.CONTEST_PROBLEM_NOT_FOUND, contestId, problemNum);
    }
    Problem problem = contestService.getProblem(contestId, problemNum, null);
    return submit0(Submission.builder().contest(contest.isEnded() ? null : contestId).problem(problem.getOrigin()).ip(ip), source, userId, languageId);
}
Also used : BusinessException(cn.edu.zjnu.acm.judge.exception.BusinessException) Problem(cn.edu.zjnu.acm.judge.domain.Problem) Contest(cn.edu.zjnu.acm.judge.domain.Contest)

Aggregations

Contest (cn.edu.zjnu.acm.judge.domain.Contest)13 Problem (cn.edu.zjnu.acm.judge.domain.Problem)4 Test (org.junit.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 BusinessException (cn.edu.zjnu.acm.judge.exception.BusinessException)3 Nonnull (javax.annotation.Nonnull)3 Instant (java.time.Instant)2 MvcResult (org.springframework.test.web.servlet.MvcResult)2 SubmissionDetail (cn.edu.zjnu.acm.judge.data.dto.SubmissionDetail)1 Language (cn.edu.zjnu.acm.judge.domain.Language)1 Submission (cn.edu.zjnu.acm.judge.domain.Submission)1 MessageException (cn.edu.zjnu.acm.judge.exception.MessageException)1 Path (java.nio.file.Path)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1