refactor(backend): 重命名后端项目为 gym-manage-api,修改包名为 cn.novalon.gym.manage
This commit is contained in:
+91
@@ -0,0 +1,91 @@
|
||||
package cn.novalon.gym.manage.db.config;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class FlywayMigrationScriptTest {
|
||||
|
||||
@Test
|
||||
void testMigrationScriptsExist() throws IOException {
|
||||
Path migrationDir = Paths.get("src/main/resources/db/migration");
|
||||
|
||||
assertTrue(Files.exists(migrationDir), "Migration directory should exist");
|
||||
|
||||
List<Path> sqlFiles = Files.list(migrationDir)
|
||||
.filter(p -> p.toString().endsWith(".sql"))
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertFalse(sqlFiles.isEmpty(), "Should have migration scripts");
|
||||
|
||||
System.out.println("Found migration scripts:");
|
||||
sqlFiles.forEach(p -> System.out.println(" - " + p.getFileName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMigrationScriptNaming() throws IOException {
|
||||
Path migrationDir = Paths.get("src/main/resources/db/migration");
|
||||
|
||||
List<Path> sqlFiles = Files.list(migrationDir)
|
||||
.filter(p -> p.toString().endsWith(".sql"))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
for (Path file : sqlFiles) {
|
||||
String filename = file.getFileName().toString();
|
||||
assertTrue(filename.matches("V\\d+__.*\\.sql"),
|
||||
"Migration script should follow Flyway naming convention: " + filename);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMigrationScriptContent() throws IOException {
|
||||
Path migrationDir = Paths.get("src/main/resources/db/migration");
|
||||
|
||||
List<Path> sqlFiles = Files.list(migrationDir)
|
||||
.filter(p -> p.toString().endsWith(".sql"))
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
for (Path file : sqlFiles) {
|
||||
String content = Files.readString(file);
|
||||
assertNotNull(content, "Migration script should have content: " + file.getFileName());
|
||||
assertFalse(content.trim().isEmpty(), "Migration script should not be empty: " + file.getFileName());
|
||||
|
||||
if (content.contains("CREATE TABLE")) {
|
||||
assertTrue(content.contains("IF NOT EXISTS"),
|
||||
"CREATE TABLE statements should use IF NOT EXISTS: " + file.getFileName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMigrationScriptVersionOrder() throws IOException {
|
||||
Path migrationDir = Paths.get("src/main/resources/db/migration");
|
||||
|
||||
List<Path> sqlFiles = Files.list(migrationDir)
|
||||
.filter(p -> p.toString().endsWith(".sql"))
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<Integer> versions = sqlFiles.stream()
|
||||
.map(p -> {
|
||||
String filename = p.getFileName().toString();
|
||||
String versionStr = filename.substring(1, filename.indexOf("__"));
|
||||
return Integer.parseInt(versionStr);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
for (int i = 1; i < versions.size(); i++) {
|
||||
assertTrue(versions.get(i) > versions.get(i - 1),
|
||||
"Migration versions should be in ascending order");
|
||||
}
|
||||
}
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
package cn.novalon.gym.manage.db.converter;
|
||||
|
||||
import cn.novalon.gym.manage.sys.core.domain.Dictionary;
|
||||
import cn.novalon.gym.manage.db.entity.DictionaryEntity;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class DictionaryConverterTest {
|
||||
|
||||
private DictionaryConverter converter;
|
||||
private DictionaryEntity testEntity;
|
||||
private Dictionary testDomain;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
converter = new DictionaryConverter();
|
||||
|
||||
testEntity = new DictionaryEntity();
|
||||
testEntity.setId(1L);
|
||||
testEntity.setType("user_status");
|
||||
testEntity.setCode("active");
|
||||
testEntity.setName("正常");
|
||||
testEntity.setValue("0");
|
||||
testEntity.setRemark("用户正常状态");
|
||||
testEntity.setSort(1);
|
||||
testEntity.setCreateBy("admin");
|
||||
testEntity.setCreatedAt(LocalDateTime.now());
|
||||
testEntity.setUpdatedAt(LocalDateTime.now());
|
||||
|
||||
testDomain = new Dictionary();
|
||||
testDomain.setId(1L);
|
||||
testDomain.setType("user_status");
|
||||
testDomain.setCode("active");
|
||||
testDomain.setName("正常");
|
||||
testDomain.setValue("0");
|
||||
testDomain.setRemark("用户正常状态");
|
||||
testDomain.setSort(1);
|
||||
testDomain.setCreateBy("admin");
|
||||
testDomain.setCreatedAt(LocalDateTime.now());
|
||||
testDomain.setUpdatedAt(LocalDateTime.now());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToDomain() {
|
||||
Dictionary result = converter.toDomain(testEntity);
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getId()).isEqualTo(testEntity.getId());
|
||||
assertThat(result.getType()).isEqualTo(testEntity.getType());
|
||||
assertThat(result.getCode()).isEqualTo(testEntity.getCode());
|
||||
assertThat(result.getName()).isEqualTo(testEntity.getName());
|
||||
assertThat(result.getValue()).isEqualTo(testEntity.getValue());
|
||||
assertThat(result.getRemark()).isEqualTo(testEntity.getRemark());
|
||||
assertThat(result.getSort()).isEqualTo(testEntity.getSort());
|
||||
assertThat(result.getCreateBy()).isEqualTo(testEntity.getCreateBy());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToEntity() {
|
||||
DictionaryEntity result = converter.toEntity(testDomain);
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getId()).isEqualTo(testDomain.getId());
|
||||
assertThat(result.getType()).isEqualTo(testDomain.getType());
|
||||
assertThat(result.getCode()).isEqualTo(testDomain.getCode());
|
||||
assertThat(result.getName()).isEqualTo(testDomain.getName());
|
||||
assertThat(result.getValue()).isEqualTo(testDomain.getValue());
|
||||
assertThat(result.getRemark()).isEqualTo(testDomain.getRemark());
|
||||
assertThat(result.getSort()).isEqualTo(testDomain.getSort());
|
||||
assertThat(result.getCreateBy()).isEqualTo(testDomain.getCreateBy());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToDomainWithNull() {
|
||||
Dictionary result = converter.toDomain(null);
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToEntityWithNull() {
|
||||
DictionaryEntity result = converter.toEntity(null);
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
package cn.novalon.gym.manage.db.converter;
|
||||
|
||||
import cn.novalon.gym.manage.sys.core.domain.OperationLog;
|
||||
import cn.novalon.gym.manage.db.entity.OperationLogEntity;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class OperationLogConverterTest {
|
||||
|
||||
private OperationLogConverter converter;
|
||||
private OperationLogEntity testEntity;
|
||||
private OperationLog testDomain;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
converter = new OperationLogConverter();
|
||||
|
||||
testEntity = new OperationLogEntity();
|
||||
testEntity.setId(1L);
|
||||
testEntity.setUsername("admin");
|
||||
testEntity.setOperation("用户登录");
|
||||
testEntity.setMethod("login");
|
||||
testEntity.setParams("{\"username\":\"admin\"}");
|
||||
testEntity.setResult("success");
|
||||
testEntity.setIp("127.0.0.1");
|
||||
testEntity.setDuration(100L);
|
||||
testEntity.setStatus("0");
|
||||
testEntity.setErrorMsg(null);
|
||||
testEntity.setCreatedAt(LocalDateTime.now());
|
||||
testEntity.setUpdatedAt(LocalDateTime.now());
|
||||
|
||||
testDomain = new OperationLog();
|
||||
testDomain.setId(1L);
|
||||
testDomain.setUsername("admin");
|
||||
testDomain.setOperation("用户登录");
|
||||
testDomain.setMethod("login");
|
||||
testDomain.setParams("{\"username\":\"admin\"}");
|
||||
testDomain.setResult("success");
|
||||
testDomain.setIp("127.0.0.1");
|
||||
testDomain.setDuration(100L);
|
||||
testDomain.setStatus("0");
|
||||
testDomain.setErrorMsg(null);
|
||||
testDomain.setCreatedAt(LocalDateTime.now());
|
||||
testDomain.setUpdatedAt(LocalDateTime.now());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToDomain() {
|
||||
OperationLog result = converter.toDomain(testEntity);
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getId()).isEqualTo(testEntity.getId());
|
||||
assertThat(result.getUsername()).isEqualTo(testEntity.getUsername());
|
||||
assertThat(result.getOperation()).isEqualTo(testEntity.getOperation());
|
||||
assertThat(result.getMethod()).isEqualTo(testEntity.getMethod());
|
||||
assertThat(result.getParams()).isEqualTo(testEntity.getParams());
|
||||
assertThat(result.getResult()).isEqualTo(testEntity.getResult());
|
||||
assertThat(result.getIp()).isEqualTo(testEntity.getIp());
|
||||
assertThat(result.getDuration()).isEqualTo(testEntity.getDuration());
|
||||
assertThat(result.getStatus()).isEqualTo(testEntity.getStatus());
|
||||
assertThat(result.getErrorMsg()).isEqualTo(testEntity.getErrorMsg());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToEntity() {
|
||||
OperationLogEntity result = converter.toEntity(testDomain);
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getId()).isEqualTo(testDomain.getId());
|
||||
assertThat(result.getUsername()).isEqualTo(testDomain.getUsername());
|
||||
assertThat(result.getOperation()).isEqualTo(testDomain.getOperation());
|
||||
assertThat(result.getMethod()).isEqualTo(testDomain.getMethod());
|
||||
assertThat(result.getParams()).isEqualTo(testDomain.getParams());
|
||||
assertThat(result.getResult()).isEqualTo(testDomain.getResult());
|
||||
assertThat(result.getIp()).isEqualTo(testDomain.getIp());
|
||||
assertThat(result.getDuration()).isEqualTo(testDomain.getDuration());
|
||||
assertThat(result.getStatus()).isEqualTo(testDomain.getStatus());
|
||||
assertThat(result.getErrorMsg()).isEqualTo(testDomain.getErrorMsg());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToDomainWithNull() {
|
||||
OperationLog result = converter.toDomain(null);
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToEntityWithNull() {
|
||||
OperationLogEntity result = converter.toEntity(null);
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
package cn.novalon.gym.manage.db.converter;
|
||||
|
||||
import cn.novalon.gym.manage.sys.core.domain.SysConfig;
|
||||
import cn.novalon.gym.manage.db.entity.SysConfigEntity;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class SysConfigConverterTest {
|
||||
|
||||
private SysConfigConverter converter;
|
||||
private SysConfigEntity testEntity;
|
||||
private SysConfig testDomain;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
converter = new SysConfigConverter();
|
||||
|
||||
testEntity = new SysConfigEntity();
|
||||
testEntity.setId(1L);
|
||||
testEntity.setConfigName("系统名称");
|
||||
testEntity.setConfigKey("system.name");
|
||||
testEntity.setConfigValue("Novalon管理系统");
|
||||
testEntity.setConfigType("string");
|
||||
testEntity.setCreatedAt(LocalDateTime.now());
|
||||
testEntity.setUpdatedAt(LocalDateTime.now());
|
||||
|
||||
testDomain = new SysConfig();
|
||||
testDomain.setId(1L);
|
||||
testDomain.setConfigName("系统名称");
|
||||
testDomain.setConfigKey("system.name");
|
||||
testDomain.setConfigValue("Novalon管理系统");
|
||||
testDomain.setConfigType("string");
|
||||
testDomain.setCreatedAt(LocalDateTime.now());
|
||||
testDomain.setUpdatedAt(LocalDateTime.now());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToDomain() {
|
||||
SysConfig result = converter.toDomain(testEntity);
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getId()).isEqualTo(testEntity.getId());
|
||||
assertThat(result.getConfigName()).isEqualTo(testEntity.getConfigName());
|
||||
assertThat(result.getConfigKey()).isEqualTo(testEntity.getConfigKey());
|
||||
assertThat(result.getConfigValue()).isEqualTo(testEntity.getConfigValue());
|
||||
assertThat(result.getConfigType()).isEqualTo(testEntity.getConfigType());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToEntity() {
|
||||
SysConfigEntity result = converter.toEntity(testDomain);
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getId()).isEqualTo(testDomain.getId());
|
||||
assertThat(result.getConfigName()).isEqualTo(testDomain.getConfigName());
|
||||
assertThat(result.getConfigKey()).isEqualTo(testDomain.getConfigKey());
|
||||
assertThat(result.getConfigValue()).isEqualTo(testDomain.getConfigValue());
|
||||
assertThat(result.getConfigType()).isEqualTo(testDomain.getConfigType());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToDomainWithNull() {
|
||||
SysConfig result = converter.toDomain(null);
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToEntityWithNull() {
|
||||
SysConfigEntity result = converter.toEntity(null);
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
}
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
package cn.novalon.gym.manage.db.converter;
|
||||
|
||||
import cn.novalon.gym.manage.sys.core.domain.SysDictData;
|
||||
import cn.novalon.gym.manage.db.entity.SysDictDataEntity;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class SysDictDataConverterTest {
|
||||
|
||||
private SysDictDataConverter converter;
|
||||
private SysDictDataEntity testEntity;
|
||||
private SysDictData testDomain;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
converter = new SysDictDataConverter();
|
||||
|
||||
testEntity = new SysDictDataEntity();
|
||||
testEntity.setId(1L);
|
||||
testEntity.setDictSort(1);
|
||||
testEntity.setDictLabel("正常");
|
||||
testEntity.setDictValue("0");
|
||||
testEntity.setDictType("user_status");
|
||||
testEntity.setCssClass("default");
|
||||
testEntity.setListClass("default");
|
||||
testEntity.setIsDefault("Y");
|
||||
testEntity.setStatus("0");
|
||||
testEntity.setCreatedAt(LocalDateTime.now());
|
||||
testEntity.setUpdatedAt(LocalDateTime.now());
|
||||
|
||||
testDomain = new SysDictData();
|
||||
testDomain.setId(1L);
|
||||
testDomain.setDictSort(1);
|
||||
testDomain.setDictLabel("正常");
|
||||
testDomain.setDictValue("0");
|
||||
testDomain.setDictType("user_status");
|
||||
testDomain.setCssClass("default");
|
||||
testDomain.setListClass("default");
|
||||
testDomain.setIsDefault("Y");
|
||||
testDomain.setStatus("0");
|
||||
testDomain.setCreatedAt(LocalDateTime.now());
|
||||
testDomain.setUpdatedAt(LocalDateTime.now());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToDomain() {
|
||||
SysDictData result = converter.toDomain(testEntity);
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getId()).isEqualTo(testEntity.getId());
|
||||
assertThat(result.getDictSort()).isEqualTo(testEntity.getDictSort());
|
||||
assertThat(result.getDictLabel()).isEqualTo(testEntity.getDictLabel());
|
||||
assertThat(result.getDictValue()).isEqualTo(testEntity.getDictValue());
|
||||
assertThat(result.getDictType()).isEqualTo(testEntity.getDictType());
|
||||
assertThat(result.getCssClass()).isEqualTo(testEntity.getCssClass());
|
||||
assertThat(result.getListClass()).isEqualTo(testEntity.getListClass());
|
||||
assertThat(result.getIsDefault()).isEqualTo(testEntity.getIsDefault());
|
||||
assertThat(result.getStatus()).isEqualTo(testEntity.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToEntity() {
|
||||
SysDictDataEntity result = converter.toEntity(testDomain);
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getId()).isEqualTo(testDomain.getId());
|
||||
assertThat(result.getDictSort()).isEqualTo(testDomain.getDictSort());
|
||||
assertThat(result.getDictLabel()).isEqualTo(testDomain.getDictLabel());
|
||||
assertThat(result.getDictValue()).isEqualTo(testDomain.getDictValue());
|
||||
assertThat(result.getDictType()).isEqualTo(testDomain.getDictType());
|
||||
assertThat(result.getCssClass()).isEqualTo(testDomain.getCssClass());
|
||||
assertThat(result.getListClass()).isEqualTo(testDomain.getListClass());
|
||||
assertThat(result.getIsDefault()).isEqualTo(testDomain.getIsDefault());
|
||||
assertThat(result.getStatus()).isEqualTo(testDomain.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToDomainWithNull() {
|
||||
SysDictData result = converter.toDomain(null);
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToEntityWithNull() {
|
||||
SysDictDataEntity result = converter.toEntity(null);
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
package cn.novalon.gym.manage.db.converter;
|
||||
|
||||
import cn.novalon.gym.manage.sys.core.domain.SysDictType;
|
||||
import cn.novalon.gym.manage.db.entity.SysDictTypeEntity;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class SysDictTypeConverterTest {
|
||||
|
||||
private SysDictTypeConverter converter;
|
||||
private SysDictTypeEntity testEntity;
|
||||
private SysDictType testDomain;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
converter = new SysDictTypeConverter();
|
||||
|
||||
testEntity = new SysDictTypeEntity();
|
||||
testEntity.setId(1L);
|
||||
testEntity.setDictName("用户状态");
|
||||
testEntity.setDictType("user_status");
|
||||
testEntity.setStatus("1");
|
||||
testEntity.setRemark("用户状态字典");
|
||||
testEntity.setCreatedAt(LocalDateTime.now());
|
||||
testEntity.setUpdatedAt(LocalDateTime.now());
|
||||
|
||||
testDomain = new SysDictType();
|
||||
testDomain.setId(1L);
|
||||
testDomain.setDictName("用户状态");
|
||||
testDomain.setDictType("user_status");
|
||||
testDomain.setStatus("1");
|
||||
testDomain.setRemark("用户状态字典");
|
||||
testDomain.setCreatedAt(LocalDateTime.now());
|
||||
testDomain.setUpdatedAt(LocalDateTime.now());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToDomain() {
|
||||
SysDictType result = converter.toDomain(testEntity);
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getId()).isEqualTo(testEntity.getId());
|
||||
assertThat(result.getDictName()).isEqualTo(testEntity.getDictName());
|
||||
assertThat(result.getDictType()).isEqualTo(testEntity.getDictType());
|
||||
assertThat(result.getStatus()).isEqualTo(testEntity.getStatus());
|
||||
assertThat(result.getRemark()).isEqualTo(testEntity.getRemark());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToEntity() {
|
||||
SysDictTypeEntity result = converter.toEntity(testDomain);
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getId()).isEqualTo(testDomain.getId());
|
||||
assertThat(result.getDictName()).isEqualTo(testDomain.getDictName());
|
||||
assertThat(result.getDictType()).isEqualTo(testDomain.getDictType());
|
||||
assertThat(result.getStatus()).isEqualTo(testDomain.getStatus());
|
||||
assertThat(result.getRemark()).isEqualTo(testDomain.getRemark());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToDomainWithNull() {
|
||||
SysDictType result = converter.toDomain(null);
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToEntityWithNull() {
|
||||
SysDictTypeEntity result = converter.toEntity(null);
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
}
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
package cn.novalon.gym.manage.db.converter;
|
||||
|
||||
import cn.novalon.gym.manage.sys.core.domain.SysExceptionLog;
|
||||
import cn.novalon.gym.manage.db.entity.SysExceptionLogEntity;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class SysExceptionLogConverterTest {
|
||||
|
||||
private SysExceptionLogConverter converter;
|
||||
private SysExceptionLogEntity testEntity;
|
||||
private SysExceptionLog testDomain;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
converter = new SysExceptionLogConverter();
|
||||
|
||||
testEntity = new SysExceptionLogEntity();
|
||||
testEntity.setId(1L);
|
||||
testEntity.setUsername("admin");
|
||||
testEntity.setTitle("系统异常");
|
||||
testEntity.setExceptionName("NullPointerException");
|
||||
testEntity.setMethodName("getUserById");
|
||||
testEntity.setMethodParams("{\"id\":1}");
|
||||
testEntity.setExceptionMsg("空指针异常");
|
||||
testEntity.setExceptionStack("java.lang.NullPointerException\n\tat...");
|
||||
testEntity.setIp("127.0.0.1");
|
||||
testEntity.setCreateTime(LocalDateTime.now());
|
||||
|
||||
testDomain = new SysExceptionLog();
|
||||
testDomain.setId(1L);
|
||||
testDomain.setUsername("admin");
|
||||
testDomain.setTitle("系统异常");
|
||||
testDomain.setExceptionName("NullPointerException");
|
||||
testDomain.setMethodName("getUserById");
|
||||
testDomain.setMethodParams("{\"id\":1}");
|
||||
testDomain.setExceptionMsg("空指针异常");
|
||||
testDomain.setExceptionStack("java.lang.NullPointerException\n\tat...");
|
||||
testDomain.setIp("127.0.0.1");
|
||||
testDomain.setCreateTime(LocalDateTime.now());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToDomain() {
|
||||
SysExceptionLog result = converter.toDomain(testEntity);
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getId()).isEqualTo(testEntity.getId());
|
||||
assertThat(result.getUsername()).isEqualTo(testEntity.getUsername());
|
||||
assertThat(result.getTitle()).isEqualTo(testEntity.getTitle());
|
||||
assertThat(result.getExceptionName()).isEqualTo(testEntity.getExceptionName());
|
||||
assertThat(result.getMethodName()).isEqualTo(testEntity.getMethodName());
|
||||
assertThat(result.getMethodParams()).isEqualTo(testEntity.getMethodParams());
|
||||
assertThat(result.getExceptionMsg()).isEqualTo(testEntity.getExceptionMsg());
|
||||
assertThat(result.getExceptionStack()).isEqualTo(testEntity.getExceptionStack());
|
||||
assertThat(result.getIp()).isEqualTo(testEntity.getIp());
|
||||
assertThat(result.getCreateTime()).isEqualTo(testEntity.getCreateTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToEntity() {
|
||||
SysExceptionLogEntity result = converter.toEntity(testDomain);
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getId()).isEqualTo(testDomain.getId());
|
||||
assertThat(result.getUsername()).isEqualTo(testDomain.getUsername());
|
||||
assertThat(result.getTitle()).isEqualTo(testDomain.getTitle());
|
||||
assertThat(result.getExceptionName()).isEqualTo(testDomain.getExceptionName());
|
||||
assertThat(result.getMethodName()).isEqualTo(testDomain.getMethodName());
|
||||
assertThat(result.getMethodParams()).isEqualTo(testDomain.getMethodParams());
|
||||
assertThat(result.getExceptionMsg()).isEqualTo(testDomain.getExceptionMsg());
|
||||
assertThat(result.getExceptionStack()).isEqualTo(testDomain.getExceptionStack());
|
||||
assertThat(result.getIp()).isEqualTo(testDomain.getIp());
|
||||
assertThat(result.getCreateTime()).isEqualTo(testDomain.getCreateTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToDomainWithNull() {
|
||||
SysExceptionLog result = converter.toDomain(null);
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToEntityWithNull() {
|
||||
SysExceptionLogEntity result = converter.toEntity(null);
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
package cn.novalon.gym.manage.db.converter;
|
||||
|
||||
import cn.novalon.gym.manage.sys.core.domain.SysLoginLog;
|
||||
import cn.novalon.gym.manage.db.entity.SysLoginLogEntity;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class SysLoginLogConverterTest {
|
||||
|
||||
private SysLoginLogConverter converter;
|
||||
private SysLoginLogEntity testEntity;
|
||||
private SysLoginLog testDomain;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
converter = new SysLoginLogConverter();
|
||||
|
||||
testEntity = new SysLoginLogEntity();
|
||||
testEntity.setId(1L);
|
||||
testEntity.setUsername("admin");
|
||||
testEntity.setIp("127.0.0.1");
|
||||
testEntity.setLocation("北京");
|
||||
testEntity.setBrowser("Chrome");
|
||||
testEntity.setOs("Windows 10");
|
||||
testEntity.setStatus("0");
|
||||
testEntity.setMessage("登录成功");
|
||||
testEntity.setLoginTime(LocalDateTime.now());
|
||||
|
||||
testDomain = new SysLoginLog();
|
||||
testDomain.setId(1L);
|
||||
testDomain.setUsername("admin");
|
||||
testDomain.setIp("127.0.0.1");
|
||||
testDomain.setLocation("北京");
|
||||
testDomain.setBrowser("Chrome");
|
||||
testDomain.setOs("Windows 10");
|
||||
testDomain.setStatus("0");
|
||||
testDomain.setMessage("登录成功");
|
||||
testDomain.setLoginTime(LocalDateTime.now());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToDomain() {
|
||||
SysLoginLog result = converter.toDomain(testEntity);
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getId()).isEqualTo(testEntity.getId());
|
||||
assertThat(result.getUsername()).isEqualTo(testEntity.getUsername());
|
||||
assertThat(result.getIp()).isEqualTo(testEntity.getIp());
|
||||
assertThat(result.getLocation()).isEqualTo(testEntity.getLocation());
|
||||
assertThat(result.getBrowser()).isEqualTo(testEntity.getBrowser());
|
||||
assertThat(result.getOs()).isEqualTo(testEntity.getOs());
|
||||
assertThat(result.getStatus()).isEqualTo(testEntity.getStatus());
|
||||
assertThat(result.getMessage()).isEqualTo(testEntity.getMessage());
|
||||
assertThat(result.getLoginTime()).isEqualTo(testEntity.getLoginTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToEntity() {
|
||||
SysLoginLogEntity result = converter.toEntity(testDomain);
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getId()).isEqualTo(testDomain.getId());
|
||||
assertThat(result.getUsername()).isEqualTo(testDomain.getUsername());
|
||||
assertThat(result.getIp()).isEqualTo(testDomain.getIp());
|
||||
assertThat(result.getLocation()).isEqualTo(testDomain.getLocation());
|
||||
assertThat(result.getBrowser()).isEqualTo(testDomain.getBrowser());
|
||||
assertThat(result.getOs()).isEqualTo(testDomain.getOs());
|
||||
assertThat(result.getStatus()).isEqualTo(testDomain.getStatus());
|
||||
assertThat(result.getMessage()).isEqualTo(testDomain.getMessage());
|
||||
assertThat(result.getLoginTime()).isEqualTo(testDomain.getLoginTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToDomainWithNull() {
|
||||
SysLoginLog result = converter.toDomain(null);
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToEntityWithNull() {
|
||||
SysLoginLogEntity result = converter.toEntity(null);
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
package cn.novalon.gym.manage.db.converter;
|
||||
|
||||
import cn.novalon.gym.manage.sys.core.domain.SysMenu;
|
||||
import cn.novalon.gym.manage.db.entity.SysMenuEntity;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class SysMenuConverterTest {
|
||||
|
||||
private SysMenuConverter converter;
|
||||
private SysMenuEntity testEntity;
|
||||
private SysMenu testDomain;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
converter = new SysMenuConverter();
|
||||
|
||||
testEntity = new SysMenuEntity();
|
||||
testEntity.setId(1L);
|
||||
testEntity.setMenuName("用户管理");
|
||||
testEntity.setParentId(0L);
|
||||
testEntity.setOrderNum(1);
|
||||
testEntity.setMenuType("M");
|
||||
testEntity.setPerms("user:list");
|
||||
testEntity.setComponent("user/index");
|
||||
testEntity.setStatus(1);
|
||||
testEntity.setCreateBy("admin");
|
||||
testEntity.setUpdateBy("admin");
|
||||
testEntity.setCreatedAt(LocalDateTime.now());
|
||||
testEntity.setUpdatedAt(LocalDateTime.now());
|
||||
|
||||
testDomain = new SysMenu();
|
||||
testDomain.setId(1L);
|
||||
testDomain.setMenuName("用户管理");
|
||||
testDomain.setParentId(0L);
|
||||
testDomain.setOrderNum(1);
|
||||
testDomain.setMenuType("M");
|
||||
testDomain.setPerms("user:list");
|
||||
testDomain.setComponent("user/index");
|
||||
testDomain.setStatus(1);
|
||||
testDomain.setCreateBy("admin");
|
||||
testDomain.setUpdateBy("admin");
|
||||
testDomain.setCreatedAt(LocalDateTime.now());
|
||||
testDomain.setUpdatedAt(LocalDateTime.now());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToDomain() {
|
||||
SysMenu result = converter.toDomain(testEntity);
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getId()).isEqualTo(testEntity.getId());
|
||||
assertThat(result.getMenuName()).isEqualTo(testEntity.getMenuName());
|
||||
assertThat(result.getParentId()).isEqualTo(testEntity.getParentId());
|
||||
assertThat(result.getOrderNum()).isEqualTo(testEntity.getOrderNum());
|
||||
assertThat(result.getMenuType()).isEqualTo(testEntity.getMenuType());
|
||||
assertThat(result.getPerms()).isEqualTo(testEntity.getPerms());
|
||||
assertThat(result.getComponent()).isEqualTo(testEntity.getComponent());
|
||||
assertThat(result.getStatus()).isEqualTo(testEntity.getStatus());
|
||||
assertThat(result.getCreateBy()).isEqualTo(testEntity.getCreateBy());
|
||||
assertThat(result.getUpdateBy()).isEqualTo(testEntity.getUpdateBy());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToEntity() {
|
||||
SysMenuEntity result = converter.toEntity(testDomain);
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getId()).isEqualTo(testDomain.getId());
|
||||
assertThat(result.getMenuName()).isEqualTo(testDomain.getMenuName());
|
||||
assertThat(result.getParentId()).isEqualTo(testDomain.getParentId());
|
||||
assertThat(result.getOrderNum()).isEqualTo(testDomain.getOrderNum());
|
||||
assertThat(result.getMenuType()).isEqualTo(testDomain.getMenuType());
|
||||
assertThat(result.getPerms()).isEqualTo(testDomain.getPerms());
|
||||
assertThat(result.getComponent()).isEqualTo(testDomain.getComponent());
|
||||
assertThat(result.getStatus()).isEqualTo(testDomain.getStatus());
|
||||
assertThat(result.getCreateBy()).isEqualTo(testDomain.getCreateBy());
|
||||
assertThat(result.getUpdateBy()).isEqualTo(testDomain.getUpdateBy());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToDomainWithNull() {
|
||||
SysMenu result = converter.toDomain(null);
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToEntityWithNull() {
|
||||
SysMenuEntity result = converter.toEntity(null);
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
package cn.novalon.gym.manage.db.converter;
|
||||
|
||||
import cn.novalon.gym.manage.sys.core.domain.SysRole;
|
||||
import cn.novalon.gym.manage.db.entity.SysRoleEntity;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class SysRoleConverterTest {
|
||||
|
||||
private SysRoleConverter converter;
|
||||
private SysRoleEntity testEntity;
|
||||
private SysRole testDomain;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
converter = new SysRoleConverter();
|
||||
|
||||
testEntity = new SysRoleEntity();
|
||||
testEntity.setId(1L);
|
||||
testEntity.setRoleName("ADMIN");
|
||||
testEntity.setRoleKey("admin");
|
||||
testEntity.setRoleSort(1);
|
||||
testEntity.setStatus(1);
|
||||
testEntity.setCreatedAt(LocalDateTime.now());
|
||||
testEntity.setUpdatedAt(LocalDateTime.now());
|
||||
|
||||
testDomain = new SysRole();
|
||||
testDomain.setId(1L);
|
||||
testDomain.setRoleName("ADMIN");
|
||||
testDomain.setRoleKey("admin");
|
||||
testDomain.setRoleSort(1);
|
||||
testDomain.setStatus(1);
|
||||
testDomain.setCreatedAt(LocalDateTime.now());
|
||||
testDomain.setUpdatedAt(LocalDateTime.now());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToDomain() {
|
||||
SysRole result = converter.toDomain(testEntity);
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getId()).isEqualTo(testEntity.getId());
|
||||
assertThat(result.getRoleName()).isEqualTo(testEntity.getRoleName());
|
||||
assertThat(result.getRoleKey()).isEqualTo(testEntity.getRoleKey());
|
||||
assertThat(result.getRoleSort()).isEqualTo(testEntity.getRoleSort());
|
||||
assertThat(result.getStatus()).isEqualTo(testEntity.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToEntity() {
|
||||
SysRoleEntity result = converter.toEntity(testDomain);
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getId()).isEqualTo(testDomain.getId());
|
||||
assertThat(result.getRoleName()).isEqualTo(testDomain.getRoleName());
|
||||
assertThat(result.getRoleKey()).isEqualTo(testDomain.getRoleKey());
|
||||
assertThat(result.getRoleSort()).isEqualTo(testDomain.getRoleSort());
|
||||
assertThat(result.getStatus()).isEqualTo(testDomain.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToDomainWithNull() {
|
||||
SysRole result = converter.toDomain(null);
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToEntityWithNull() {
|
||||
SysRoleEntity result = converter.toEntity(null);
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
package cn.novalon.gym.manage.db.converter;
|
||||
|
||||
import cn.novalon.gym.manage.sys.core.domain.SysUser;
|
||||
import cn.novalon.gym.manage.db.entity.SysUserEntity;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class SysUserConverterTest {
|
||||
|
||||
private SysUserConverter converter;
|
||||
private SysUserEntity testEntity;
|
||||
private SysUser testDomain;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
converter = new SysUserConverter();
|
||||
|
||||
testEntity = new SysUserEntity();
|
||||
testEntity.setId(1L);
|
||||
testEntity.setUsername("testuser");
|
||||
testEntity.setPassword("encoded_password");
|
||||
testEntity.setEmail("test@example.com");
|
||||
testEntity.setRoleId(1L);
|
||||
testEntity.setStatus(1);
|
||||
testEntity.setCreatedAt(LocalDateTime.now());
|
||||
testEntity.setUpdatedAt(LocalDateTime.now());
|
||||
|
||||
testDomain = new SysUser();
|
||||
testDomain.setId(1L);
|
||||
testDomain.setUsername("testuser");
|
||||
testDomain.setPassword("encoded_password");
|
||||
testDomain.setEmail("test@example.com");
|
||||
testDomain.setRoleId(1L);
|
||||
testDomain.setStatus(1);
|
||||
testDomain.setCreatedAt(LocalDateTime.now());
|
||||
testDomain.setUpdatedAt(LocalDateTime.now());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToDomain() {
|
||||
SysUser result = converter.toDomain(testEntity);
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getId()).isEqualTo(testEntity.getId());
|
||||
assertThat(result.getUsername()).isEqualTo(testEntity.getUsername());
|
||||
assertThat(result.getPassword()).isEqualTo(testEntity.getPassword());
|
||||
assertThat(result.getEmail()).isEqualTo(testEntity.getEmail());
|
||||
assertThat(result.getRoleId()).isEqualTo(testEntity.getRoleId());
|
||||
assertThat(result.getStatus()).isEqualTo(testEntity.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToEntity() {
|
||||
SysUserEntity result = converter.toEntity(testDomain);
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getId()).isEqualTo(testDomain.getId());
|
||||
assertThat(result.getUsername()).isEqualTo(testDomain.getUsername());
|
||||
assertThat(result.getPassword()).isEqualTo(testDomain.getPassword());
|
||||
assertThat(result.getEmail()).isEqualTo(testDomain.getEmail());
|
||||
assertThat(result.getRoleId()).isEqualTo(testDomain.getRoleId());
|
||||
assertThat(result.getStatus()).isEqualTo(testDomain.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToDomainWithNull() {
|
||||
SysUser result = converter.toDomain(null);
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToEntityWithNull() {
|
||||
SysUserEntity result = converter.toEntity(null);
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
}
|
||||
+327
@@ -0,0 +1,327 @@
|
||||
package cn.novalon.gym.manage.db.dao;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.relational.core.query.Criteria;
|
||||
import org.springframework.data.relational.core.query.Query;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* QueryUtil详细测试 - 提升分支覆盖率
|
||||
*
|
||||
* @author 张翔
|
||||
* @date 2026-03-24
|
||||
*/
|
||||
class QueryUtilDetailedTest {
|
||||
|
||||
static class TestQuery {
|
||||
@QueryField(propName = "name", type = QueryField.Type.EQUAL)
|
||||
private String name;
|
||||
|
||||
@QueryField(propName = "age", type = QueryField.Type.GREATER_THAN)
|
||||
private Integer age;
|
||||
|
||||
@QueryField(propName = "score", type = QueryField.Type.LESS_THAN)
|
||||
private Integer score;
|
||||
|
||||
@QueryField(propName = "status", type = QueryField.Type.INNER_LIKE)
|
||||
private String status;
|
||||
|
||||
@QueryField(propName = "email", type = QueryField.Type.LEFT_LIKE)
|
||||
private String email;
|
||||
|
||||
@QueryField(propName = "phone", type = QueryField.Type.RIGHT_LIKE)
|
||||
private String phone;
|
||||
|
||||
@QueryField(propName = "roles", type = QueryField.Type.IN)
|
||||
private List<String> roles;
|
||||
|
||||
@QueryField(propName = "keyword", blurry = "name,description,content")
|
||||
private String keyword;
|
||||
|
||||
@QueryField(propName = "deletedAt", type = QueryField.Type.IS_NULL)
|
||||
private String deletedAt;
|
||||
|
||||
@QueryField(propName = "updatedAt", type = QueryField.Type.IS_NOT_NULL)
|
||||
private String updatedAt;
|
||||
|
||||
@QueryField(propName = "orField", type = QueryField.Type.OR, orPropVal = QueryField.Type.IS_NULL, orPropNames = {
|
||||
"field1", "field2" })
|
||||
private String orField;
|
||||
|
||||
public TestQuery() {
|
||||
}
|
||||
|
||||
public TestQuery(String name, Integer age, Integer score, String status, String email,
|
||||
String phone, List<String> roles, String keyword, String deletedAt,
|
||||
String updatedAt, String orField) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
this.score = score;
|
||||
this.status = status;
|
||||
this.email = email;
|
||||
this.phone = phone;
|
||||
this.roles = roles;
|
||||
this.keyword = keyword;
|
||||
this.deletedAt = deletedAt;
|
||||
this.updatedAt = updatedAt;
|
||||
this.orField = orField;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Integer getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public Integer getScore() {
|
||||
return score;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public String getPhone() {
|
||||
return phone;
|
||||
}
|
||||
|
||||
public List<String> getRoles() {
|
||||
return roles;
|
||||
}
|
||||
|
||||
public String getKeyword() {
|
||||
return keyword;
|
||||
}
|
||||
|
||||
public String getDeletedAt() {
|
||||
return deletedAt;
|
||||
}
|
||||
|
||||
public String getUpdatedAt() {
|
||||
return updatedAt;
|
||||
}
|
||||
|
||||
public String getOrField() {
|
||||
return orField;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNullQuery() {
|
||||
Query query = QueryUtil.getQuery(null);
|
||||
assertNotNull(query);
|
||||
Criteria criteria = (Criteria) query.getCriteria().orElse(Criteria.empty());
|
||||
assertNotNull(criteria);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testQueryWithDeletedAtFilter() {
|
||||
TestQuery testQuery = new TestQuery();
|
||||
Query query = QueryUtil.getQuery(testQuery, true);
|
||||
assertNotNull(query);
|
||||
Criteria criteria = (Criteria) query.getCriteria().orElse(Criteria.empty());
|
||||
assertNotNull(criteria);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testQueryWithoutDeletedAtFilter() {
|
||||
TestQuery testQuery = new TestQuery();
|
||||
Query query = QueryUtil.getQuery(testQuery, false);
|
||||
assertNotNull(query);
|
||||
Criteria criteria = (Criteria) query.getCriteria().orElse(Criteria.empty());
|
||||
assertNotNull(criteria);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualCondition() {
|
||||
TestQuery testQuery = new TestQuery("John", null, null, null, null, null, null, null, null, null, null);
|
||||
Query query = QueryUtil.getQuery(testQuery);
|
||||
assertNotNull(query);
|
||||
Criteria criteria = (Criteria) query.getCriteria().orElse(Criteria.empty());
|
||||
assertNotNull(criteria);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGreaterThanCondition() {
|
||||
TestQuery testQuery = new TestQuery(null, 18, null, null, null, null, null, null, null, null, null);
|
||||
Query query = QueryUtil.getQuery(testQuery);
|
||||
assertNotNull(query);
|
||||
Criteria criteria = (Criteria) query.getCriteria().orElse(Criteria.empty());
|
||||
assertNotNull(criteria);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLessThanCondition() {
|
||||
TestQuery testQuery = new TestQuery(null, null, 100, null, null, null, null, null, null, null, null);
|
||||
Query query = QueryUtil.getQuery(testQuery);
|
||||
assertNotNull(query);
|
||||
Criteria criteria = (Criteria) query.getCriteria().orElse(Criteria.empty());
|
||||
assertNotNull(criteria);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInnerLikeCondition() {
|
||||
TestQuery testQuery = new TestQuery(null, null, null, "active", null, null, null, null, null, null, null);
|
||||
Query query = QueryUtil.getQuery(testQuery);
|
||||
assertNotNull(query);
|
||||
Criteria criteria = (Criteria) query.getCriteria().orElse(Criteria.empty());
|
||||
assertNotNull(criteria);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLeftLikeCondition() {
|
||||
TestQuery testQuery = new TestQuery(null, null, null, null, "@example.com", null, null, null, null, null, null);
|
||||
Query query = QueryUtil.getQuery(testQuery);
|
||||
assertNotNull(query);
|
||||
Criteria criteria = (Criteria) query.getCriteria().orElse(Criteria.empty());
|
||||
assertNotNull(criteria);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRightLikeCondition() {
|
||||
TestQuery testQuery = new TestQuery(null, null, null, null, null, "123", null, null, null, null, null);
|
||||
Query query = QueryUtil.getQuery(testQuery);
|
||||
assertNotNull(query);
|
||||
Criteria criteria = (Criteria) query.getCriteria().orElse(Criteria.empty());
|
||||
assertNotNull(criteria);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInCondition() {
|
||||
TestQuery testQuery = new TestQuery(null, null, null, null, null, null,
|
||||
Arrays.asList("admin", "user"), null, null, null, null);
|
||||
Query query = QueryUtil.getQuery(testQuery);
|
||||
assertNotNull(query);
|
||||
Criteria criteria = (Criteria) query.getCriteria().orElse(Criteria.empty());
|
||||
assertNotNull(criteria);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInConditionWithEmptyList() {
|
||||
TestQuery testQuery = new TestQuery(null, null, null, null, null, null,
|
||||
Collections.emptyList(), null, null, null, null);
|
||||
Query query = QueryUtil.getQuery(testQuery);
|
||||
assertNotNull(query);
|
||||
Criteria criteria = (Criteria) query.getCriteria().orElse(Criteria.empty());
|
||||
assertNotNull(criteria);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBlurrySearchSingleField() {
|
||||
TestQuery testQuery = new TestQuery(null, null, null, null, null, null, null, "test", null, null, null);
|
||||
Query query = QueryUtil.getQuery(testQuery);
|
||||
assertNotNull(query);
|
||||
Criteria criteria = (Criteria) query.getCriteria().orElse(Criteria.empty());
|
||||
assertNotNull(criteria);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBlurrySearchMultipleFields() {
|
||||
TestQuery testQuery = new TestQuery(null, null, null, null, null, null, null, "keyword", null, null, null);
|
||||
Query query = QueryUtil.getQuery(testQuery);
|
||||
assertNotNull(query);
|
||||
Criteria criteria = (Criteria) query.getCriteria().orElse(Criteria.empty());
|
||||
assertNotNull(criteria);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testIsNullCondition() {
|
||||
TestQuery testQuery = new TestQuery(null, null, null, null, null, null, null, null, "null", null, null);
|
||||
Query query = QueryUtil.getQuery(testQuery);
|
||||
assertNotNull(query);
|
||||
Criteria criteria = (Criteria) query.getCriteria().orElse(Criteria.empty());
|
||||
assertNotNull(criteria);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testIsNotNullCondition() {
|
||||
TestQuery testQuery = new TestQuery(null, null, null, null, null, null, null, null, null, "value", null);
|
||||
Query query = QueryUtil.getQuery(testQuery);
|
||||
assertNotNull(query);
|
||||
Criteria criteria = (Criteria) query.getCriteria().orElse(Criteria.empty());
|
||||
assertNotNull(criteria);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testOrConditionIsNull() {
|
||||
TestQuery testQuery = new TestQuery(null, null, null, null, null, null, null, null, null, null, "value");
|
||||
Query query = QueryUtil.getQuery(testQuery);
|
||||
assertNotNull(query);
|
||||
Criteria criteria = (Criteria) query.getCriteria().orElse(Criteria.empty());
|
||||
assertNotNull(criteria);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEmptyStringValue() {
|
||||
TestQuery testQuery = new TestQuery("", null, null, null, null, null, null, null, null, null, null);
|
||||
Query query = QueryUtil.getQuery(testQuery);
|
||||
assertNotNull(query);
|
||||
Criteria criteria = (Criteria) query.getCriteria().orElse(Criteria.empty());
|
||||
assertNotNull(criteria);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNullFieldValue() {
|
||||
TestQuery testQuery = new TestQuery(null, null, null, null, null, null, null, null, null, null, null);
|
||||
Query query = QueryUtil.getQuery(testQuery);
|
||||
assertNotNull(query);
|
||||
Criteria criteria = (Criteria) query.getCriteria().orElse(Criteria.empty());
|
||||
assertNotNull(criteria);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMultipleConditions() {
|
||||
TestQuery testQuery = new TestQuery("John", 18, 100, "active", "@example.com",
|
||||
"123", Arrays.asList("admin"), "test", null, "value", null);
|
||||
Query query = QueryUtil.getQuery(testQuery);
|
||||
assertNotNull(query);
|
||||
Criteria criteria = (Criteria) query.getCriteria().orElse(Criteria.empty());
|
||||
assertNotNull(criteria);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testQueryAllWithoutDeletedAtFilter() {
|
||||
TestQuery testQuery = new TestQuery("John", 18, 100, "active", "@example.com",
|
||||
"123", Arrays.asList("admin"), "test", null, "value", null);
|
||||
Query query = QueryUtil.getQueryAll(testQuery);
|
||||
assertNotNull(query);
|
||||
Criteria criteria = (Criteria) query.getCriteria().orElse(Criteria.empty());
|
||||
assertNotNull(criteria);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testIsBlankWithNull() {
|
||||
assertTrue(QueryUtil.isBlank(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testIsBlankWithEmptyString() {
|
||||
assertTrue(QueryUtil.isBlank(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testIsBlankWithWhitespace() {
|
||||
assertTrue(QueryUtil.isBlank(" "));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testIsBlankWithValidString() {
|
||||
assertFalse(QueryUtil.isBlank("test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testIsBlankWithMixedWhitespace() {
|
||||
assertFalse(QueryUtil.isBlank(" test "));
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
package cn.novalon.gym.manage.db.dao;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.relational.core.query.Criteria;
|
||||
|
||||
class QueryUtilOrTest {
|
||||
|
||||
@Test
|
||||
void testOrCriteriaConstruction() {
|
||||
String[] blurrys = {"username", "email"};
|
||||
String val = "search";
|
||||
|
||||
// 测试当前实现
|
||||
Criteria orCriteria = null;
|
||||
for (int i = 0; i < blurrys.length; i++) {
|
||||
String s = blurrys[i];
|
||||
if (i == 0) {
|
||||
orCriteria = Criteria.where(s).like("%" + val + "%");
|
||||
} else {
|
||||
orCriteria = orCriteria.or(s).like("%" + val + "%");
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("当前实现的Criteria: " + orCriteria);
|
||||
System.out.println("Criteria类型: " + orCriteria.getClass().getName());
|
||||
|
||||
// 测试链式调用
|
||||
Criteria chainedCriteria = Criteria.where("username").like("%" + val + "%")
|
||||
.or("email").like("%" + val + "%");
|
||||
|
||||
System.out.println("链式调用的Criteria: " + chainedCriteria);
|
||||
System.out.println("链式调用类型: " + chainedCriteria.getClass().getName());
|
||||
|
||||
// 测试是否相等
|
||||
System.out.println("两种实现是否相同: " + orCriteria.equals(chainedCriteria));
|
||||
|
||||
// 测试toString
|
||||
System.out.println("当前实现toString: " + orCriteria.toString());
|
||||
System.out.println("链式调用toString: " + chainedCriteria.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testOrCriteriaWithThreeFields() {
|
||||
String[] blurrys = {"username", "email", "phone"};
|
||||
String val = "test";
|
||||
|
||||
Criteria orCriteria = null;
|
||||
for (int i = 0; i < blurrys.length; i++) {
|
||||
String s = blurrys[i];
|
||||
if (i == 0) {
|
||||
orCriteria = Criteria.where(s).like("%" + val + "%");
|
||||
} else {
|
||||
orCriteria = orCriteria.or(s).like("%" + val + "%");
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("三个字段的OR条件: " + orCriteria);
|
||||
|
||||
// 链式调用
|
||||
Criteria chainedCriteria = Criteria.where("username").like("%" + val + "%")
|
||||
.or("email").like("%" + val + "%")
|
||||
.or("phone").like("%" + val + "%");
|
||||
|
||||
System.out.println("三个字段链式调用: " + chainedCriteria);
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package cn.novalon.gym.manage.db.dao;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.relational.core.query.Criteria;
|
||||
|
||||
/**
|
||||
* QueryUtil测试类
|
||||
*/
|
||||
class QueryUtilTest {
|
||||
|
||||
@Test
|
||||
void testOrCriteriaConstruction() {
|
||||
String[] blurrys = {"username", "email"};
|
||||
String val = "search";
|
||||
|
||||
// 当前的实现方式
|
||||
Criteria orCriteria = Criteria.empty();
|
||||
for (String s : blurrys) {
|
||||
orCriteria = orCriteria.or(s).like("%" + val + "%");
|
||||
}
|
||||
|
||||
System.out.println("当前实现的Criteria: " + orCriteria);
|
||||
|
||||
// 正确的实现方式
|
||||
Criteria correctOrCriteria = Criteria.where("username").like("%" + val + "%")
|
||||
.or("email").like("%" + val + "%");
|
||||
|
||||
System.out.println("正确实现的Criteria: " + correctOrCriteria);
|
||||
|
||||
// 比较两种实现
|
||||
System.out.println("两种实现是否相同: " + orCriteria.equals(correctOrCriteria));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
spring:
|
||||
r2dbc:
|
||||
url: r2dbc:h2:mem:testdb;MODE=PostgreSQL
|
||||
username: sa
|
||||
password:
|
||||
flyway:
|
||||
enabled: true
|
||||
locations: classpath:db/migration
|
||||
baseline-on-migrate: true
|
||||
baseline-version: 0
|
||||
table: flyway_schema_history
|
||||
validate-on-migrate: true
|
||||
out-of-order: false
|
||||
Reference in New Issue
Block a user