🛹 목표
목표 | 난이도 | 달성 여부 |
패스트 캠퍼스 강의 듣기 |
🥺 | ✔️ |
알고리즘 문제풀이 | 😘 | ✔️ |
📋 공부 내용 & 기록
1. 뷰 엔드포인트 테스트 정의하기
package com.fastcampus.projectboardadmin.controller;
import com.fastcampus.projectboardadmin.config.SecurityConfig;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.context.annotation.Import;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
@DisplayName("View 컨트롤러 - 어드민 회원")
@Import(SecurityConfig.class) // 시큐리티 적용을 위한 Import. 해당 어노테이션을 제거하면 도중 시큐리티에 의해 막힌다. 에러는 302
@WebMvcTest(AdminUserAccountController.class)
class AdminUserAccountControllerTest {
private final MockMvc mvc;
public AdminUserAccountControllerTest(@Autowired MockMvc mvc) {
this.mvc = mvc;
}
@DisplayName("[view][GET] 어드민 회원 페이지 - 정상 호출")
@Test
void givenNothing_whenRequestingAdminMembersView_thenReturnsAdminMembersView() throws Exception {
// Given
// When & Then
mvc.perform(get("/admin/members"))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.TEXT_HTML)) // contentTypeCompatibleWith() -> 인코딩이 다른 경우 contentType()메소드는 테스트 실패를 발생시킬 수 있다.
.andExpect(view().name("admin/members")); // 해당 부분은 resources/admin 폴더에서 members html을 찾아야 한다.
}
}
2. @Dyanmic Update
JPA의 @DynamicUpdate
개요 JPA를 사용하다보면 @DynamicUpdate라는 어노테이션이 있다. JPA Entity에 사용하는 어노테이션인데, 실제 값이 변경된 컬럼으로만 update 쿼리를 만드는 기능이다. 너무 당연한 이야기 같지만, JPA의
velog.io
🏷️ 하루 정리 & 느낀 점
열심히 살자
📌 내일 해야할 일
이펙티브 자바 학습
'TIL' 카테고리의 다른 글
[TIL] 🌱 2023.03.20 - Objects.requireNonNull() (0) | 2023.03.20 |
---|---|
[TIL] 🌱 2023.03.16 - 빌더 패턴 (0) | 2023.03.16 |
[TIL] 🌱 2023.03.13 - Spring Security (0) | 2023.03.13 |
[TIL] 🌱 2023.03.09 - git squash & merge 그리고 rebase (0) | 2023.03.09 |
[TIL] 🌱 2023.03.08 - Thymeleaf의 Decoupled Logic (1) | 2023.03.09 |