카드 매입 승인 경로 Spring Boot 3 전환 (ACX-E2E-1785394564819)
This commit is contained in:
parent
c829679c3d
commit
6cd9fbdf8c
1 changed files with 155 additions and 0 deletions
|
|
@ -0,0 +1,155 @@
|
|||
package com.acquirex.service;
|
||||
|
||||
import com.acquirex.domain.AcquisitionApproval;
|
||||
import com.acquirex.domain.AcquisitionApproval.ApprovalStatus;
|
||||
import com.acquirex.dto.ApprovalRequest;
|
||||
import com.acquirex.dto.ApprovalResponse;
|
||||
import com.acquirex.exception.ApprovalProcessingException;
|
||||
import com.acquirex.repository.AcquisitionApprovalRepository;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class AcquisitionApprovalServiceTest {
|
||||
|
||||
@Mock
|
||||
private AcquisitionApprovalRepository repository;
|
||||
|
||||
@InjectMocks
|
||||
private AcquisitionApprovalService service;
|
||||
|
||||
private ApprovalRequest validRequest;
|
||||
private AcquisitionApproval savedApproval;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
validRequest = new ApprovalRequest("MERCHANT001", "4111111111111111", new BigDecimal("100.00"), "KRW");
|
||||
|
||||
savedApproval = new AcquisitionApproval();
|
||||
savedApproval.setId(1L);
|
||||
savedApproval.setMerchantId("MERCHANT001");
|
||||
savedApproval.setCardNumber("****-****-****-1111");
|
||||
savedApproval.setAmount(new BigDecimal("100.00"));
|
||||
savedApproval.setCurrency("KRW");
|
||||
savedApproval.setStatus(ApprovalStatus.PENDING);
|
||||
}
|
||||
|
||||
@Test
|
||||
void requestApproval_ValidRequest_ReturnsApprovalResponse() {
|
||||
when(repository.save(any(AcquisitionApproval.class))).thenReturn(savedApproval);
|
||||
|
||||
ApprovalResponse response = service.requestApproval(validRequest);
|
||||
|
||||
assertNotNull(response);
|
||||
assertEquals(1L, response.getId());
|
||||
assertEquals("MERCHANT001", response.getMerchantId());
|
||||
assertEquals("PENDING", response.getStatus());
|
||||
assertTrue(response.getCardNumber().startsWith("****"));
|
||||
verify(repository, times(1)).save(any(AcquisitionApproval.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void requestApproval_InvalidMerchantId_ThrowsException() {
|
||||
validRequest.setMerchantId("");
|
||||
assertThrows(ApprovalProcessingException.class, () -> service.requestApproval(validRequest));
|
||||
}
|
||||
|
||||
@Test
|
||||
void requestApproval_InvalidAmount_ThrowsException() {
|
||||
validRequest.setAmount(BigDecimal.ZERO);
|
||||
assertThrows(ApprovalProcessingException.class, () -> service.requestApproval(validRequest));
|
||||
}
|
||||
|
||||
@Test
|
||||
void processApproval_Approve_UpdatesStatusToApproved() {
|
||||
savedApproval.setStatus(ApprovalStatus.PENDING);
|
||||
when(repository.findById(1L)).thenReturn(Optional.of(savedApproval));
|
||||
when(repository.save(any(AcquisitionApproval.class))).thenAnswer(inv -> inv.getArgument(0));
|
||||
|
||||
ApprovalResponse response = service.processApproval(1L, true, null);
|
||||
|
||||
assertEquals("APPROVED", response.getStatus());
|
||||
assertNotNull(response.getApprovalCode());
|
||||
assertTrue(response.getApprovalCode().startsWith("APP-"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void processApproval_Reject_UpdatesStatusToRejected() {
|
||||
savedApproval.setStatus(ApprovalStatus.PENDING);
|
||||
when(repository.findById(1L)).thenReturn(Optional.of(savedApproval));
|
||||
when(repository.save(any(AcquisitionApproval.class))).thenAnswer(inv -> inv.getArgument(0));
|
||||
|
||||
ApprovalResponse response = service.processApproval(1L, false, "Insufficient funds");
|
||||
|
||||
assertEquals("REJECTED", response.getStatus());
|
||||
assertEquals("Insufficient funds", response.getRejectionReason());
|
||||
assertNull(response.getApprovalCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void processApproval_AlreadyProcessed_ThrowsException() {
|
||||
savedApproval.setStatus(ApprovalStatus.APPROVED);
|
||||
when(repository.findById(1L)).thenReturn(Optional.of(savedApproval));
|
||||
assertThrows(ApprovalProcessingException.class, () -> service.processApproval(1L, true, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void processApproval_NotFound_ThrowsException() {
|
||||
when(repository.findById(999L)).thenReturn(Optional.empty());
|
||||
assertThrows(ApprovalProcessingException.class, () -> service.processApproval(999L, true, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getApproval_ExistingId_ReturnsApproval() {
|
||||
when(repository.findById(1L)).thenReturn(Optional.of(savedApproval));
|
||||
ApprovalResponse response = service.getApproval(1L);
|
||||
assertNotNull(response);
|
||||
assertEquals(1L, response.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getApproval_NonExistingId_ThrowsException() {
|
||||
when(repository.findById(999L)).thenReturn(Optional.empty());
|
||||
assertThrows(ApprovalProcessingException.class, () -> service.getApproval(999L));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getPendingApprovals_ReturnsPendingList() {
|
||||
AcquisitionApproval pending1 = new AcquisitionApproval();
|
||||
pending1.setId(1L);
|
||||
pending1.setStatus(ApprovalStatus.PENDING);
|
||||
pending1.setMerchantId("MERCHANT001");
|
||||
|
||||
AcquisitionApproval pending2 = new AcquisitionApproval();
|
||||
pending2.setId(2L);
|
||||
pending2.setStatus(ApprovalStatus.PENDING);
|
||||
pending2.setMerchantId("MERCHANT002");
|
||||
|
||||
when(repository.findByStatus(ApprovalStatus.PENDING)).thenReturn(Arrays.asList(pending1, pending2));
|
||||
|
||||
List<ApprovalResponse> responses = service.getPendingApprovals();
|
||||
assertEquals(2, responses.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getApprovalsByMerchant_ReturnsMerchantApprovals() {
|
||||
when(repository.findByMerchantId("MERCHANT001")).thenReturn(Arrays.asList(savedApproval));
|
||||
|
||||
List<ApprovalResponse> responses = service.getApprovalsByMerchant("MERCHANT001");
|
||||
assertEquals(1, responses.size());
|
||||
assertEquals("MERCHANT001", responses.get(0).getMerchantId());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue