feat: add system quality improvement plan and implementation
This commit is contained in:
+91
@@ -0,0 +1,91 @@
|
||||
package cn.novalon.manage.sys.core.service.impl;
|
||||
|
||||
import cn.novalon.manage.sys.core.domain.Dictionary;
|
||||
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 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.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class DictionaryServiceTest {
|
||||
|
||||
@Mock
|
||||
private DictionaryDao dao;
|
||||
|
||||
@Mock
|
||||
private DictionaryConverter converter;
|
||||
|
||||
private IDictionaryService service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
service = new DictionaryService(dao, converter);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFindAll() {
|
||||
Dictionary dict1 = new Dictionary();
|
||||
dict1.setId(1L);
|
||||
dict1.setType("type1");
|
||||
|
||||
Dictionary dict2 = new Dictionary();
|
||||
dict2.setId(2L);
|
||||
dict2.setType("type2");
|
||||
|
||||
when(dao.findByDeletedAtIsNullOrderBySortAsc()).thenReturn(Flux.empty());
|
||||
|
||||
StepVerifier.create(service.findAll())
|
||||
.verifyComplete();
|
||||
|
||||
verify(dao).findByDeletedAtIsNullOrderBySortAsc();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFindById() {
|
||||
Dictionary dict = new Dictionary();
|
||||
dict.setId(1L);
|
||||
dict.setType("type1");
|
||||
|
||||
when(dao.findById(1L)).thenReturn(Mono.empty());
|
||||
|
||||
StepVerifier.create(service.findById(1L))
|
||||
.verifyComplete();
|
||||
|
||||
verify(dao).findById(1L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSave() {
|
||||
Dictionary dict = new Dictionary();
|
||||
dict.setId(1L);
|
||||
dict.setType("type1");
|
||||
|
||||
when(dao.save(any())).thenReturn(Mono.empty());
|
||||
|
||||
StepVerifier.create(service.save(dict))
|
||||
.verifyComplete();
|
||||
|
||||
verify(dao).save(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeleteById() {
|
||||
when(dao.deleteByIdAndDeletedAtIsNull(1L)).thenReturn(Mono.empty());
|
||||
|
||||
StepVerifier.create(service.deleteById(1L))
|
||||
.verifyComplete();
|
||||
|
||||
verify(dao).deleteByIdAndDeletedAtIsNull(1L);
|
||||
}
|
||||
}
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
package cn.novalon.manage.sys.handler.dictionary;
|
||||
|
||||
import cn.novalon.manage.sys.core.domain.Dictionary;
|
||||
import cn.novalon.manage.sys.core.service.IDictionaryService;
|
||||
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 org.springframework.http.HttpStatus;
|
||||
import org.springframework.mock.web.reactive.function.server.MockServerRequest;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class DictionaryHandlerTest {
|
||||
|
||||
@Mock
|
||||
private IDictionaryService service;
|
||||
|
||||
private DictionaryHandler handler;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
handler = new DictionaryHandler(service);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetAllDictionaries() {
|
||||
Dictionary dict = new Dictionary();
|
||||
dict.setId(1L);
|
||||
dict.setType("type1");
|
||||
|
||||
when(service.findAll()).thenReturn(Flux.just(dict));
|
||||
|
||||
Mono<ServerResponse> responseMono = handler.getAllDictionaries(null);
|
||||
|
||||
StepVerifier.create(responseMono)
|
||||
.expectNextMatches(response -> response.statusCode().equals(HttpStatus.OK))
|
||||
.verifyComplete();
|
||||
|
||||
verify(service).findAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetDictionaryById() {
|
||||
Dictionary dict = new Dictionary();
|
||||
dict.setId(1L);
|
||||
dict.setType("type1");
|
||||
|
||||
when(service.findById(1L)).thenReturn(Mono.just(dict));
|
||||
|
||||
MockServerRequest request = MockServerRequest.builder()
|
||||
.pathVariable("id", "1")
|
||||
.build();
|
||||
|
||||
Mono<ServerResponse> responseMono = handler.getDictionaryById(request);
|
||||
|
||||
StepVerifier.create(responseMono)
|
||||
.expectNextMatches(response -> response.statusCode().equals(HttpStatus.OK))
|
||||
.verifyComplete();
|
||||
|
||||
verify(service).findById(1L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateDictionary() {
|
||||
Dictionary dict = new Dictionary();
|
||||
dict.setId(1L);
|
||||
dict.setType("type1");
|
||||
|
||||
when(service.save(any())).thenReturn(Mono.just(dict));
|
||||
|
||||
Mono<ServerResponse> responseMono = handler.createDictionary(MockServerRequest.builder()
|
||||
.build());
|
||||
|
||||
StepVerifier.create(responseMono)
|
||||
.expectNextMatches(response -> response.statusCode().equals(HttpStatus.CREATED))
|
||||
.verifyComplete();
|
||||
|
||||
verify(service).save(any());
|
||||
}
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
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 = DictionaryMapper.INSTANCE;
|
||||
|
||||
@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());
|
||||
}
|
||||
}
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
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.ArgumentMatchers.any;
|
||||
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