[Security Error] Authentication, Caused by: java.lang.NullPointerException
·
Server/Error
에러발생 TestCode를 진행하다 보니 org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException NullPointerException이 발생하고 있었다. 컨트롤러 @RestController @RequestMapping("/api/v1/blog") @RequiredArgsConstructor public class BlogRestController { private final BlogService blogService; @PostMapping("/rename/{blogId}") public Response renameBlog( ..
[Junit] MultipartFile과 DTO가 있는 컨트롤러 테스트
·
Server/Spring&Spring Boot
기획상 게시물에 이미지를 업로드를 해야 하므로, S3를 구축하고 @RequestPart를 사용해서 이미지를 받아올 수 있게 Controller를 수정했다. Controller를 수정하고 난 뒤, 테스트 코드를 돌려봤더니 400 에러가 발생하고 있었다. 기존 Test code @Test @DisplayName("추천글 작성") void success_post_recommend_test() throws Exception { RecommendPostRequest request = new RecommendPostRequest("제목", "내용", "유튜브", 100L, 1L); RecommendPostResponse response = new RecommendPostResponse(1L, "제목", 100L);..
[Junit] 테스트 코드 할 때 가상의 Token 만들어주기
·
Server/Spring&Spring Boot
테스트 코드란 결국 가상의 상황을 제시해 주는 것. 사실 없어도 되고 아무런 문자열을 넣어줘도 무방하지만 이왕 JWT를 만들었는데 토큰을 넣어주는 상황을 가정하면 더욱 몰입할 수 있지 않을까. (사실 이런저런 문제 해결하다가 토큰이라도 만들어볼까 하다가 만들게 되었다.) ... class RecommendRestControllerTest { ... String jwtToken; @BeforeEach void getToken() { Key key = Keys.secretKeyFor(SignatureAlgorithm.HS256); jwtToken = Jwts.builder() .setSubject("user") .setIssuer("issuer") .setExpiration(new Date(System.cu..
[Junit Error] OAuth2 등록 후 발생하는 "org.springframework.security.core.userdetails.UserDetails.getAuthorities()" because "userDetails" is null
·
Server/Error
문제 OAuth2를 사용하는 SNS로그인을 구현하고 난 다음, 갑자기 대부분의 테스트 코드에서 에러가 발생하기 시작했다. @Test @DisplayName("추천글 작성") void success_post_recommend() throws Exception { RecommendPostRequest request = new RecommendPostRequest("제목", "내용", "유튜브", 100L, 1L); RecommendPostResponse response = new RecommendPostResponse(1L, "제목", 100L); given(recommendService.uploadPost(any(), any(), any())).willReturn(response); MockMultipar..
[Spring] test code에 대한 회고
·
Server/Spring&Spring Boot
거창한 회고는 아니다. 그냥 오랜만에 혼자 천천히 진행하고 있는, 학원의 종합 프로젝트를 진행하면서 무기한 보류 중인, 개인프로젝트의 코드를 다시 꺼내봤다. 현재 계정부분의 로그인, 회원가입만 구현되어 있는 작고 소중한 프로젝트이며, 여기서 구현 완료된 계정 부분의 컨트롤러 테스트 코드를 작성해 보았다. 테스트 코드 작성 전 나의 JOIN API public class MemberRestController { @PostMapping("/join") public Response join(@RequestBody @Valid final MemberJoinRequest dto) { MemberDto member = memberService.join(dto); return Response.success( Memb..
[06] Comment Api 개발 - 2
·
프로젝트/Archive
이전글 https://chordplaylist.tistory.com/231 댓글 조회 앤드포인트 GET /posts/{postId}/comments[?page=0] 리턴 { "resultCode": "SUCCESS", "result":{ "content":[ { "id": 3, "comment": "comment test3", "userName": "test", "postId": 2, "createdAt": "2022-12-20T16:07:25.699346" }, { "id": 2, "comment": "comment test2", "userName": "test", "postId": 2, "createdAt": "2022-12-20T16:03:30.670768" } ], "pageable":{"sort..
[Error] 테스트 코드 실행 시 Parameter 1 of constructor in com.PostRestController required a bean of type 'com.service.LikeService' that could not be found. 발생 이유
·
Server/Error
문제 발생 새로운 API를 제작하면서 테스트코드를 진행하던 도중, 모든 테스트 코드가 먹통이 되기 시작했다. Application Run을 했을 경우에는 에러가 발생하지 않았다. 에러코드 Description: Parameter 1 of constructor in com.likelion.finalproject.controller.restcontroller.PostRestController required a bean of type 'com.likelion.finalproject.service.LikeService' that could not be found. Action: Consider defining a bean of type 'com.likelion.finalproject.service.LikeSe..
[04] Post Test 코드 작성 - 2 (Service Test)
·
프로젝트/Archive
이전글 [04] Post Test 코드 작성 - 1 (Controller Test) 이전글 [04] User Test 코드 작성 이전글 [03] 게시된 포스트 삭제 이전글 [03] 게시된 포스트 수정 이전글 [03] 게시된 모든 포스트 목록 보기 이전글 [03] 포스트 등록 만들기 체크 사항 로그인이 되어 chordplaylist.tistory.com 목표 1. controller / 2. service로 나눠서 테스트를 진행해야 함. 1. 성공, 2. 실패 테스트 케이스를 모두 통과하는 실제 코드 작성. Exception 처리는 enum Error코드에 작성 후 호출 해서 사용 실패의 경우 enum값의 errorCode로 처리하기 when(어떤 상황일 때)를 각각 설계해 보고, Test case에 따라..
코드플리
'junit' 태그의 글 목록