|
|
|
|
package com.sztzjy.linkCommerce.controller.stu;
|
|
|
|
|
|
|
|
|
|
import com.sztzjy.linkCommerce.entity.School;
|
|
|
|
|
import com.sztzjy.linkCommerce.entity.SchoolClass;
|
|
|
|
|
import com.sztzjy.linkCommerce.entity.SchoolClassExample;
|
|
|
|
|
import com.sztzjy.linkCommerce.entity.SchoolFaculty;
|
|
|
|
|
import com.sztzjy.linkCommerce.entity.SchoolMajor;
|
|
|
|
|
import com.sztzjy.linkCommerce.entity.TeachingClassStudent;
|
|
|
|
|
import com.sztzjy.linkCommerce.entity.Userinfo;
|
|
|
|
|
import com.sztzjy.linkCommerce.mapper.SchoolClassMapper;
|
|
|
|
|
import com.sztzjy.linkCommerce.mapper.SchoolFacultyMapper;
|
|
|
|
|
import com.sztzjy.linkCommerce.mapper.SchoolMapper;
|
|
|
|
|
import com.sztzjy.linkCommerce.mapper.SchoolMajorMapper;
|
|
|
|
|
import com.sztzjy.linkCommerce.mapper.TeachingClassStudentMapper;
|
|
|
|
|
import com.sztzjy.linkCommerce.mapper.UserinfoMapper;
|
|
|
|
|
import com.sztzjy.linkCommerce.service.UserInfoService;
|
|
|
|
|
import com.sztzjy.linkCommerce.util.Pinyin4jUtil;
|
|
|
|
|
import com.sztzjy.linkCommerce.util.ResultEntity;
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
import org.mockito.ArgumentCaptor;
|
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
|
|
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
|
|
|
import static org.mockito.ArgumentMatchers.argThat;
|
|
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
|
import static org.mockito.Mockito.never;
|
|
|
|
|
import static org.mockito.Mockito.verify;
|
|
|
|
|
import static org.mockito.Mockito.when;
|
|
|
|
|
|
|
|
|
|
class UserControllerTeacherAdminTest {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void addTeacherAccountAlwaysCreatesOrdinaryTeacher() {
|
|
|
|
|
UserController controller = controllerWithCommonMocks();
|
|
|
|
|
when(controller.userinfoMapper.selectByPrimaryKey("teacher-admin")).thenReturn(teacher("teacher-admin", true));
|
|
|
|
|
when(controller.userInfoService.existsByUserName("t001")).thenReturn(false);
|
|
|
|
|
when(controller.userinfoMapper.insert(any(Userinfo.class))).thenReturn(1);
|
|
|
|
|
|
|
|
|
|
ResultEntity result = controller.addTeacherAccount("school-1", "school", "faculty-1", "major-1",
|
|
|
|
|
"major", "张老师", "t001", null, null, "teacher-admin");
|
|
|
|
|
|
|
|
|
|
ArgumentCaptor<Userinfo> captor = ArgumentCaptor.forClass(Userinfo.class);
|
|
|
|
|
verify(controller.userinfoMapper).insert(captor.capture());
|
|
|
|
|
assertEquals(HttpStatus.OK, result.getStatusCode());
|
|
|
|
|
assertEquals(3, captor.getValue().getRole());
|
|
|
|
|
assertFalse(captor.getValue().getTeacherAdmin());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void ordinaryTeacherCannotAddFaculty() {
|
|
|
|
|
UserController controller = controllerWithCommonMocks();
|
|
|
|
|
when(controller.userinfoMapper.selectByPrimaryKey("teacher-1")).thenReturn(teacher("teacher-1", false));
|
|
|
|
|
|
|
|
|
|
ResultEntity result = controller.addSchoolFaculty("school-1", "faculty", null, null, null, "teacher-1");
|
|
|
|
|
|
|
|
|
|
assertEquals(HttpStatus.BAD_REQUEST, result.getStatusCode());
|
|
|
|
|
verify(controller.schoolFacultyMapper, never()).insert(any(SchoolFaculty.class));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void teacherAdminCanAddFaculty() {
|
|
|
|
|
UserController controller = controllerWithCommonMocks();
|
|
|
|
|
when(controller.userinfoMapper.selectByPrimaryKey("teacher-admin")).thenReturn(teacher("teacher-admin", true));
|
|
|
|
|
when(controller.schoolFacultyMapper.selectByExample(any())).thenReturn(Collections.emptyList());
|
|
|
|
|
when(controller.schoolFacultyMapper.insert(any(SchoolFaculty.class))).thenReturn(1);
|
|
|
|
|
|
|
|
|
|
ResultEntity result = controller.addSchoolFaculty("school-1", "faculty", null, null, null, "teacher-admin");
|
|
|
|
|
|
|
|
|
|
assertEquals(HttpStatus.OK, result.getStatusCode());
|
|
|
|
|
verify(controller.schoolFacultyMapper).insert(any(SchoolFaculty.class));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void ordinaryTeacherCannotAddMajor() {
|
|
|
|
|
UserController controller = controllerWithCommonMocks();
|
|
|
|
|
when(controller.userinfoMapper.selectByPrimaryKey("teacher-1")).thenReturn(teacher("teacher-1", false));
|
|
|
|
|
|
|
|
|
|
ResultEntity result = controller.addSchoolMajor("school-1", "faculty-1", "major", null, null, "teacher-1");
|
|
|
|
|
|
|
|
|
|
assertEquals(HttpStatus.BAD_REQUEST, result.getStatusCode());
|
|
|
|
|
verify(controller.schoolMajorMapper, never()).insert(any(SchoolMajor.class));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void ordinaryTeacherCannotUpdateTeacherAccount() {
|
|
|
|
|
UserController controller = controllerWithCommonMocks();
|
|
|
|
|
Userinfo update = teacher("teacher-2", false);
|
|
|
|
|
update.setName("updated");
|
|
|
|
|
when(controller.userinfoMapper.selectByPrimaryKey("teacher-1")).thenReturn(teacher("teacher-1", false));
|
|
|
|
|
|
|
|
|
|
ResultEntity result = controller.updateTeacher(update, "teacher-1");
|
|
|
|
|
|
|
|
|
|
assertEquals(HttpStatus.BAD_REQUEST, result.getStatusCode());
|
|
|
|
|
verify(controller.userinfoMapper, never()).updateByPrimaryKey(any(Userinfo.class));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void addSchoolClassStoresCreatorTeacher() {
|
|
|
|
|
UserController controller = controllerWithCommonMocks();
|
|
|
|
|
when(controller.schoolClassMapper.selectByExample(any())).thenReturn(Collections.emptyList());
|
|
|
|
|
when(controller.schoolClassMapper.insert(any(SchoolClass.class))).thenReturn(1);
|
|
|
|
|
when(controller.pinyin4jUtil.convertToPinyin(any())).thenReturn("py");
|
|
|
|
|
|
|
|
|
|
ResultEntity result = controller.addSchoolClass("school-1", "faculty-1", "major-1", "class-1",
|
|
|
|
|
"teacher-1", null, null);
|
|
|
|
|
|
|
|
|
|
ArgumentCaptor<SchoolClass> captor = ArgumentCaptor.forClass(SchoolClass.class);
|
|
|
|
|
verify(controller.schoolClassMapper).insert(captor.capture());
|
|
|
|
|
assertEquals(HttpStatus.OK, result.getStatusCode());
|
|
|
|
|
assertEquals("teacher-1", captor.getValue().getCreatedBy());
|
|
|
|
|
assertEquals("TEACHING", captor.getValue().getClassType());
|
|
|
|
|
assertEquals("LOCAL", captor.getValue().getDataSource());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void addSchoolClassRejectsDuplicateNameInSameSchool() {
|
|
|
|
|
UserController controller = controllerWithCommonMocks();
|
|
|
|
|
when(controller.schoolClassMapper.selectByExample(argThat(example -> hasCondition(example, "school_id ="))))
|
|
|
|
|
.thenReturn(Collections.singletonList(new SchoolClass()));
|
|
|
|
|
|
|
|
|
|
ResultEntity result = controller.addSchoolClass("school-1", "faculty-1", "major-1", "class-1",
|
|
|
|
|
"teacher-1", null, null);
|
|
|
|
|
|
|
|
|
|
assertEquals(HttpStatus.BAD_REQUEST, result.getStatusCode());
|
|
|
|
|
verify(controller.schoolClassMapper, never()).insert(any(SchoolClass.class));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void deleteFacultyRejectsWhenMajorExists() {
|
|
|
|
|
UserController controller = controllerWithCommonMocks();
|
|
|
|
|
when(controller.userinfoMapper.selectByPrimaryKey("teacher-1")).thenReturn(teacher("teacher-1"));
|
|
|
|
|
SchoolFaculty faculty = new SchoolFaculty();
|
|
|
|
|
faculty.setSchoolFacultyId("faculty-1");
|
|
|
|
|
faculty.setSchoolId("school-1");
|
|
|
|
|
when(controller.schoolFacultyMapper.selectByPrimaryKey("faculty-1")).thenReturn(faculty);
|
|
|
|
|
when(controller.schoolMajorMapper.selectByExample(any())).thenReturn(Collections.singletonList(new SchoolMajor()));
|
|
|
|
|
|
|
|
|
|
ResultEntity result = controller.deleteSchoolFaculty("faculty-1", "teacher-1");
|
|
|
|
|
|
|
|
|
|
assertEquals(HttpStatus.BAD_REQUEST, result.getStatusCode());
|
|
|
|
|
verify(controller.schoolFacultyMapper, never()).deleteByPrimaryKey("faculty-1");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void deleteMajorRejectsWhenClassExists() {
|
|
|
|
|
UserController controller = controllerWithCommonMocks();
|
|
|
|
|
when(controller.schoolClassMapper.selectByExample(any())).thenReturn(Collections.singletonList(new SchoolClass()));
|
|
|
|
|
|
|
|
|
|
ResultEntity result = controller.deleteSchoolMajor("major-1", "teacher-1");
|
|
|
|
|
|
|
|
|
|
assertEquals(HttpStatus.BAD_REQUEST, result.getStatusCode());
|
|
|
|
|
verify(controller.schoolMajorMapper, never()).deleteByPrimaryKey("major-1");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void deleteClassRejectsWhenStudentsExist() {
|
|
|
|
|
UserController controller = controllerWithCommonMocks();
|
|
|
|
|
SchoolClass adminClass = classCreatedBy("teacher-1");
|
|
|
|
|
adminClass.setClassType("ADMIN");
|
|
|
|
|
when(controller.userinfoMapper.selectByPrimaryKey("teacher-1")).thenReturn(teacher("teacher-1"));
|
|
|
|
|
when(controller.schoolClassMapper.selectByPrimaryKey("class-1")).thenReturn(adminClass);
|
|
|
|
|
when(controller.userinfoMapper.selectByExample(any())).thenReturn(Collections.singletonList(new Userinfo()));
|
|
|
|
|
|
|
|
|
|
ResultEntity result = controller.deleteSchoolClass("class-1", "teacher-1");
|
|
|
|
|
|
|
|
|
|
assertEquals(HttpStatus.BAD_REQUEST, result.getStatusCode());
|
|
|
|
|
verify(controller.schoolClassMapper, never()).deleteByPrimaryKey("class-1");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void teacherCannotDeleteClassCreatedByAnotherTeacher() {
|
|
|
|
|
UserController controller = controllerWithCommonMocks();
|
|
|
|
|
Userinfo teacher = teacher("teacher-1");
|
|
|
|
|
SchoolClass schoolClass = classCreatedBy("teacher-2");
|
|
|
|
|
when(controller.userinfoMapper.selectByPrimaryKey("teacher-1")).thenReturn(teacher);
|
|
|
|
|
when(controller.schoolClassMapper.selectByPrimaryKey("class-1")).thenReturn(schoolClass);
|
|
|
|
|
|
|
|
|
|
ResultEntity result = controller.deleteSchoolClass("class-1", "teacher-1");
|
|
|
|
|
|
|
|
|
|
assertEquals(HttpStatus.BAD_REQUEST, result.getStatusCode());
|
|
|
|
|
verify(controller.schoolClassMapper, never()).deleteByPrimaryKey("class-1");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void teacherUpdatesOnlyOwnedClass() {
|
|
|
|
|
UserController controller = controllerWithCommonMocks();
|
|
|
|
|
Userinfo teacher = teacher("teacher-1");
|
|
|
|
|
SchoolClass existing = classCreatedBy("teacher-1");
|
|
|
|
|
SchoolClass update = new SchoolClass();
|
|
|
|
|
update.setSchoolClassId("class-1");
|
|
|
|
|
update.setClassName("new-class");
|
|
|
|
|
when(controller.userinfoMapper.selectByPrimaryKey("teacher-1")).thenReturn(teacher);
|
|
|
|
|
when(controller.schoolClassMapper.selectByPrimaryKey("class-1")).thenReturn(existing);
|
|
|
|
|
when(controller.schoolClassMapper.updateByPrimaryKeySelective(any(SchoolClass.class))).thenReturn(1);
|
|
|
|
|
|
|
|
|
|
ResultEntity result = controller.updateSchoolClass(update, "teacher-1");
|
|
|
|
|
|
|
|
|
|
assertEquals(HttpStatus.OK, result.getStatusCode());
|
|
|
|
|
verify(controller.schoolClassMapper).updateByPrimaryKeySelective(update);
|
|
|
|
|
verify(controller.schoolClassMapper, never()).deleteByPrimaryKey("class-1");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void teacherCannotDeleteStudentFromClassCreatedByAnotherTeacher() {
|
|
|
|
|
UserController controller = controllerWithCommonMocks();
|
|
|
|
|
Userinfo teacher = teacher("teacher-1");
|
|
|
|
|
Userinfo student = new Userinfo();
|
|
|
|
|
student.setUserId("student-1");
|
|
|
|
|
student.setRole(4);
|
|
|
|
|
student.setSchoolClassId("class-1");
|
|
|
|
|
when(controller.userinfoMapper.selectByPrimaryKey("teacher-1")).thenReturn(teacher);
|
|
|
|
|
when(controller.userinfoMapper.selectByPrimaryKey("student-1")).thenReturn(student);
|
|
|
|
|
when(controller.schoolClassMapper.selectByPrimaryKey("class-1")).thenReturn(classCreatedBy("teacher-2"));
|
|
|
|
|
|
|
|
|
|
ResultEntity result = controller.deleteStudent("student-1", "teacher-1");
|
|
|
|
|
|
|
|
|
|
assertEquals(HttpStatus.BAD_REQUEST, result.getStatusCode());
|
|
|
|
|
verify(controller.userinfoMapper, never()).deleteByPrimaryKey("student-1");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void teacherCanAddStudentOnlyToOwnedClass() {
|
|
|
|
|
UserController controller = controllerWithCommonMocks();
|
|
|
|
|
when(controller.schoolClassMapper.selectByPrimaryKey("class-1")).thenReturn(classCreatedBy("teacher-1"));
|
|
|
|
|
when(controller.userinfoMapper.selectByPrimaryKey("teacher-1")).thenReturn(teacher("teacher-1"));
|
|
|
|
|
when(controller.userInfoService.existsByUserName("s001")).thenReturn(false);
|
|
|
|
|
when(controller.userinfoMapper.insert(any(Userinfo.class))).thenReturn(1);
|
|
|
|
|
|
|
|
|
|
ResultEntity result = controller.addStudentAccount("school-1", "school", "faculty-1", "major-1",
|
|
|
|
|
"major", "class-1", "class-1", "学生", "s001", null, null, "teacher-1");
|
|
|
|
|
|
|
|
|
|
assertEquals(HttpStatus.OK, result.getStatusCode());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void addStudentToTeachingClassCreatesMembershipInsteadOfChangingAdminClass() {
|
|
|
|
|
UserController controller = controllerWithCommonMocks();
|
|
|
|
|
SchoolClass teachingClass = classCreatedBy("teacher-1");
|
|
|
|
|
teachingClass.setSourceClassIds("admin-1");
|
|
|
|
|
when(controller.schoolClassMapper.selectByPrimaryKey("teaching-1")).thenReturn(teachingClass);
|
|
|
|
|
when(controller.userinfoMapper.selectByPrimaryKey("teacher-1")).thenReturn(teacher("teacher-1"));
|
|
|
|
|
when(controller.userInfoService.existsByUserName("s001")).thenReturn(false);
|
|
|
|
|
when(controller.userinfoMapper.insert(any(Userinfo.class))).thenReturn(1);
|
|
|
|
|
when(controller.teachingClassStudentMapper.insertSelective(any(TeachingClassStudent.class))).thenReturn(1);
|
|
|
|
|
|
|
|
|
|
ResultEntity result = controller.addStudentAccount("school-1", "school", "faculty-1", "major-1",
|
|
|
|
|
"major", "teaching", "teaching-1", "瀛︾敓", "s001", null, null, "teacher-1");
|
|
|
|
|
|
|
|
|
|
ArgumentCaptor<Userinfo> userCaptor = ArgumentCaptor.forClass(Userinfo.class);
|
|
|
|
|
ArgumentCaptor<TeachingClassStudent> memberCaptor = ArgumentCaptor.forClass(TeachingClassStudent.class);
|
|
|
|
|
verify(controller.userinfoMapper).insert(userCaptor.capture());
|
|
|
|
|
verify(controller.teachingClassStudentMapper).insertSelective(memberCaptor.capture());
|
|
|
|
|
assertEquals(HttpStatus.OK, result.getStatusCode());
|
|
|
|
|
assertEquals("admin-1", userCaptor.getValue().getSchoolClassId());
|
|
|
|
|
assertEquals("teaching-1", memberCaptor.getValue().getTeachingClassId());
|
|
|
|
|
assertEquals(userCaptor.getValue().getUserId(), memberCaptor.getValue().getStudentUserId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void teacherCannotInitializeTeachingClassCreatedByAnotherTeacher() {
|
|
|
|
|
UserController controller = controllerWithCommonMocks();
|
|
|
|
|
when(controller.schoolClassMapper.selectByPrimaryKey("class-1")).thenReturn(classCreatedBy("teacher-2"));
|
|
|
|
|
|
|
|
|
|
ResultEntity result = controller.initializeTeachingClassTrainingData("class-1", "teacher-1");
|
|
|
|
|
|
|
|
|
|
assertEquals(HttpStatus.BAD_REQUEST, result.getStatusCode());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void teacherCanInitializeSingleStudentOnlyInOwnedTeachingClass() {
|
|
|
|
|
UserController controller = controllerWithCommonMocks();
|
|
|
|
|
when(controller.schoolClassMapper.selectByPrimaryKey("class-1")).thenReturn(classCreatedBy("teacher-1"));
|
|
|
|
|
when(controller.teachingClassStudentMapper.countByStudentUserIdAndTeachingClassId("student-1", "class-1"))
|
|
|
|
|
.thenReturn(1L);
|
|
|
|
|
|
|
|
|
|
ResultEntity result = controller.initializeTeachingClassStudentTrainingData("class-1", "student-1", "teacher-1");
|
|
|
|
|
|
|
|
|
|
assertEquals(HttpStatus.OK, result.getStatusCode());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void selectStudentByTeachingClassUsesMembershipRows() {
|
|
|
|
|
UserController controller = controllerWithCommonMocks();
|
|
|
|
|
SchoolClass teachingClass = classCreatedBy("teacher-1");
|
|
|
|
|
when(controller.schoolClassMapper.selectByPrimaryKey("teaching-1")).thenReturn(teachingClass);
|
|
|
|
|
TeachingClassStudent member = new TeachingClassStudent();
|
|
|
|
|
member.setStudentUserId("student-1");
|
|
|
|
|
when(controller.teachingClassStudentMapper.selectByTeachingClassId("teaching-1"))
|
|
|
|
|
.thenReturn(Collections.singletonList(member));
|
|
|
|
|
Userinfo student = new Userinfo();
|
|
|
|
|
student.setUserId("student-1");
|
|
|
|
|
student.setRole(4);
|
|
|
|
|
student.setSchoolId("school-1");
|
|
|
|
|
student.setSchoolClassId("admin-1");
|
|
|
|
|
when(controller.userinfoMapper.selectByExample(any())).thenReturn(Collections.singletonList(student));
|
|
|
|
|
|
|
|
|
|
ResultEntity result = controller.selectStudent("school-1", "teaching-1", null, null, 1, 10);
|
|
|
|
|
|
|
|
|
|
assertEquals(HttpStatus.OK, result.getStatusCode());
|
|
|
|
|
verify(controller.teachingClassStudentMapper).selectByTeachingClassId("teaching-1");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private UserController controllerWithCommonMocks() {
|
|
|
|
|
UserController controller = new UserController();
|
|
|
|
|
controller.schoolMapper = mock(SchoolMapper.class);
|
|
|
|
|
controller.schoolFacultyMapper = mock(SchoolFacultyMapper.class);
|
|
|
|
|
controller.schoolMajorMapper = mock(SchoolMajorMapper.class);
|
|
|
|
|
controller.schoolClassMapper = mock(SchoolClassMapper.class);
|
|
|
|
|
controller.teachingClassStudentMapper = mock(TeachingClassStudentMapper.class);
|
|
|
|
|
controller.userinfoMapper = mock(UserinfoMapper.class);
|
|
|
|
|
controller.userInfoService = mock(UserInfoService.class);
|
|
|
|
|
controller.pinyin4jUtil = mock(Pinyin4jUtil.class);
|
|
|
|
|
|
|
|
|
|
School school = new School();
|
|
|
|
|
school.setSchoolId("school-1");
|
|
|
|
|
school.setSchoolName("school");
|
|
|
|
|
SchoolFaculty faculty = new SchoolFaculty();
|
|
|
|
|
faculty.setSchoolFacultyId("faculty-1");
|
|
|
|
|
faculty.setSchoolId("school-1");
|
|
|
|
|
SchoolMajor major = new SchoolMajor();
|
|
|
|
|
major.setSchoolMajorId("major-1");
|
|
|
|
|
major.setSchoolFacultyId("faculty-1");
|
|
|
|
|
|
|
|
|
|
when(controller.schoolMapper.selectByPrimaryKey("school-1")).thenReturn(school);
|
|
|
|
|
when(controller.schoolFacultyMapper.selectByPrimaryKey("faculty-1")).thenReturn(faculty);
|
|
|
|
|
when(controller.schoolMajorMapper.selectByPrimaryKey("major-1")).thenReturn(major);
|
|
|
|
|
return controller;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Userinfo teacher(String userId) {
|
|
|
|
|
return teacher(userId, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Userinfo teacher(String userId, boolean teacherAdmin) {
|
|
|
|
|
Userinfo teacher = new Userinfo();
|
|
|
|
|
teacher.setUserId(userId);
|
|
|
|
|
teacher.setRole(3);
|
|
|
|
|
teacher.setSchoolId("school-1");
|
|
|
|
|
teacher.setTeacherAdmin(teacherAdmin);
|
|
|
|
|
return teacher;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private SchoolClass classCreatedBy(String teacherId) {
|
|
|
|
|
SchoolClass schoolClass = new SchoolClass();
|
|
|
|
|
schoolClass.setSchoolClassId("class-1");
|
|
|
|
|
schoolClass.setSchoolId("school-1");
|
|
|
|
|
schoolClass.setCreatedBy(teacherId);
|
|
|
|
|
schoolClass.setClassType("TEACHING");
|
|
|
|
|
return schoolClass;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean hasCondition(SchoolClassExample example, String condition) {
|
|
|
|
|
return example.getOredCriteria().stream()
|
|
|
|
|
.flatMap(criteria -> criteria.getAllCriteria().stream())
|
|
|
|
|
.anyMatch(criterion -> condition.equals(criterion.getCondition()));
|
|
|
|
|
}
|
|
|
|
|
}
|