Skip to content

Commit 6652a7c

Browse files
committed
Unit Test
1 parent 5131a4a commit 6652a7c

File tree

8 files changed

+476
-33
lines changed

8 files changed

+476
-33
lines changed

pom.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,20 @@
190190
<artifactId>spring-boot-maven-plugin</artifactId>
191191
</plugin>
192192

193+
<!-- Maven Surefire Plugin for JUnit 5 -->
194+
<plugin>
195+
<groupId>org.apache.maven.plugins</groupId>
196+
<artifactId>maven-surefire-plugin</artifactId>
197+
<version>3.5.2</version>
198+
<configuration>
199+
<useSystemClassLoader>false</useSystemClassLoader>
200+
<includes>
201+
<include>**/*Test.java</include>
202+
<include>**/*Tests.java</include>
203+
</includes>
204+
</configuration>
205+
</plugin>
206+
193207
<!-- JaCoCo Maven Plugin for Code Coverage -->
194208
<plugin>
195209
<groupId>org.jacoco</groupId>

src/main/java/com/softdev/system/generator/entity/enums/ParserTypeEnum.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,33 @@ public enum ParserTypeEnum {
2727
}
2828

2929
public static ParserTypeEnum fromValue(String value) {
30+
if (value == null || value.trim().isEmpty()) {
31+
return SQL;
32+
}
33+
34+
String trimmedValue = value.trim();
35+
36+
// 首先尝试精确匹配枚举值
37+
for (ParserTypeEnum type : ParserTypeEnum.values()) {
38+
if (type.getValue().equals(trimmedValue)) {
39+
return type;
40+
}
41+
}
42+
43+
// 如果精确匹配失败,尝试忽略大小写匹配
44+
for (ParserTypeEnum type : ParserTypeEnum.values()) {
45+
if (type.getValue().equalsIgnoreCase(trimmedValue)) {
46+
return type;
47+
}
48+
}
49+
50+
// 尝试匹配枚举名称
3051
for (ParserTypeEnum type : ParserTypeEnum.values()) {
31-
if (type.getValue().equals(value)) {
52+
if (type.name().equalsIgnoreCase(trimmedValue)) {
3253
return type;
3354
}
3455
}
56+
3557
// 默认返回SQL类型
3658
return SQL;
3759
}

src/main/java/com/softdev/system/generator/service/impl/CodeGenServiceImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ public Map<String, String> getResultByParams(Map<String, Object> params) throws
9292
private ClassInfo parseTableStructure(ParamInfo paramInfo) throws Exception {
9393
String dataType = MapUtil.getString(paramInfo.getOptions(), "dataType");
9494
ParserTypeEnum parserType = ParserTypeEnum.fromValue(dataType);
95+
96+
// 添加调试信息
97+
log.debug("解析数据类型: {}, 解析结果: {}", dataType, parserType);
9598

9699
switch (parserType) {
97100
case SQL:

src/test/java/com/softdev/system/generator/controller/CodeGenControllerTest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,15 @@ class CodeGenControllerTest {
4747
void setUp() {
4848
// 初始化测试数据
4949
paramInfo = new ParamInfo();
50-
paramInfo.setTableSql("CREATE TABLE test (id INT PRIMARY KEY, name VARCHAR(50));");
50+
paramInfo.setTableSql("""
51+
CREATE TABLE 'sys_user_info' (
52+
'user_id' int(11) NOT NULL AUTO_INCREMENT COMMENT '用户编号',
53+
'user_name' varchar(255) NOT NULL COMMENT '用户名',
54+
'status' tinyint(1) NOT NULL COMMENT '状态',
55+
'create_time' datetime NOT NULL COMMENT '创建时间',
56+
PRIMARY KEY ('user_id')
57+
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户信息'
58+
""");
5159

5260
Map<String, Object> options = new HashMap<>();
5361
options.put("dataType", "SQL");

src/test/java/com/softdev/system/generator/entity/ParamInfoTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ void testSetOptions() {
4848

4949
@Test
5050
void testNameCaseTypeConstants() {
51-
assertEquals("camelCase", ParamInfo.NAME_CASE_TYPE.CAMEL_CASE);
52-
assertEquals("underScoreCase", ParamInfo.NAME_CASE_TYPE.UNDER_SCORE_CASE);
53-
assertEquals("upperUnderScoreCase", ParamInfo.NAME_CASE_TYPE.UPPER_UNDER_SCORE_CASE);
51+
assertEquals("CamelCase", ParamInfo.NAME_CASE_TYPE.CAMEL_CASE);
52+
assertEquals("UnderScoreCase", ParamInfo.NAME_CASE_TYPE.UNDER_SCORE_CASE);
53+
assertEquals("UpperUnderScoreCase", ParamInfo.NAME_CASE_TYPE.UPPER_UNDER_SCORE_CASE);
5454
}
5555
}

0 commit comments

Comments
 (0)