Skip to content

Commit

Permalink
hotfix : Test 주석 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
packdev937 committed Aug 13, 2023
1 parent f723788 commit 7756b06
Show file tree
Hide file tree
Showing 10 changed files with 1,032 additions and 1,032 deletions.
Empty file modified gradlew
100644 → 100755
Empty file.
114 changes: 57 additions & 57 deletions src/test/java/com/umc/yourweather/controller/ReportControllerTest.java
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
package com.umc.yourweather.controller;

import static org.junit.jupiter.api.Assertions.*;

import com.umc.yourweather.auth.CustomUserDetails;
import com.umc.yourweather.domain.entity.User;
import com.umc.yourweather.domain.enums.Status;
import com.umc.yourweather.repository.MemoRepository;
import com.umc.yourweather.repository.test.MemoTestRepository;
import com.umc.yourweather.response.ResponseDto;
import com.umc.yourweather.response.SpecificMemoResponseDto;
import com.umc.yourweather.service.ReportService;
import org.junit.jupiter.api.Test;

class ReportControllerTest {
private MemoRepository memoRepository = new MemoTestRepository(31);
private ReportService reportService = new ReportService(memoRepository);
private ReportController reportController = new ReportController(reportService);

@Test
void getSpecificMemoList() {
// given
User user = User.builder()
.email("[email protected]")
.build();
CustomUserDetails customUserDetails = new CustomUserDetails(user);
int month = 7;
Status sunny = Status.SUNNY;

// when
ResponseDto<SpecificMemoResponseDto> specificMemoList = reportController.getMonthlySpecificWeatherList(
customUserDetails, month, sunny);

// then
System.out.println(specificMemoList.toString());
assertEquals(200, specificMemoList.getCode());
}
}
/**
* ResponseDto(success=true, code=200, message=월간 특정 날씨 일자 조회 성공.,
* result= SpecificMemoResponseDto(
* memoList=[
* MemoReportResponseDto(memoId=null, dateTime=2023-07-28T21:19:01.570862400),
* MemoReportResponseDto(memoId=null, dateTime=2023-07-29T21:19:01.570862400),
* MemoReportResponseDto(memoId=null, dateTime=2023-07-30T21:19:01.570862400),
* MemoReportResponseDto(memoId=null, dateTime=2023-07-31T21:19:01.570862400),
* MemoReportResponseDto(memoId=null, dateTime=2023-08-01T21:19:01.570862400),
* MemoReportResponseDto(memoId=null, dateTime=2023-08-02T21:19:01.570862400),
* MemoReportResponseDto(memoId=null, dateTime=2023-08-03T21:19:01.570862400),
* MemoReportResponseDto(memoId=null, dateTime=2023-08-04T21:19:01.570862400),
* MemoReportResponseDto(memoId=null, dateTime=2023-08-05T21:19:01.570862400),
* MemoReportResponseDto(memoId=null, dateTime=2023-08-06T21:19:01.570862400),
* MemoReportResponseDto(memoId=null, dateTime=2023-08-07T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-08T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-09T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-10T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-11T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-12T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-13T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-14T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-15T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-16T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-17T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-18T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-19T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-20T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-21T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-22T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-23T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-24T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-25T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-26T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-27T21:19:01.570862400)],
* proportion=12.903225
* )
* )
* **/
//package com.umc.yourweather.controller;
//
//import static org.junit.jupiter.api.Assertions.*;
//
//import com.umc.yourweather.auth.CustomUserDetails;
//import com.umc.yourweather.domain.entity.User;
//import com.umc.yourweather.domain.enums.Status;
//import com.umc.yourweather.repository.MemoRepository;
//import com.umc.yourweather.repository.test.MemoTestRepository;
//import com.umc.yourweather.response.ResponseDto;
//import com.umc.yourweather.response.SpecificMemoResponseDto;
//import com.umc.yourweather.service.ReportService;
//import org.junit.jupiter.api.Test;
//
//class ReportControllerTest {
// private MemoRepository memoRepository = new MemoTestRepository(31);
// private ReportService reportService = new ReportService(memoRepository);
// private ReportController reportController = new ReportController(reportService);
//
// @Test
// void getSpecificMemoList() {
// // given
// User user = User.builder()
// .email("[email protected]")
// .build();
// CustomUserDetails customUserDetails = new CustomUserDetails(user);
// int month = 7;
// Status sunny = Status.SUNNY;
//
// // when
// ResponseDto<SpecificMemoResponseDto> specificMemoList = reportController.getMonthlySpecificWeatherList(
// customUserDetails, month, sunny);
//
// // then
// System.out.println(specificMemoList.toString());
// assertEquals(200, specificMemoList.getCode());
// }
//}
///**
// * ResponseDto(success=true, code=200, message=월간 특정 날씨 일자 조회 성공.,
// * result= SpecificMemoResponseDto(
// * memoList=[
// * MemoReportResponseDto(memoId=null, dateTime=2023-07-28T21:19:01.570862400),
// * MemoReportResponseDto(memoId=null, dateTime=2023-07-29T21:19:01.570862400),
// * MemoReportResponseDto(memoId=null, dateTime=2023-07-30T21:19:01.570862400),
// * MemoReportResponseDto(memoId=null, dateTime=2023-07-31T21:19:01.570862400),
// * MemoReportResponseDto(memoId=null, dateTime=2023-08-01T21:19:01.570862400),
// * MemoReportResponseDto(memoId=null, dateTime=2023-08-02T21:19:01.570862400),
// * MemoReportResponseDto(memoId=null, dateTime=2023-08-03T21:19:01.570862400),
// * MemoReportResponseDto(memoId=null, dateTime=2023-08-04T21:19:01.570862400),
// * MemoReportResponseDto(memoId=null, dateTime=2023-08-05T21:19:01.570862400),
// * MemoReportResponseDto(memoId=null, dateTime=2023-08-06T21:19:01.570862400),
// * MemoReportResponseDto(memoId=null, dateTime=2023-08-07T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-08T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-09T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-10T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-11T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-12T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-13T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-14T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-15T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-16T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-17T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-18T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-19T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-20T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-21T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-22T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-23T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-24T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-25T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-26T21:19:01.570862400), MemoReportResponseDto(memoId=null, dateTime=2023-08-27T21:19:01.570862400)],
// * proportion=12.903225
// * )
// * )
// * **/
234 changes: 117 additions & 117 deletions src/test/java/com/umc/yourweather/jwt/JwtTokenManagerTest.java
Original file line number Diff line number Diff line change
@@ -1,122 +1,122 @@
package com.umc.yourweather.jwt;

import com.umc.yourweather.domain.entity.User;
import com.umc.yourweather.domain.enums.Platform;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletWebRequest;

import static org.junit.jupiter.api.Assertions.*;

@SpringBootTest
class JwtTokenManagerTest {
@Autowired
private JwtTokenManager jwtTokenManager;
private User user;

@BeforeEach
void setUser() {
user = User.builder()
.email("[email protected]")
.password("asdf")
.nickname("ffff")
.platform(Platform.GOOGLE)
.build();
}

@Test
@DisplayName("createAccessToken 테스트")
void test1() {
//given
String accessToken = "";

//when
accessToken = jwtTokenManager.createAccessToken(user);

//then
System.out.println(accessToken);
assertNotNull(accessToken);
}

@Test
@DisplayName("createRefreshToken 테스트")
void test2() {
//given
String refreshToken = "";

//when
refreshToken = jwtTokenManager.createRefreshToken();

//then
System.out.println(refreshToken);
assertNotNull(refreshToken);
}

@Test
@DisplayName("sendAccessTokenAndRefreshToken 테스트")
void test3() throws IOException {
//given
ServletWebRequest servletContainer = (ServletWebRequest) RequestContextHolder.getRequestAttributes();
HttpServletResponse httpServletResponse = servletContainer.getResponse();

String accessToken = jwtTokenManager.createAccessToken(user);
String refreshToken = jwtTokenManager.createRefreshToken();

//when
jwtTokenManager.sendAccessTokenAndRefreshToken(httpServletResponse, accessToken, refreshToken);

//then
System.out.println(httpServletResponse.getHeader("Authorization"));
System.out.println(httpServletResponse.getHeader("Authorization-refresh"));

assertEquals(accessToken, httpServletResponse.getHeader("Authorization"));
assertEquals(refreshToken, httpServletResponse.getHeader("Authorization-refresh"));
}

@Test
@DisplayName("extractToken 테스트")
void test4() {
//given
String accessToken = jwtTokenManager.createAccessToken(user);
String refreshToken = jwtTokenManager.createRefreshToken();

//when
String accessTokenFromManager = jwtTokenManager.extractToken("Bearer " + accessToken)
.orElseGet(null);
String refreshTokenFromManager = jwtTokenManager.extractToken("Bearer " + refreshToken)
.orElseGet(null);

//then
System.out.println(accessTokenFromManager);
System.out.println(refreshTokenFromManager);

assertEquals(accessToken, accessTokenFromManager);
assertEquals(refreshToken, refreshTokenFromManager);
}

@Test
@DisplayName("isTokenValid 테스트")
void test5() {
// 테스트 통과!
// 단 토큰 생성, 검증로직이 시크릿키와 토큰 만료 시간에 강하게 의존하고 있기 때문에 어느정도 이 의존성은 풀어주자.
// 막 사용해도 상관없는 더미를 만들어서, 메서드에 넣어도 기대값을 얻을 수 있도록!
//package com.umc.yourweather.jwt;
//
//import com.umc.yourweather.domain.entity.User;
//import com.umc.yourweather.domain.enums.Platform;
//import jakarta.servlet.http.HttpServletResponse;
//import java.io.IOException;
//import org.junit.jupiter.api.BeforeEach;
//import org.junit.jupiter.api.DisplayName;
//import org.junit.jupiter.api.Test;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.test.context.SpringBootTest;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletWebRequest;
//
//import static org.junit.jupiter.api.Assertions.*;
//
//@SpringBootTest
//class JwtTokenManagerTest {
// @Autowired
// private JwtTokenManager jwtTokenManager;
// private User user;
//
// @BeforeEach
// void setUser() {
// user = User.builder()
// .email("[email protected]")
// .password("asdf")
// .nickname("ffff")
// .platform(Platform.GOOGLE)
// .build();
// }
//
// @Test
// @DisplayName("createAccessToken 테스트")
// void test1() {
// //given
// String accessToken = "";
//
// //when
// accessToken = jwtTokenManager.createAccessToken(user);
//
// //then
// System.out.println(accessToken);
// assertNotNull(accessToken);
// }
//
// @Test
// @DisplayName("createRefreshToken 테스트")
// void test2() {
// //given
// Date now = new Date();
// String token = JWT.create()
// .withSubject("AccessToken")
// .withExpiresAt(new Date(now.getTime() - tokenExpriation * 2))
// .sign(Algorithm.HMAC512(secret));
// String refreshToken = "";
//
// //when
// boolean isvalid = jwtTokenManager.isTokenValid(token);
// refreshToken = jwtTokenManager.createRefreshToken();
//
// //then
// assertEquals(isvalid, false);
}
}
// System.out.println(refreshToken);
// assertNotNull(refreshToken);
// }
//
// @Test
// @DisplayName("sendAccessTokenAndRefreshToken 테스트")
// void test3() throws IOException {
// //given
// ServletWebRequest servletContainer = (ServletWebRequest) RequestContextHolder.getRequestAttributes();
// HttpServletResponse httpServletResponse = servletContainer.getResponse();
//
// String accessToken = jwtTokenManager.createAccessToken(user);
// String refreshToken = jwtTokenManager.createRefreshToken();
//
// //when
// jwtTokenManager.sendAccessTokenAndRefreshToken(httpServletResponse, accessToken, refreshToken);
//
// //then
// System.out.println(httpServletResponse.getHeader("Authorization"));
// System.out.println(httpServletResponse.getHeader("Authorization-refresh"));
//
// assertEquals(accessToken, httpServletResponse.getHeader("Authorization"));
// assertEquals(refreshToken, httpServletResponse.getHeader("Authorization-refresh"));
// }
//
// @Test
// @DisplayName("extractToken 테스트")
// void test4() {
// //given
// String accessToken = jwtTokenManager.createAccessToken(user);
// String refreshToken = jwtTokenManager.createRefreshToken();
//
// //when
// String accessTokenFromManager = jwtTokenManager.extractToken("Bearer " + accessToken)
// .orElseGet(null);
// String refreshTokenFromManager = jwtTokenManager.extractToken("Bearer " + refreshToken)
// .orElseGet(null);
//
// //then
// System.out.println(accessTokenFromManager);
// System.out.println(refreshTokenFromManager);
//
// assertEquals(accessToken, accessTokenFromManager);
// assertEquals(refreshToken, refreshTokenFromManager);
// }
//
// @Test
// @DisplayName("isTokenValid 테스트")
// void test5() {
// // 테스트 통과!
// // 단 토큰 생성, 검증로직이 시크릿키와 토큰 만료 시간에 강하게 의존하고 있기 때문에 어느정도 이 의존성은 풀어주자.
// // 막 사용해도 상관없는 더미를 만들어서, 메서드에 넣어도 기대값을 얻을 수 있도록!
//// //given
//// Date now = new Date();
//// String token = JWT.create()
//// .withSubject("AccessToken")
//// .withExpiresAt(new Date(now.getTime() - tokenExpriation * 2))
//// .sign(Algorithm.HMAC512(secret));
////
//// //when
//// boolean isvalid = jwtTokenManager.isTokenValid(token);
////
//// //then
//// assertEquals(isvalid, false);
// }
//}
Loading

0 comments on commit 7756b06

Please sign in to comment.