TA 역할 Spring 경계 smoke (role-ta-live-1522-001)
Some checks failed
ci / test (pull_request) Failing after 1m16s
Some checks failed
ci / test (pull_request) Failing after 1m16s
This commit is contained in:
parent
0a7b2d9a4f
commit
ff29deb091
1 changed files with 58 additions and 0 deletions
|
|
@ -0,0 +1,58 @@
|
||||||
|
package com.klaroworks.runtime.service;
|
||||||
|
|
||||||
|
import com.klaroworks.runtime.dto.RoleCreateRequest;
|
||||||
|
import com.klaroworks.runtime.dto.RoleResponse;
|
||||||
|
import com.klaroworks.runtime.entity.Role;
|
||||||
|
import com.klaroworks.runtime.exception.RoleNotFoundException;
|
||||||
|
import com.klaroworks.runtime.repository.RoleRepository;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
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.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 RoleMatrixServiceTest {
|
||||||
|
|
||||||
|
@Mock private RoleRepository roleRepository;
|
||||||
|
@InjectMocks private RoleMatrixService service;
|
||||||
|
private Role testRole;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
testRole = Role.builder().id(1L).name("ADMIN").description("Administrator").build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("역할 생성 시 save 호출 및 응답 반환")
|
||||||
|
void createRole_callsSaveAndReturnsResponse() {
|
||||||
|
when(roleRepository.save(any(Role.class))).thenReturn(testRole);
|
||||||
|
RoleResponse response = service.createRole(new RoleCreateRequest("ADMIN", "Administrator"));
|
||||||
|
assertNotNull(response);
|
||||||
|
assertEquals("ADMIN", response.getName());
|
||||||
|
verify(roleRepository, times(1)).save(any(Role.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("존재하지 않는 역할 조회 시 RoleNotFoundException 발생")
|
||||||
|
void getRoleById_whenNotFound_throwsException() {
|
||||||
|
when(roleRepository.findById(999L)).thenReturn(Optional.empty());
|
||||||
|
assertThrows(RoleNotFoundException.class, () -> service.getRoleById(999L));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("모든 역할 조회 시 Role 목록 반환")
|
||||||
|
void getAllRoles_returnsListOfRoles() {
|
||||||
|
when(roleRepository.findAll()).thenReturn(List.of(testRole));
|
||||||
|
List<RoleResponse> roles = service.getAllRoles();
|
||||||
|
assertEquals(1, roles.size());
|
||||||
|
assertEquals("ADMIN", roles.get(0).getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue