-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: CCTV 삭제 통합 테스트코드 작성 (#72) (KAN-129)
- Loading branch information
Showing
1 changed file
with
85 additions
and
0 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
src/test/java/org/ioteatime/meonghanyangserver/cctv/controller/CctvControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package org.ioteatime.meonghanyangserver.cctv.controller; | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
||
import org.apache.http.HttpHeaders; | ||
import org.assertj.core.api.Assertions; | ||
import org.ioteatime.meonghanyangserver.cctv.domain.CctvEntity; | ||
import org.ioteatime.meonghanyangserver.cctv.repository.CctvRepository; | ||
import org.ioteatime.meonghanyangserver.common.utils.JwtUtils; | ||
import org.ioteatime.meonghanyangserver.config.ControllerTestConfig; | ||
import org.ioteatime.meonghanyangserver.device.doamin.DeviceEntity; | ||
import org.ioteatime.meonghanyangserver.device.doamin.enums.DeviceRole; | ||
import org.ioteatime.meonghanyangserver.device.repository.DeviceRepository; | ||
import org.ioteatime.meonghanyangserver.group.domain.GroupEntity; | ||
import org.ioteatime.meonghanyangserver.group.repository.GroupRepository; | ||
import org.ioteatime.meonghanyangserver.user.domain.UserEntity; | ||
import org.ioteatime.meonghanyangserver.user.repository.UserRepository; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.http.MediaType; | ||
|
||
@SpringBootTest | ||
class CctvControllerTest extends ControllerTestConfig { | ||
@Autowired private JwtUtils jwtUtils; | ||
@Autowired private UserRepository userRepository; | ||
@Autowired private CctvRepository cctvRepository; | ||
@Autowired private GroupRepository groupRepository; | ||
@Autowired private DeviceRepository deviceRepository; | ||
|
||
private String accessToken; | ||
private UserEntity user; | ||
|
||
@BeforeEach | ||
public void beforeEach() { | ||
user = | ||
UserEntity.builder() | ||
.email("[email protected]") | ||
.nickname("test") | ||
.password("testpassword") | ||
.build(); | ||
userRepository.save(user); | ||
accessToken = jwtUtils.includeBearer(jwtUtils.generateAccessToken(user)); | ||
} | ||
|
||
@Test | ||
void CCTV를_삭제합니다() throws Exception { | ||
GroupEntity group = GroupEntity.builder().groupName("testgroup").build(); | ||
groupRepository.save(group); | ||
|
||
DeviceEntity device2 = | ||
DeviceEntity.builder() | ||
.user(user) | ||
.group(group) | ||
.deviceUuid("test2") | ||
.role(DeviceRole.ROLE_CCTV) | ||
.build(); | ||
device2 = deviceRepository.save(device2); | ||
|
||
String kvsChannelName = "delete-test-channel"; // KVS에 채널이 존재해야 함 | ||
CctvEntity cctv = | ||
CctvEntity.builder() | ||
.cctvNickname("delcctv") | ||
.device(device2) | ||
.kvsChannelName(kvsChannelName) | ||
.build(); | ||
cctvRepository.save(cctv); | ||
|
||
mockMvc.perform( | ||
delete("/api/cctv/{cctvId}", cctv.getId()) | ||
.header(HttpHeaders.AUTHORIZATION, accessToken) | ||
.contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.result.message").value("OK")) | ||
.andExpect(jsonPath("$.result.description").value("CCTV 삭제(퇴출)에 성공하였습니다.")) | ||
.andDo(print()); | ||
|
||
Assertions.assertThat(cctvRepository.existsByKvsChannelName(kvsChannelName)) | ||
.isEqualTo(false); | ||
Assertions.assertThat(deviceRepository.findByDeviceId(device2.getId())).isEmpty(); | ||
} | ||
} |