refactor(domain): 将领域模型移动到common模块
重构项目结构,将分散在各模块的领域模型统一移动到manage-common模块 更新相关依赖和引用路径 调整docker-compose配置和测试标记 添加新的Playwright测试配置 优化Dockerfile构建过程
This commit is contained in:
+43
-79
@@ -1,11 +1,9 @@
|
||||
package cn.novalon.manage.sys.core.service.impl;
|
||||
|
||||
import cn.novalon.manage.sys.core.domain.Dictionary;
|
||||
import cn.novalon.manage.common.domain.Dictionary;
|
||||
import cn.novalon.manage.sys.core.exception.DictionaryAlreadyExistsException;
|
||||
import cn.novalon.manage.sys.core.service.IDictionaryService;
|
||||
import cn.novalon.manage.sys.infrastructure.db.dao.DictionaryDao;
|
||||
import cn.novalon.manage.sys.infrastructure.db.converter.DictionaryConverter;
|
||||
import cn.novalon.manage.sys.infrastructure.db.entity.DictionaryEntity;
|
||||
import cn.novalon.manage.db.repository.DictionaryRepository;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@@ -24,19 +22,15 @@ import static org.mockito.Mockito.*;
|
||||
class DictionaryServiceTest {
|
||||
|
||||
@Mock
|
||||
private DictionaryDao dao;
|
||||
|
||||
@Mock
|
||||
private DictionaryConverter converter;
|
||||
private DictionaryRepository repository;
|
||||
|
||||
private IDictionaryService service;
|
||||
|
||||
private Dictionary testDictionary;
|
||||
private DictionaryEntity testEntity;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
service = new DictionaryService(dao, converter);
|
||||
service = new DictionaryService(repository);
|
||||
|
||||
testDictionary = new Dictionary();
|
||||
testDictionary.setId(1L);
|
||||
@@ -48,89 +42,71 @@ class DictionaryServiceTest {
|
||||
testDictionary.setRemark("Test remark");
|
||||
testDictionary.setCreatedAt(LocalDateTime.now());
|
||||
testDictionary.setUpdatedAt(LocalDateTime.now());
|
||||
|
||||
testEntity = new DictionaryEntity();
|
||||
testEntity.setId(1L);
|
||||
testEntity.setType("test_type");
|
||||
testEntity.setCode("test_code");
|
||||
testEntity.setName("Test Label");
|
||||
testEntity.setValue("test_value");
|
||||
testEntity.setSort(1);
|
||||
testEntity.setRemark("Test remark");
|
||||
testEntity.setCreatedAt(LocalDateTime.now());
|
||||
testEntity.setUpdatedAt(LocalDateTime.now());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFindAll() {
|
||||
when(dao.findByDeletedAtIsNullOrderBySortAsc()).thenReturn(Flux.just(testEntity));
|
||||
when(converter.toDomain(testEntity)).thenReturn(testDictionary);
|
||||
when(repository.findAll()).thenReturn(Flux.just(testDictionary));
|
||||
|
||||
StepVerifier.create(service.findAll())
|
||||
.expectNext(testDictionary)
|
||||
.verifyComplete();
|
||||
|
||||
verify(dao).findByDeletedAtIsNullOrderBySortAsc();
|
||||
verify(converter).toDomain(testEntity);
|
||||
verify(repository).findAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFindById() {
|
||||
when(dao.findById(1L)).thenReturn(Mono.just(testEntity));
|
||||
when(converter.toDomain(testEntity)).thenReturn(testDictionary);
|
||||
when(repository.findById(1L)).thenReturn(Mono.just(testDictionary));
|
||||
|
||||
StepVerifier.create(service.findById(1L))
|
||||
.expectNext(testDictionary)
|
||||
.verifyComplete();
|
||||
|
||||
verify(dao).findById(1L);
|
||||
verify(converter).toDomain(testEntity);
|
||||
verify(repository).findById(1L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFindById_NotFound() {
|
||||
when(dao.findById(999L)).thenReturn(Mono.empty());
|
||||
when(repository.findById(999L)).thenReturn(Mono.empty());
|
||||
|
||||
StepVerifier.create(service.findById(999L))
|
||||
.verifyComplete();
|
||||
|
||||
verify(dao).findById(999L);
|
||||
verify(converter, never()).toDomain(any());
|
||||
verify(repository).findById(999L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFindByType() {
|
||||
when(dao.findByType("test_type")).thenReturn(Flux.just(testEntity));
|
||||
when(converter.toDomain(testEntity)).thenReturn(testDictionary);
|
||||
when(repository.findByType("test_type")).thenReturn(Flux.just(testDictionary));
|
||||
|
||||
StepVerifier.create(service.findByType("test_type"))
|
||||
.expectNext(testDictionary)
|
||||
.verifyComplete();
|
||||
|
||||
verify(dao).findByType("test_type");
|
||||
verify(converter).toDomain(testEntity);
|
||||
verify(repository).findByType("test_type");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckTypeAndCodeExists_True() {
|
||||
when(dao.findByTypeAndCode("test_type", "test_code")).thenReturn(Mono.just(testEntity));
|
||||
when(repository.existsByTypeAndCode("test_type", "test_code")).thenReturn(Mono.just(true));
|
||||
|
||||
StepVerifier.create(service.checkTypeAndCodeExists("test_type", "test_code"))
|
||||
.expectNext(true)
|
||||
.verifyComplete();
|
||||
|
||||
verify(dao).findByTypeAndCode("test_type", "test_code");
|
||||
verify(repository).existsByTypeAndCode("test_type", "test_code");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckTypeAndCodeExists_False() {
|
||||
when(dao.findByTypeAndCode("test_type", "test_code")).thenReturn(Mono.empty());
|
||||
when(repository.existsByTypeAndCode("test_type", "test_code")).thenReturn(Mono.just(false));
|
||||
|
||||
StepVerifier.create(service.checkTypeAndCodeExists("test_type", "test_code"))
|
||||
.expectNext(false)
|
||||
.verifyComplete();
|
||||
|
||||
verify(dao).findByTypeAndCode("test_type", "test_code");
|
||||
verify(repository).existsByTypeAndCode("test_type", "test_code");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -141,19 +117,15 @@ class DictionaryServiceTest {
|
||||
newDict.setName("Test Label");
|
||||
newDict.setValue("test_value");
|
||||
|
||||
when(dao.findByTypeAndCode("test_type", "test_code")).thenReturn(Mono.empty());
|
||||
when(converter.toEntity(any())).thenReturn(testEntity);
|
||||
when(dao.save(any())).thenReturn(Mono.just(testEntity));
|
||||
when(converter.toDomain(testEntity)).thenReturn(testDictionary);
|
||||
when(repository.existsByTypeAndCode("test_type", "test_code")).thenReturn(Mono.just(false));
|
||||
when(repository.save(any())).thenReturn(Mono.just(testDictionary));
|
||||
|
||||
StepVerifier.create(service.save(newDict))
|
||||
.expectNextMatches(dict -> dict.getId() != null)
|
||||
.verifyComplete();
|
||||
|
||||
verify(dao).findByTypeAndCode("test_type", "test_code");
|
||||
verify(converter).toEntity(any());
|
||||
verify(dao).save(any());
|
||||
verify(converter).toDomain(testEntity);
|
||||
verify(repository).existsByTypeAndCode("test_type", "test_code");
|
||||
verify(repository).save(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -162,15 +134,14 @@ class DictionaryServiceTest {
|
||||
newDict.setType("test_type");
|
||||
newDict.setCode("test_code");
|
||||
|
||||
when(dao.findByTypeAndCode("test_type", "test_code")).thenReturn(Mono.just(testEntity));
|
||||
when(repository.existsByTypeAndCode("test_type", "test_code")).thenReturn(Mono.just(true));
|
||||
|
||||
StepVerifier.create(service.save(newDict))
|
||||
.expectError(DictionaryAlreadyExistsException.class)
|
||||
.verify();
|
||||
|
||||
verify(dao).findByTypeAndCode("test_type", "test_code");
|
||||
verify(converter, never()).toEntity(any());
|
||||
verify(dao, never()).save(any());
|
||||
verify(repository).existsByTypeAndCode("test_type", "test_code");
|
||||
verify(repository, never()).save(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -180,18 +151,14 @@ class DictionaryServiceTest {
|
||||
existingDict.setType("test_type");
|
||||
existingDict.setCode("test_code");
|
||||
|
||||
when(converter.toEntity(existingDict)).thenReturn(testEntity);
|
||||
when(dao.save(any())).thenReturn(Mono.just(testEntity));
|
||||
when(converter.toDomain(testEntity)).thenReturn(testDictionary);
|
||||
when(repository.save(any())).thenReturn(Mono.just(testDictionary));
|
||||
|
||||
StepVerifier.create(service.save(existingDict))
|
||||
.expectNextMatches(dict -> dict.getId() == 1L)
|
||||
.verifyComplete();
|
||||
|
||||
verify(dao, never()).findByTypeAndCode(anyString(), anyString());
|
||||
verify(converter).toEntity(existingDict);
|
||||
verify(dao).save(any());
|
||||
verify(converter).toDomain(testEntity);
|
||||
verify(repository, never()).existsByTypeAndCode(anyString(), anyString());
|
||||
verify(repository).save(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -202,26 +169,24 @@ class DictionaryServiceTest {
|
||||
updateDict.setRemark("Updated remark");
|
||||
updateDict.setSort(2);
|
||||
|
||||
DictionaryEntity existingEntity = new DictionaryEntity();
|
||||
existingEntity.setId(1L);
|
||||
existingEntity.setType("test_type");
|
||||
existingEntity.setCode("test_code");
|
||||
existingEntity.setName("Old Name");
|
||||
existingEntity.setValue("old_value");
|
||||
existingEntity.setRemark("Old remark");
|
||||
existingEntity.setSort(1);
|
||||
Dictionary existingDict = new Dictionary();
|
||||
existingDict.setId(1L);
|
||||
existingDict.setType("test_type");
|
||||
existingDict.setCode("test_code");
|
||||
existingDict.setName("Old Name");
|
||||
existingDict.setValue("old_value");
|
||||
existingDict.setRemark("Old remark");
|
||||
existingDict.setSort(1);
|
||||
|
||||
when(dao.findById(1L)).thenReturn(Mono.just(existingEntity));
|
||||
when(dao.save(any())).thenReturn(Mono.just(existingEntity));
|
||||
when(converter.toDomain(existingEntity)).thenReturn(testDictionary);
|
||||
when(repository.findById(1L)).thenReturn(Mono.just(existingDict));
|
||||
when(repository.save(any())).thenReturn(Mono.just(testDictionary));
|
||||
|
||||
StepVerifier.create(service.update(1L, updateDict))
|
||||
.expectNextMatches(dict -> dict.getId() == 1L)
|
||||
.verifyComplete();
|
||||
|
||||
verify(dao).findById(1L);
|
||||
verify(dao).save(any());
|
||||
verify(converter).toDomain(existingEntity);
|
||||
verify(repository).findById(1L);
|
||||
verify(repository).save(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -229,23 +194,22 @@ class DictionaryServiceTest {
|
||||
Dictionary updateDict = new Dictionary();
|
||||
updateDict.setName("Updated Name");
|
||||
|
||||
when(dao.findById(999L)).thenReturn(Mono.empty());
|
||||
when(repository.findById(999L)).thenReturn(Mono.empty());
|
||||
|
||||
StepVerifier.create(service.update(999L, updateDict))
|
||||
.verifyComplete();
|
||||
|
||||
verify(dao).findById(999L);
|
||||
verify(dao, never()).save(any());
|
||||
verify(converter, never()).toDomain(any());
|
||||
verify(repository).findById(999L);
|
||||
verify(repository, never()).save(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeleteById() {
|
||||
when(dao.deleteByIdAndDeletedAtIsNull(1L)).thenReturn(Mono.empty());
|
||||
when(repository.deleteById(1L)).thenReturn(Mono.empty());
|
||||
|
||||
StepVerifier.create(service.deleteById(1L))
|
||||
.verifyComplete();
|
||||
|
||||
verify(dao).deleteByIdAndDeletedAtIsNull(1L);
|
||||
verify(repository).deleteById(1L);
|
||||
}
|
||||
}
|
||||
+22
-49
@@ -1,9 +1,7 @@
|
||||
package cn.novalon.manage.sys.core.service.impl;
|
||||
|
||||
import cn.novalon.manage.sys.core.domain.SysConfig;
|
||||
import cn.novalon.manage.sys.infrastructure.db.converter.SysConfigConverter;
|
||||
import cn.novalon.manage.sys.infrastructure.db.dao.SysConfigDao;
|
||||
import cn.novalon.manage.sys.infrastructure.db.entity.SysConfigEntity;
|
||||
import cn.novalon.manage.common.domain.SysConfig;
|
||||
import cn.novalon.manage.db.repository.ISysConfigRepository;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@@ -20,19 +18,15 @@ import static org.mockito.Mockito.*;
|
||||
class SysConfigServiceTest {
|
||||
|
||||
@Mock
|
||||
private SysConfigDao dao;
|
||||
|
||||
@Mock
|
||||
private SysConfigConverter converter;
|
||||
private ISysConfigRepository repository;
|
||||
|
||||
private SysConfigService configService;
|
||||
|
||||
private SysConfig testConfig;
|
||||
private SysConfigEntity testEntity;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
configService = new SysConfigService(dao, converter);
|
||||
configService = new SysConfigService(repository);
|
||||
|
||||
testConfig = new SysConfig();
|
||||
testConfig.setId(1L);
|
||||
@@ -40,121 +34,100 @@ class SysConfigServiceTest {
|
||||
testConfig.setConfigValue("Novalon Manage System");
|
||||
testConfig.setConfigName("Application Name");
|
||||
testConfig.setConfigType("system");
|
||||
|
||||
testEntity = new SysConfigEntity();
|
||||
testEntity.setId(1L);
|
||||
testEntity.setConfigKey("app.name");
|
||||
testEntity.setConfigValue("Novalon Manage System");
|
||||
testEntity.setConfigName("Application Name");
|
||||
testEntity.setConfigType("system");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFindAll() {
|
||||
when(dao.findByDeletedAtIsNull()).thenReturn(Flux.just(testEntity));
|
||||
when(converter.toDomain(testEntity)).thenReturn(testConfig);
|
||||
when(repository.findByDeletedAtIsNull()).thenReturn(Flux.just(testConfig));
|
||||
|
||||
StepVerifier.create(configService.findAll())
|
||||
.expectNext(testConfig)
|
||||
.verifyComplete();
|
||||
|
||||
verify(dao).findByDeletedAtIsNull();
|
||||
verify(converter).toDomain(testEntity);
|
||||
verify(repository).findByDeletedAtIsNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFindById() {
|
||||
when(dao.findById(1L)).thenReturn(Mono.just(testEntity));
|
||||
when(converter.toDomain(testEntity)).thenReturn(testConfig);
|
||||
when(repository.findById(1L)).thenReturn(Mono.just(testConfig));
|
||||
|
||||
StepVerifier.create(configService.findById(1L))
|
||||
.expectNext(testConfig)
|
||||
.verifyComplete();
|
||||
|
||||
verify(dao).findById(1L);
|
||||
verify(converter).toDomain(testEntity);
|
||||
verify(repository).findById(1L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFindById_NotFound() {
|
||||
when(dao.findById(999L)).thenReturn(Mono.empty());
|
||||
when(repository.findById(999L)).thenReturn(Mono.empty());
|
||||
|
||||
StepVerifier.create(configService.findById(999L))
|
||||
.verifyComplete();
|
||||
|
||||
verify(dao).findById(999L);
|
||||
verify(converter, never()).toDomain(any());
|
||||
verify(repository).findById(999L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFindByConfigKey() {
|
||||
when(dao.findByConfigKeyAndDeletedAtIsNull("app.name")).thenReturn(Mono.just(testEntity));
|
||||
when(converter.toDomain(testEntity)).thenReturn(testConfig);
|
||||
when(repository.findByConfigKeyAndDeletedAtIsNull("app.name")).thenReturn(Mono.just(testConfig));
|
||||
|
||||
StepVerifier.create(configService.findByConfigKey("app.name"))
|
||||
.expectNext(testConfig)
|
||||
.verifyComplete();
|
||||
|
||||
verify(dao).findByConfigKeyAndDeletedAtIsNull("app.name");
|
||||
verify(converter).toDomain(testEntity);
|
||||
verify(repository).findByConfigKeyAndDeletedAtIsNull("app.name");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFindByConfigKey_NotFound() {
|
||||
when(dao.findByConfigKeyAndDeletedAtIsNull("nonexistent")).thenReturn(Mono.empty());
|
||||
when(repository.findByConfigKeyAndDeletedAtIsNull("nonexistent")).thenReturn(Mono.empty());
|
||||
|
||||
StepVerifier.create(configService.findByConfigKey("nonexistent"))
|
||||
.verifyComplete();
|
||||
|
||||
verify(dao).findByConfigKeyAndDeletedAtIsNull("nonexistent");
|
||||
verify(converter, never()).toDomain(any());
|
||||
verify(repository).findByConfigKeyAndDeletedAtIsNull("nonexistent");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSave() {
|
||||
when(converter.toEntity(testConfig)).thenReturn(testEntity);
|
||||
when(dao.save(testEntity)).thenReturn(Mono.just(testEntity));
|
||||
when(converter.toDomain(testEntity)).thenReturn(testConfig);
|
||||
when(repository.save(testConfig)).thenReturn(Mono.just(testConfig));
|
||||
|
||||
StepVerifier.create(configService.save(testConfig))
|
||||
.expectNext(testConfig)
|
||||
.verifyComplete();
|
||||
|
||||
verify(converter).toEntity(testConfig);
|
||||
verify(dao).save(testEntity);
|
||||
verify(converter).toDomain(testEntity);
|
||||
verify(repository).save(testConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeleteById() {
|
||||
when(dao.deleteByIdAndDeletedAtIsNull(1L)).thenReturn(Mono.empty());
|
||||
when(repository.deleteByIdAndDeletedAtIsNull(1L)).thenReturn(Mono.empty());
|
||||
|
||||
StepVerifier.create(configService.deleteById(1L))
|
||||
.verifyComplete();
|
||||
|
||||
verify(dao).deleteByIdAndDeletedAtIsNull(1L);
|
||||
verify(repository).deleteByIdAndDeletedAtIsNull(1L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetConfigValue() {
|
||||
when(dao.findByConfigKeyAndDeletedAtIsNull("app.name")).thenReturn(Mono.just(testEntity));
|
||||
when(converter.toDomain(testEntity)).thenReturn(testConfig);
|
||||
when(repository.findByConfigKeyAndDeletedAtIsNull("app.name")).thenReturn(Mono.just(testConfig));
|
||||
|
||||
StepVerifier.create(configService.getConfigValue("app.name"))
|
||||
.expectNext("Novalon Manage System")
|
||||
.verifyComplete();
|
||||
|
||||
verify(dao).findByConfigKeyAndDeletedAtIsNull("app.name");
|
||||
verify(converter).toDomain(testEntity);
|
||||
verify(repository).findByConfigKeyAndDeletedAtIsNull("app.name");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetConfigValue_NotFound() {
|
||||
when(dao.findByConfigKeyAndDeletedAtIsNull("nonexistent")).thenReturn(Mono.empty());
|
||||
when(repository.findByConfigKeyAndDeletedAtIsNull("nonexistent")).thenReturn(Mono.empty());
|
||||
|
||||
StepVerifier.create(configService.getConfigValue("nonexistent"))
|
||||
.verifyComplete();
|
||||
|
||||
verify(dao).findByConfigKeyAndDeletedAtIsNull("nonexistent");
|
||||
verify(repository).findByConfigKeyAndDeletedAtIsNull("nonexistent");
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -1,10 +1,10 @@
|
||||
package cn.novalon.manage.sys.core.service.impl;
|
||||
|
||||
import cn.novalon.manage.sys.core.constants.StatusConstants;
|
||||
import cn.novalon.manage.sys.core.domain.SysRole;
|
||||
import cn.novalon.manage.sys.core.repository.ISysRoleRepository;
|
||||
import cn.novalon.manage.sys.dto.request.PageRequest;
|
||||
import cn.novalon.manage.sys.dto.response.PageResponse;
|
||||
import cn.novalon.manage.common.util.StatusConstants;
|
||||
import cn.novalon.manage.common.domain.SysRole;
|
||||
import cn.novalon.manage.db.repository.ISysRoleRepository;
|
||||
import cn.novalon.manage.common.dto.PageRequest;
|
||||
import cn.novalon.manage.common.dto.PageResponse;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
+5
-5
@@ -1,10 +1,10 @@
|
||||
package cn.novalon.manage.sys.core.service.impl;
|
||||
|
||||
import cn.novalon.manage.sys.core.constants.StatusConstants;
|
||||
import cn.novalon.manage.sys.core.domain.SysUser;
|
||||
import cn.novalon.manage.sys.core.repository.ISysUserRepository;
|
||||
import cn.novalon.manage.sys.dto.request.PageRequest;
|
||||
import cn.novalon.manage.sys.dto.response.PageResponse;
|
||||
import cn.novalon.manage.common.util.StatusConstants;
|
||||
import cn.novalon.manage.common.domain.SysUser;
|
||||
import cn.novalon.manage.db.repository.ISysUserRepository;
|
||||
import cn.novalon.manage.common.dto.PageRequest;
|
||||
import cn.novalon.manage.common.dto.PageResponse;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package cn.novalon.manage.sys.handler.dictionary;
|
||||
|
||||
import cn.novalon.manage.sys.core.domain.Dictionary;
|
||||
import cn.novalon.manage.common.domain.Dictionary;
|
||||
import cn.novalon.manage.sys.core.service.IDictionaryService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
-96
@@ -1,96 +0,0 @@
|
||||
package cn.novalon.manage.sys.infrastructure.db.mapper;
|
||||
|
||||
import cn.novalon.manage.sys.core.domain.Dictionary;
|
||||
import cn.novalon.manage.sys.infrastructure.db.entity.DictionaryEntity;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class DictionaryMapperTest {
|
||||
|
||||
private final DictionaryMapper mapper = Mappers.getMapper(DictionaryMapper.class);
|
||||
|
||||
@Test
|
||||
void testToDomain() {
|
||||
DictionaryEntity entity = new DictionaryEntity();
|
||||
entity.setId(1L);
|
||||
entity.setType("test_type");
|
||||
entity.setCode("test_code");
|
||||
entity.setName("Test Name");
|
||||
entity.setSort(1);
|
||||
entity.setDeletedAt(null);
|
||||
|
||||
Dictionary domain = mapper.toDomain(entity);
|
||||
|
||||
assertNotNull(domain);
|
||||
assertEquals(1L, domain.getId());
|
||||
assertEquals("test_type", domain.getType());
|
||||
assertEquals("test_code", domain.getCode());
|
||||
assertEquals("Test Name", domain.getName());
|
||||
assertEquals(1, domain.getSort());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToEntity() {
|
||||
Dictionary domain = new Dictionary();
|
||||
domain.setId(1L);
|
||||
domain.setType("test_type");
|
||||
domain.setCode("test_code");
|
||||
domain.setName("Test Name");
|
||||
domain.setSort(1);
|
||||
|
||||
DictionaryEntity entity = mapper.toEntity(domain);
|
||||
|
||||
assertNotNull(entity);
|
||||
assertEquals(1L, entity.getId());
|
||||
assertEquals("test_type", entity.getType());
|
||||
assertEquals("test_code", entity.getCode());
|
||||
assertEquals("Test Name", entity.getName());
|
||||
assertEquals(1, entity.getSort());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToDomainList() {
|
||||
DictionaryEntity entity1 = new DictionaryEntity();
|
||||
entity1.setId(1L);
|
||||
entity1.setType("type1");
|
||||
entity1.setCode("code1");
|
||||
|
||||
DictionaryEntity entity2 = new DictionaryEntity();
|
||||
entity2.setId(2L);
|
||||
entity2.setType("type2");
|
||||
entity2.setCode("code2");
|
||||
|
||||
List<DictionaryEntity> entities = Arrays.asList(entity1, entity2);
|
||||
List<Dictionary> domains = mapper.toDomainList(entities);
|
||||
|
||||
assertNotNull(domains);
|
||||
assertEquals(2, domains.size());
|
||||
assertEquals(1L, domains.get(0).getId());
|
||||
assertEquals(2L, domains.get(1).getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToEntityList() {
|
||||
Dictionary domain1 = new Dictionary();
|
||||
domain1.setId(1L);
|
||||
domain1.setType("type1");
|
||||
domain1.setCode("code1");
|
||||
|
||||
Dictionary domain2 = new Dictionary();
|
||||
domain2.setId(2L);
|
||||
domain2.setType("type2");
|
||||
domain2.setCode("code2");
|
||||
|
||||
List<Dictionary> domains = Arrays.asList(domain1, domain2);
|
||||
List<DictionaryEntity> entities = mapper.toEntityList(domains);
|
||||
|
||||
assertNotNull(entities);
|
||||
assertEquals(2, entities.size());
|
||||
assertEquals(1L, entities.get(0).getId());
|
||||
assertEquals(2L, entities.get(1).getId());
|
||||
}
|
||||
}
|
||||
-108
@@ -1,108 +0,0 @@
|
||||
package cn.novalon.manage.sys.infrastructure.db.repository;
|
||||
|
||||
import cn.novalon.manage.sys.core.domain.Dictionary;
|
||||
import cn.novalon.manage.sys.infrastructure.db.dao.DictionaryDao;
|
||||
import cn.novalon.manage.sys.infrastructure.db.entity.DictionaryEntity;
|
||||
import cn.novalon.manage.sys.infrastructure.db.mapper.DictionaryMapper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class DictionaryRepositoryTest {
|
||||
|
||||
@Mock
|
||||
private DictionaryDao dao;
|
||||
|
||||
@Mock
|
||||
private DictionaryMapper mapper;
|
||||
|
||||
private DictionaryRepository repository;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
repository = new DictionaryRepository(dao, mapper);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFindByType() {
|
||||
DictionaryEntity entity = new DictionaryEntity();
|
||||
entity.setId(1L);
|
||||
entity.setType("test_type");
|
||||
entity.setCode("test_code");
|
||||
|
||||
Dictionary domain = new Dictionary();
|
||||
domain.setId(1L);
|
||||
domain.setType("test_type");
|
||||
domain.setCode("test_code");
|
||||
|
||||
when(dao.findByType("test_type")).thenReturn(Flux.just(entity));
|
||||
when(mapper.toDomain(entity)).thenReturn(domain);
|
||||
|
||||
StepVerifier.create(repository.findByType("test_type"))
|
||||
.expectNextMatches(dict -> dict.getId().equals(1L))
|
||||
.verifyComplete();
|
||||
|
||||
verify(dao).findByType("test_type");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFindById() {
|
||||
DictionaryEntity entity = new DictionaryEntity();
|
||||
entity.setId(1L);
|
||||
entity.setType("test_type");
|
||||
|
||||
Dictionary domain = new Dictionary();
|
||||
domain.setId(1L);
|
||||
domain.setType("test_type");
|
||||
|
||||
when(dao.findById(1L)).thenReturn(Mono.just(entity));
|
||||
when(mapper.toDomain(entity)).thenReturn(domain);
|
||||
|
||||
StepVerifier.create(repository.findById(1L))
|
||||
.expectNextMatches(dict -> dict.getId().equals(1L))
|
||||
.verifyComplete();
|
||||
|
||||
verify(dao).findById(1L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSave() {
|
||||
Dictionary domain = new Dictionary();
|
||||
domain.setId(1L);
|
||||
domain.setType("test_type");
|
||||
domain.setCode("test_code");
|
||||
|
||||
DictionaryEntity entity = new DictionaryEntity();
|
||||
entity.setId(1L);
|
||||
entity.setType("test_type");
|
||||
|
||||
when(mapper.toEntity(domain)).thenReturn(entity);
|
||||
when(dao.save(entity)).thenReturn(Mono.just(entity));
|
||||
when(mapper.toDomain(entity)).thenReturn(domain);
|
||||
|
||||
StepVerifier.create(repository.save(domain))
|
||||
.expectNextMatches(dict -> dict.getId().equals(1L))
|
||||
.verifyComplete();
|
||||
|
||||
verify(dao).save(entity);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeleteById() {
|
||||
when(dao.deleteByIdAndDeletedAtIsNull(1L)).thenReturn(Mono.empty());
|
||||
|
||||
StepVerifier.create(repository.deleteById(1L))
|
||||
.verifyComplete();
|
||||
|
||||
verify(dao).deleteByIdAndDeletedAtIsNull(1L);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user