From 408708322edf8e57e1270eaf912464b284b5d7c4 Mon Sep 17 00:00:00 2001 From: 3y Date: Mon, 25 Apr 2022 20:34:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=95=E5=85=A5=E5=8D=95=E4=BE=8B=E6=A1=86?= =?UTF-8?q?=E6=9E=B6=EF=BC=8C=E7=BC=96=E5=86=99=E5=8D=95=E4=BE=8B=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/impl/service/SendServiceImplTest.java | 95 +++++++++++++++++++ austin-support/pom.xml | 5 + 2 files changed, 100 insertions(+) create mode 100644 austin-service-api-impl/src/test/java/com/java3y/austin/service/api/impl/service/SendServiceImplTest.java diff --git a/austin-service-api-impl/src/test/java/com/java3y/austin/service/api/impl/service/SendServiceImplTest.java b/austin-service-api-impl/src/test/java/com/java3y/austin/service/api/impl/service/SendServiceImplTest.java new file mode 100644 index 0000000..6e8e5cd --- /dev/null +++ b/austin-service-api-impl/src/test/java/com/java3y/austin/service/api/impl/service/SendServiceImplTest.java @@ -0,0 +1,95 @@ +package com.java3y.austin.service.api.impl.service; + +import com.java3y.austin.common.enums.RespStatusEnum; +import com.java3y.austin.common.vo.BasicResultVO; +import com.java3y.austin.service.api.domain.BatchSendRequest; +import com.java3y.austin.service.api.domain.MessageParam; +import com.java3y.austin.service.api.domain.SendRequest; +import com.java3y.austin.service.api.domain.SendResponse; +import com.java3y.austin.service.api.enums.BusinessCode; +import com.java3y.austin.service.api.impl.domain.SendTaskModel; +import com.java3y.austin.support.pipeline.BusinessProcess; +import com.java3y.austin.support.pipeline.ProcessContext; +import com.java3y.austin.support.pipeline.ProcessController; +import com.java3y.austin.support.pipeline.ProcessTemplate; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Spy; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class SendServiceImplTest { + + @Spy + private ProcessController processController; + + @Mock + private Map templateConfig; + + @Spy + private ProcessTemplate processTemplate; + + @Mock + private BusinessProcess businessProcess; + + @InjectMocks + private SendServiceImpl sendServiceImplUnderTest; + + @Test + void testSend() { + + // params + final SendRequest sendRequest = new SendRequest("send", 1L, + new MessageParam("13711111111", new HashMap<>(), new HashMap<>())); + + // predict result + final ProcessContext processContext = new ProcessContext<>(sendRequest.getCode(), new SendTaskModel(), false, new BasicResultVO<>( + RespStatusEnum.SUCCESS, "data")); + final SendResponse expectedResult = new SendResponse(processContext.getResponse().getStatus(), processContext.getResponse().getMsg()); + + + // stub + Map templateConfig = new HashMap<>(4); + processTemplate.setProcessList(Arrays.asList(businessProcess)); + templateConfig.put(BusinessCode.COMMON_SEND.getCode(), processTemplate); + + processController.setTemplateConfig(templateConfig); + + + // Run the test + final SendResponse result = sendServiceImplUnderTest.send(sendRequest); + + // Verify the results + assertEquals(expectedResult, result); + } + + @Test + void testBatchSend() { + // Setup + final BatchSendRequest batchSendRequest = new BatchSendRequest("code", 0L, + Arrays.asList(new MessageParam("receiver", new HashMap<>(), new HashMap<>()))); + final SendResponse expectedResult = new SendResponse("status", "msg"); + + // Configure ProcessController.process(...). + final ProcessContext processContext = new ProcessContext<>("code", null, false, new BasicResultVO<>( + RespStatusEnum.SUCCESS, "data")); + when(processController.process(new ProcessContext<>("code", null, false, new BasicResultVO<>( + RespStatusEnum.SUCCESS, "data")))).thenReturn(processContext); + + // Run the test + final SendResponse result = sendServiceImplUnderTest.batchSend(batchSendRequest); + + // Verify the results + assertEquals(expectedResult, result); + } +} diff --git a/austin-support/pom.xml b/austin-support/pom.xml index 6a9b651..96ae2e0 100644 --- a/austin-support/pom.xml +++ b/austin-support/pom.xml @@ -22,6 +22,11 @@ org.springframework.boot spring-boot-starter + + org.springframework.boot + spring-boot-starter-test + + mysql mysql-connector-java