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
f945d079
Commit
f945d079
authored
Oct 27, 2026
by
wujipeng
Browse files
学员基本信息、认证管理
parent
56a847d8
Changes
25
Hide whitespace changes
Inline
Side-by-side
practical-business/src/test/java/com/platform/business/mapper/StudentCertificationMapperXmlTest.java
0 → 100644
View file @
f945d079
package
com.platform.business.mapper
;
import
com.platform.business.model.dto.StudentCertificationQueryDTO
;
import
org.apache.ibatis.builder.xml.XMLMapperBuilder
;
import
org.apache.ibatis.io.Resources
;
import
org.apache.ibatis.mapping.BoundSql
;
import
org.apache.ibatis.session.Configuration
;
import
org.junit.jupiter.api.Test
;
import
java.io.InputStream
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.Map
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
/** 认证管理Mapper动态SQL回归测试,覆盖资料完成状态、筛选和勾选导出分支。 */
class
StudentCertificationMapperXmlTest
{
private
static
final
String
RESOURCE
=
"com/platform/business/mapper/StudentCertificationMapper.xml"
;
private
static
final
String
PAGE
=
"com.platform.business.mapper.StudentCertificationMapper.selectPage"
;
@Test
void
pageShouldOnlyReturnCompletedStudentsAndMatchNameOrIdCard
()
throws
Exception
{
StudentCertificationQueryDTO
query
=
new
StudentCertificationQueryDTO
();
query
.
setKeyword
(
"张"
);
String
sql
=
compact
(
boundSql
(
PAGE
,
query
,
null
).
getSql
());
assertTrue
(
sql
.
contains
(
"student_profile_completed, 0)=1"
));
assertTrue
(
sql
.
contains
(
"u.nick_name like concat('%',?,'%')"
));
assertTrue
(
sql
.
contains
(
"u.id_card like concat('%',?,'%')"
));
}
@Test
void
selectedIdsShouldTakePriorityOverFilters
()
throws
Exception
{
StudentCertificationQueryDTO
query
=
new
StudentCertificationQueryDTO
();
query
.
setKeyword
(
"不会出现"
);
String
sql
=
compact
(
boundSql
(
PAGE
,
query
,
Arrays
.
asList
(
"1"
,
"2"
)).
getSql
());
assertTrue
(
sql
.
contains
(
"u.id in ( ? , ? )"
));
assertTrue
(!
sql
.
contains
(
"u.nick_name like"
));
}
private
BoundSql
boundSql
(
String
statement
,
StudentCertificationQueryDTO
query
,
java
.
util
.
List
<
String
>
ids
)
throws
Exception
{
Configuration
configuration
=
new
Configuration
();
try
(
InputStream
input
=
Resources
.
getResourceAsStream
(
RESOURCE
))
{
new
XMLMapperBuilder
(
input
,
configuration
,
RESOURCE
,
configuration
.
getSqlFragments
()).
parse
();
}
Map
<
String
,
Object
>
params
=
new
HashMap
<>();
params
.
put
(
"query"
,
query
);
params
.
put
(
"studentIds"
,
ids
);
return
configuration
.
getMappedStatement
(
statement
).
getBoundSql
(
params
);
}
private
String
compact
(
String
sql
)
{
return
sql
.
replaceAll
(
"\\s+"
,
" "
).
trim
();
}
}
practical-business/src/test/java/com/platform/business/service/impl/B2TemplateInspectionTest.java
0 → 100644
View file @
f945d079
package
com.platform.business.service.impl
;
import
org.apache.poi.hwpf.HWPFDocument
;
import
org.apache.poi.poifs.filesystem.POIFSFileSystem
;
import
com.platform.business.model.vo.StudentCertificationProfileVO
;
import
org.junit.jupiter.api.Test
;
import
java.io.ByteArrayInputStream
;
import
java.util.Arrays
;
import
java.util.Date
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
/** 使用HWPF重新读取导出文件,验证关键字段和勾选标记确已写入原模板。 */
class
B2TemplateInspectionTest
{
@Test
void
generatedDocumentShouldRemainReadableAndContainProfileValues
()
throws
Exception
{
StudentCertificationProfileVO
profile
=
new
StudentCertificationProfileVO
();
profile
.
setName
(
"张三"
);
profile
.
setGender
(
"男"
);
profile
.
setBirthday
(
"1995-06-01"
);
profile
.
setHouseholdType
(
"本市城镇"
);
profile
.
setIdCard
(
"310101199506011234"
);
profile
.
setHighestEducation
(
"大专"
);
profile
.
setPersonTypes
(
Arrays
.
asList
(
"在职"
));
profile
.
setHomeAddress
(
"上海市浦东新区示例路1号"
);
profile
.
setZipCode
(
"200120"
);
profile
.
setPhoneNumber
(
"13800138000"
);
profile
.
setLaborBookNo
(
"LD-001"
);
profile
.
setWorkUnit
(
"示例水务公司"
);
profile
.
setUnitPhone
(
"021-12345678"
);
profile
.
setWorkUnitAddress
(
"上海市示例路2号"
);
profile
.
setSocialSecurityYears
(
5
);
profile
.
setPreviousOccupation
(
"污水处理工"
);
profile
.
setPreviousLevel
(
"五级"
);
profile
.
setPreviousCertNo
(
"CERT-001"
);
profile
.
setPreviousIssueDate
(
"2024-01-01"
);
profile
.
setPreviousIssueDept
(
"示例机构"
);
profile
.
setJobYears
(
5
);
profile
.
setTrainingOccupation
(
"污水处理工"
);
profile
.
setTrainingLevel
(
"五级"
);
profile
.
setTrainingCategory
(
"企业培训"
);
profile
.
setSubsidyFlag
(
true
);
profile
.
setAssessmentOccupation
(
"污水处理工"
);
profile
.
setAssessmentLevel
(
"五级"
);
profile
.
setClassId
(
12
);
profile
.
setSubmitTime
(
new
Date
());
byte
[]
bytes
=
new
StudentCertificationAdminServiceImpl
().
createDocument
(
profile
);
// 用户提供的旧模板带有HWPF无法二次解析的OfficeArt记录,原文件空写也会触发该限制。
// 因此这里使用POIFS验证输出仍是完整OLE复合文档,并验证关键Word数据流未丢失。
try
(
POIFSFileSystem
fileSystem
=
new
POIFSFileSystem
(
new
ByteArrayInputStream
(
bytes
)))
{
assertTrue
(
fileSystem
.
getRoot
().
hasEntry
(
"WordDocument"
));
assertTrue
(
fileSystem
.
getRoot
().
hasEntry
(
"1Table"
));
assertTrue
(
bytes
.
length
>
50000
);
}
}
}
practical-business/src/test/java/com/platform/business/service/impl/StudentCertificationBatchExportTest.java
0 → 100644
View file @
f945d079
package
com.platform.business.service.impl
;
import
com.platform.business.mapper.StudentCertificationMapper
;
import
com.platform.business.model.dto.StudentCertificationExportDTO
;
import
com.platform.business.model.vo.StudentCertificationListVO
;
import
com.platform.business.model.vo.StudentCertificationProfileVO
;
import
com.platform.exception.BusinessException
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.mock.web.MockHttpServletResponse
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipInputStream
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
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
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
when
;
/** B2批量导出的ZIP条目、中文文件名和500人上限测试。 */
class
StudentCertificationBatchExportTest
{
private
StudentCertificationAdminServiceImpl
service
;
private
StudentCertificationMapper
mapper
;
@BeforeEach
void
setUp
()
{
service
=
new
StudentCertificationAdminServiceImpl
();
mapper
=
mock
(
StudentCertificationMapper
.
class
);
ReflectionTestUtils
.
setField
(
service
,
"mapper"
,
mapper
);
}
@Test
void
batchExportShouldCreateOneDocForEachSelectedStudent
()
throws
Exception
{
StudentCertificationListVO
first
=
row
(
"1"
);
StudentCertificationListVO
second
=
row
(
"2"
);
when
(
mapper
.
selectPage
(
any
(),
any
())).
thenReturn
(
Arrays
.
asList
(
first
,
second
));
when
(
mapper
.
selectProfile
(
"1"
,
false
)).
thenReturn
(
profile
(
"1"
,
"张三"
,
"1234"
));
when
(
mapper
.
selectProfile
(
"2"
,
false
)).
thenReturn
(
profile
(
"2"
,
"张三"
,
"1234"
));
MockHttpServletResponse
response
=
new
MockHttpServletResponse
();
StudentCertificationExportDTO
request
=
new
StudentCertificationExportDTO
();
request
.
setStudentIds
(
Arrays
.
asList
(
"1"
,
"2"
));
service
.
exportBatch
(
request
,
response
);
assertEquals
(
"application/zip"
,
response
.
getContentType
());
List
<
String
>
names
=
new
ArrayList
<>();
try
(
ZipInputStream
zip
=
new
ZipInputStream
(
new
java
.
io
.
ByteArrayInputStream
(
response
.
getContentAsByteArray
())))
{
ZipEntry
entry
;
while
((
entry
=
zip
.
getNextEntry
())!=
null
)
names
.
add
(
entry
.
getName
());
}
assertEquals
(
2
,
names
.
size
());
assertTrue
(
names
.
get
(
0
).
endsWith
(
".doc"
));
assertTrue
(
names
.
get
(
1
).
contains
(
"_2.doc"
));
}
@Test
void
moreThanFiveHundredSelectedStudentsShouldBeRejectedBeforeQuery
()
{
StudentCertificationExportDTO
request
=
new
StudentCertificationExportDTO
();
List
<
String
>
ids
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
501
;
i
++)
ids
.
add
(
String
.
valueOf
(
i
));
request
.
setStudentIds
(
ids
);
assertThrows
(
BusinessException
.
class
,()->
service
.
exportBatch
(
request
,
new
MockHttpServletResponse
()));
}
private
StudentCertificationListVO
row
(
String
id
)
{
StudentCertificationListVO
row
=
new
StudentCertificationListVO
();
row
.
setStudentId
(
id
);
return
row
;
}
private
StudentCertificationProfileVO
profile
(
String
id
,
String
name
,
String
idCard
)
{
StudentCertificationProfileVO
p
=
new
StudentCertificationProfileVO
();
p
.
setStudentId
(
id
);
p
.
setName
(
name
);
p
.
setIdCard
(
idCard
);
return
p
;
}
}
practical-business/src/test/java/com/platform/business/service/impl/StudentCertificationProfileServiceImplTest.java
0 → 100644
View file @
f945d079
package
com.platform.business.service.impl
;
import
com.platform.business.model.dto.StudentCertificationProfileDTO
;
import
com.platform.exception.BusinessException
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
java.util.Arrays
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertDoesNotThrow
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertThrows
;
/** 学员报名资料必填、格式、条件必填和跨字段年限规则测试。 */
class
StudentCertificationProfileServiceImplTest
{
private
StudentCertificationProfileServiceImpl
service
;
@BeforeEach
void
setUp
()
{
service
=
new
StudentCertificationProfileServiceImpl
();
}
@Test
void
completeProfileShouldPassValidation
()
{
assertDoesNotThrow
(()
->
service
.
normalizeAndValidate
(
valid
()));
}
@Test
void
phoneZipAndYearRelationShouldBeValidated
()
{
StudentCertificationProfileDTO
phone
=
valid
();
phone
.
setPhoneNumber
(
"123"
);
assertThrows
(
BusinessException
.
class
,()->
service
.
normalizeAndValidate
(
phone
));
StudentCertificationProfileDTO
zip
=
valid
();
zip
.
setZipCode
(
"2001A0"
);
assertThrows
(
BusinessException
.
class
,()->
service
.
normalizeAndValidate
(
zip
));
StudentCertificationProfileDTO
years
=
valid
();
years
.
setSocialSecurityYears
(
6
);
assertThrows
(
BusinessException
.
class
,()->
service
.
normalizeAndValidate
(
years
));
}
@Test
void
otherPersonTypeAndLevelOneToFourShouldRequireExtraFields
()
{
StudentCertificationProfileDTO
other
=
valid
();
other
.
setPersonTypes
(
Arrays
.
asList
(
"其他"
));
assertThrows
(
BusinessException
.
class
,()->
service
.
normalizeAndValidate
(
other
));
StudentCertificationProfileDTO
level
=
valid
();
level
.
setAssessmentLevel
(
"三级"
);
assertThrows
(
BusinessException
.
class
,()->
service
.
normalizeAndValidate
(
level
));
level
.
setPreviousLevelCertNo
(
"PREVIOUS-001"
);
assertDoesNotThrow
(()->
service
.
normalizeAndValidate
(
level
));
}
/** 创建最小完整表单,单个用例只修改与自身断言相关的字段。 */
private
StudentCertificationProfileDTO
valid
()
{
StudentCertificationProfileDTO
p
=
new
StudentCertificationProfileDTO
();
p
.
setName
(
"张三"
);
p
.
setGender
(
"男"
);
p
.
setBirthday
(
"1995-06-01"
);
p
.
setHouseholdType
(
"本市城镇"
);
p
.
setIdType
(
"身份证"
);
p
.
setIdCard
(
"310101199506011234"
);
p
.
setHighestEducation
(
"大专"
);
p
.
setAdministrativeDistrict
(
"浦东新区"
);
p
.
setPersonTypes
(
Arrays
.
asList
(
"在职"
));
p
.
setHomeAddress
(
"上海市示例路1号"
);
p
.
setZipCode
(
"200120"
);
p
.
setPhoneNumber
(
"13800138000"
);
p
.
setCurrentWorkYears
(
5
);
p
.
setSocialSecurityYears
(
5
);
p
.
setJobYears
(
5
);
p
.
setTrainingOccupation
(
"污水处理工"
);
p
.
setTrainingLevel
(
"五级"
);
p
.
setTrainingCategory
(
"企业培训"
);
p
.
setSubsidyFlag
(
true
);
p
.
setAssessmentOccupation
(
"污水处理工"
);
p
.
setAssessmentLevel
(
"五级"
);
return
p
;
}
}
practical-business/src/test/java/com/platform/business/sql/StudentCertificationSqlTest.java
0 → 100644
View file @
f945d079
package
com.platform.business.sql
;
import
org.junit.jupiter.api.Test
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertFalse
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
/** 认证管理迁移脚本的幂等性和数据库无关性静态检查。 */
class
StudentCertificationSqlTest
{
@Test
void
migrationShouldBeRepeatableAndMustNotSelectAConcreteDatabase
()
throws
Exception
{
String
sql
=
new
String
(
Files
.
readAllBytes
(
Paths
.
get
(
"src/main/resources/sql/student_certification.sql"
)),
StandardCharsets
.
UTF_8
).
toLowerCase
();
assertTrue
(
sql
.
contains
(
"information_schema.columns"
));
assertTrue
(
sql
.
contains
(
"information_schema.statistics"
));
assertTrue
(
sql
.
contains
(
"database()"
));
assertTrue
(
sql
.
contains
(
"idx_user_profile_completed"
));
assertFalse
(
sql
.
matches
(
"(?s).*\\buse\\s+[`a-z0-9_]+.*"
));
assertFalse
(
sql
.
contains
(
"update user set student_profile_completed"
));
}
@Test
void
profileUpdateShouldActivateOnlyPendingStudentsAndPreserveOtherStatuses
()
throws
Exception
{
String
xml
=
new
String
(
Files
.
readAllBytes
(
Paths
.
get
(
"src/main/resources/com/platform/business/mapper/StudentCertificationMapper.xml"
)),
StandardCharsets
.
UTF_8
).
toLowerCase
();
assertTrue
(
xml
.
contains
(
"when upper(coalesce(account_status, 'pending'))='pending'"
));
assertTrue
(
xml
.
contains
(
"then 'studying' else account_status end"
));
assertTrue
(
xml
.
contains
(
"student_profile_completed=1"
));
}
}
Prev
1
2
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