测试开启并行;

修改一些BUG
beetlsql3-dev
Mlxa0324 3 years ago
parent c965423dc5
commit 1ece4cd0ef

@ -13,7 +13,7 @@ import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static java.lang.Math.min;
import static java.lang.Math.max;
/**
*
@ -136,7 +136,8 @@ public class RandomUtils {
public static <T, R> String getRandomString(List<T> list, int randomLength, Function<T, R> function, CharSequence delimiter) {
Objects.requireNonNull(list);
// 取随机数长度的集合
List<T> questionList = RandomUtil.randomEleList(list, RandomUtil.randomInt(min(list.size() == 0 ? 1: list.size(), randomLength)));
int size = max(randomLength, list.size()) + 1;
List<T> questionList = RandomUtil.randomEleList(list, RandomUtil.randomInt(1, size));
return questionList.stream()
.map(e -> String.valueOf(function.apply(e)))

@ -118,6 +118,10 @@ public class ResourcesQuestionOptionEntity {
List<String> optionTextList = optionEntity.getOptionTextList();
// 答案和选项ABCDEF..对应
Map<String, String> answerMap = new HashMap<>(6);
// 判断题目是否有重复的值
Assert.isTrue(optionTextList.size() == lastLetterFieldNameList.size(),
"答案中有重复的值,请检查!");
// 乱序集合处理
for (int i = 0; i < lastLetterFieldNameList.size(); i++) {
// 选项的子母

@ -160,11 +160,10 @@ public class ResourcesQuestionSnapshotService extends CoreBaseService<ResourcesQ
* @return
*/
public TeacherOpenCourseQuestionLogScoreInfo getScoreInfo(final Long fromId, final TeacherOpenCourseQuestionFromTypeEnum fromType) {
ResourcesQuestionSnapshotQuery resourcesQuestionSnapshotQuery = new ResourcesQuestionSnapshotQuery();
resourcesQuestionSnapshotQuery.setFromId(fromId);
resourcesQuestionSnapshotQuery.setFromType(fromType);
List<ResourcesQuestionSnapshot> valuesByQuery = getValuesByQuery(resourcesQuestionSnapshotQuery);
// ResourcesQuestionSnapshotQuery resourcesQuestionSnapshotQuery = new ResourcesQuestionSnapshotQuery();
// resourcesQuestionSnapshotQuery.setFromId(fromId);
// resourcesQuestionSnapshotQuery.setFromType(fromType);
// List<ResourcesQuestionSnapshot> valuesByQuery = getValuesByQuery(resourcesQuestionSnapshotQuery);
// 查询学生身份
Student student = studentDao.getByUserId(getUserId());

@ -1,5 +1,6 @@
package com.ibeetl.jlw.service;
import cn.hutool.core.lang.Assert;
import cn.hutool.extra.validation.BeanValidationResult;
import cn.hutool.extra.validation.ValidationUtil;
import cn.jlw.util.ToolUtils;
@ -20,7 +21,6 @@ import com.ibeetl.jlw.web.query.TeacherOpenCourseHomeworkSettingQuery;
import org.apache.commons.lang3.StringUtils;
import org.beetl.sql.core.SqlId;
import org.beetl.sql.core.engine.PageQuery;
import org.junit.Assert;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -174,7 +174,7 @@ public class TeacherOpenCourseHomeworkService extends CoreBaseService<TeacherOpe
homeworkQuery.getClazzByType());
// 断言验证属性
Assert.assertTrue(toJsonStr(beanValidationResult.getErrorMessages()), beanValidationResult.isSuccess());
Assert.isTrue(beanValidationResult.isSuccess(), toJsonStr(beanValidationResult.getErrorMessages()));
// 添加到作业主表中
add(homeworkQuery);

@ -4,7 +4,9 @@ import cn.hutool.core.util.ObjectUtil;
import cn.jlw.web.WebApplication;
import com.ibeetl.admin.test.util.test.TestEnvUtil;
import com.ibeetl.jlw.dao.StudentDao;
import com.ibeetl.jlw.dao.TeacherDao;
import com.ibeetl.jlw.entity.Student;
import com.ibeetl.jlw.entity.Teacher;
import org.junit.Assert;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.TestMethodOrder;
@ -39,15 +41,19 @@ public class BaseTest {
@Resource
StudentDao studentDao;
@Resource
TeacherDao teacherDao;
@Autowired
protected MockMvc mvc;
/**
* session
* application-test.properties
*
* @throws Exception
*/
public void putEnvLoginInfoStudent() throws Exception {
public void putStudentLoginInfoToEnv() throws Exception {
// 随机取一个学生的登录信息
List<Student> studentList = studentDao.execute(
"select org_id, user_id " +
@ -63,6 +69,29 @@ public class BaseTest {
TestEnvUtil.setProperty("user.orgId", student.getOrgId().toString());
}
/**
* session
* application-test.properties
*
* @throws Exception
*/
public void putTeacherLoginInfoToEnv() throws Exception {
// 随机取一个学生的登录信息
List<Teacher> teacherList = teacherDao.execute(
"select org_id, user_id " +
"from teacher t \n" +
"where t.teacher_status = 1\t\n" +
"order by RAND() \n" +
"limit 1 ");
Assert.assertTrue("教师表表为空,程序中断!", ObjectUtil.isNotEmpty(teacherList));
// 学生ID
Teacher teacher = CollectionUtils.firstElement(teacherList);
// 换学生身份登录系统
TestEnvUtil.setProperty("user.id", teacher.getUserId().toString());
TestEnvUtil.setProperty("user.orgId", teacher.getOrgId().toString());
}
/**
* ,session
* @throws Exception

@ -2,9 +2,9 @@ package com.ibeetl.jlw.web;
import base.BaseTest;
import cn.hutool.core.util.ObjectUtil;
import com.ibeetl.jlw.dao.ResourcesQuestionSnapshotDao;
import com.ibeetl.jlw.entity.ResourcesQuestionSnapshot;
import com.ibeetl.jlw.enums.TeacherOpenCourseQuestionFromTypeEnum;
import com.ibeetl.admin.test.util.test.TestEnvUtil;
import com.ibeetl.jlw.dao.TeacherOpenCourseQuestionLogDao;
import com.ibeetl.jlw.entity.TeacherOpenCourseQuestionLog;
import org.junit.Assert;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
@ -16,7 +16,6 @@ import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.List;
import static com.ibeetl.admin.test.util.test.RandomUtils.randomSet;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
/**
@ -34,42 +33,46 @@ class ResourcesQuestionSnapshotControllerTest extends BaseTest {
private static final String API = "/api/resourcesQuestionSnapshot";
@Resource
ResourcesQuestionSnapshotDao resourcesQuestionSnapshotDao;
TeacherOpenCourseQuestionLogDao teacherOpenCourseQuestionLogDao;
@Test
void getScoreInfo() throws Exception {
// 获取一个状态正常的作业ID
try {
TeacherOpenCourseQuestionLog entity = new TeacherOpenCourseQuestionLog();
entity.setTeacherOpenCourseQuestionLogStatus(1);
List<TeacherOpenCourseQuestionLog> questionLogs = teacherOpenCourseQuestionLogDao.template(entity);
// 断言
Assert.assertTrue(ObjectUtil.isNotEmpty(questionLogs));
ResourcesQuestionSnapshot entity = new ResourcesQuestionSnapshot();
entity.setQuestionStatus(1);
List<ResourcesQuestionSnapshot> homeworkList = resourcesQuestionSnapshotDao.template(entity);
// 断言
Assert.assertTrue(ObjectUtil.isNotEmpty(homeworkList));
// 取第一个
TeacherOpenCourseQuestionLog questionLog = CollectionUtils.firstElement(questionLogs);
// 随机取一个学生的登录信息
putEnvLoginInfoStudent();
// 模拟登录学生身份
TestEnvUtil.setProperty("user.id", questionLog.getUserId().toString());
TestEnvUtil.setProperty("user.orgId", questionLog.getOrgId().toString());
// 随机来源类型
TeacherOpenCourseQuestionFromTypeEnum fromTypeEnum = CollectionUtils
.firstElement(randomSet(TeacherOpenCourseQuestionFromTypeEnum.class));
// 随机取一个学生的登录信息
putStudentLoginInfoToEnv();
//构造请求参数
RequestBuilder rb = MockMvcRequestBuilders.post(MODEL + "/getScoreInfo.json")
.contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE)
.param("fromType", fromTypeEnum.name())
// TODO 这里需要修改灵活的来源ID
.param("fromId", fromTypeEnum.name())
;
//构造请求参数
RequestBuilder rb = MockMvcRequestBuilders.post(MODEL + "/getScoreInfo.json")
.contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE)
.param("fromType", questionLog.getTeacherOpenCourseQuestionLogFromType().toString())
.param("fromId", questionLog.getTeacherOpenCourseQuestionLogFromId().toString())
;
//发送请求,验证返回结果
String result = mvc.perform(rb)
.andExpect(status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$.code").value("0"))
.andReturn().getResponse().getContentAsString();
//发送请求,验证返回结果
String result = mvc.perform(rb)
.andExpect(status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$.code").value("0"))
.andReturn().getResponse().getContentAsString();
// 换回去原始的登录方式
clearEnvLoginInfo();
System.out.println(result);
System.out.println(result);
}catch (Exception e) {
throw e;
}finally {
// 清除登录信息
clearEnvLoginInfo();
}
}
}

@ -31,6 +31,7 @@ import java.util.List;
import static cn.hutool.json.JSONUtil.toJsonStr;
import static com.ibeetl.admin.test.util.test.RandomUtils.getRandomString;
import static com.ibeetl.admin.test.util.test.RandomUtils.randomPojo;
import static java.util.stream.Collectors.joining;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@Slf4j
@ -114,7 +115,8 @@ class TeacherOpenCourseHomeworkControllerTest extends BaseTest {
// 所有题目
ResourcesQuestion resourcesQuestion = new ResourcesQuestion();
resourcesQuestion.setQuestionStatus(1);
List<ResourcesQuestion> valuesByQuery = resourcesQuestionDao.template(resourcesQuestion);
List<ResourcesQuestion> valuesByQuery = resourcesQuestionDao.execute("select * from resources_question where\n" +
"question_status = 1 limit 50");
// 断言 题目表不能为空
Assert.assertTrue(ObjectUtil.isNotEmpty(valuesByQuery));
@ -128,7 +130,8 @@ class TeacherOpenCourseHomeworkControllerTest extends BaseTest {
Assert.assertTrue(ObjectUtil.isNotEmpty(schoolClassList));
// 随机选题
String resourcesQuestionIds = getRandomString(valuesByQuery, ResourcesQuestion::getResourcesQuestionId);
String resourcesQuestionIds = valuesByQuery.stream().map(ResourcesQuestion::getResourcesQuestionId)
.map(String::valueOf).collect(joining(","));
// 随机产生班级ID集合
String schoolClassIds = getRandomString(schoolClassList, SchoolClass::getClassId);

@ -41,62 +41,66 @@ class TeacherOpenCourseQuestionLogControllerTest extends BaseTest {
*/
@Test
void addQuestionLog() throws Exception {
// 通过查询数据库来random实体类属性
// 随机取一个学生的登录信息
List<ResourcesQuestionSnapshot> questionSnapshots = resourcesQuestionSnapshotDao.execute(
"select t.* \n" +
"from resources_question_snapshot t \n" +
"where t.question_status = 1\t\n" +
"order by RAND() \n" +
"limit 10 ");
try {
// 通过查询数据库来random实体类属性
// 随机取一个学生的登录信息
List<ResourcesQuestionSnapshot> questionSnapshots = resourcesQuestionSnapshotDao.execute(
"select t.* \n" +
"from resources_question_snapshot t \n" +
"where t.question_status = 1\t\n" +
"order by RAND() \n" +
"limit 10 ");
// 随机取题目ID和答案
Map<Long, TreeSet<String>> answerRandomMap = new ConcurrentHashMap<>();
questionSnapshots.stream().forEach(item -> {
TreeSet<String> answer = new TreeSet<>();
// 单选
if (item.getQuestionType().equals(1)) {
String[] simpleOptions = ObjectUtil.isEmpty(item.getQuestionOptionE())
? new String[]{"A", "B", "C", "D"} : new String[]{"A", "B", "C", "D", "E"};
answer.add(RandomUtil.randomEle(simpleOptions));
}
// 多选
if (item.getQuestionType().equals(2)) {
String[] multipleOptions = ObjectUtil.isEmpty(item.getQuestionOptionE())
? new String[]{"A", "B", "C", "D"} : new String[]{"A", "B", "C", "D", "E"};
Set<String> randomAnswerSet = RandomUtil
.randomEleSet(Arrays.asList(multipleOptions), RandomUtil.randomInt(2, multipleOptions.length));
//排序去重 逗号分割
answer.add(join(new TreeSet<>(randomAnswerSet).toArray(), ","));
}
// 判断
if (item.getQuestionType().equals(3)) {
answer.add(RandomUtil.randomEle(Arrays.asList("对", "错")));
}
answerRandomMap.put(item.getResourcesQuestionSnapshotId(), answer);
});
// 随机取题目ID和答案
Map<Long, TreeSet<String>> answerRandomMap = new ConcurrentHashMap<>();
questionSnapshots.stream().forEach(item -> {
TreeSet<String> answer = new TreeSet<>();
// 单选
if (item.getQuestionType().equals(1)) {
String[] simpleOptions = ObjectUtil.isEmpty(item.getQuestionOptionE())
? new String[]{"A", "B", "C", "D"} : new String[]{"A", "B", "C", "D", "E"};
answer.add(RandomUtil.randomEle(simpleOptions));
}
// 多选
if (item.getQuestionType().equals(2)) {
String[] multipleOptions = ObjectUtil.isEmpty(item.getQuestionOptionE())
? new String[]{"A", "B", "C", "D"} : new String[]{"A", "B", "C", "D", "E"};
Set<String> randomAnswerSet = RandomUtil
.randomEleSet(Arrays.asList(multipleOptions), RandomUtil.randomInt(2, multipleOptions.length));
//排序去重 逗号分割
answer.add(join(new TreeSet<>(randomAnswerSet).toArray(), ","));
}
// 判断
if (item.getQuestionType().equals(3)) {
answer.add(RandomUtil.randomEle(Arrays.asList("对", "错")));
}
answerRandomMap.put(item.getResourcesQuestionSnapshotId(), answer);
});
// 随机取一个学生的登录信息
putEnvLoginInfoStudent();
// 随机取一个学生的登录信息
putStudentLoginInfoToEnv();
// 随机来源类型
TeacherOpenCourseQuestionFromTypeEnum fromTypeEnum = CollectionUtils
.firstElement(randomSet(TeacherOpenCourseQuestionFromTypeEnum.class));
// 随机来源类型
TeacherOpenCourseQuestionFromTypeEnum fromTypeEnum = CollectionUtils
.firstElement(randomSet(TeacherOpenCourseQuestionFromTypeEnum.class));
//构造请求参数
RequestBuilder rb = MockMvcRequestBuilders.post(MODEL + "/addQuestionLog.json")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.param("fromType", fromTypeEnum.name())
.content(toJsonStr(answerRandomMap));
//发送请求,验证返回结果
String result = mvc.perform(rb)
.andExpect(status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$.code").value("0"))
.andReturn().getResponse().getContentAsString();
//构造请求参数
RequestBuilder rb = MockMvcRequestBuilders.post(MODEL + "/addQuestionLog.json")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.param("fromType", fromTypeEnum.name())
.content(toJsonStr(answerRandomMap));
//发送请求,验证返回结果
String result = mvc.perform(rb)
.andExpect(status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$.code").value("0"))
.andReturn().getResponse().getContentAsString();
// 换回去原始的登录方式
clearEnvLoginInfo();
System.out.println(result);
System.out.println(result);
}catch (Exception e) {
throw e;
}finally {
// 清除登录信息
clearEnvLoginInfo();
}
}
}

@ -35,4 +35,8 @@ dynamic.beetlsql.master.dbStyle = org.beetl.sql.core.db.MySqlStyle
# \u6A21\u62DF\u7528\u6237\u767B\u5F55 \u53EA\u80FD\u7528\u5728\u672C\u5730\u6D4B\u8BD5\u65F6\u5019\u4F7F\u7528
user.id=1
user.orgId=1
user.orgId=1
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = concurrent
junit.jupiter.execution.parallel.mode.classes.default = concurrent
Loading…
Cancel
Save