diff --git a/judger/src/test/java/org/verwandlung/voj/judger/core/ComparatorTest.java b/judger/src/test/java/org/verwandlung/voj/judger/core/ComparatorTest.java index c6c35b2a..6d019a60 100644 --- a/judger/src/test/java/org/verwandlung/voj/judger/core/ComparatorTest.java +++ b/judger/src/test/java/org/verwandlung/voj/judger/core/ComparatorTest.java @@ -25,115 +25,115 @@ @Transactional @ContextConfiguration({ "classpath:test-spring-context.xml" }) public class ComparatorTest { - /** - * 构建测试用例. - */ - @BeforeClass - public static void setUp() throws IOException { - FileOutputStream stdOutputStream = null; - FileOutputStream outputStream = null; - // Make Directory for TestCases - File checkpointsDirFile = new File("/tmp/voj-matcher-tests"); - if (!checkpointsDirFile.exists()) { - checkpointsDirFile.mkdirs(); - } - // TestCase: MatchExactly - stdOutputStream = new FileOutputStream(new File( - "/tmp/voj-matcher-tests/match-exactly-std.txt")); - outputStream = new FileOutputStream(new File( - "/tmp/voj-matcher-tests/match-exactly.txt")); - String matchExactlyString = "32768"; - IOUtils.write(matchExactlyString, stdOutputStream); - IOUtils.write(matchExactlyString, outputStream); - // TestCase: MatchWithSpaces - stdOutputStream = new FileOutputStream(new File( - "/tmp/voj-matcher-tests/match-with-spaces-std.txt")); - outputStream = new FileOutputStream(new File( - "/tmp/voj-matcher-tests/match-with-spaces.txt")); - String matchWithSpacesString = "Output Test with Spaces"; - IOUtils.write(matchWithSpacesString, stdOutputStream); - IOUtils.write(matchWithSpacesString + " \n \n", outputStream); - // TestCase: Mismatch - stdOutputStream = new FileOutputStream(new File( - "/tmp/voj-matcher-tests/mimatch-std.txt")); - outputStream = new FileOutputStream(new File( - "/tmp/voj-matcher-tests/mimatch.txt")); - String mismatchString1 = "45652 \n\n"; - String mismatchString2 = "24334"; - IOUtils.write(mismatchString1, stdOutputStream); - IOUtils.write(mismatchString2, outputStream); - // TestCase: OutOfMemoryException - File outOfMemoryOutFile = new File( - "/tmp/voj-matcher-tests/match-out-of-memory.txt"); - String outOfMemoryString = "A line of output causes out of memory exception. "; - for ( int i = 0; i < 10000000; ++ i ) { - FileUtils.writeStringToFile(outOfMemoryOutFile, outOfMemoryString, true); - } - } + /** + * 构建测试用例. + */ + @BeforeClass + public static void setUp() throws IOException { + FileOutputStream stdOutputStream = null; + FileOutputStream outputStream = null; + // Make Directory for TestCases + File checkpointsDirFile = new File("/tmp/voj-matcher-tests"); + if (!checkpointsDirFile.exists()) { + checkpointsDirFile.mkdirs(); + } + // TestCase: MatchExactly + stdOutputStream = new FileOutputStream(new File( + "/tmp/voj-matcher-tests/match-exactly-std.txt")); + outputStream = new FileOutputStream(new File( + "/tmp/voj-matcher-tests/match-exactly.txt")); + String matchExactlyString = "32768"; + IOUtils.write(matchExactlyString, stdOutputStream); + IOUtils.write(matchExactlyString, outputStream); + // TestCase: MatchWithSpaces + stdOutputStream = new FileOutputStream(new File( + "/tmp/voj-matcher-tests/match-with-spaces-std.txt")); + outputStream = new FileOutputStream(new File( + "/tmp/voj-matcher-tests/match-with-spaces.txt")); + String matchWithSpacesString = "Output Test with Spaces"; + IOUtils.write(matchWithSpacesString, stdOutputStream); + IOUtils.write(matchWithSpacesString + " \n \n", outputStream); + // TestCase: Mismatch + stdOutputStream = new FileOutputStream(new File( + "/tmp/voj-matcher-tests/mimatch-std.txt")); + outputStream = new FileOutputStream(new File( + "/tmp/voj-matcher-tests/mimatch.txt")); + String mismatchString1 = "45652 \n\n"; + String mismatchString2 = "24334"; + IOUtils.write(mismatchString1, stdOutputStream); + IOUtils.write(mismatchString2, outputStream); + // TestCase: OutOfMemoryException + File outOfMemoryOutFile = new File( + "/tmp/voj-matcher-tests/match-out-of-memory.txt"); + String outOfMemoryString = "A line of output causes out of memory exception. "; + for ( int i = 0; i < 10000000; ++ i ) { + FileUtils.writeStringToFile(outOfMemoryOutFile, outOfMemoryString, true); + } + } - /** - * 清除测试用例. - */ - @AfterClass - public static void tearDown() { - File checkpointsDirFile = new File("/tmp/voj-matcher-tests"); - if (checkpointsDirFile.exists()) { - checkpointsDirFile.delete(); - } - } + /** + * 清除测试用例. + */ + @AfterClass + public static void tearDown() { + File checkpointsDirFile = new File("/tmp/voj-matcher-tests"); + if (checkpointsDirFile.exists()) { + checkpointsDirFile.delete(); + } + } - /** - * 测试用例: 测试isOutputTheSame(String, String)方法 - * 测试数据: 输入和输出完全相同 - * 测试结果: 返回true, 表示输出结果正确 - */ - @Test - public void testMatchExactly() throws IOException { - String standardOutputFilePath = "/tmp/voj-matcher-tests/match-exactly-std.txt"; - String outputFilePath = "/tmp/voj-matcher-tests/match-exactly.txt"; - Assert.assertTrue(comparator.isOutputTheSame(standardOutputFilePath, outputFilePath)); - } + /** + * 测试用例: 测试isOutputTheSame(String, String)方法 + * 测试数据: 输入和输出完全相同 + * 测试结果: 返回true, 表示输出结果正确 + */ + @Test + public void testMatchExactly() throws IOException { + String standardOutputFilePath = "/tmp/voj-matcher-tests/match-exactly-std.txt"; + String outputFilePath = "/tmp/voj-matcher-tests/match-exactly.txt"; + Assert.assertTrue(comparator.isOutputTheSame(standardOutputFilePath, outputFilePath)); + } - /** - * 测试用例: 测试isOutputTheSame(String, String)方法 - * 测试数据: 输入和输出基本相同, 在行尾存在多余的空白字符 - * 测试结果: 返回true, 表示输出结果正确 - */ - @Test - public void testMatchWithSpaces() throws IOException { - String standardOutputFilePath = "/tmp/voj-matcher-tests/match-with-spaces-std.txt"; - String outputFilePath = "/tmp/voj-matcher-tests/match-with-spaces.txt"; - Assert.assertTrue(comparator.isOutputTheSame(standardOutputFilePath, - outputFilePath)); - Assert.assertTrue(comparator.isOutputTheSame(outputFilePath, standardOutputFilePath)); - } + /** + * 测试用例: 测试isOutputTheSame(String, String)方法 + * 测试数据: 输入和输出基本相同, 在行尾存在多余的空白字符 + * 测试结果: 返回true, 表示输出结果正确 + */ + @Test + public void testMatchWithSpaces() throws IOException { + String standardOutputFilePath = "/tmp/voj-matcher-tests/match-with-spaces-std.txt"; + String outputFilePath = "/tmp/voj-matcher-tests/match-with-spaces.txt"; + Assert.assertTrue(comparator.isOutputTheSame(standardOutputFilePath, + outputFilePath)); + Assert.assertTrue(comparator.isOutputTheSame(outputFilePath, standardOutputFilePath)); + } - /** - * 测试用例: 测试isOutputTheSame(String, String)方法 - * 测试数据: 输入和输出不完全相同 - * 测试结果: 返回false, 表示输出结果不正确 - */ - @Test - public void testMismatch() throws IOException { - String standardOutputFilePath = "/tmp/voj-matcher-tests/mimatch-std.txt"; - String outputFilePath = "/tmp/voj-matcher-tests/mimatch.txt"; - Assert.assertFalse(comparator.isOutputTheSame(standardOutputFilePath, outputFilePath)); - } + /** + * 测试用例: 测试isOutputTheSame(String, String)方法 + * 测试数据: 输入和输出不完全相同 + * 测试结果: 返回false, 表示输出结果不正确 + */ + @Test + public void testMismatch() throws IOException { + String standardOutputFilePath = "/tmp/voj-matcher-tests/mimatch-std.txt"; + String outputFilePath = "/tmp/voj-matcher-tests/mimatch.txt"; + Assert.assertFalse(comparator.isOutputTheSame(standardOutputFilePath, outputFilePath)); + } - /** - * 测试用例: 测试isOutputTheSame(String, String)方法 - * 测试数据: 过长的输出文件流 - * 测试结果: 返回false, 表示输出结果不正确 - */ - @Test - public void testMatchWithOutOfMemory() throws IOException { - String outputFilePath = "/tmp/voj-matcher-tests/match-out-of-memory.txt"; - Assert.assertFalse(comparator.isOutputTheSame(outputFilePath, outputFilePath)); - } + /** + * 测试用例: 测试isOutputTheSame(String, String)方法 + * 测试数据: 过长的输出文件流 + * 测试结果: 返回false, 表示输出结果不正确 + */ + @Test + public void testMatchWithOutOfMemory() throws IOException { + String outputFilePath = "/tmp/voj-matcher-tests/match-out-of-memory.txt"; + Assert.assertFalse(comparator.isOutputTheSame(outputFilePath, outputFilePath)); + } - /** - * 待测试的Matcher对象. - */ - @Autowired - private Comparator comparator; + /** + * 待测试的Matcher对象. + */ + @Autowired + private Comparator comparator; } diff --git a/judger/src/test/java/org/verwandlung/voj/judger/core/CompilerTest.java b/judger/src/test/java/org/verwandlung/voj/judger/core/CompilerTest.java index 8bc63b01..694a759f 100644 --- a/judger/src/test/java/org/verwandlung/voj/judger/core/CompilerTest.java +++ b/judger/src/test/java/org/verwandlung/voj/judger/core/CompilerTest.java @@ -23,78 +23,78 @@ @Transactional @ContextConfiguration({"classpath:test-spring-context.xml"}) public class CompilerTest { - /** - * 测试用例: 测试getCompileResult()方法 - * 测试数据: 使用可以编译通过的C++代码 - * 预期结果: 编译通过 - */ - @Test - public void testGetCompileResultCppWithSuccess() throws Exception { - String workDirectory = workBaseDirectory + "/voj-1000"; - String baseFileName = "random-name"; - Submission submission = submissionMapper.getSubmission(1000); - preprocessor.createTestCode(submission, workDirectory, baseFileName); - - Map result = compiler.getCompileResult(submission, workDirectory, baseFileName); - Assert.assertEquals(true, result.get("isSuccessful")); - } - - /** - * 测试用例: 测试getCompileResult()方法 - * 测试数据: 使用可以编译通过的Java代码 - * 预期结果: 编译通过 - */ - @Test - public void testGetCompileResultJavaWithSuccess() throws Exception { - String workDirectory = workBaseDirectory + "/voj-1001"; - String baseFileName = "RandomName"; - Submission submission = submissionMapper.getSubmission(1001); - preprocessor.createTestCode(submission, workDirectory, baseFileName); - - Map result = compiler.getCompileResult(submission, workDirectory, baseFileName); - Assert.assertEquals(true, result.get("isSuccessful")); - } - - /** - * 测试用例: 测试getCompileResult()方法 - * 测试数据: 使用可以无法编译通过的C++代码 - * 预期结果: 编译失败 - */ - @Test - public void testGetCompileResultCppWithError() throws Exception { - String workDirectory = workBaseDirectory + "/voj-1002"; - String baseFileName = "random-name"; - Submission submission = submissionMapper.getSubmission(1002); - preprocessor.createTestCode(submission, workDirectory, baseFileName); - - Map result = compiler.getCompileResult(submission, workDirectory, baseFileName); - Assert.assertEquals(false, result.get("isSuccessful")); - } - - /** - * 待测试的Compiler对象. - */ - @Autowired - private Compiler compiler; - - /** - * 自动注入的Preprocessor对象. - * 用于构建测试用例. - */ - @Autowired - private Preprocessor preprocessor; - - /** - * 自动注入的SubmissionMapper对象. - * 用于构建测试用例. - */ - @Autowired - private SubmissionMapper submissionMapper; - - /** - * 评测机的工作目录. - * 用于存储编译结果以及程序输出结果. - */ - @Value("${judger.workDir}") - private String workBaseDirectory; + /** + * 测试用例: 测试getCompileResult()方法 + * 测试数据: 使用可以编译通过的C++代码 + * 预期结果: 编译通过 + */ + @Test + public void testGetCompileResultCppWithSuccess() throws Exception { + String workDirectory = workBaseDirectory + "/voj-1000"; + String baseFileName = "random-name"; + Submission submission = submissionMapper.getSubmission(1000); + preprocessor.createTestCode(submission, workDirectory, baseFileName); + + Map result = compiler.getCompileResult(submission, workDirectory, baseFileName); + Assert.assertEquals(true, result.get("isSuccessful")); + } + + /** + * 测试用例: 测试getCompileResult()方法 + * 测试数据: 使用可以编译通过的Java代码 + * 预期结果: 编译通过 + */ + @Test + public void testGetCompileResultJavaWithSuccess() throws Exception { + String workDirectory = workBaseDirectory + "/voj-1001"; + String baseFileName = "RandomName"; + Submission submission = submissionMapper.getSubmission(1001); + preprocessor.createTestCode(submission, workDirectory, baseFileName); + + Map result = compiler.getCompileResult(submission, workDirectory, baseFileName); + Assert.assertEquals(true, result.get("isSuccessful")); + } + + /** + * 测试用例: 测试getCompileResult()方法 + * 测试数据: 使用可以无法编译通过的C++代码 + * 预期结果: 编译失败 + */ + @Test + public void testGetCompileResultCppWithError() throws Exception { + String workDirectory = workBaseDirectory + "/voj-1002"; + String baseFileName = "random-name"; + Submission submission = submissionMapper.getSubmission(1002); + preprocessor.createTestCode(submission, workDirectory, baseFileName); + + Map result = compiler.getCompileResult(submission, workDirectory, baseFileName); + Assert.assertEquals(false, result.get("isSuccessful")); + } + + /** + * 待测试的Compiler对象. + */ + @Autowired + private Compiler compiler; + + /** + * 自动注入的Preprocessor对象. + * 用于构建测试用例. + */ + @Autowired + private Preprocessor preprocessor; + + /** + * 自动注入的SubmissionMapper对象. + * 用于构建测试用例. + */ + @Autowired + private SubmissionMapper submissionMapper; + + /** + * 评测机的工作目录. + * 用于存储编译结果以及程序输出结果. + */ + @Value("${judger.workDir}") + private String workBaseDirectory; } diff --git a/judger/src/test/java/org/verwandlung/voj/judger/core/PreprocessorTest.java b/judger/src/test/java/org/verwandlung/voj/judger/core/PreprocessorTest.java index d2d44f26..cb2fe0a6 100644 --- a/judger/src/test/java/org/verwandlung/voj/judger/core/PreprocessorTest.java +++ b/judger/src/test/java/org/verwandlung/voj/judger/core/PreprocessorTest.java @@ -23,54 +23,54 @@ @Transactional @ContextConfiguration({"classpath:test-spring-context.xml"}) public class PreprocessorTest { - /** - * 测试用例: 测试createTestCode(Submission, String, String)方法 - * 测试数据: 使用存在的提交记录(Submission#1000) - * 预期结果: 在指定位置创建源代码文件 - * @throws Exception - */ - @Test - public void testCreateTestCodeCpp() throws Exception { - Submission submission = submissionMapper.getSubmission(1000); - String workDirectory = "/tmp/voj-1000/"; - String baseFileName = "random-name"; - - preprocessor.createTestCode(submission, workDirectory, baseFileName); - FileInputStream inputStream = new FileInputStream("/tmp/voj-1000/random-name.cpp"); - String code = IOUtils.toString(inputStream); - inputStream.close(); - Assert.assertEquals(submission.getCode(), code); - } - - /** - * 测试用例: 测试createTestCode(Submission, String, String)方法 - * 测试数据: 使用存在的提交记录(Submission#1001) - * 预期结果: 在指定位置创建源代码文件 - * @throws Exception - */ - @Test - public void testCreateTestCodeJava() throws Exception { - Submission submission = submissionMapper.getSubmission(1001); - String workDirectory = "/tmp/voj-1001/"; - String baseFileName = "RandomName"; - - preprocessor.createTestCode(submission, workDirectory, baseFileName); - FileInputStream inputStream = new FileInputStream("/tmp/voj-1001/RandomName.java"); - String code = IOUtils.toString(inputStream).replace("RandomName", "Main"); - inputStream.close(); - Assert.assertEquals(submission.getCode(), code); - } - - /** - * 待测试的Preprocessor对象. - */ - @Autowired - private Preprocessor preprocessor; - - /** - * 自动注入的SubmissionMapper对象. - * 用于构造测试用例. - */ - @Autowired - private SubmissionMapper submissionMapper; + /** + * 测试用例: 测试createTestCode(Submission, String, String)方法 + * 测试数据: 使用存在的提交记录(Submission#1000) + * 预期结果: 在指定位置创建源代码文件 + * @throws Exception + */ + @Test + public void testCreateTestCodeCpp() throws Exception { + Submission submission = submissionMapper.getSubmission(1000); + String workDirectory = "/tmp/voj-1000/"; + String baseFileName = "random-name"; + + preprocessor.createTestCode(submission, workDirectory, baseFileName); + FileInputStream inputStream = new FileInputStream("/tmp/voj-1000/random-name.cpp"); + String code = IOUtils.toString(inputStream); + inputStream.close(); + Assert.assertEquals(submission.getCode(), code); + } + + /** + * 测试用例: 测试createTestCode(Submission, String, String)方法 + * 测试数据: 使用存在的提交记录(Submission#1001) + * 预期结果: 在指定位置创建源代码文件 + * @throws Exception + */ + @Test + public void testCreateTestCodeJava() throws Exception { + Submission submission = submissionMapper.getSubmission(1001); + String workDirectory = "/tmp/voj-1001/"; + String baseFileName = "RandomName"; + + preprocessor.createTestCode(submission, workDirectory, baseFileName); + FileInputStream inputStream = new FileInputStream("/tmp/voj-1001/RandomName.java"); + String code = IOUtils.toString(inputStream).replace("RandomName", "Main"); + inputStream.close(); + Assert.assertEquals(submission.getCode(), code); + } + + /** + * 待测试的Preprocessor对象. + */ + @Autowired + private Preprocessor preprocessor; + + /** + * 自动注入的SubmissionMapper对象. + * 用于构造测试用例. + */ + @Autowired + private SubmissionMapper submissionMapper; } diff --git a/judger/src/test/java/org/verwandlung/voj/judger/core/RunnerTest.java b/judger/src/test/java/org/verwandlung/voj/judger/core/RunnerTest.java index 3cc7fc93..b6fb13b1 100644 --- a/judger/src/test/java/org/verwandlung/voj/judger/core/RunnerTest.java +++ b/judger/src/test/java/org/verwandlung/voj/judger/core/RunnerTest.java @@ -23,83 +23,83 @@ @Transactional @ContextConfiguration({"classpath:test-spring-context.xml"}) public class RunnerTest { - /** - * 测试用例: 测试getRuntimeResult(Submission, int, String, String, String, String)方法 - * 测试数据: 使用可以编译通过的C++代码 - * 预期结果: 编译成功并运行产生输出 - */ - @Test - public void testGetRuntimeResultCpp() throws Exception { - String workDirectory = workBaseDirectory + "/voj-1000"; - String baseFileName = "random-name"; - Submission submission = submissionMapper.getSubmission(1000); + /** + * 测试用例: 测试getRuntimeResult(Submission, int, String, String, String, String)方法 + * 测试数据: 使用可以编译通过的C++代码 + * 预期结果: 编译成功并运行产生输出 + */ + @Test + public void testGetRuntimeResultCpp() throws Exception { + String workDirectory = workBaseDirectory + "/voj-1000"; + String baseFileName = "random-name"; + Submission submission = submissionMapper.getSubmission(1000); - String inputFilePath = workBaseDirectory + "/testpoints/1000/input#0.txt"; - String outputFilePath = workBaseDirectory + "/voj-1000/output#0.txt"; - - preprocessor.createTestCode(submission, workDirectory, baseFileName); - preprocessor.fetchTestPoints(submission.getProblem().getProblemId()); - compiler.getCompileResult(submission, workDirectory, baseFileName); - - Map result = - runner.getRuntimeResult(submission, workDirectory, baseFileName, inputFilePath, outputFilePath); - Assert.assertEquals("AC", result.get("runtimeResult")); - } - - /** - * 测试用例: 测试getRuntimeResult(Submission, int, String, String, String, String)方法 - * 测试数据: 使用可以编译通过的Java代码 - * 预期结果: 编译成功并运行产生输出 - */ - @Test - public void testGetRuntimeResultJava() throws Exception { - String workDirectory = workBaseDirectory + "/voj-1001"; - String baseFileName = "RandomName"; - Submission submission = submissionMapper.getSubmission(1001); + String inputFilePath = workBaseDirectory + "/testpoints/1000/input#0.txt"; + String outputFilePath = workBaseDirectory + "/voj-1000/output#0.txt"; + + preprocessor.createTestCode(submission, workDirectory, baseFileName); + preprocessor.fetchTestPoints(submission.getProblem().getProblemId()); + compiler.getCompileResult(submission, workDirectory, baseFileName); + + Map result = + runner.getRuntimeResult(submission, workDirectory, baseFileName, inputFilePath, outputFilePath); + Assert.assertEquals("AC", result.get("runtimeResult")); + } + + /** + * 测试用例: 测试getRuntimeResult(Submission, int, String, String, String, String)方法 + * 测试数据: 使用可以编译通过的Java代码 + * 预期结果: 编译成功并运行产生输出 + */ + @Test + public void testGetRuntimeResultJava() throws Exception { + String workDirectory = workBaseDirectory + "/voj-1001"; + String baseFileName = "RandomName"; + Submission submission = submissionMapper.getSubmission(1001); - String inputFilePath = workBaseDirectory + "/testpoints/1001/input#0.txt"; - String outputFilePath = workBaseDirectory + "/voj-1000/output#0.txt"; - - preprocessor.createTestCode(submission, workDirectory, baseFileName); - preprocessor.fetchTestPoints(submission.getProblem().getProblemId()); - compiler.getCompileResult(submission, workDirectory, baseFileName); - - Map result = - runner.getRuntimeResult(submission, workDirectory, baseFileName, inputFilePath, outputFilePath); - Assert.assertEquals("AC", result.get("runtimeResult")); - } - - /** - * 待测试的Runner对象. - */ - @Autowired - private Runner runner; - - /** - * 自动注入的Compiler对象. - * 用于构建测试用例. - */ - @Autowired - private Compiler compiler; - - /** - * 自动注入的Preprocessor对象. - * 用于构建测试用例. - */ - @Autowired - private Preprocessor preprocessor; - - /** - * 自动注入的SubmissionMapper对象. - * 用于构建测试用例. - */ - @Autowired - private SubmissionMapper submissionMapper; - - /** - * 评测机的工作目录. - * 用于存储编译结果以及程序输出结果. - */ - @Value("${judger.workDir}") - private String workBaseDirectory; + String inputFilePath = workBaseDirectory + "/testpoints/1001/input#0.txt"; + String outputFilePath = workBaseDirectory + "/voj-1000/output#0.txt"; + + preprocessor.createTestCode(submission, workDirectory, baseFileName); + preprocessor.fetchTestPoints(submission.getProblem().getProblemId()); + compiler.getCompileResult(submission, workDirectory, baseFileName); + + Map result = + runner.getRuntimeResult(submission, workDirectory, baseFileName, inputFilePath, outputFilePath); + Assert.assertEquals("AC", result.get("runtimeResult")); + } + + /** + * 待测试的Runner对象. + */ + @Autowired + private Runner runner; + + /** + * 自动注入的Compiler对象. + * 用于构建测试用例. + */ + @Autowired + private Compiler compiler; + + /** + * 自动注入的Preprocessor对象. + * 用于构建测试用例. + */ + @Autowired + private Preprocessor preprocessor; + + /** + * 自动注入的SubmissionMapper对象. + * 用于构建测试用例. + */ + @Autowired + private SubmissionMapper submissionMapper; + + /** + * 评测机的工作目录. + * 用于存储编译结果以及程序输出结果. + */ + @Value("${judger.workDir}") + private String workBaseDirectory; } diff --git a/judger/src/test/java/org/verwandlung/voj/judger/mapper/CheckpointMapperTest.java b/judger/src/test/java/org/verwandlung/voj/judger/mapper/CheckpointMapperTest.java index 10ab901d..b43649f3 100644 --- a/judger/src/test/java/org/verwandlung/voj/judger/mapper/CheckpointMapperTest.java +++ b/judger/src/test/java/org/verwandlung/voj/judger/mapper/CheckpointMapperTest.java @@ -21,35 +21,35 @@ @Transactional @ContextConfiguration({"classpath:test-spring-context.xml"}) public class CheckpointMapperTest { - /** - * 测试用例: 测试getCheckpointsUsingProblemId(long)方法 - * 测试数据: 使用存在的试题唯一标识符(1000) - * 预期结果: 返回对应的测试点列表(10个项目) - */ - @Test - public void testGetCheckpointsUsingProblemIdExists() { - List checkpoints = checkpointMapper.getCheckpointsUsingProblemId(1000); - Assert.assertEquals(10, checkpoints.size()); - - Checkpoint firstCheckpoint = checkpoints.get(0); - String output = firstCheckpoint.getOutput(); - Assert.assertEquals("45652\r\n", output); - } - - /** - * 测试用例: 测试getCheckpointsUsingProblemId(long)方法 - * 测试数据: 使用不存在的试题唯一标识符(0) - * 预期结果: 返回对应的测试点列表(0个项目) - */ - @Test - public void testGetCheckpointsUsingProblemIdNotExists() { - List checkpoints = checkpointMapper.getCheckpointsUsingProblemId(0); - Assert.assertEquals(0, checkpoints.size()); - } - - /** - * 待测试的CheckpointMapper对象. - */ - @Autowired - private CheckpointMapper checkpointMapper; + /** + * 测试用例: 测试getCheckpointsUsingProblemId(long)方法 + * 测试数据: 使用存在的试题唯一标识符(1000) + * 预期结果: 返回对应的测试点列表(10个项目) + */ + @Test + public void testGetCheckpointsUsingProblemIdExists() { + List checkpoints = checkpointMapper.getCheckpointsUsingProblemId(1000); + Assert.assertEquals(10, checkpoints.size()); + + Checkpoint firstCheckpoint = checkpoints.get(0); + String output = firstCheckpoint.getOutput(); + Assert.assertEquals("45652\r\n", output); + } + + /** + * 测试用例: 测试getCheckpointsUsingProblemId(long)方法 + * 测试数据: 使用不存在的试题唯一标识符(0) + * 预期结果: 返回对应的测试点列表(0个项目) + */ + @Test + public void testGetCheckpointsUsingProblemIdNotExists() { + List checkpoints = checkpointMapper.getCheckpointsUsingProblemId(0); + Assert.assertEquals(0, checkpoints.size()); + } + + /** + * 待测试的CheckpointMapper对象. + */ + @Autowired + private CheckpointMapper checkpointMapper; } diff --git a/judger/src/test/java/org/verwandlung/voj/judger/mapper/JudgeResultMapperTest.java b/judger/src/test/java/org/verwandlung/voj/judger/mapper/JudgeResultMapperTest.java index 5d6b0df4..196d873f 100644 --- a/judger/src/test/java/org/verwandlung/voj/judger/mapper/JudgeResultMapperTest.java +++ b/judger/src/test/java/org/verwandlung/voj/judger/mapper/JudgeResultMapperTest.java @@ -18,34 +18,34 @@ @Transactional @ContextConfiguration({"classpath:test-spring-context.xml"}) public class JudgeResultMapperTest { - /** - * 测试用例: 测试getJudgeResultUsingSlug(String)方法 - * 测试数据: 普通评测结果(JudgeResult)的评测结果组唯一英文缩写 - * 预期结果: 返回评测结果(JudgeResult)的评测结果组对象 - */ - @Test - public void testGetJudgeResultUsingSlugExists() { - JudgeResult judgeResult = judgeResultMapper.getJudgeResultUsingSlug("AC"); - Assert.assertNotNull(judgeResult); - - int judgeResultId = judgeResult.getJudgeResultId(); - Assert.assertEquals(2, judgeResultId); - } - - /** - * 测试用例: 测试getJudgeResultUsingSlug(String)方法 - * 测试数据: 不存在的评测结果组唯一英文缩写 - * 预期结果: 返回空引用 - */ - @Test - public void testGetJudgeResultUsingSlugNotExists() { - JudgeResult judgeResult = judgeResultMapper.getJudgeResultUsingSlug("Not-Exists"); - Assert.assertNull(judgeResult); - } - - /** - * 待测试的JudgeResultMapper对象. - */ - @Autowired - private JudgeResultMapper judgeResultMapper; + /** + * 测试用例: 测试getJudgeResultUsingSlug(String)方法 + * 测试数据: 普通评测结果(JudgeResult)的评测结果组唯一英文缩写 + * 预期结果: 返回评测结果(JudgeResult)的评测结果组对象 + */ + @Test + public void testGetJudgeResultUsingSlugExists() { + JudgeResult judgeResult = judgeResultMapper.getJudgeResultUsingSlug("AC"); + Assert.assertNotNull(judgeResult); + + int judgeResultId = judgeResult.getJudgeResultId(); + Assert.assertEquals(2, judgeResultId); + } + + /** + * 测试用例: 测试getJudgeResultUsingSlug(String)方法 + * 测试数据: 不存在的评测结果组唯一英文缩写 + * 预期结果: 返回空引用 + */ + @Test + public void testGetJudgeResultUsingSlugNotExists() { + JudgeResult judgeResult = judgeResultMapper.getJudgeResultUsingSlug("Not-Exists"); + Assert.assertNull(judgeResult); + } + + /** + * 待测试的JudgeResultMapper对象. + */ + @Autowired + private JudgeResultMapper judgeResultMapper; } diff --git a/judger/src/test/java/org/verwandlung/voj/judger/mapper/LanguageMapperTest.java b/judger/src/test/java/org/verwandlung/voj/judger/mapper/LanguageMapperTest.java index f7a42ea2..e4794d91 100644 --- a/judger/src/test/java/org/verwandlung/voj/judger/mapper/LanguageMapperTest.java +++ b/judger/src/test/java/org/verwandlung/voj/judger/mapper/LanguageMapperTest.java @@ -21,76 +21,76 @@ @Transactional @ContextConfiguration({"classpath:test-spring-context.xml"}) public class LanguageMapperTest { - /** - * 测试用例: 测试getLanguageUsingId(int)方法 - * 测试数据: C语言的编程语言唯一标识符 - * 预期结果: 返回C语言的编程语言对象 - */ - @Test - public void testGetLanguageUsingIdExists() { - Language language = languageMapper.getLanguageUsingId(1); - Assert.assertNotNull(language); - - String languageName = language.getLanguageName(); - Assert.assertEquals("C", languageName); - } - - /** - * 测试用例: 测试getLanguageUsingId(int)方法 - * 测试数据: 不存在的编程语言唯一标识符 - * 预期结果: 返回空引用 - */ - @Test - public void testGetLanguageUsingIdNotExists() { - Language language = languageMapper.getLanguageUsingId(0); - Assert.assertNull(language); - } - - /** - * 测试用例: 测试getLanguageUsingSlug(String)方法 - * 测试数据: C语言的编程语言唯一英文缩写 - * 预期结果: 返回C语言的编程语言对象 - */ - @Test - public void testGetLanguageUsingSlugExists() { - Language language = languageMapper.getLanguageUsingSlug("text/x-csrc"); - Assert.assertNotNull(language); - - String languageName = language.getLanguageName(); - Assert.assertEquals("C", languageName); - } - - /** - * 测试用例: 测试getLanguageUsingSlug(String)方法 - * 测试数据: 不存在的编程语言唯一英文缩写 - * 预期结果: 返回空引用 - */ - @Test - public void testGetLanguageUsingSlugNotExists() { - Language language = languageMapper.getLanguageUsingSlug("Not-Exists"); - Assert.assertNull(language); - } + /** + * 测试用例: 测试getLanguageUsingId(int)方法 + * 测试数据: C语言的编程语言唯一标识符 + * 预期结果: 返回C语言的编程语言对象 + */ + @Test + public void testGetLanguageUsingIdExists() { + Language language = languageMapper.getLanguageUsingId(1); + Assert.assertNotNull(language); + + String languageName = language.getLanguageName(); + Assert.assertEquals("C", languageName); + } + + /** + * 测试用例: 测试getLanguageUsingId(int)方法 + * 测试数据: 不存在的编程语言唯一标识符 + * 预期结果: 返回空引用 + */ + @Test + public void testGetLanguageUsingIdNotExists() { + Language language = languageMapper.getLanguageUsingId(0); + Assert.assertNull(language); + } + + /** + * 测试用例: 测试getLanguageUsingSlug(String)方法 + * 测试数据: C语言的编程语言唯一英文缩写 + * 预期结果: 返回C语言的编程语言对象 + */ + @Test + public void testGetLanguageUsingSlugExists() { + Language language = languageMapper.getLanguageUsingSlug("text/x-csrc"); + Assert.assertNotNull(language); + + String languageName = language.getLanguageName(); + Assert.assertEquals("C", languageName); + } + + /** + * 测试用例: 测试getLanguageUsingSlug(String)方法 + * 测试数据: 不存在的编程语言唯一英文缩写 + * 预期结果: 返回空引用 + */ + @Test + public void testGetLanguageUsingSlugNotExists() { + Language language = languageMapper.getLanguageUsingSlug("Not-Exists"); + Assert.assertNull(language); + } - /** - * 测试用例: 测试getAllLanguages()方法 - * 测试数据: N/a - * 预期结果: 返回全部的编程语言列表(共6种语言) - */ - @Test - public void testGetAllLanguages() { - List languages = languageMapper.getAllLanguages(); - Assert.assertNotNull(languages); - Assert.assertEquals(6, languages.size()); - - Language firstLanguage = languages.get(0); - Assert.assertNotNull(firstLanguage); - - String languageName = firstLanguage.getLanguageName(); - Assert.assertEquals("C", languageName); - } - /** - * 待测试的LanguageMapper对象. - */ - @Autowired - private LanguageMapper languageMapper; + /** + * 测试用例: 测试getAllLanguages()方法 + * 测试数据: N/a + * 预期结果: 返回全部的编程语言列表(共6种语言) + */ + @Test + public void testGetAllLanguages() { + List languages = languageMapper.getAllLanguages(); + Assert.assertNotNull(languages); + Assert.assertEquals(6, languages.size()); + + Language firstLanguage = languages.get(0); + Assert.assertNotNull(firstLanguage); + + String languageName = firstLanguage.getLanguageName(); + Assert.assertEquals("C", languageName); + } + /** + * 待测试的LanguageMapper对象. + */ + @Autowired + private LanguageMapper languageMapper; } diff --git a/judger/src/test/java/org/verwandlung/voj/judger/mapper/ProblemMapperTest.java b/judger/src/test/java/org/verwandlung/voj/judger/mapper/ProblemMapperTest.java index a5d3d46e..63a37996 100644 --- a/judger/src/test/java/org/verwandlung/voj/judger/mapper/ProblemMapperTest.java +++ b/judger/src/test/java/org/verwandlung/voj/judger/mapper/ProblemMapperTest.java @@ -18,34 +18,34 @@ @Transactional @ContextConfiguration({"classpath:test-spring-context.xml"}) public class ProblemMapperTest { - /** - * 测试用例: 测试getProblem()方法 - * 测试数据: 使用A+B Problem的试题唯一标识符 - * 预期结果: 返回预期的试题对象 - */ - @Test - public void testGetProblemExists() { - Problem problem = problemMapper.getProblem(1000); - Assert.assertNotNull(problem); - - String problemName = problem.getProblemName(); - Assert.assertEquals("A+B Problem", problemName); - } - - /** - * 测试用例: 测试getProblem()方法 - * 测试数据: 使用不存在的试题唯一标识符 - * 预期结果: 返回空引用 - */ - @Test - public void testGetProblemNotExists() { - Problem problem = problemMapper.getProblem(0); - Assert.assertNull(problem); - } - - /** - * 待测试的ProblemMapper对象. - */ - @Autowired - private ProblemMapper problemMapper; + /** + * 测试用例: 测试getProblem()方法 + * 测试数据: 使用A+B Problem的试题唯一标识符 + * 预期结果: 返回预期的试题对象 + */ + @Test + public void testGetProblemExists() { + Problem problem = problemMapper.getProblem(1000); + Assert.assertNotNull(problem); + + String problemName = problem.getProblemName(); + Assert.assertEquals("A+B Problem", problemName); + } + + /** + * 测试用例: 测试getProblem()方法 + * 测试数据: 使用不存在的试题唯一标识符 + * 预期结果: 返回空引用 + */ + @Test + public void testGetProblemNotExists() { + Problem problem = problemMapper.getProblem(0); + Assert.assertNull(problem); + } + + /** + * 待测试的ProblemMapper对象. + */ + @Autowired + private ProblemMapper problemMapper; } diff --git a/judger/src/test/java/org/verwandlung/voj/judger/mapper/SubmissionMapperTest.java b/judger/src/test/java/org/verwandlung/voj/judger/mapper/SubmissionMapperTest.java index 0200e619..81f47e8b 100644 --- a/judger/src/test/java/org/verwandlung/voj/judger/mapper/SubmissionMapperTest.java +++ b/judger/src/test/java/org/verwandlung/voj/judger/mapper/SubmissionMapperTest.java @@ -18,34 +18,34 @@ @Transactional @ContextConfiguration({"classpath:test-spring-context.xml"}) public class SubmissionMapperTest { - /** - * 测试用例: 测试getSubmission(long)方法 - * 测试数据: Problem#1000的提交记录的唯一标识符 - * 预期结果: 返回预期的Submission对象 - */ - @Test - public void testGetSubmissionExists() { - Submission submission = submissionMapper.getSubmission(1000); - Assert.assertNotNull(submission); - - long problemId = submission.getProblem().getProblemId(); - Assert.assertEquals(1000, problemId); - } - - /** - * 测试用例: 测试getSubmission(long)方法 - * 测试数据: 不存在的的提交记录唯一标识符 - * 预期结果: 返回空引用 - */ - @Test - public void testGetSubmissionNotExists() { - Submission submission = submissionMapper.getSubmission(0); - Assert.assertNull(submission); - } - - /** - * 待测试的SubmissionMapper对象. - */ - @Autowired - private SubmissionMapper submissionMapper; + /** + * 测试用例: 测试getSubmission(long)方法 + * 测试数据: Problem#1000的提交记录的唯一标识符 + * 预期结果: 返回预期的Submission对象 + */ + @Test + public void testGetSubmissionExists() { + Submission submission = submissionMapper.getSubmission(1000); + Assert.assertNotNull(submission); + + long problemId = submission.getProblem().getProblemId(); + Assert.assertEquals(1000, problemId); + } + + /** + * 测试用例: 测试getSubmission(long)方法 + * 测试数据: 不存在的的提交记录唯一标识符 + * 预期结果: 返回空引用 + */ + @Test + public void testGetSubmissionNotExists() { + Submission submission = submissionMapper.getSubmission(0); + Assert.assertNull(submission); + } + + /** + * 待测试的SubmissionMapper对象. + */ + @Autowired + private SubmissionMapper submissionMapper; } diff --git a/judger/src/test/java/org/verwandlung/voj/judger/mapper/UserGroupMapperTest.java b/judger/src/test/java/org/verwandlung/voj/judger/mapper/UserGroupMapperTest.java index e04fb7f2..ada23933 100644 --- a/judger/src/test/java/org/verwandlung/voj/judger/mapper/UserGroupMapperTest.java +++ b/judger/src/test/java/org/verwandlung/voj/judger/mapper/UserGroupMapperTest.java @@ -19,34 +19,34 @@ @Transactional @ContextConfiguration({"classpath:test-spring-context.xml"}) public class UserGroupMapperTest { - /** - * 测试用例: 测试getUserGroupUsingId(int)方法 - * 测试数据: 普通用户(User)的用户组唯一标识符 - * 预期结果: 返回用户(User)的用户组对象 - */ - @Test - public void testGetUserGroupUsingIdExists() { - UserGroup userGroup = userGroupMapper.getUserGroupUsingId(1); - Assert.assertNotNull(userGroup); - - String userGroupSlug = userGroup.getUserGroupSlug(); - Assert.assertEquals("forbidden", userGroupSlug); - } - - /** - * 测试用例: 测试getUserGroupUsingId(int)方法 - * 测试数据: 不存在的用户组唯一标识符 - * 预期结果: 返回空引用 - */ - @Test - public void testGetUserGroupUsingIdNotExists() { - UserGroup userGroup = userGroupMapper.getUserGroupUsingId(0); - Assert.assertNull(userGroup); - } - - /** - * 待测试的UserGroupMapper对象. - */ - @Autowired - private UserGroupMapper userGroupMapper; + /** + * 测试用例: 测试getUserGroupUsingId(int)方法 + * 测试数据: 普通用户(User)的用户组唯一标识符 + * 预期结果: 返回用户(User)的用户组对象 + */ + @Test + public void testGetUserGroupUsingIdExists() { + UserGroup userGroup = userGroupMapper.getUserGroupUsingId(1); + Assert.assertNotNull(userGroup); + + String userGroupSlug = userGroup.getUserGroupSlug(); + Assert.assertEquals("forbidden", userGroupSlug); + } + + /** + * 测试用例: 测试getUserGroupUsingId(int)方法 + * 测试数据: 不存在的用户组唯一标识符 + * 预期结果: 返回空引用 + */ + @Test + public void testGetUserGroupUsingIdNotExists() { + UserGroup userGroup = userGroupMapper.getUserGroupUsingId(0); + Assert.assertNull(userGroup); + } + + /** + * 待测试的UserGroupMapper对象. + */ + @Autowired + private UserGroupMapper userGroupMapper; } diff --git a/judger/src/test/java/org/verwandlung/voj/judger/mapper/UserMapperTest.java b/judger/src/test/java/org/verwandlung/voj/judger/mapper/UserMapperTest.java index d98192de..7b0cbbe1 100644 --- a/judger/src/test/java/org/verwandlung/voj/judger/mapper/UserMapperTest.java +++ b/judger/src/test/java/org/verwandlung/voj/judger/mapper/UserMapperTest.java @@ -19,34 +19,34 @@ @Transactional @ContextConfiguration({"classpath:test-spring-context.xml"}) public class UserMapperTest { - /** - * 测试用例: 测试getUserUsingUsername(String)方法 - * 测试数据: 使用用户名为zjhzxhz的用户 - * 预期结果: 返回预期的用户对象 - */ - @Test - public void testGetUserUsingUsernameExists() { - User user = userMapper.getUserUsingUsername("Zjhzxhz"); - Assert.assertNotNull(user); - - long uid = user.getUid(); - Assert.assertEquals(1000, uid); - } - - /** - * 测试用例: 测试getUserUsingUsername(String)方法 - * 测试数据: 使用不存在的用户名 - * 预期结果: 返回空引用 - */ - @Test - public void testGetUserUsingUsernameNotExists() { - User user = userMapper.getUserUsingUsername("Not-Exists"); - Assert.assertNull(user); - } - - /** - * 待测试的UserMapper对象. - */ - @Autowired - private UserMapper userMapper; + /** + * 测试用例: 测试getUserUsingUsername(String)方法 + * 测试数据: 使用用户名为zjhzxhz的用户 + * 预期结果: 返回预期的用户对象 + */ + @Test + public void testGetUserUsingUsernameExists() { + User user = userMapper.getUserUsingUsername("Zjhzxhz"); + Assert.assertNotNull(user); + + long uid = user.getUid(); + Assert.assertEquals(1000, uid); + } + + /** + * 测试用例: 测试getUserUsingUsername(String)方法 + * 测试数据: 使用不存在的用户名 + * 预期结果: 返回空引用 + */ + @Test + public void testGetUserUsingUsernameNotExists() { + User user = userMapper.getUserUsingUsername("Not-Exists"); + Assert.assertNull(user); + } + + /** + * 待测试的UserMapper对象. + */ + @Autowired + private UserMapper userMapper; } diff --git a/voj.sql b/voj.sql index a142eb34..22c585b7 100644 --- a/voj.sql +++ b/voj.sql @@ -335,7 +335,11 @@ CREATE TABLE IF NOT EXISTS `voj_problem_tag_relationships` ( -- INSERT INTO `voj_problem_tag_relationships` (`problem_id`, `problem_tag_id`) VALUES -(1001, 1); +(1000, 1), +(1001, 1), +(1001, 2), +(1002, 1), +(1003, 2); -- -------------------------------------------------------- diff --git a/web/src/main/java/org/verwandlung/voj/web/controller/AdministrationController.java b/web/src/main/java/org/verwandlung/voj/web/controller/AdministrationController.java index 5e11c672..eba72302 100644 --- a/web/src/main/java/org/verwandlung/voj/web/controller/AdministrationController.java +++ b/web/src/main/java/org/verwandlung/voj/web/controller/AdministrationController.java @@ -368,9 +368,17 @@ public ModelAndView allProblemsView( final int NUMBER_OF_PROBLEMS_PER_PAGE = 100; List problemCategories = problemService.getProblemCategories(); long totalProblems = problemService.getNumberOfProblemsUsingFilters(keyword, problemCategorySlug, false); + long offset = (pageNumber >= 1 ? pageNumber - 1 : 0) * NUMBER_OF_PROBLEMS_PER_PAGE; - List problems = problemService.getProblemsUsingFilters(offset, keyword, problemCategorySlug, false, NUMBER_OF_PROBLEMS_PER_PAGE); - + long problemIdLowerBound = problemService.getFirstIndexOfProblems() + offset; + long problemIdUpperBound = problemIdLowerBound + NUMBER_OF_PROBLEMS_PER_PAGE - 1; + + List problems = problemService.getProblemsUsingFilters(problemIdLowerBound, keyword, problemCategorySlug, problemTagSlug, false, NUMBER_OF_PROBLEMS_PER_PAGE); + Map> problemCategoryRelationships = + problemService.getProblemCategoriesOfProblems(problemIdLowerBound, problemIdUpperBound); + Map> problemTagRelationships = + problemService.getProblemTagsOfProblems(problemIdLowerBound, problemIdUpperBound); + ModelAndView view = new ModelAndView("administration/all-problems"); view.addObject("problemCategories", problemCategories); view.addObject("selectedProblemCategory", problemCategorySlug); @@ -378,9 +386,11 @@ public ModelAndView allProblemsView( view.addObject("currentPage", pageNumber); view.addObject("totalPages", (long) Math.ceil(totalProblems * 1.0 / NUMBER_OF_PROBLEMS_PER_PAGE)); view.addObject("problems", problems); + view.addObject("problemCategoryRelationships", problemCategoryRelationships); + view.addObject("problemTagRelationships", problemTagRelationships); return view; } - + /** * 删除选定的试题. * @param problems - 试题ID的集合, 以逗号(, )分隔 @@ -414,42 +424,12 @@ public ModelAndView allProblemsView( @RequestMapping(value = "/new-problem", method = RequestMethod.GET) public ModelAndView newProblemView( HttpServletRequest request, HttpServletResponse response) { - Map> problemCategories = getProblemCategories(); + Map> problemCategories = problemService.getProblemCategoriesWithHierarchy(); ModelAndView view = new ModelAndView("administration/new-problem"); view.addObject("problemCategories", problemCategories); return view; } - - /** - * 获得具有层次关系的试题分类列表. - * @return 包含试题分类及其继承关系的List对象 - */ - private Map> getProblemCategories() { - List problemCategories = problemService.getProblemCategories(); - Map> problemCategoriesIndexer = new HashMap>(); - Map> problemCategoriesHierarchy = new HashMap>(); - - // 将无父亲的试题分类加入列表 - for ( ProblemCategory pc : problemCategories ) { - if ( pc.getParentProblemCategoryId() == 0 ) { - List subProblemCategories = new ArrayList(); - problemCategoriesHierarchy.put(pc, subProblemCategories); - problemCategoriesIndexer.put(pc.getProblemCategoryId(), subProblemCategories); - } - } - // 将其他试题分类加入列表 - for ( ProblemCategory pc : problemCategories ) { - int parentProblemCategoryId = pc.getParentProblemCategoryId() ; - if ( parentProblemCategoryId != 0 ) { - List subProblemCategories = problemCategoriesIndexer.get(parentProblemCategoryId); - if ( subProblemCategories != null ) { - subProblemCategories.add(pc); - } - } - } - return problemCategoriesHierarchy; - } /** * 处理用户创建试题的请求. @@ -525,7 +505,7 @@ public ModelAndView editProblemsView( } List checkpoints = problemService.getCheckpointsUsingProblemId(problemId); List selectedProblemCategories = problemService.getProblemCategoriesUsingProblemId(problemId); - Map> problemCategories = getProblemCategories(); + Map> problemCategories = problemService.getProblemCategoriesWithHierarchy(); List problemTags = problemService.getProblemTagsUsingProblemId(problemId); ModelAndView view = new ModelAndView("administration/edit-problem"); diff --git a/web/src/main/java/org/verwandlung/voj/web/controller/ProblemsController.java b/web/src/main/java/org/verwandlung/voj/web/controller/ProblemsController.java index cbac1947..5ce90fc5 100644 --- a/web/src/main/java/org/verwandlung/voj/web/controller/ProblemsController.java +++ b/web/src/main/java/org/verwandlung/voj/web/controller/ProblemsController.java @@ -63,7 +63,7 @@ public ModelAndView problemsView( startIndex = startIndexOfProblems; } - List problems = problemService.getProblemsUsingFilters(startIndex, keyword, problemCategorySlug, true, NUMBER_OF_PROBLEMS_PER_PAGE); + List problems = problemService.getProblemsUsingFilters(startIndex, keyword, problemCategorySlug, null, true, NUMBER_OF_PROBLEMS_PER_PAGE); long totalProblems = problemService.getNumberOfProblemsUsingFilters(keyword, problemCategorySlug, true); ModelAndView view = new ModelAndView("problems/problems"); view.addObject("problems", problems) @@ -71,7 +71,7 @@ public ModelAndView problemsView( .addObject("numberOfProblemsPerPage", NUMBER_OF_PROBLEMS_PER_PAGE) .addObject("totalProblems", totalProblems) .addObject("keyword", keyword) - .addObject("problemCategories", getProblemCategories()) + .addObject("problemCategories", problemService.getProblemCategoriesWithHierarchy()) .addObject("selectedCategorySlug", problemCategorySlug); HttpSession session = request.getSession(); @@ -91,36 +91,6 @@ public ModelAndView problemsView( private long getFirstIndexOfProblems() { return problemService.getFirstIndexOfProblems(); } - - /** - * 获得具有层次关系的试题分类列表. - * @return 包含试题分类及其继承关系的List对象 - */ - private Map> getProblemCategories() { - List problemCategories = problemService.getProblemCategories(); - Map> problemCategoriesIndexer = new HashMap>(); - Map> problemCategoriesHierarchy = new HashMap>(); - - // 将无父亲的试题分类加入列表 - for ( ProblemCategory pc : problemCategories ) { - if ( pc.getParentProblemCategoryId() == 0 ) { - List subProblemCategories = new ArrayList(); - problemCategoriesHierarchy.put(pc, subProblemCategories); - problemCategoriesIndexer.put(pc.getProblemCategoryId(), subProblemCategories); - } - } - // 将其他试题分类加入列表 - for ( ProblemCategory pc : problemCategories ) { - int parentProblemCategoryId = pc.getParentProblemCategoryId() ; - if ( parentProblemCategoryId != 0 ) { - List subProblemCategories = problemCategoriesIndexer.get(parentProblemCategoryId); - if ( subProblemCategories != null ) { - subProblemCategories.add(pc); - } - } - } - return problemCategoriesHierarchy; - } /** * 获取试题列表. @@ -135,7 +105,7 @@ private Map> getProblemCategories() { @RequestParam(value = "category", required = false) String problemCategorySlug, HttpServletRequest request) { HttpSession session = request.getSession(); - List problems = problemService.getProblemsUsingFilters(startIndex, keyword, problemCategorySlug, true, NUMBER_OF_PROBLEMS_PER_PAGE); + List problems = problemService.getProblemsUsingFilters(startIndex, keyword, problemCategorySlug, null, true, NUMBER_OF_PROBLEMS_PER_PAGE); Map submissionOfProblems = null; if ( isLoggedIn(session) ) { long userId = (Long)session.getAttribute("uid"); diff --git a/web/src/main/java/org/verwandlung/voj/web/mapper/ProblemCategoryMapper.java b/web/src/main/java/org/verwandlung/voj/web/mapper/ProblemCategoryMapper.java index 04a35800..80fe7c76 100644 --- a/web/src/main/java/org/verwandlung/voj/web/mapper/ProblemCategoryMapper.java +++ b/web/src/main/java/org/verwandlung/voj/web/mapper/ProblemCategoryMapper.java @@ -1,10 +1,12 @@ package org.verwandlung.voj.web.mapper; import java.util.List; +import java.util.Map; import org.apache.ibatis.annotations.CacheNamespace; import org.apache.ibatis.annotations.Param; import org.verwandlung.voj.web.model.ProblemCategory; +import org.verwandlung.voj.web.model.ProblemCategoryRelationship; /** * ProblemCategory Data Access Object. @@ -39,7 +41,9 @@ public interface ProblemCategoryMapper { * @param problemIdUpperBound - 试题ID区间的上界 * @return 包含试题分类信息的列表 */ - public List getProblemCategoriesOfProblems(long problemIdLowerBound, long problemIdUpperBound); + public List getProblemCategoriesOfProblems( + @Param(value = "problemIdLowerBound") long problemIdLowerBound, + @Param(value = "problemIdUpperBound") long problemIdUpperBound); /** * 通过试题分类的别名获取试题分类对象. diff --git a/web/src/main/java/org/verwandlung/voj/web/mapper/ProblemMapper.java b/web/src/main/java/org/verwandlung/voj/web/mapper/ProblemMapper.java index 68e8511c..bed66268 100644 --- a/web/src/main/java/org/verwandlung/voj/web/mapper/ProblemMapper.java +++ b/web/src/main/java/org/verwandlung/voj/web/mapper/ProblemMapper.java @@ -67,6 +67,7 @@ public long getUpperBoundOfProblemsWithLimit( * 通过试题唯一标识符和关键字获取某个范围内的所有试题. * @param keyword - 关键词 * @param problemCategoryId - 试题分类的唯一标识符 + * @param problemTagId - 试题标签的唯一标识符 * @param isPublicOnly - 是否只筛选公开试题 * @param offset - 试题唯一标识符的起始编号 * @param limit - 需要获取的试题的数量 @@ -75,6 +76,7 @@ public long getUpperBoundOfProblemsWithLimit( public List getProblemsUsingFilters( @Param("keyword") String keyword, @Param("problemCategoryId") int problemCategoryId, + @Param("problemTagId") long problemTagId, @Param("isPublicOnly") boolean isPublicOnly, @Param("problemId") long offset, @Param("limit") int limit); diff --git a/web/src/main/java/org/verwandlung/voj/web/mapper/ProblemTagMapper.java b/web/src/main/java/org/verwandlung/voj/web/mapper/ProblemTagMapper.java index 642884e8..8fd6644a 100644 --- a/web/src/main/java/org/verwandlung/voj/web/mapper/ProblemTagMapper.java +++ b/web/src/main/java/org/verwandlung/voj/web/mapper/ProblemTagMapper.java @@ -5,6 +5,7 @@ import org.apache.ibatis.annotations.CacheNamespace; import org.apache.ibatis.annotations.Param; import org.verwandlung.voj.web.model.ProblemTag; +import org.verwandlung.voj.web.model.ProblemTagRelationship; /** * ProblemTag Data Access Object. @@ -31,8 +32,19 @@ public interface ProblemTagMapper { * @param problemId - 试题的唯一标识符 * @return 预期的试题标签对象列表 */ - public List getProblemTagUsingProblemId(long problemId); - + public List getProblemTagsUsingProblemId(long problemId); + + /** + * 获取某个区间内各试题的标签. + * @param problemIdLowerBound - 试题ID区间的下界 + * @param problemIdUpperBound - 试题ID区间的上界 + * @return 包含试题标签信息的列表 + */ + public List getProblemTagsOfProblems( + @Param(value = "problemIdLowerBound") long problemIdLowerBound, + @Param(value = "problemIdUpperBound") long problemIdUpperBound); + + /** * 通过试题标签的别名获取试题标签对象. * @param problemTagSlug - 试题标签的别名 diff --git a/web/src/main/java/org/verwandlung/voj/web/model/ProblemCategoryRelationship.java b/web/src/main/java/org/verwandlung/voj/web/model/ProblemCategoryRelationship.java new file mode 100644 index 00000000..dc4b4cbf --- /dev/null +++ b/web/src/main/java/org/verwandlung/voj/web/model/ProblemCategoryRelationship.java @@ -0,0 +1,146 @@ +package org.verwandlung.voj.web.model; + +import java.io.Serializable; + +/** + * 试题分类关系的 Model. + * 对应数据库中的voj_problem_category_relationships数据表. + * + * @author Haozhe Xie + */ +public class ProblemCategoryRelationship implements Serializable { + /** + * ProblemCategoryRelationship的默认构造函数. + */ + public ProblemCategoryRelationship() { } + + /** + * ProblemCategoryRelationship的构造函数. + * @param problemId - 试题的唯一标识符 + * @param problemCategoryId - 试题分类的唯一标识符 + * @param problemCategorySlug - 试题分类的别名 + * @param problemCategoryName - 试题分类的名称 + */ + public ProblemCategoryRelationship(long problemId, int problemCategoryId, String problemCategorySlug, String problemCategoryName) { + this.problemId = problemId; + this.problemCategoryId = problemCategoryId; + this.problemCategorySlug = problemCategorySlug; + this.problemCategoryName = problemCategoryName; + } + + /** + * 获取试题的唯一标识符. + * @return 试题的唯一标识符 + */ + public long getProblemId() { + return problemId; + } + + /** + * 设置试题的唯一标识符. + * @param problemId - 试题的唯一标识符 + */ + public void setProblemId(long problemId) { + this.problemId = problemId; + } + + /** + * 获取试题分类的唯一标识符. + * @return 试题分类的唯一标识符 + */ + public int getProblemCategoryId() { + return problemCategoryId; + } + + /** + * 设置试题分类的唯一标识符. + * @param problemCategoryId - 试题分类的唯一标识符 + */ + public void setProblemCategoryId(int problemCategoryId) { + this.problemCategoryId = problemCategoryId; + } + + /** + * 获取试题分类的别名. + * @return 试题分类的别名 + */ + public String getProblemCategorySlug() { + return problemCategorySlug; + } + + /** + * 设置试题分类的别名. + * @param problemCategorySlug - 试题分类的别名 + */ + public void setProblemCategorySlug(String problemCategorySlug) { + this.problemCategorySlug = problemCategorySlug; + } + + /** + * 获取试题分类的名称. + * @return 试题分类的名称 + */ + public String getProblemCategoryName() { + return problemCategoryName; + } + + /** + * 设置试题分类的名称. + * @param problemCategoryName - 试题分类的名称 + */ + public void setProblemCategoryName(String problemCategoryName) { + this.problemCategoryName = problemCategoryName; + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + public int hashCode() { + return (int) problemId + (int) problemCategoryId; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals(Object obj) { + if ( obj instanceof ProblemCategoryRelationship ) { + ProblemCategoryRelationship anotherCategoryRelationship = (ProblemCategoryRelationship)obj; + return anotherCategoryRelationship.getProblemId() == problemId && + anotherCategoryRelationship.getProblemCategoryId() == problemCategoryId; + } + return false; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + public String toString() { + return String.format("ProblemCategoryRelationship [ProblemID=%d, CategoryID=%d, Slug=%s, Name=%s]", + new Object[] { problemId, problemCategoryId, problemCategorySlug, problemCategoryName }); + } + + /** + * 试题的唯一标识符. + */ + private long problemId; + + /** + * 试题分类的唯一标识符. + */ + private int problemCategoryId; + + /** + * 试题分类的别名. + */ + private String problemCategorySlug; + + /** + * 试题分类的名称. + */ + private String problemCategoryName; + + /** + * 唯一的序列化标识符. + */ + private static final long serialVersionUID = 5108958918621777517L; +} diff --git a/web/src/main/java/org/verwandlung/voj/web/model/ProblemTagRelationship.java b/web/src/main/java/org/verwandlung/voj/web/model/ProblemTagRelationship.java new file mode 100644 index 00000000..17b6bfff --- /dev/null +++ b/web/src/main/java/org/verwandlung/voj/web/model/ProblemTagRelationship.java @@ -0,0 +1,146 @@ +package org.verwandlung.voj.web.model; + +import java.io.Serializable; + +/** + * 试题标签关系的 Model. + * 对应数据库中的voj_problem_tag_relationships数据表. + * + * @author Haozhe Xie + */ +public class ProblemTagRelationship implements Serializable { + /** + * ProblemTagRelationship的默认构造函数. + */ + public ProblemTagRelationship() { } + + /** + * ProblemTagRelationship的构造函数. + * @param problemId - 试题的唯一标识符 + * @param problemTagId - 试题标签的唯一标识符 + * @param problemTagSlug - 试题标签的别名 + * @param problemTagName - 试题标签的名称 + */ + public ProblemTagRelationship(long problemId, long problemTagId, String problemTagSlug, String problemTagName) { + this.problemId = problemId; + this.problemTagId = problemTagId; + this.problemTagSlug = problemTagSlug; + this.problemTagName = problemTagName; + } + + /** + * 获取试题的唯一标识符. + * @return 试题的唯一标识符 + */ + public long getProblemId() { + return problemId; + } + + /** + * 设置试题的唯一标识符. + * @param problemId - 试题的唯一标识符 + */ + public void setProblemId(long problemId) { + this.problemId = problemId; + } + + /** + * 获取试题标签的唯一标识符. + * @return 试题标签的唯一标识符 + */ + public long getProblemTagId() { + return problemTagId; + } + + /** + * 设置试题标签的唯一标识符. + * @param problemTagId - 试题标签的唯一标识符 + */ + public void setProblemTagId(long problemTagId) { + this.problemTagId = problemTagId; + } + + /** + * 获取试题标签的别名. + * @return 试题标签的别名 + */ + public String getProblemTagSlug() { + return problemTagSlug; + } + + /** + * 设置试题标签的别名. + * @param problemTagSlug - 试题标签的别名 + */ + public void setProblemTagSlug(String problemTagSlug) { + this.problemTagSlug = problemTagSlug; + } + + /** + * 获取试题标签的名称. + * @return 试题标签的名称 + */ + public String getProblemTagName() { + return problemTagName; + } + + /** + * 设置试题标签的名称. + * @param problemTagName - 试题标签的名称 + */ + public void setProblemTagName(String problemTagName) { + this.problemTagName = problemTagName; + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + public int hashCode() { + return (int) problemId + (int) problemTagId; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals(Object obj) { + if ( obj instanceof ProblemTagRelationship ) { + ProblemTagRelationship anotherTagRelationship = (ProblemTagRelationship)obj; + return anotherTagRelationship.getProblemId() == problemId && + anotherTagRelationship.getProblemTagId() == problemTagId; + } + return false; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + public String toString() { + return String.format("ProblemTagRelationship [ProblemID=%d, TagID=%d, Slug=%s, Name=%s]", + new Object[] { problemId, problemTagId, problemTagSlug, problemTagName }); + } + + /** + * 试题的唯一标识符. + */ + private long problemId; + + /** + * 试题标签的唯一标识符. + */ + private long problemTagId; + + /** + * 试题标签的别名. + */ + private String problemTagSlug; + + /** + * 试题标签的名称. + */ + private String problemTagName; + + /** + * 唯一的序列化标识符. + */ + private static final long serialVersionUID = -1636820984815816993L; +} diff --git a/web/src/main/java/org/verwandlung/voj/web/service/ProblemService.java b/web/src/main/java/org/verwandlung/voj/web/service/ProblemService.java index bc5faee3..5644bf49 100644 --- a/web/src/main/java/org/verwandlung/voj/web/service/ProblemService.java +++ b/web/src/main/java/org/verwandlung/voj/web/service/ProblemService.java @@ -1,10 +1,6 @@ package org.verwandlung.voj.web.service; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -14,10 +10,7 @@ import org.verwandlung.voj.web.mapper.ProblemCategoryMapper; import org.verwandlung.voj.web.mapper.ProblemMapper; import org.verwandlung.voj.web.mapper.ProblemTagMapper; -import org.verwandlung.voj.web.model.Checkpoint; -import org.verwandlung.voj.web.model.Problem; -import org.verwandlung.voj.web.model.ProblemCategory; -import org.verwandlung.voj.web.model.ProblemTag; +import org.verwandlung.voj.web.model.*; import org.verwandlung.voj.web.util.SlugifyUtils; import com.alibaba.fastjson.JSON; @@ -60,21 +53,28 @@ public Problem getProblem(long problemId) { } /** - * 获取公开的试题列表. + * 获取试题列表. * @param offset - 试题唯一标识符的起始序号 * @param keyword - 关键字 * @param problemCategorySlug - 试题分类的别名 + * @param problemTagSlug - 试题标签的别名 * @param isPublicOnly - 是否只筛选公开试题 * @param limit - 每次加载试题的数量 * @return 试题列表(List对象) */ - public List getProblemsUsingFilters(long offset, String keyword, String problemCategorySlug, boolean isPublicOnly, int limit) { + public List getProblemsUsingFilters(long offset, String keyword, String problemCategorySlug, + String problemTagSlug, boolean isPublicOnly, int limit) { ProblemCategory problemCategory = problemCategoryMapper.getProblemCategoryUsingCategorySlug(problemCategorySlug); + ProblemTag problemTag = problemTagMapper.getProblemTagUsingTagSlug(SlugifyUtils.getSlug(problemTagSlug)); int problemCategoryId = 0; + long problemTagId = 0; if ( problemCategory != null ) { problemCategoryId = problemCategory.getProblemCategoryId(); } - return problemMapper.getProblemsUsingFilters(keyword, problemCategoryId, isPublicOnly, offset, limit); + if ( problemTag != null ) { + problemTagId = problemTag.getProblemTagId(); + } + return problemMapper.getProblemsUsingFilters(keyword, problemCategoryId, problemTagId, isPublicOnly, offset, limit); } /** @@ -92,6 +92,32 @@ public long getNumberOfProblemsUsingFilters(String keyword, String problemCatego } return problemMapper.getNumberOfProblemsUsingFilters(keyword, problemCategoryId, isPublicOnly); } + + /** + * 获取某个区间内各试题的分类. + * @param problemIdLowerBound - 试题ID区间的下界 + * @param problemIdUpperBound - 试题ID区间的上界 + * @return 包含试题分类信息的列表 + */ + public Map> getProblemCategoriesOfProblems( + long problemIdLowerBound, long problemIdUpperBound) { + List problemCategoryRelationships = + problemCategoryMapper.getProblemCategoriesOfProblems(problemIdLowerBound, problemIdUpperBound); + + Map> problemCategoriesOfProblems = new HashMap<>(); + for ( ProblemCategoryRelationship pcr : problemCategoryRelationships ) { + long problemId = pcr.getProblemId(); + if ( !problemCategoriesOfProblems.containsKey(problemId) ) { + problemCategoriesOfProblems.put(problemId, new ArrayList()); + } + + List problemCategories = problemCategoriesOfProblems.get(problemId); + problemCategories.add(new ProblemCategory( + pcr.getProblemCategoryId(), pcr.getProblemCategorySlug(), + pcr.getProblemCategoryName(), 0)); + } + return problemCategoriesOfProblems; + } /** * 获取试题的分类列表. @@ -101,6 +127,32 @@ public long getNumberOfProblemsUsingFilters(String keyword, String problemCatego public List getProblemCategoriesUsingProblemId(long problemId) { return problemCategoryMapper.getProblemCategoriesUsingProblemId(problemId); } + + /** + * 获取某个区间内各试题的标签. + * @param problemIdLowerBound - 试题ID区间的下界 + * @param problemIdUpperBound - 试题ID区间的上界 + * @return 包含试题标签信息的列表 + */ + public Map> getProblemTagsOfProblems( + long problemIdLowerBound, long problemIdUpperBound) { + List problemTagRelationships = + problemTagMapper.getProblemTagsOfProblems(problemIdLowerBound, problemIdUpperBound); + + Map> problemTagsOfProblems = new HashMap<>(); + for ( ProblemTagRelationship ptr : problemTagRelationships ) { + long problemId = ptr.getProblemId(); + if ( !problemTagsOfProblems.containsKey(problemId) ) { + problemTagsOfProblems.put(problemId, new ArrayList()); + } + + List problemTags = problemTagsOfProblems.get(problemId); + problemTags.add(new ProblemTag( + ptr.getProblemTagId(), ptr.getProblemTagSlug(), + ptr.getProblemTagName())); + } + return problemTagsOfProblems; + } /** * 获取试题的标签列表. @@ -108,7 +160,37 @@ public List getProblemCategoriesUsingProblemId(long problemId) * @return 包含试题标签的列表 */ public List getProblemTagsUsingProblemId(long problemId) { - return problemTagMapper.getProblemTagUsingProblemId(problemId); + return problemTagMapper.getProblemTagsUsingProblemId(problemId); + } + + /** + * 获得具有层次关系的试题分类列表. + * @return 包含试题分类及其继承关系的Map>对象 + */ + public Map> getProblemCategoriesWithHierarchy() { + List problemCategories = getProblemCategories(); + Map> problemCategoriesIndexer = new HashMap>(); + Map> problemCategoriesHierarchy = new HashMap>(); + + // 将无父亲的试题分类加入列表 + for ( ProblemCategory pc : problemCategories ) { + if ( pc.getParentProblemCategoryId() == 0 ) { + List subProblemCategories = new ArrayList(); + problemCategoriesHierarchy.put(pc, subProblemCategories); + problemCategoriesIndexer.put(pc.getProblemCategoryId(), subProblemCategories); + } + } + // 将其他试题分类加入列表 + for ( ProblemCategory pc : problemCategories ) { + int parentProblemCategoryId = pc.getParentProblemCategoryId() ; + if ( parentProblemCategoryId != 0 ) { + List subProblemCategories = problemCategoriesIndexer.get(parentProblemCategoryId); + if ( subProblemCategories != null ) { + subProblemCategories.add(pc); + } + } + } + return problemCategoriesHierarchy; } /** diff --git a/web/src/main/resources/mappers/ProblemCategoryMapper.xml b/web/src/main/resources/mappers/ProblemCategoryMapper.xml index b0961583..c013a72f 100644 --- a/web/src/main/resources/mappers/ProblemCategoryMapper.xml +++ b/web/src/main/resources/mappers/ProblemCategoryMapper.xml @@ -11,6 +11,13 @@ + + + + + + SELECT * FROM voj_problem_category_relationships diff --git a/web/src/main/resources/mappers/ProblemMapper.xml b/web/src/main/resources/mappers/ProblemMapper.xml index 1fc20b9c..dd79e658 100644 --- a/web/src/main/resources/mappers/ProblemMapper.xml +++ b/web/src/main/resources/mappers/ProblemMapper.xml @@ -94,7 +94,7 @@ parameterType="map" resultMap="ProblemResultMap" useCache="true"> - SELECT DISTINCT(problem_id), problem_name, problem_is_public, ( + SELECT DISTINCT(p.problem_id), problem_name, problem_is_public, ( SELECT COUNT(*) FROM voj_submissions s WHERE s.problem_id = p.problem_id @@ -105,8 +105,10 @@ ) AS accepted_submission FROM voj_problems p NATURAL JOIN voj_problem_category_relationships pcr - NATURAL JOIN voj_problem_categories pc - WHERE problem_id >= #{problemId} + + NATURAL JOIN voj_problem_tag_relationships ptr + + WHERE p.problem_id >= #{problemId} AND problem_is_public = 1 @@ -114,7 +116,10 @@ AND problem_name LIKE "%"#{keyword}"%" - AND problem_category_id = #{problemCategoryId} + AND problem_category_id = #{problemCategoryId} + + + AND problem_tag_id = #{problemTagId} LIMIT #{limit} diff --git a/web/src/main/resources/mappers/ProblemTagMapper.xml b/web/src/main/resources/mappers/ProblemTagMapper.xml index 56581cf0..4020f5c6 100644 --- a/web/src/main/resources/mappers/ProblemTagMapper.xml +++ b/web/src/main/resources/mappers/ProblemTagMapper.xml @@ -10,6 +10,13 @@ + + + + + + @@ -35,6 +42,16 @@ NATURAL JOIN voj_problem_tag_relationships WHERE problem_id = #{problemId} + " value="${keyword}" /> -
+
-
-
- -
+
+
+ +
@@ -117,8 +117,30 @@ ${problem.problemName} - - + + + + + + "> + ${problemCategory.problemCategoryName} + , + + + + + + + + + + "> + ${problemTag.problemTagName} + , + + + + ${problem.totalSubmission} ${problem.acceptedSubmission} diff --git a/web/src/test/java/org/verwandlung/voj/web/mapper/CheckpointMapperTest.java b/web/src/test/java/org/verwandlung/voj/web/mapper/CheckpointMapperTest.java index 76bbc324..50ce2bcf 100644 --- a/web/src/test/java/org/verwandlung/voj/web/mapper/CheckpointMapperTest.java +++ b/web/src/test/java/org/verwandlung/voj/web/mapper/CheckpointMapperTest.java @@ -21,83 +21,83 @@ @Transactional @ContextConfiguration({"classpath:test-spring-context.xml"}) public class CheckpointMapperTest { - /** - * 测试用例: 测试getCheckpointsUsingProblemId(long)方法 - * 测试数据: 使用存在的试题唯一标识符(1000) - * 预期结果: 返回对应的测试点列表(10个项目) - */ - @Test - public void testGetCheckpointsUsingProblemIdExists() { - List checkpoints = checkpointMapper.getCheckpointsUsingProblemId(1000); - Assert.assertEquals(10, checkpoints.size()); - - Checkpoint firstCheckpoint = checkpoints.get(0); - String output = firstCheckpoint.getOutput(); - Assert.assertEquals("45652\r\n", output); - } - - /** - * 测试用例: 测试getCheckpointsUsingProblemId(long)方法 - * 测试数据: 使用不存在的试题唯一标识符(0) - * 预期结果: 返回对应的测试点列表(0个项目) - */ - @Test - public void testGetCheckpointsUsingProblemIdNotExists() { - List checkpoints = checkpointMapper.getCheckpointsUsingProblemId(0); - Assert.assertEquals(0, checkpoints.size()); - } - - /** - * 测试用例: 测试createCheckpoint(Checkpoint)方法 - * 测试数据: 使用正常的数据集创建测试点 - * 预期结果: 测试点被成功创建 - */ - @Test - public void testCreateCheckpointNormally() { - Checkpoint checkpoint = new Checkpoint(1000, 100, false, 10, "input", "output"); - checkpointMapper.createCheckpoint(checkpoint); - } - - /** - * 测试用例: 测试createCheckpoint(Checkpoint)方法 - * 测试数据: 使用重复的主键创建测试点 - * 预期结果: 抛出DuplicateKeyException异常 - */ - @Test(expected = org.springframework.dao.DuplicateKeyException.class) - public void testCreateCheckpointUsingExistingProblemIdAndCheckpointId() { - Checkpoint checkpoint = new Checkpoint(1000, 0, false, 10, "input", "output"); - checkpointMapper.createCheckpoint(checkpoint); - } - - /** - * 测试用例: 测试createCheckpoint(Checkpoint)方法 - * 测试数据: 使用不存在的试题ID创建测试点 - * 预期结果: 抛出DataIntegrityViolationException异常 - */ - @Test(expected = org.springframework.dao.DataIntegrityViolationException.class) - public void testCreateCheckpointUsingNotExistingProblemId() { - Checkpoint checkpoint = new Checkpoint(0, 100, false, 10, "input", "output"); - checkpointMapper.createCheckpoint(checkpoint); - } - - /** - * 测试用例: 测试deleteCheckpoint(long)方法 - * 测试数据: 使用存在的试题ID删除测试点 - * 预期结果: 指定试题的全部测试点被删除 - */ - @Test - public void testDeleteCheckpointUsingExistsingProblemId() { - List checkpoints = checkpointMapper.getCheckpointsUsingProblemId(1000); - Assert.assertEquals(10, checkpoints.size()); - - checkpointMapper.deleteCheckpoint(1000); - checkpoints = checkpointMapper.getCheckpointsUsingProblemId(1000); - Assert.assertEquals(0, checkpoints.size()); - } - - /** - * 待测试的CheckpointMapper对象. - */ - @Autowired - private CheckpointMapper checkpointMapper; + /** + * 测试用例: 测试getCheckpointsUsingProblemId(long)方法 + * 测试数据: 使用存在的试题唯一标识符(1000) + * 预期结果: 返回对应的测试点列表(10个项目) + */ + @Test + public void testGetCheckpointsUsingProblemIdExists() { + List checkpoints = checkpointMapper.getCheckpointsUsingProblemId(1000); + Assert.assertEquals(10, checkpoints.size()); + + Checkpoint firstCheckpoint = checkpoints.get(0); + String output = firstCheckpoint.getOutput(); + Assert.assertEquals("45652\r\n", output); + } + + /** + * 测试用例: 测试getCheckpointsUsingProblemId(long)方法 + * 测试数据: 使用不存在的试题唯一标识符(0) + * 预期结果: 返回对应的测试点列表(0个项目) + */ + @Test + public void testGetCheckpointsUsingProblemIdNotExists() { + List checkpoints = checkpointMapper.getCheckpointsUsingProblemId(0); + Assert.assertEquals(0, checkpoints.size()); + } + + /** + * 测试用例: 测试createCheckpoint(Checkpoint)方法 + * 测试数据: 使用正常的数据集创建测试点 + * 预期结果: 测试点被成功创建 + */ + @Test + public void testCreateCheckpointNormally() { + Checkpoint checkpoint = new Checkpoint(1000, 100, false, 10, "input", "output"); + checkpointMapper.createCheckpoint(checkpoint); + } + + /** + * 测试用例: 测试createCheckpoint(Checkpoint)方法 + * 测试数据: 使用重复的主键创建测试点 + * 预期结果: 抛出DuplicateKeyException异常 + */ + @Test(expected = org.springframework.dao.DuplicateKeyException.class) + public void testCreateCheckpointUsingExistingProblemIdAndCheckpointId() { + Checkpoint checkpoint = new Checkpoint(1000, 0, false, 10, "input", "output"); + checkpointMapper.createCheckpoint(checkpoint); + } + + /** + * 测试用例: 测试createCheckpoint(Checkpoint)方法 + * 测试数据: 使用不存在的试题ID创建测试点 + * 预期结果: 抛出DataIntegrityViolationException异常 + */ + @Test(expected = org.springframework.dao.DataIntegrityViolationException.class) + public void testCreateCheckpointUsingNotExistingProblemId() { + Checkpoint checkpoint = new Checkpoint(0, 100, false, 10, "input", "output"); + checkpointMapper.createCheckpoint(checkpoint); + } + + /** + * 测试用例: 测试deleteCheckpoint(long)方法 + * 测试数据: 使用存在的试题ID删除测试点 + * 预期结果: 指定试题的全部测试点被删除 + */ + @Test + public void testDeleteCheckpointUsingExistsingProblemId() { + List checkpoints = checkpointMapper.getCheckpointsUsingProblemId(1000); + Assert.assertEquals(10, checkpoints.size()); + + checkpointMapper.deleteCheckpoint(1000); + checkpoints = checkpointMapper.getCheckpointsUsingProblemId(1000); + Assert.assertEquals(0, checkpoints.size()); + } + + /** + * 待测试的CheckpointMapper对象. + */ + @Autowired + private CheckpointMapper checkpointMapper; } diff --git a/web/src/test/java/org/verwandlung/voj/web/mapper/EmailValidationMapperTest.java b/web/src/test/java/org/verwandlung/voj/web/mapper/EmailValidationMapperTest.java index cc05f160..2278dbbe 100644 --- a/web/src/test/java/org/verwandlung/voj/web/mapper/EmailValidationMapperTest.java +++ b/web/src/test/java/org/verwandlung/voj/web/mapper/EmailValidationMapperTest.java @@ -21,99 +21,99 @@ @Transactional @ContextConfiguration({"classpath:test-spring-context.xml"}) public class EmailValidationMapperTest { - /** - * 测试用例: 测试getEmailValidation(String)方法 - * 测试数据: 使用存在的电子邮件地址 - * 预期结果: 返回预期的EmailValidation对象 - */ - @Test - public void testGetEmailValidationExists() { - EmailValidation emailValidation = emailValidationMapper.getEmailValidation("support@zjhzxhz.com"); - Assert.assertNotNull(emailValidation); - - String token = emailValidation.getToken(); - Assert.assertEquals("Random-String-Generated", token); - } + /** + * 测试用例: 测试getEmailValidation(String)方法 + * 测试数据: 使用存在的电子邮件地址 + * 预期结果: 返回预期的EmailValidation对象 + */ + @Test + public void testGetEmailValidationExists() { + EmailValidation emailValidation = emailValidationMapper.getEmailValidation("support@zjhzxhz.com"); + Assert.assertNotNull(emailValidation); + + String token = emailValidation.getToken(); + Assert.assertEquals("Random-String-Generated", token); + } - /** - * 测试用例: 测试getEmailValidation(String)方法 - * 测试数据: 使用不存在的电子邮件地址 - * 预期结果: 返回空引用 - */ - @Test - public void testGetEmailValidationNotExists() { - EmailValidation emailValidation = emailValidationMapper.getEmailValidation("not-exists@zjhzxhz.com"); - Assert.assertNull(emailValidation); - } + /** + * 测试用例: 测试getEmailValidation(String)方法 + * 测试数据: 使用不存在的电子邮件地址 + * 预期结果: 返回空引用 + */ + @Test + public void testGetEmailValidationNotExists() { + EmailValidation emailValidation = emailValidationMapper.getEmailValidation("not-exists@zjhzxhz.com"); + Assert.assertNull(emailValidation); + } - /** - * 测试用例: 测试createEmailValidation(EmailValidation)方法 - * 测试数据: 使用合法的数据集, 并且该电子邮件地址不存在相应的记录 - * 预期结果: 数据插入操作成功完成 - */ - @Test - public void testCreateEmailValidationNormally() { - EmailValidation emailValidation = new EmailValidation("zjhzxhz@gmail.com", "RandomToken", new Date()); - emailValidationMapper.createEmailValidation(emailValidation); + /** + * 测试用例: 测试createEmailValidation(EmailValidation)方法 + * 测试数据: 使用合法的数据集, 并且该电子邮件地址不存在相应的记录 + * 预期结果: 数据插入操作成功完成 + */ + @Test + public void testCreateEmailValidationNormally() { + EmailValidation emailValidation = new EmailValidation("zjhzxhz@gmail.com", "RandomToken", new Date()); + emailValidationMapper.createEmailValidation(emailValidation); - EmailValidation insertedEmailValidation = emailValidationMapper.getEmailValidation("zjhzxhz@gmail.com"); - Assert.assertNotNull(insertedEmailValidation); + EmailValidation insertedEmailValidation = emailValidationMapper.getEmailValidation("zjhzxhz@gmail.com"); + Assert.assertNotNull(insertedEmailValidation); - String token = emailValidation.getToken(); - Assert.assertEquals("RandomToken", token); - } + String token = emailValidation.getToken(); + Assert.assertEquals("RandomToken", token); + } - /** - * 测试用例: 测试createEmailValidation(EmailValidation)方法 - * 测试数据: 使用合法的数据集, 但已存在该电子邮件地址对应的记录 - * 预期结果: 抛出DuplicateKeyException异常 - */ - @Test(expected = org.springframework.dao.DuplicateKeyException.class) - public void testCreateEmailValidationUsingExistingEmail() { - EmailValidation emailValidation = new EmailValidation("support@zjhzxhz.com", "RandomToken", new Date()); - emailValidationMapper.createEmailValidation(emailValidation); - } + /** + * 测试用例: 测试createEmailValidation(EmailValidation)方法 + * 测试数据: 使用合法的数据集, 但已存在该电子邮件地址对应的记录 + * 预期结果: 抛出DuplicateKeyException异常 + */ + @Test(expected = org.springframework.dao.DuplicateKeyException.class) + public void testCreateEmailValidationUsingExistingEmail() { + EmailValidation emailValidation = new EmailValidation("support@zjhzxhz.com", "RandomToken", new Date()); + emailValidationMapper.createEmailValidation(emailValidation); + } - /** - * 测试用例: 测试createEmailValidation(EmailValidation)方法 - * 测试数据: 使用合法的数据集, 但该电子邮件地址无用户使用(不满足外键参照完整性) - * 预期结果: 抛出DataIntegrityViolationException异常 - */ - @Test(expected = org.springframework.dao.DataIntegrityViolationException.class) - public void testCreateEmailValidationUsingNotExistingEmail() { - EmailValidation emailValidation = new EmailValidation("not-exists@zjhzxhz.com", "RandomToken", new Date()); - emailValidationMapper.createEmailValidation(emailValidation); - } + /** + * 测试用例: 测试createEmailValidation(EmailValidation)方法 + * 测试数据: 使用合法的数据集, 但该电子邮件地址无用户使用(不满足外键参照完整性) + * 预期结果: 抛出DataIntegrityViolationException异常 + */ + @Test(expected = org.springframework.dao.DataIntegrityViolationException.class) + public void testCreateEmailValidationUsingNotExistingEmail() { + EmailValidation emailValidation = new EmailValidation("not-exists@zjhzxhz.com", "RandomToken", new Date()); + emailValidationMapper.createEmailValidation(emailValidation); + } - /** - * 测试用例: 测试deleteEmailValidation(String)方法 - * 测试数据: 存在的电子邮件地址 - * 预期结果: 数据删除操作成功完成 - */ - @Test - public void testDeleteEmailValidationExists() { - EmailValidation emailValidation = emailValidationMapper.getEmailValidation("support@zjhzxhz.com"); - Assert.assertNotNull(emailValidation); + /** + * 测试用例: 测试deleteEmailValidation(String)方法 + * 测试数据: 存在的电子邮件地址 + * 预期结果: 数据删除操作成功完成 + */ + @Test + public void testDeleteEmailValidationExists() { + EmailValidation emailValidation = emailValidationMapper.getEmailValidation("support@zjhzxhz.com"); + Assert.assertNotNull(emailValidation); - emailValidationMapper.deleteEmailValidation("support@zjhzxhz.com"); + emailValidationMapper.deleteEmailValidation("support@zjhzxhz.com"); - emailValidation = emailValidationMapper.getEmailValidation("support@zjhzxhz.com"); - Assert.assertNull(emailValidation); - } + emailValidation = emailValidationMapper.getEmailValidation("support@zjhzxhz.com"); + Assert.assertNull(emailValidation); + } - /** - * 测试用例: 测试deleteEmailValidation(String)方法 - * 测试数据: 不存在的电子邮件地址 - * 预期结果: 方法正常执行, 未影响数据表中的数据 - */ - @Test - public void testDeleteEmailValidationNotExists() { - emailValidationMapper.deleteEmailValidation("not-exist@zjhzxhz.com"); - } - - /** - * 待测试的EmailValidationMapper对象. - */ - @Autowired - private EmailValidationMapper emailValidationMapper; + /** + * 测试用例: 测试deleteEmailValidation(String)方法 + * 测试数据: 不存在的电子邮件地址 + * 预期结果: 方法正常执行, 未影响数据表中的数据 + */ + @Test + public void testDeleteEmailValidationNotExists() { + emailValidationMapper.deleteEmailValidation("not-exist@zjhzxhz.com"); + } + + /** + * 待测试的EmailValidationMapper对象. + */ + @Autowired + private EmailValidationMapper emailValidationMapper; } diff --git a/web/src/test/java/org/verwandlung/voj/web/mapper/JudgeResultMapperTest.java b/web/src/test/java/org/verwandlung/voj/web/mapper/JudgeResultMapperTest.java index 7f02b8c0..dec2654b 100644 --- a/web/src/test/java/org/verwandlung/voj/web/mapper/JudgeResultMapperTest.java +++ b/web/src/test/java/org/verwandlung/voj/web/mapper/JudgeResultMapperTest.java @@ -18,59 +18,59 @@ @Transactional @ContextConfiguration({"classpath:test-spring-context.xml"}) public class JudgeResultMapperTest { - /** - * 测试用例: 测试getJudgeResultUsingId(int)方法 - * 测试数据: Accept评测结果(JudgeResult)的评测结果组唯一标识符 - * 预期结果: 返回评测结果(JudgeResult)的评测结果组对象 - */ - @Test - public void testGetJudgeResultUsingIdExists() { - JudgeResult judgeResult = judgeResultMapper.getJudgeResultUsingId(2); - Assert.assertNotNull(judgeResult); - - String judgeResultSlug = judgeResult.getJudgeResultSlug(); - Assert.assertEquals("AC", judgeResultSlug); - } - - /** - * 测试用例: 测试getJudgeResultUsingId(int)方法 - * 测试数据: 不存在的评测结果组唯一标识符 - * 预期结果: 返回空引用 - */ - @Test - public void testGetJudgeResultUsingIdNotExists() { - JudgeResult judgeResult = judgeResultMapper.getJudgeResultUsingId(0); - Assert.assertNull(judgeResult); - } - - /** - * 测试用例: 测试getJudgeResultUsingSlug(String)方法 - * 测试数据: 普通评测结果(JudgeResult)的评测结果组别名 - * 预期结果: 返回评测结果(JudgeResult)的评测结果组对象 - */ - @Test - public void testGetJudgeResultUsingSlugExists() { - JudgeResult judgeResult = judgeResultMapper.getJudgeResultUsingSlug("AC"); - Assert.assertNotNull(judgeResult); - - int judgeResultId = judgeResult.getJudgeResultId(); - Assert.assertEquals(2, judgeResultId); - } - - /** - * 测试用例: 测试getJudgeResultUsingSlug(String)方法 - * 测试数据: 不存在的评测结果组别名 - * 预期结果: 返回空引用 - */ - @Test - public void testGetJudgeResultUsingSlugNotExists() { - JudgeResult judgeResult = judgeResultMapper.getJudgeResultUsingSlug("Not-Exists"); - Assert.assertNull(judgeResult); - } - - /** - * 待测试的JudgeResultMapper对象. - */ - @Autowired - private JudgeResultMapper judgeResultMapper; + /** + * 测试用例: 测试getJudgeResultUsingId(int)方法 + * 测试数据: Accept评测结果(JudgeResult)的评测结果组唯一标识符 + * 预期结果: 返回评测结果(JudgeResult)的评测结果组对象 + */ + @Test + public void testGetJudgeResultUsingIdExists() { + JudgeResult judgeResult = judgeResultMapper.getJudgeResultUsingId(2); + Assert.assertNotNull(judgeResult); + + String judgeResultSlug = judgeResult.getJudgeResultSlug(); + Assert.assertEquals("AC", judgeResultSlug); + } + + /** + * 测试用例: 测试getJudgeResultUsingId(int)方法 + * 测试数据: 不存在的评测结果组唯一标识符 + * 预期结果: 返回空引用 + */ + @Test + public void testGetJudgeResultUsingIdNotExists() { + JudgeResult judgeResult = judgeResultMapper.getJudgeResultUsingId(0); + Assert.assertNull(judgeResult); + } + + /** + * 测试用例: 测试getJudgeResultUsingSlug(String)方法 + * 测试数据: 普通评测结果(JudgeResult)的评测结果组别名 + * 预期结果: 返回评测结果(JudgeResult)的评测结果组对象 + */ + @Test + public void testGetJudgeResultUsingSlugExists() { + JudgeResult judgeResult = judgeResultMapper.getJudgeResultUsingSlug("AC"); + Assert.assertNotNull(judgeResult); + + int judgeResultId = judgeResult.getJudgeResultId(); + Assert.assertEquals(2, judgeResultId); + } + + /** + * 测试用例: 测试getJudgeResultUsingSlug(String)方法 + * 测试数据: 不存在的评测结果组别名 + * 预期结果: 返回空引用 + */ + @Test + public void testGetJudgeResultUsingSlugNotExists() { + JudgeResult judgeResult = judgeResultMapper.getJudgeResultUsingSlug("Not-Exists"); + Assert.assertNull(judgeResult); + } + + /** + * 待测试的JudgeResultMapper对象. + */ + @Autowired + private JudgeResultMapper judgeResultMapper; } diff --git a/web/src/test/java/org/verwandlung/voj/web/mapper/LanguageMapperTest.java b/web/src/test/java/org/verwandlung/voj/web/mapper/LanguageMapperTest.java index e7eaa37f..9df4463e 100644 --- a/web/src/test/java/org/verwandlung/voj/web/mapper/LanguageMapperTest.java +++ b/web/src/test/java/org/verwandlung/voj/web/mapper/LanguageMapperTest.java @@ -20,156 +20,156 @@ @Transactional @ContextConfiguration({"classpath:test-spring-context.xml"}) public class LanguageMapperTest { - /** - * 测试用例: 测试getLanguageUsingId(int)方法 - * 测试数据: C语言的编程语言唯一标识符 - * 预期结果: 返回C语言的编程语言对象 - */ - @Test - public void testGetLanguageUsingIdExists() { - Language language = languageMapper.getLanguageUsingId(1); - Assert.assertNotNull(language); - - String languageName = language.getLanguageName(); - Assert.assertEquals("C", languageName); - } - - /** - * 测试用例: 测试getLanguageUsingId(int)方法 - * 测试数据: 不存在的编程语言唯一标识符 - * 预期结果: 返回空引用 - */ - @Test - public void testGetLanguageUsingIdNotExists() { - Language language = languageMapper.getLanguageUsingId(0); - Assert.assertNull(language); - } - - /** - * 测试用例: 测试getLanguageUsingSlug(String)方法 - * 测试数据: C语言的编程语言别名 - * 预期结果: 返回C语言的编程语言对象 - */ - @Test - public void testGetLanguageUsingSlugExists() { - Language language = languageMapper.getLanguageUsingSlug("text/x-csrc"); - Assert.assertNotNull(language); - - String languageName = language.getLanguageName(); - Assert.assertEquals("C", languageName); - } - - /** - * 测试用例: 测试getLanguageUsingSlug(String)方法 - * 测试数据: 不存在的编程语言别名 - * 预期结果: 返回空引用 - */ - @Test - public void testGetLanguageUsingSlugNotExists() { - Language language = languageMapper.getLanguageUsingSlug("Not-Exists"); - Assert.assertNull(language); - } - - /** - * 测试用例: 测试getAllLanguages()方法 - * 测试数据: N/a - * 预期结果: 返回全部的编程语言列表(共6种语言) - */ - @Test - public void testGetAllLanguages() { - List languages = languageMapper.getAllLanguages(); - Assert.assertNotNull(languages); - Assert.assertEquals(6, languages.size()); - - Language firstLanguage = languages.get(0); - Assert.assertNotNull(firstLanguage); - - String languageName = firstLanguage.getLanguageName(); - Assert.assertEquals("C", languageName); - } - - /** - * 测试用例: 测试createLanguage(Language)方法 - * 测试数据: 合法的数据集 - * 预期结果: 数据插入操作成功完成 - */ - @Test - public void testCreateLanguageNormally() { - Language language = new Language("text/x-php", "PHP", "php foo.php", "php foo.php"); - languageMapper.createLanguage(language); - } - - /** - * 测试用例: 测试createLanguage(Language)方法 - * 测试数据: 不合法的数据集(过长的编程语言英文缩写) - * 预期结果: 抛出DataIntegrityViolationException异常 - */ - @Test(expected = org.springframework.dao.DataIntegrityViolationException.class) - public void testCreateLanguageUsingTooLongSlug() { - Language language = new Language("TooLongLanguageSlug", "Invalid Langauge", "Compile Command", "Run Command"); - languageMapper.createLanguage(language); - } - - /** - * 测试用例: 测试updateLanguage(Language)方法 - * 测试数据: 合法的数据集, 且数据表中存在对应ID的记录 - * 预期结果: 数据更新操作成功完成 - */ - @Test - public void testUpdateLanguageNormally() { - Language language = languageMapper.getLanguageUsingId(2); - Assert.assertNotNull(language); - - language.setLanguageName("D"); - languageMapper.updateLanguage(language); - - language = languageMapper.getLanguageUsingId(2); - Assert.assertEquals("D", language.getLanguageName()); - } - - /** - * 测试用例: 测试updateLanguage(Language)方法 - * 测试数据: 合法的数据集, 但数据表中不存在该编程语言 - * 预期结果: 方法正常执行, 未影响数据表中的数据 - */ - @Test - public void testUpdateLanguageNotExists() { - Language language = new Language(0, "not-exist", "Not Exist", "Not Exist", "Not Exist"); - languageMapper.updateLanguage(language); - } - - /** - * 测试用例: 测试deleteLanguage(int)方法 - * 测试数据: Ruby语言的编程语言唯一标识符 - * 预期结果: 数据删除操作成功完成 - */ - @Test - public void testDeleteLanguageExists() { - Language language = languageMapper.getLanguageUsingId(6); - Assert.assertNotNull(language); - - languageMapper.deleteLanguage(6); - - language = languageMapper.getLanguageUsingId(6); - Assert.assertNull(language); - } - - /** - * 测试用例: 测试deleteLanguage(int)方法 - * 测试数据: 不存在的编程语言唯一标识符 - * 预期结果: 方法正常执行, 未影响数据表中的数据 - */ - @Test - public void testDeleteLanguageNotExists() { - Language language = languageMapper.getLanguageUsingId(0); - Assert.assertNull(language); - - languageMapper.deleteLanguage(0); - } - - /** - * 待测试的LanguageMapper对象. - */ - @Autowired - private LanguageMapper languageMapper; + /** + * 测试用例: 测试getLanguageUsingId(int)方法 + * 测试数据: C语言的编程语言唯一标识符 + * 预期结果: 返回C语言的编程语言对象 + */ + @Test + public void testGetLanguageUsingIdExists() { + Language language = languageMapper.getLanguageUsingId(1); + Assert.assertNotNull(language); + + String languageName = language.getLanguageName(); + Assert.assertEquals("C", languageName); + } + + /** + * 测试用例: 测试getLanguageUsingId(int)方法 + * 测试数据: 不存在的编程语言唯一标识符 + * 预期结果: 返回空引用 + */ + @Test + public void testGetLanguageUsingIdNotExists() { + Language language = languageMapper.getLanguageUsingId(0); + Assert.assertNull(language); + } + + /** + * 测试用例: 测试getLanguageUsingSlug(String)方法 + * 测试数据: C语言的编程语言别名 + * 预期结果: 返回C语言的编程语言对象 + */ + @Test + public void testGetLanguageUsingSlugExists() { + Language language = languageMapper.getLanguageUsingSlug("text/x-csrc"); + Assert.assertNotNull(language); + + String languageName = language.getLanguageName(); + Assert.assertEquals("C", languageName); + } + + /** + * 测试用例: 测试getLanguageUsingSlug(String)方法 + * 测试数据: 不存在的编程语言别名 + * 预期结果: 返回空引用 + */ + @Test + public void testGetLanguageUsingSlugNotExists() { + Language language = languageMapper.getLanguageUsingSlug("Not-Exists"); + Assert.assertNull(language); + } + + /** + * 测试用例: 测试getAllLanguages()方法 + * 测试数据: N/a + * 预期结果: 返回全部的编程语言列表(共6种语言) + */ + @Test + public void testGetAllLanguages() { + List languages = languageMapper.getAllLanguages(); + Assert.assertNotNull(languages); + Assert.assertEquals(6, languages.size()); + + Language firstLanguage = languages.get(0); + Assert.assertNotNull(firstLanguage); + + String languageName = firstLanguage.getLanguageName(); + Assert.assertEquals("C", languageName); + } + + /** + * 测试用例: 测试createLanguage(Language)方法 + * 测试数据: 合法的数据集 + * 预期结果: 数据插入操作成功完成 + */ + @Test + public void testCreateLanguageNormally() { + Language language = new Language("text/x-php", "PHP", "php foo.php", "php foo.php"); + languageMapper.createLanguage(language); + } + + /** + * 测试用例: 测试createLanguage(Language)方法 + * 测试数据: 不合法的数据集(过长的编程语言英文缩写) + * 预期结果: 抛出DataIntegrityViolationException异常 + */ + @Test(expected = org.springframework.dao.DataIntegrityViolationException.class) + public void testCreateLanguageUsingTooLongSlug() { + Language language = new Language("TooLongLanguageSlug", "Invalid Langauge", "Compile Command", "Run Command"); + languageMapper.createLanguage(language); + } + + /** + * 测试用例: 测试updateLanguage(Language)方法 + * 测试数据: 合法的数据集, 且数据表中存在对应ID的记录 + * 预期结果: 数据更新操作成功完成 + */ + @Test + public void testUpdateLanguageNormally() { + Language language = languageMapper.getLanguageUsingId(2); + Assert.assertNotNull(language); + + language.setLanguageName("D"); + languageMapper.updateLanguage(language); + + language = languageMapper.getLanguageUsingId(2); + Assert.assertEquals("D", language.getLanguageName()); + } + + /** + * 测试用例: 测试updateLanguage(Language)方法 + * 测试数据: 合法的数据集, 但数据表中不存在该编程语言 + * 预期结果: 方法正常执行, 未影响数据表中的数据 + */ + @Test + public void testUpdateLanguageNotExists() { + Language language = new Language(0, "not-exist", "Not Exist", "Not Exist", "Not Exist"); + languageMapper.updateLanguage(language); + } + + /** + * 测试用例: 测试deleteLanguage(int)方法 + * 测试数据: Ruby语言的编程语言唯一标识符 + * 预期结果: 数据删除操作成功完成 + */ + @Test + public void testDeleteLanguageExists() { + Language language = languageMapper.getLanguageUsingId(6); + Assert.assertNotNull(language); + + languageMapper.deleteLanguage(6); + + language = languageMapper.getLanguageUsingId(6); + Assert.assertNull(language); + } + + /** + * 测试用例: 测试deleteLanguage(int)方法 + * 测试数据: 不存在的编程语言唯一标识符 + * 预期结果: 方法正常执行, 未影响数据表中的数据 + */ + @Test + public void testDeleteLanguageNotExists() { + Language language = languageMapper.getLanguageUsingId(0); + Assert.assertNull(language); + + languageMapper.deleteLanguage(0); + } + + /** + * 待测试的LanguageMapper对象. + */ + @Autowired + private LanguageMapper languageMapper; } diff --git a/web/src/test/java/org/verwandlung/voj/web/mapper/OptionMapperTest.java b/web/src/test/java/org/verwandlung/voj/web/mapper/OptionMapperTest.java index 8dba3520..0dfbb906 100644 --- a/web/src/test/java/org/verwandlung/voj/web/mapper/OptionMapperTest.java +++ b/web/src/test/java/org/verwandlung/voj/web/mapper/OptionMapperTest.java @@ -21,80 +21,80 @@ @Transactional @ContextConfiguration({"classpath:test-spring-context.xml"}) public class OptionMapperTest { - /** - * 测试用例: 测试getAutoloadOptions()方法 - * 测试数据: N/a - * 预期结果: 返回自动加载的系统选项的列表 - */ - @Test - public void testGetAutoloadOptions() { - List