Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
邬吉朋
practical_train
Commits
66392f2e
Commit
66392f2e
authored
Sep 15, 2026
by
wujipeng
Browse files
bug修复
parent
4e10634c
Changes
46
Show whitespace changes
Inline
Side-by-side
practical-business/src/test/java/com/platform/business/mapper/PracticeRuleAndTeacherMapperXmlTest.java
0 → 100644
View file @
66392f2e
package
com.platform.business.mapper
;
import
org.apache.ibatis.builder.xml.XMLMapperBuilder
;
import
org.apache.ibatis.io.Resources
;
import
org.apache.ibatis.session.Configuration
;
import
org.junit.jupiter.api.Test
;
import
java.io.InputStream
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
/** 启动前验证新增规则、教师关系及权限SQL都能被MyBatis解析。 */
class
PracticeRuleAndTeacherMapperXmlTest
{
@Test
void
newMapperStatementsAndPermissionFragmentsShouldParse
()
throws
Exception
{
Configuration
configuration
=
new
Configuration
();
parse
(
configuration
,
"com/platform/business/mapper/PracticePaperRuleMapper.xml"
);
parse
(
configuration
,
"com/platform/business/mapper/ExamTeacherAssignmentMapper.xml"
);
parse
(
configuration
,
"com/platform/business/mapper/ExamReviewMapper.xml"
);
parse
(
configuration
,
"com/platform/business/mapper/TeacherHomeMapper.xml"
);
assertTrue
(
configuration
.
hasStatement
(
"com.platform.business.mapper.PracticePaperRuleMapper.pageDefinitions"
));
assertTrue
(
configuration
.
hasStatement
(
"com.platform.business.mapper.PracticePaperRuleMapper.insertDefinitionDetails"
));
assertTrue
(
configuration
.
hasStatement
(
"com.platform.business.mapper.ExamTeacherAssignmentMapper.insertBatch"
));
assertTrue
(
configuration
.
hasStatement
(
"com.platform.business.mapper.ExamReviewMapper.lockTask"
));
assertTrue
(
configuration
.
hasStatement
(
"com.platform.business.mapper.TeacherHomeMapper.selectUpcomingExams"
));
}
private
void
parse
(
Configuration
configuration
,
String
resource
)
throws
Exception
{
try
(
InputStream
input
=
Resources
.
getResourceAsStream
(
resource
))
{
XMLMapperBuilder
builder
=
new
XMLMapperBuilder
(
input
,
configuration
,
resource
,
configuration
.
getSqlFragments
());
builder
.
parse
();
}
}
}
practical-business/src/test/java/com/platform/business/mapper/TeacherScoreMapperXmlTest.java
View file @
66392f2e
...
...
@@ -96,12 +96,14 @@ class TeacherScoreMapperXmlTest {
* 管理端只允许创建未来考试,因此列表一旦重新加入 DATE_ADD/NOW 时间门槛,新增考试
* 就会再次被隐藏。这里明确锁定“只按主考教师归属过滤”的同步规则。
*/
assertTrue
(
listSql
.
contains
(
"where e.chief_id = ?"
));
assertTrue
(
listSql
.
contains
(
"from exam_teacher_assignment chief_assignment"
));
assertTrue
(
listSql
.
contains
(
"e.chief_id = ?"
));
assertFalse
(
listSql
.
contains
(
"date_add(e.exam_time"
));
assertFalse
(
listSql
.
contains
(
"<= now()"
));
}
private
void
assertVisibleExamProtection
(
String
sql
)
{
assertTrue
(
sql
.
contains
(
"from exam_teacher_assignment chief_assignment"
));
assertTrue
(
sql
.
contains
(
"e.chief_id = ?"
));
assertFalse
(
sql
.
contains
(
"date_add(e.exam_time"
));
}
...
...
practical-business/src/test/java/com/platform/business/service/impl/ExamAdminServiceImplTest.java
View file @
66392f2e
...
...
@@ -2,18 +2,22 @@ package com.platform.business.service.impl;
import
com.platform.business.constant.ExamAdminConstants
;
import
com.platform.business.mapper.ExamMapper
;
import
com.platform.business.mapper.ExamTeacherAssignmentMapper
;
import
com.platform.business.model.dto.ExamAdminSaveDTO
;
import
com.platform.business.model.dto.ExamAdminUpdateDTO
;
import
com.platform.business.model.dto.NotificationPublishDTO
;
import
com.platform.business.model.entity.ExamEntity
;
import
com.platform.business.model.entity.ExamStudentEntity
;
import
com.platform.business.model.entity.ExamTeacherAssignmentEntity
;
import
com.platform.business.model.entity.TheoreticalPaperEntity
;
import
com.platform.business.model.entity.PracticePaperRuleDefinitionEntity
;
import
com.platform.business.model.vo.ExamAdminClassVO
;
import
com.platform.business.model.vo.ExamAdminDetailVO
;
import
com.platform.business.service.ClassAdminService
;
import
com.platform.business.service.BusinessNotificationPublisher
;
import
com.platform.business.service.ExamStudentService
;
import
com.platform.business.service.TheoreticalPaperService
;
import
com.platform.business.service.PracticePaperRuleService
;
import
com.platform.exception.BusinessException
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
...
...
@@ -37,6 +41,7 @@ import static org.mockito.ArgumentMatchers.any;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyList
;
import
static
org
.
mockito
.
ArgumentMatchers
.
eq
;
import
static
org
.
mockito
.
Mockito
.
never
;
import
static
org
.
mockito
.
Mockito
.
lenient
;
import
static
org
.
mockito
.
Mockito
.
times
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
...
...
@@ -48,12 +53,18 @@ class ExamAdminServiceImplTest {
@Mock
private
ExamMapper
examMapper
;
@Mock
private
ExamTeacherAssignmentMapper
examTeacherAssignmentMapper
;
@Mock
private
ClassAdminService
classAdminService
;
@Mock
private
TheoreticalPaperService
theoreticalPaperService
;
@Mock
private
PracticePaperRuleService
practicePaperRuleService
;
@Mock
private
ExamStudentService
examStudentService
;
...
...
@@ -96,7 +107,7 @@ class ExamAdminServiceImplTest {
mockValidRelationships
();
when
(
examMapper
.
countAdminExamDuplicateName
(
1
,
"测试考试"
,
null
)).
thenReturn
(
0
);
when
(
examMapper
.
selectAdminExamConflicts
(
any
(),
eq
(
90
),
eq
(
1
),
eq
(
"teacher-1"
),
eq
(
"teacher-2"
),
anyList
(),
eq
(
null
)))
anyList
(
),
anyList
(),
eq
(
null
)))
.
thenReturn
(
Collections
.
emptyList
());
when
(
examMapper
.
insert
(
any
(
ExamEntity
.
class
))).
thenAnswer
(
invocation
->
{
ExamEntity
entity
=
invocation
.
getArgument
(
0
);
...
...
@@ -145,17 +156,20 @@ class ExamAdminServiceImplTest {
}
@Test
void
createPracticeShouldUse
Manual
TotalAndKeepPaperEmpty
()
{
void
createPracticeShouldUse
PublishedRule
TotalAndKeepPaperEmpty
()
{
ExamAdminSaveDTO
request
=
validCreateRequest
();
request
.
setType
(
"实训"
);
request
.
setPaperId
(
null
);
request
.
setTotalScore
(
new
BigDecimal
(
"120"
));
request
.
setTotalScore
(
null
);
request
.
setPracticeRuleId
(
6
);
request
.
setPassScore
(
null
);
mockWritableClass
();
mockValidRelationships
();
when
(
practicePaperRuleService
.
requirePublishedDefinition
(
6
,
"污水一级"
))
.
thenReturn
(
practiceRule
(
6
,
"一级"
,
"120.00"
));
when
(
examMapper
.
countAdminExamDuplicateName
(
1
,
"测试考试"
,
null
)).
thenReturn
(
0
);
when
(
examMapper
.
selectAdminExamConflicts
(
any
(),
eq
(
90
),
eq
(
1
),
eq
(
"teacher-1"
),
eq
(
"teacher-2"
),
anyList
(),
eq
(
null
)))
anyList
(
),
anyList
(),
eq
(
null
)))
.
thenReturn
(
Collections
.
emptyList
());
when
(
examMapper
.
insert
(
any
(
ExamEntity
.
class
))).
thenAnswer
(
invocation
->
{
ExamEntity
entity
=
invocation
.
getArgument
(
0
);
...
...
@@ -175,6 +189,7 @@ class ExamAdminServiceImplTest {
ArgumentCaptor
<
ExamEntity
>
captor
=
ArgumentCaptor
.
forClass
(
ExamEntity
.
class
);
verify
(
examMapper
).
insert
(
captor
.
capture
());
assertEquals
(
null
,
captor
.
getValue
().
getPaperId
());
assertEquals
(
6
,
captor
.
getValue
().
getPracticeRuleId
());
assertEquals
(
new
BigDecimal
(
"120.00"
),
captor
.
getValue
().
getTotalScore
());
assertEquals
(
new
BigDecimal
(
"72.00"
),
captor
.
getValue
().
getPassScore
());
verify
(
theoreticalPaperService
,
never
()).
getById
(
any
());
...
...
@@ -217,8 +232,8 @@ class ExamAdminServiceImplTest {
mockValidPaper
();
when
(
examMapper
.
lockAdminExamUsers
(
anyList
()))
.
thenReturn
(
Arrays
.
asList
(
"student-1"
,
"student-2"
,
"teacher-1"
,
"teacher-2"
));
when
(
examMapper
.
coun
tAdminExamActiveTeacher
(
"teacher-1"
)).
thenReturn
(
1
);
when
(
examMapper
.
countAdminExamActiveT
eacher
(
"teacher-2"
))
.
thenReturn
(
1
)
;
when
(
examMapper
.
selec
tAdminExamActiveTeacher
Ids
(
anyList
()))
.
thenReturn
(
Arrays
.
asList
(
"t
eacher
-1"
,
"teacher-2"
));
when
(
examMapper
.
lockAdminExamStudents
(
1
,
request
.
getStudentIds
()))
.
thenReturn
(
Collections
.
singletonList
(
"student-1"
));
...
...
@@ -241,7 +256,7 @@ class ExamAdminServiceImplTest {
conflict
.
setClassId
(
1
);
conflict
.
setName
(
"已有考试"
);
when
(
examMapper
.
selectAdminExamConflicts
(
any
(),
eq
(
90
),
eq
(
1
),
eq
(
"teacher-1"
),
eq
(
"teacher-2"
),
anyList
(),
eq
(
null
)))
anyList
(
),
anyList
(),
eq
(
null
)))
.
thenReturn
(
Collections
.
singletonList
(
conflict
));
BusinessException
error
=
assertThrows
(
BusinessException
.
class
,
...
...
@@ -265,7 +280,7 @@ class ExamAdminServiceImplTest {
conflict
.
setChiefExaminerId
(
"teacher-3"
);
conflict
.
setInvigilatorId
(
"teacher-4"
);
when
(
examMapper
.
selectAdminExamConflicts
(
any
(),
eq
(
90
),
eq
(
1
),
eq
(
"teacher-1"
),
eq
(
"teacher-2"
),
anyList
(),
eq
(
null
)))
anyList
(
),
anyList
(),
eq
(
null
)))
.
thenReturn
(
Collections
.
singletonList
(
conflict
));
BusinessException
error
=
assertThrows
(
BusinessException
.
class
,
...
...
@@ -321,6 +336,8 @@ class ExamAdminServiceImplTest {
existing
.
setType
(
ExamAdminConstants
.
TYPE_PRACTICE
);
existing
.
setExamTime
(
Timestamp
.
valueOf
(
"2099-09-18 09:00:00"
));
existing
.
setInvigilationId
(
"teacher-2"
);
existing
.
setChiefId
(
"teacher-1"
);
existing
.
setPracticeRuleId
(
6
);
existing
.
setPaperId
(
"paper-1"
);
existing
.
setTotalScore
(
new
BigDecimal
(
"100.00"
));
existing
.
setPassScore
(
new
BigDecimal
(
"60.00"
));
...
...
@@ -331,9 +348,11 @@ class ExamAdminServiceImplTest {
when
(
examMapper
.
selectAdminExamStudentIds
(
7
))
.
thenReturn
(
Arrays
.
asList
(
"student-1"
,
"student-2"
));
mockValidRelationships
();
when
(
practicePaperRuleService
.
requirePublishedDefinition
(
6
,
"污水一级"
))
.
thenReturn
(
practiceRule
(
6
,
"一级"
,
"100.00"
));
when
(
examMapper
.
countAdminExamDuplicateName
(
1
,
"修改后考试"
,
7
)).
thenReturn
(
0
);
when
(
examMapper
.
selectAdminExamConflicts
(
any
(),
eq
(
120
),
eq
(
1
),
eq
(
"teacher-1"
),
eq
(
"teacher-2"
),
anyList
(),
eq
(
7
)))
anyList
(
),
anyList
(),
eq
(
7
)))
.
thenReturn
(
Collections
.
emptyList
());
when
(
examMapper
.
updateAdminExam
(
any
(
ExamEntity
.
class
))).
thenReturn
(
1
);
ExamAdminDetailVO
detail
=
new
ExamAdminDetailVO
();
...
...
@@ -356,10 +375,57 @@ class ExamAdminServiceImplTest {
ArgumentCaptor
<
ExamEntity
>
captor
=
ArgumentCaptor
.
forClass
(
ExamEntity
.
class
);
verify
(
examMapper
).
updateAdminExam
(
captor
.
capture
());
assertEquals
(
new
BigDecimal
(
"70.00"
),
captor
.
getValue
().
getPassScore
());
//
SQL更新语句不包含以下字段;实体保持null可防止后续误改试卷、监考和总分快照
。
//
理论试卷仍不变;实训规则、监考人员及总分快照允许在锁定条件下更新
。
assertEquals
(
null
,
captor
.
getValue
().
getPaperId
());
assertEquals
(
null
,
captor
.
getValue
().
getInvigilationId
());
assertEquals
(
null
,
captor
.
getValue
().
getTotalScore
());
assertEquals
(
"teacher-2"
,
captor
.
getValue
().
getInvigilationId
());
assertEquals
(
6
,
captor
.
getValue
().
getPracticeRuleId
());
assertEquals
(
new
BigDecimal
(
"100.00"
),
captor
.
getValue
().
getTotalScore
());
}
@Test
void
updateShouldRecalculateDefaultPassScoreWhenPracticeRuleChanges
()
{
ExamEntity
existing
=
new
ExamEntity
();
existing
.
setId
(
7
);
existing
.
setClassId
(
1
);
existing
.
setType
(
ExamAdminConstants
.
TYPE_PRACTICE
);
existing
.
setExamTime
(
Timestamp
.
valueOf
(
"2099-09-18 09:00:00"
));
existing
.
setChiefId
(
"teacher-1"
);
existing
.
setInvigilationId
(
"teacher-2"
);
existing
.
setPracticeRuleId
(
6
);
existing
.
setTotalScore
(
new
BigDecimal
(
"100.00"
));
existing
.
setPassScore
(
new
BigDecimal
(
"70.00"
));
when
(
examMapper
.
selectAdminExamForUpdate
(
7
)).
thenReturn
(
existing
);
when
(
examMapper
.
countAdminExamAttempts
(
7
)).
thenReturn
(
0
);
when
(
examMapper
.
lockAdminExamClass
(
1
)).
thenReturn
(
1
);
when
(
examMapper
.
selectAdminExamClass
(
1
)).
thenReturn
(
managedClass
());
when
(
examMapper
.
selectAdminExamStudentIds
(
7
))
.
thenReturn
(
Arrays
.
asList
(
"student-1"
,
"student-2"
));
mockValidRelationships
();
when
(
practicePaperRuleService
.
requirePublishedDefinition
(
7
,
"污水一级"
))
.
thenReturn
(
practiceRule
(
7
,
"一级"
,
"120.00"
));
when
(
examMapper
.
countAdminExamDuplicateName
(
1
,
"切换实操规则"
,
7
)).
thenReturn
(
0
);
when
(
examMapper
.
selectAdminExamConflicts
(
any
(),
eq
(
90
),
eq
(
1
),
anyList
(),
anyList
(),
eq
(
7
))).
thenReturn
(
Collections
.
emptyList
());
when
(
examMapper
.
updateAdminExam
(
any
(
ExamEntity
.
class
))).
thenReturn
(
1
);
ExamAdminDetailVO
detail
=
new
ExamAdminDetailVO
();
detail
.
setId
(
7
);
detail
.
setExamTime
(
Timestamp
.
valueOf
(
"2099-09-19 10:00:00"
));
detail
.
setDuration
(
90
);
when
(
examMapper
.
selectAdminExamDetail
(
7
)).
thenReturn
(
detail
);
ExamAdminUpdateDTO
request
=
new
ExamAdminUpdateDTO
();
request
.
setName
(
"切换实操规则"
);
request
.
setType
(
ExamAdminConstants
.
TYPE_PRACTICE
);
request
.
setExamTime
(
Timestamp
.
valueOf
(
"2099-09-19 10:00:00"
));
request
.
setDuration
(
90
);
request
.
setPracticeRuleId
(
7
);
service
.
update
(
7
,
request
);
ArgumentCaptor
<
ExamEntity
>
captor
=
ArgumentCaptor
.
forClass
(
ExamEntity
.
class
);
verify
(
examMapper
).
updateAdminExam
(
captor
.
capture
());
assertEquals
(
new
BigDecimal
(
"120.00"
),
captor
.
getValue
().
getTotalScore
());
assertEquals
(
new
BigDecimal
(
"72.00"
),
captor
.
getValue
().
getPassScore
());
}
@Test
...
...
@@ -370,7 +436,7 @@ class ExamAdminServiceImplTest {
mockValidRelationships
();
when
(
examMapper
.
countAdminExamDuplicateName
(
1
,
"测试考试"
,
null
)).
thenReturn
(
0
);
when
(
examMapper
.
selectAdminExamConflicts
(
any
(),
eq
(
90
),
eq
(
1
),
eq
(
"teacher-1"
),
eq
(
"teacher-2"
),
anyList
(),
eq
(
null
)))
anyList
(
),
anyList
(),
eq
(
null
)))
.
thenReturn
(
Collections
.
emptyList
());
when
(
examMapper
.
insert
(
any
(
ExamEntity
.
class
))).
thenAnswer
(
invocation
->
{
ExamEntity
entity
=
invocation
.
getArgument
(
0
);
...
...
@@ -464,10 +530,12 @@ class ExamAdminServiceImplTest {
private
void
mockValidRelationships
()
{
when
(
examMapper
.
lockAdminExamUsers
(
anyList
()))
.
thenReturn
(
Arrays
.
asList
(
"student-1"
,
"student-2"
,
"teacher-1"
,
"teacher-2"
));
when
(
examMapper
.
coun
tAdminExamActiveTeacher
(
"teacher-1"
)).
thenReturn
(
1
);
when
(
examMapper
.
countAdminExamActiveT
eacher
(
"teacher-2"
))
.
thenReturn
(
1
)
;
when
(
examMapper
.
selec
tAdminExamActiveTeacher
Ids
(
anyList
()))
.
thenReturn
(
Arrays
.
asList
(
"t
eacher
-1"
,
"teacher-2"
));
when
(
examMapper
.
lockAdminExamStudents
(
eq
(
1
),
anyList
()))
.
thenReturn
(
Arrays
.
asList
(
"student-1"
,
"student-2"
));
lenient
().
when
(
examTeacherAssignmentMapper
.
insertBatch
(
anyList
()))
.
thenAnswer
(
invocation
->
((
List
<?>)
invocation
.
getArgument
(
0
)).
size
());
}
private
ExamAdminClassVO
managedClass
()
{
...
...
@@ -496,4 +564,77 @@ class ExamAdminServiceImplTest {
request
.
setStudentIds
(
Arrays
.
asList
(
"student-1"
,
"student-2"
));
return
request
;
}
@Test
void
createShouldRejectExplicitEmptyTeacherArrayInsteadOfFallingBackToLegacyField
()
{
ExamAdminSaveDTO
request
=
validCreateRequest
();
request
.
setChiefExaminerIds
(
Collections
.
emptyList
());
mockWritableClass
();
BusinessException
error
=
assertThrows
(
BusinessException
.
class
,
()
->
service
.
create
(
request
));
assertEquals
(
"首席考评员至少选择一人"
,
error
.
getMessage
());
verify
(
examMapper
,
never
()).
insert
(
any
(
ExamEntity
.
class
));
}
@Test
void
createShouldPersistMultiRoleTeachersAndDeduplicateRecipients
()
{
ExamAdminSaveDTO
request
=
validCreateRequest
();
request
.
setChiefExaminerIds
(
Arrays
.
asList
(
"teacher-1"
,
"teacher-3"
,
"teacher-1"
));
request
.
setInvigilatorIds
(
Arrays
.
asList
(
"teacher-1"
,
"teacher-2"
));
mockWritableClass
();
mockValidPaper
();
when
(
examMapper
.
lockAdminExamUsers
(
anyList
())).
thenReturn
(
Arrays
.
asList
(
"student-1"
,
"student-2"
,
"teacher-1"
,
"teacher-2"
,
"teacher-3"
));
when
(
examMapper
.
selectAdminExamActiveTeacherIds
(
anyList
()))
.
thenReturn
(
Arrays
.
asList
(
"teacher-1"
,
"teacher-2"
,
"teacher-3"
));
when
(
examMapper
.
lockAdminExamStudents
(
eq
(
1
),
anyList
()))
.
thenReturn
(
Arrays
.
asList
(
"student-1"
,
"student-2"
));
when
(
examMapper
.
countAdminExamDuplicateName
(
1
,
"测试考试"
,
null
)).
thenReturn
(
0
);
when
(
examMapper
.
selectAdminExamConflicts
(
any
(),
eq
(
90
),
eq
(
1
),
anyList
(),
anyList
(),
eq
(
null
))).
thenReturn
(
Collections
.
emptyList
());
when
(
examMapper
.
insert
(
any
(
ExamEntity
.
class
))).
thenAnswer
(
invocation
->
{
ExamEntity
entity
=
invocation
.
getArgument
(
0
);
entity
.
setId
(
101
);
return
1
;
});
when
(
examTeacherAssignmentMapper
.
insertBatch
(
anyList
()))
.
thenAnswer
(
invocation
->
((
List
<?>)
invocation
.
getArgument
(
0
)).
size
());
when
(
examStudentService
.
saveBatch
(
anyList
())).
thenReturn
(
true
);
ExamAdminDetailVO
detail
=
new
ExamAdminDetailVO
();
detail
.
setId
(
101
);
detail
.
setExamTime
(
request
.
getExamTime
());
detail
.
setDuration
(
90
);
when
(
examMapper
.
selectAdminExamDetail
(
101
)).
thenReturn
(
detail
);
when
(
examMapper
.
selectAdminExamStudentIds
(
101
)).
thenReturn
(
request
.
getStudentIds
());
service
.
create
(
request
);
@SuppressWarnings
(
"rawtypes"
)
ArgumentCaptor
<
List
>
assignmentCaptor
=
ArgumentCaptor
.
forClass
(
List
.
class
);
verify
(
examTeacherAssignmentMapper
).
insertBatch
(
assignmentCaptor
.
capture
());
List
<?>
assignments
=
assignmentCaptor
.
getValue
();
assertEquals
(
4
,
assignments
.
size
());
assertEquals
(
"teacher-1"
,
((
ExamTeacherAssignmentEntity
)
assignments
.
get
(
0
)).
getTeacherId
());
assertEquals
(
"CHIEF"
,
((
ExamTeacherAssignmentEntity
)
assignments
.
get
(
0
)).
getRole
());
assertEquals
(
"teacher-1"
,
((
ExamTeacherAssignmentEntity
)
assignments
.
get
(
2
)).
getTeacherId
());
assertEquals
(
"INVIGILATOR"
,
((
ExamTeacherAssignmentEntity
)
assignments
.
get
(
2
)).
getRole
());
ArgumentCaptor
<
NotificationPublishDTO
>
notificationCaptor
=
ArgumentCaptor
.
forClass
(
NotificationPublishDTO
.
class
);
verify
(
notificationPublisher
,
times
(
2
))
.
publish
(
notificationCaptor
.
capture
(),
eq
(
null
),
eq
(
"管理员"
));
assertEquals
(
Arrays
.
asList
(
"teacher-1"
,
"teacher-3"
,
"teacher-2"
),
notificationCaptor
.
getAllValues
().
get
(
0
).
getRecipientUserIds
());
}
private
PracticePaperRuleDefinitionEntity
practiceRule
(
int
id
,
String
grade
,
String
score
)
{
PracticePaperRuleDefinitionEntity
rule
=
new
PracticePaperRuleDefinitionEntity
();
rule
.
setId
(
id
);
rule
.
setLevelGrade
(
grade
);
rule
.
setTotalScore
(
new
BigDecimal
(
score
));
rule
.
setStatus
(
"PUBLISHED"
);
return
rule
;
}
}
practical-business/src/test/java/com/platform/business/service/impl/ExamStaudentServiceImplTest.java
View file @
66392f2e
...
...
@@ -23,7 +23,7 @@ import static org.mockito.Mockito.never;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
/** 最近考试接口
返回实际考试类型并接入当前最新
实操配分规则
的回归测试
。 */
/** 最近考试接口
按考试保存的规则ID返回
实操配分规则。 */
@ExtendWith
(
MockitoExtension
.
class
)
class
ExamStaudentServiceImplTest
{
...
...
@@ -42,21 +42,22 @@ class ExamStaudentServiceImplTest {
}
@Test
void
recentShouldAttach
Latest
EffectiveRuleAndSameEventStudents
()
{
void
recentShouldAttach
Selected
EffectiveRuleAndSameEventStudents
()
{
RecentExamStudentVO
recent
=
new
RecentExamStudentVO
();
recent
.
setExamId
(
88
);
recent
.
setLev
(
"污水一级"
);
recent
.
setType
(
"理论考试"
);
recent
.
setType
(
"实训"
);
recent
.
setPracticeRuleId
(
6
);
PracticePaperRuleConfigurationVO
configuration
=
new
PracticePaperRuleConfigurationVO
();
configuration
.
setGrade
(
"一级"
);
when
(
mapper
.
recent
(
"student-1"
)).
thenReturn
(
recent
);
when
(
practicePaperRuleService
.
effectiveConfiguration
(
"污水一级"
))
when
(
practicePaperRuleService
.
effectiveConfiguration
(
6
))
.
thenReturn
(
configuration
);
when
(
mapper
.
theSameEvent
(
88
)).
thenReturn
(
Collections
.
singletonList
(
new
ExamStudentVO
()));
RecentExamStudentVO
result
=
service
.
recent
(
"student-1"
);
assertEquals
(
"
理论考试
"
,
result
.
getType
());
assertEquals
(
"
实训
"
,
result
.
getType
());
assertEquals
(
configuration
,
result
.
getPracticeRule
());
assertEquals
(
1
,
result
.
getData
().
size
());
}
...
...
@@ -66,7 +67,7 @@ class ExamStaudentServiceImplTest {
when
(
mapper
.
recent
(
"student-2"
)).
thenReturn
(
null
);
assertNull
(
service
.
recent
(
"student-2"
));
verify
(
practicePaperRuleService
,
never
()).
effectiveConfiguration
(
org
.
mockito
.
ArgumentMatchers
.
any
String
());
verify
(
practicePaperRuleService
,
never
()).
effectiveConfiguration
(
org
.
mockito
.
ArgumentMatchers
.
any
Int
());
verify
(
mapper
,
never
()).
theSameEvent
(
org
.
mockito
.
ArgumentMatchers
.
anyInt
());
}
...
...
practical-business/src/test/java/com/platform/business/service/impl/PracticePaperRuleServiceImplTest.java
View file @
66392f2e
...
...
@@ -4,8 +4,10 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper;
import
com.platform.business.mapper.PracticePaperRuleMapper
;
import
com.platform.business.model.dto.PracticePaperRuleItemDTO
;
import
com.platform.business.model.dto.PracticePaperRuleSaveDTO
;
import
com.platform.business.model.entity.PracticePaperRuleDefinitionEntity
;
import
com.platform.business.model.entity.PracticePaperRuleDetailEntity
;
import
com.platform.business.model.entity.PracticePaperRuleEntity
;
import
com.platform.business.model.vo.PracticePaperRule
Configuration
VO
;
import
com.platform.business.model.vo.PracticePaperRule
Item
VO
;
import
com.platform.exception.BusinessException
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
...
...
@@ -21,13 +23,17 @@ import java.util.Arrays;
import
java.util.List
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertFalse
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertThrows
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyList
;
import
static
org
.
mockito
.
ArgumentMatchers
.
eq
;
import
static
org
.
mockito
.
Mockito
.
never
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
/** 实操
组
卷规则的
等级归一化、默认值、汇总和五题上限
测试。 */
/**
具名
实操
试
卷规则的
完整保存、状态流转和删除保护
测试。 */
@ExtendWith
(
MockitoExtension
.
class
)
class
PracticePaperRuleServiceImplTest
{
...
...
@@ -39,98 +45,226 @@ class PracticePaperRuleServiceImplTest {
@BeforeEach
void
setUp
()
{
service
=
new
PracticePaperRuleServiceImpl
();
// ServiceImpl通过protected baseMapper访问数据库,单元测试显式注入以隔离Spring容器。
ReflectionTestUtils
.
setField
(
service
,
"baseMapper"
,
mapper
);
ReflectionTestUtils
.
setField
(
service
,
"ruleMapper"
,
mapper
);
}
@Test
@SuppressWarnings
(
"unchecked"
)
void
configurationShouldShareSuffixGradeAndCalculateTotals
()
{
List
<
PracticePaperRuleEntity
>
rows
=
Arrays
.
asList
(
rule
(
1
,
"一级"
,
"运行管理"
,
"项目开发"
,
20
,
"20.00"
,
2
),
rule
(
2
,
"一级"
,
"安全管理"
,
"现场安全管理"
,
30
,
"10.50"
,
1
));
when
(
mapper
.
selectList
(
any
(
Wrapper
.
class
))).
thenReturn
(
rows
);
void
createShouldNormalizeSuffixAndPersistCalculatedSnapshots
()
{
List
<
PracticePaperRuleEntity
>
catalog
=
Arrays
.
asList
(
catalog
(
1
,
"一级"
,
"运行管理"
,
"项目开发"
),
catalog
(
2
,
"一级"
,
"安全管理"
,
"现场安全管理"
));
when
(
mapper
.
selectList
(
any
(
Wrapper
.
class
))).
thenReturn
(
catalog
);
when
(
mapper
.
countDuplicateDefinition
(
"一级"
,
"规则A"
,
null
)).
thenReturn
(
0
);
when
(
mapper
.
insertDefinition
(
any
())).
thenAnswer
(
invocation
->
{
PracticePaperRuleDefinitionEntity
entity
=
invocation
.
getArgument
(
0
);
entity
.
setId
(
10
);
return
1
;
});
when
(
mapper
.
insertDefinitionDetails
(
anyList
())).
thenReturn
(
2
);
when
(
mapper
.
selectDefinition
(
10
)).
thenReturn
(
definition
(
10
,
"规则A"
,
"一级"
,
3
,
70
,
"50.50"
,
"DRAFT"
));
when
(
mapper
.
selectDefinitionDetails
(
10
)).
thenReturn
(
new
ArrayList
<>());
PracticePaperRuleConfigurationVO
result
=
service
.
configuration
(
"污泥一级"
);
PracticePaperRuleSaveDTO
request
=
request
(
"规则A"
,
"污泥一级"
,
Arrays
.
asList
(
item
(
1
,
20
,
"20.00"
,
2
),
item
(
2
,
30
,
"10.50"
,
1
)));
service
.
create
(
request
,
"admin-1"
);
assertEquals
(
"一级"
,
result
.
getGrade
());
assertEquals
(
"污泥一级"
,
result
.
getLev
());
assertEquals
(
3
,
result
.
getTotalQuestionCount
());
assertEquals
(
70
,
result
.
getTotalDuration
());
assertEquals
(
new
BigDecimal
(
"50.50"
),
result
.
getTotalScore
());
assertEquals
(
2
,
result
.
getRuleList
().
size
());
ArgumentCaptor
<
PracticePaperRuleDefinitionEntity
>
header
=
ArgumentCaptor
.
forClass
(
PracticePaperRuleDefinitionEntity
.
class
);
verify
(
mapper
).
insertDefinition
(
header
.
capture
());
assertEquals
(
"一级"
,
header
.
getValue
().
getLevelGrade
());
assertEquals
(
3
,
header
.
getValue
().
getQuestionCount
());
assertEquals
(
70
,
header
.
getValue
().
getTotalDuration
());
assertEquals
(
new
BigDecimal
(
"50.50"
),
header
.
getValue
().
getTotalScore
());
assertEquals
(
"DRAFT"
,
header
.
getValue
().
getStatus
());
@SuppressWarnings
(
"rawtypes"
)
ArgumentCaptor
<
List
>
details
=
ArgumentCaptor
.
forClass
(
List
.
class
);
verify
(
mapper
).
insertDefinitionDetails
(
details
.
capture
());
PracticePaperRuleDetailEntity
first
=
(
PracticePaperRuleDetailEntity
)
details
.
getValue
().
get
(
0
);
assertEquals
(
10
,
first
.
getRuleId
());
assertEquals
(
1
,
first
.
getCatalogId
());
}
@Test
void
saveShouldRejectMoreThanFiveQuestionsBeforeAnyUpdate
()
{
List
<
PracticePaperRuleEntity
>
stored
=
new
ArrayList
<>();
@SuppressWarnings
(
"unchecked"
)
void
createShouldRejectMoreThanFiveQuestionsBeforeWriting
()
{
List
<
PracticePaperRuleEntity
>
catalog
=
new
ArrayList
<>();
List
<
PracticePaperRuleItemDTO
>
submitted
=
new
ArrayList
<>();
for
(
int
index
=
1
;
index
<=
6
;
index
++)
{
stored
.
add
(
rule
(
index
,
"五级"
,
"项目"
+
index
,
"单元"
+
index
,
20
,
"20.00"
,
0
));
catalog
.
add
(
catalog
(
index
,
"五级"
,
"项目"
+
index
,
"单元"
+
index
));
submitted
.
add
(
item
(
index
,
20
,
"20.00"
,
1
));
}
when
(
mapper
.
selectByGradeForUpdate
(
"五级"
)).
thenReturn
(
stored
);
PracticePaperRuleSaveDTO
request
=
new
PracticePaperRuleSaveDTO
();
request
.
setLev
(
"污水五级"
);
request
.
setRuleList
(
submitted
);
when
(
mapper
.
selectList
(
any
(
Wrapper
.
class
))).
thenReturn
(
catalog
);
BusinessException
error
=
assertThrows
(
BusinessException
.
class
,
()
->
service
.
saveConfiguration
(
request
,
"admin-1"
));
()
->
service
.
create
(
request
(
"规则B"
,
"污水五级"
,
submitted
)
,
"admin-1"
));
assertEquals
(
"考核总题数必须在1到5题之间"
,
error
.
getMessage
());
verify
(
mapper
,
never
()).
updateById
(
any
(
PracticePaperRuleEntity
.
class
));
verify
(
mapper
,
never
()).
insertDefinition
(
any
());
}
@Test
@SuppressWarnings
(
"unchecked"
)
void
createShouldRejectIncompleteCatalogBeforeWriting
()
{
when
(
mapper
.
selectList
(
any
(
Wrapper
.
class
))).
thenReturn
(
Arrays
.
asList
(
catalog
(
1
,
"一级"
,
"运行管理"
,
"项目开发"
),
catalog
(
2
,
"一级"
,
"安全管理"
,
"现场安全管理"
)));
BusinessException
error
=
assertThrows
(
BusinessException
.
class
,
()
->
service
.
create
(
request
(
"规则A"
,
"一级"
,
Arrays
.
asList
(
item
(
1
,
20
,
"20.00"
,
1
))),
"admin-1"
));
assertEquals
(
"必须提交一级全部2条标准类目规则"
,
error
.
getMessage
());
verify
(
mapper
,
never
()).
insertDefinition
(
any
());
}
@Test
@SuppressWarnings
(
"unchecked"
)
void
createShouldRejectDuplicateNameWithinSameGrade
()
{
when
(
mapper
.
selectList
(
any
(
Wrapper
.
class
))).
thenReturn
(
Arrays
.
asList
(
catalog
(
1
,
"一级"
,
"运行管理"
,
"项目开发"
)));
when
(
mapper
.
countDuplicateDefinition
(
"一级"
,
"重复规则"
,
null
)).
thenReturn
(
1
);
BusinessException
error
=
assertThrows
(
BusinessException
.
class
,
()
->
service
.
create
(
request
(
"重复规则"
,
"污水一级"
,
Arrays
.
asList
(
item
(
1
,
20
,
"20.00"
,
1
))),
"admin-1"
));
assertEquals
(
"同一职级下实操试卷规则名称已存在"
,
error
.
getMessage
());
verify
(
mapper
,
never
()).
insertDefinition
(
any
());
}
@Test
void
updateShouldRejectPublishedRule
()
{
when
(
mapper
.
lockDefinition
(
7
)).
thenReturn
(
definition
(
7
,
"已发布"
,
"三级"
,
5
,
100
,
"100"
,
"PUBLISHED"
));
BusinessException
error
=
assertThrows
(
BusinessException
.
class
,
()
->
service
.
update
(
7
,
new
PracticePaperRuleSaveDTO
(),
"admin-1"
));
assertEquals
(
"已发布实操试卷规则不能编辑"
,
error
.
getMessage
());
verify
(
mapper
,
never
()).
updateDefinition
(
any
());
}
@Test
@SuppressWarnings
(
"unchecked"
)
void
updateShouldReplaceCompleteDraftDetails
()
{
when
(
mapper
.
lockDefinition
(
7
)).
thenReturn
(
definition
(
7
,
"旧名称"
,
"一级"
,
1
,
20
,
"20"
,
"DRAFT"
));
when
(
mapper
.
selectList
(
any
(
Wrapper
.
class
))).
thenReturn
(
Arrays
.
asList
(
catalog
(
1
,
"一级"
,
"运行管理"
,
"项目开发"
)));
when
(
mapper
.
countDuplicateDefinition
(
"一级"
,
"新名称"
,
7
)).
thenReturn
(
0
);
when
(
mapper
.
updateDefinition
(
any
())).
thenReturn
(
1
);
when
(
mapper
.
insertDefinitionDetails
(
anyList
())).
thenReturn
(
1
);
when
(
mapper
.
selectDefinition
(
7
)).
thenReturn
(
definition
(
7
,
"新名称"
,
"一级"
,
2
,
50
,
"30"
,
"DRAFT"
));
when
(
mapper
.
selectDefinitionDetails
(
7
)).
thenReturn
(
new
ArrayList
<>());
service
.
update
(
7
,
request
(
"新名称"
,
"一级"
,
Arrays
.
asList
(
item
(
1
,
25
,
"15.00"
,
2
))),
"admin-1"
);
verify
(
mapper
).
deleteDefinitionDetails
(
7
);
verify
(
mapper
).
insertDefinitionDetails
(
anyList
());
}
@Test
void
publishShouldOnlyMoveDraftDirectlyToPublished
()
{
when
(
mapper
.
lockDefinition
(
9
)).
thenReturn
(
definition
(
9
,
"待发布规则"
,
"三级"
,
1
,
20
,
"20"
,
"DRAFT"
));
PracticePaperRuleItemVO
detail
=
new
PracticePaperRuleItemVO
();
detail
.
setCatalogId
(
1
);
detail
.
setQuestionCount
(
1
);
when
(
mapper
.
selectDefinitionDetails
(
9
)).
thenReturn
(
Arrays
.
asList
(
detail
));
when
(
mapper
.
updateDefinitionStatus
(
eq
(
9
),
eq
(
"PUBLISHED"
),
eq
(
"admin-1"
),
any
()))
.
thenReturn
(
1
);
when
(
mapper
.
selectDefinition
(
9
)).
thenReturn
(
definition
(
9
,
"待发布规则"
,
"三级"
,
1
,
20
,
"20"
,
"PUBLISHED"
));
assertEquals
(
"PUBLISHED"
,
service
.
publish
(
9
,
"published"
,
"admin-1"
).
getStatus
());
verify
(
mapper
).
updateDefinitionStatus
(
eq
(
9
),
eq
(
"PUBLISHED"
),
eq
(
"admin-1"
),
any
());
}
@Test
void
saveShouldApplyTwentyDefaultsAndOnlyUpdateMutableColumns
()
{
PracticePaperRuleEntity
stored
=
rule
(
7
,
"三级"
,
"运行管理"
,
"工艺运行分析"
,
15
,
"15.00"
,
0
);
when
(
mapper
.
selectByGradeForUpdate
(
"三级"
)).
thenReturn
(
Arrays
.
asList
(
stored
));
when
(
mapper
.
updateById
(
any
(
PracticePaperRuleEntity
.
class
))).
thenReturn
(
1
);
PracticePaperRuleItemDTO
submitted
=
new
PracticePaperRuleItemDTO
();
submitted
.
setId
(
7
);
submitted
.
setQuestionCount
(
1
);
void
deleteShouldProtectUsedRuleRegardlessOfStatus
()
{
when
(
mapper
.
lockDefinition
(
8
)).
thenReturn
(
definition
(
8
,
"规则C"
,
"二级"
,
5
,
100
,
"100"
,
"DRAFT"
));
when
(
mapper
.
countDefinitionUsage
(
8
)).
thenReturn
(
1
);
BusinessException
error
=
assertThrows
(
BusinessException
.
class
,
()
->
service
.
delete
(
8
));
assertEquals
(
"实操试卷规则已被考试使用,不能删除"
,
error
.
getMessage
());
verify
(
mapper
,
never
()).
deleteDefinition
(
8
);
}
@Test
void
deleteShouldAllowUnusedPublishedRule
()
{
when
(
mapper
.
lockDefinition
(
8
)).
thenReturn
(
definition
(
8
,
"规则C"
,
"二级"
,
5
,
100
,
"100"
,
"PUBLISHED"
));
when
(
mapper
.
countDefinitionUsage
(
8
)).
thenReturn
(
0
);
when
(
mapper
.
deleteDefinition
(
8
)).
thenReturn
(
1
);
assertTrue
(
service
.
delete
(
8
));
verify
(
mapper
).
deleteDefinitionDetails
(
8
);
verify
(
mapper
).
deleteDefinition
(
8
);
}
@Test
void
pageShouldExposePublishedUnusedRuleAsDeletableButNotEditable
()
{
com
.
platform
.
business
.
model
.
vo
.
PracticePaperRuleConfigurationVO
row
=
new
com
.
platform
.
business
.
model
.
vo
.
PracticePaperRuleConfigurationVO
();
row
.
setStatus
(
"PUBLISHED"
);
row
.
setUsageCount
(
0
);
when
(
mapper
.
pageDefinitions
(
any
())).
thenReturn
(
Arrays
.
asList
(
row
));
com
.
platform
.
business
.
model
.
vo
.
PracticePaperRuleConfigurationVO
result
=
service
.
queryPage
(
null
).
get
(
0
);
assertFalse
(
result
.
getEditable
());
assertFalse
(
result
.
getPublishable
());
assertEquals
(
true
,
result
.
getDeletable
());
assertEquals
(
"已发布"
,
result
.
getStatusLabel
());
}
private
PracticePaperRuleSaveDTO
request
(
String
name
,
String
level
,
List
<
PracticePaperRuleItemDTO
>
items
)
{
PracticePaperRuleSaveDTO
request
=
new
PracticePaperRuleSaveDTO
();
request
.
setLev
(
"污水三级"
);
request
.
setRuleList
(
Arrays
.
asList
(
submitted
));
PracticePaperRuleConfigurationVO
result
=
service
.
saveConfiguration
(
request
,
"admin-2"
);
assertEquals
(
20
,
result
.
getTotalDuration
());
assertEquals
(
new
BigDecimal
(
"20.00"
),
result
.
getTotalScore
());
ArgumentCaptor
<
PracticePaperRuleEntity
>
captor
=
ArgumentCaptor
.
forClass
(
PracticePaperRuleEntity
.
class
);
verify
(
mapper
).
updateById
(
captor
.
capture
());
PracticePaperRuleEntity
update
=
captor
.
getValue
();
assertEquals
(
7
,
update
.
getId
());
assertEquals
(
20
,
update
.
getAssessmentDuration
());
assertEquals
(
new
BigDecimal
(
"20.00"
),
update
.
getScore
());
assertEquals
(
1
,
update
.
getQuestionCount
());
// 标准类目不进入更新对象,确保客户端永远不能修改Excel类目。
assertEquals
(
null
,
update
.
getProjectName
());
assertEquals
(
null
,
update
.
getUnitContent
());
}
private
PracticePaperRuleEntity
rule
(
int
id
,
String
grade
,
String
project
,
String
unit
,
int
duration
,
String
score
,
int
count
)
{
request
.
setName
(
name
);
request
.
setLev
(
level
);
request
.
setRuleList
(
items
);
return
request
;
}
private
PracticePaperRuleItemDTO
item
(
int
catalogId
,
int
duration
,
String
score
,
int
count
)
{
PracticePaperRuleItemDTO
item
=
new
PracticePaperRuleItemDTO
();
item
.
setCatalogId
(
catalogId
);
item
.
setAssessmentDuration
(
duration
);
item
.
setScore
(
new
BigDecimal
(
score
));
item
.
setQuestionCount
(
count
);
return
item
;
}
private
PracticePaperRuleEntity
catalog
(
int
id
,
String
grade
,
String
project
,
String
unit
)
{
PracticePaperRuleEntity
row
=
new
PracticePaperRuleEntity
();
row
.
setId
(
id
);
row
.
setLevelGrade
(
grade
);
row
.
setProjectName
(
project
);
row
.
setUnitContent
(
unit
);
row
.
setAssessmentDuration
(
duration
);
row
.
setScore
(
new
BigDecimal
(
score
));
row
.
setQuestionCount
(
count
);
return
row
;
}
private
PracticePaperRuleItemDTO
item
(
int
id
,
int
duration
,
String
score
,
int
count
)
{
PracticePaperRuleItemDTO
item
=
new
PracticePaperRuleItemDTO
();
item
.
setId
(
id
);
item
.
setAssessmentDuration
(
duration
);
item
.
setScore
(
new
BigDecimal
(
score
));
item
.
setQuestionCount
(
count
);
return
item
;
private
PracticePaperRuleDefinitionEntity
definition
(
int
id
,
String
name
,
String
grade
,
int
count
,
int
duration
,
String
score
,
String
status
)
{
PracticePaperRuleDefinitionEntity
row
=
new
PracticePaperRuleDefinitionEntity
();
row
.
setId
(
id
);
row
.
setName
(
name
);
row
.
setLevelGrade
(
grade
);
row
.
setQuestionCount
(
count
);
row
.
setTotalDuration
(
duration
);
row
.
setTotalScore
(
new
BigDecimal
(
score
));
row
.
setStatus
(
status
);
return
row
;
}
}
practical-business/src/test/java/com/platform/business/sql/PracticePaperRuleMigrationSqlTest.java
View file @
66392f2e
...
...
@@ -5,6 +5,7 @@ import org.junit.jupiter.api.Test;
import
java.io.InputStream
;
import
java.nio.charset.StandardCharsets
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertFalse
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
...
...
@@ -33,5 +34,33 @@ class PracticePaperRuleMigrationSqlTest {
assertTrue
(
sql
.
contains
(
"'设施设备操作'"
));
assertFalse
(
sql
.
contains
(
"'设施设备擦欧总'"
));
assertTrue
(
sql
.
contains
(
"'新业态项目安全管理'"
));
// 五个等级的目录条数必须与迁移约定完全一致,明细迁移会为每个目录生成一条记录。
assertEquals
(
6
,
occurrences
(
sql
,
"('五级',"
));
assertEquals
(
6
,
occurrences
(
sql
,
"('四级',"
));
assertEquals
(
6
,
occurrences
(
sql
,
"('三级',"
));
assertEquals
(
9
,
occurrences
(
sql
,
"('二级',"
));
assertEquals
(
9
,
occurrences
(
sql
,
"('一级',"
));
assertTrue
(
sql
.
contains
(
"create table if not exists practice_paper_rule_definition"
));
assertTrue
(
sql
.
contains
(
"create table if not exists practice_paper_rule_detail"
));
assertTrue
(
sql
.
contains
(
"create table if not exists exam_teacher_assignment"
));
assertTrue
(
sql
.
contains
(
"add column practice_rule_id int null"
));
assertTrue
(
sql
.
contains
(
"'published', null, now(), null, now()"
));
assertTrue
(
sql
.
contains
(
"insert ignore into practice_paper_rule_definition"
));
assertTrue
(
sql
.
contains
(
"insert ignore into practice_paper_rule_detail"
));
assertTrue
(
sql
.
contains
(
"select definition.id, catalog.id"
));
assertTrue
(
sql
.
contains
(
"insert ignore into exam_teacher_assignment"
));
assertTrue
(
sql
.
contains
(
"where e.type = '实训' and e.practice_rule_id is null"
));
assertTrue
(
sql
.
contains
(
"information_schema.columns"
));
assertTrue
(
sql
.
contains
(
"information_schema.statistics"
));
}
private
int
occurrences
(
String
source
,
String
token
)
{
int
count
=
0
;
int
offset
=
0
;
while
((
offset
=
source
.
indexOf
(
token
,
offset
))
>=
0
)
{
count
++;
offset
+=
token
.
length
();
}
return
count
;
}
}
Prev
1
2
3
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment