49 lines
2.0 KiB
Java
49 lines
2.0 KiB
Java
package com.share;
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.luqj.exam.domain.ExamQuestionPlus;
|
|
import com.luqj.exam.domain.ExamStudentPaperAnswerPlus;
|
|
import com.luqj.exam.service.IExamQuestionService;
|
|
import com.luqj.exam.service.IExamStudentPaperAnswerService;
|
|
import com.ruoyi.RuoYiApplication;
|
|
import com.ruoyi.common.enums.DataSourceType;
|
|
import com.ruoyi.framework.datasource.DynamicDataSourceContextHolder;
|
|
import org.junit.Assert;
|
|
import org.junit.Test;
|
|
import org.junit.runner.RunWith;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
import org.springframework.test.context.junit4.SpringRunner;
|
|
|
|
import javax.sql.DataSource;
|
|
import java.util.Date;
|
|
|
|
@RunWith(SpringRunner.class)
|
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = RuoYiApplication.class)
|
|
public class ShareTest {
|
|
@Autowired
|
|
private DataSource dataSource;
|
|
@Autowired
|
|
private IExamStudentPaperAnswerService examStudentPaperAnswerService;
|
|
@Autowired
|
|
private IExamQuestionService examQuestionService;
|
|
|
|
@Test
|
|
public void testScore() {
|
|
Page<ExamQuestionPlus> plusPage = examQuestionService.page(new Page<ExamQuestionPlus>(1, 2));
|
|
DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.SHARDING.name());
|
|
Page<ExamStudentPaperAnswerPlus> page = new Page<ExamStudentPaperAnswerPlus>(1, 2);
|
|
page = examStudentPaperAnswerService.page(page);
|
|
for (ExamStudentPaperAnswerPlus item : page.getRecords()) {
|
|
examStudentPaperAnswerService.removeById(item.getId());
|
|
}
|
|
Assert.assertTrue(dataSource != null);
|
|
for (int i = 0; i < 10; i++) {
|
|
ExamStudentPaperAnswerPlus examStudentPaperAnswerPlus = new ExamStudentPaperAnswerPlus();
|
|
examStudentPaperAnswerPlus.setCreateTime(new Date());
|
|
examStudentPaperAnswerPlus.setRealAnswer("hahaha");
|
|
examStudentPaperAnswerService.save(examStudentPaperAnswerPlus);
|
|
}
|
|
}
|
|
}
|