From ddab6d25210addcd8c784cd9f14defaf987189d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=BF=94?= Date: Sat, 14 Mar 2026 16:22:53 +0800 Subject: [PATCH] test: add OperationLogConverter unit tests --- .../converter/OperationLogConverterTest.java | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 novalon-manage-api/manage-db/src/test/java/cn/novalon/manage/db/converter/OperationLogConverterTest.java diff --git a/novalon-manage-api/manage-db/src/test/java/cn/novalon/manage/db/converter/OperationLogConverterTest.java b/novalon-manage-api/manage-db/src/test/java/cn/novalon/manage/db/converter/OperationLogConverterTest.java new file mode 100644 index 0000000..1c02c97 --- /dev/null +++ b/novalon-manage-api/manage-db/src/test/java/cn/novalon/manage/db/converter/OperationLogConverterTest.java @@ -0,0 +1,99 @@ +package cn.novalon.manage.db.converter; + +import cn.novalon.manage.sys.core.domain.OperationLog; +import cn.novalon.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(); + } +} \ No newline at end of file