From 9840178adfbaecc68f7e5623dffed2912b9c4e90 Mon Sep 17 00:00:00 2001 From: jujubebat Date: Fri, 16 Jul 2021 23:16:29 +0900 Subject: [PATCH 1/4] =?UTF-8?q?refactor:=20=EC=97=94=ED=8B=B0=ED=8B=B0=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=EC=8B=9C=20=EC=83=9D=EC=84=B1,=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20=EC=8B=9C=EA=B0=84=20=EA=B8=B0=EC=A4=80=EC=9D=84=20?= =?UTF-8?q?JST=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EnableJpaAuditingConfiguration.java | 10 ------- .../common/JpaAuditingConfiguration.java | 19 ++++++++++++ .../darass/comment/domain/CommentsTest.java | 3 +- .../common/domain/BaseTimeEntityTest.java | 30 ++++++++++--------- 4 files changed, 36 insertions(+), 26 deletions(-) delete mode 100644 backend/src/main/java/com/darass/darass/common/EnableJpaAuditingConfiguration.java create mode 100644 backend/src/main/java/com/darass/darass/common/JpaAuditingConfiguration.java diff --git a/backend/src/main/java/com/darass/darass/common/EnableJpaAuditingConfiguration.java b/backend/src/main/java/com/darass/darass/common/EnableJpaAuditingConfiguration.java deleted file mode 100644 index 95a00baa1..000000000 --- a/backend/src/main/java/com/darass/darass/common/EnableJpaAuditingConfiguration.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.darass.darass.common; - -import org.springframework.context.annotation.Configuration; -import org.springframework.data.jpa.repository.config.EnableJpaAuditing; - -@Configuration -@EnableJpaAuditing -public class EnableJpaAuditingConfiguration { - -} diff --git a/backend/src/main/java/com/darass/darass/common/JpaAuditingConfiguration.java b/backend/src/main/java/com/darass/darass/common/JpaAuditingConfiguration.java new file mode 100644 index 000000000..2ee2d0435 --- /dev/null +++ b/backend/src/main/java/com/darass/darass/common/JpaAuditingConfiguration.java @@ -0,0 +1,19 @@ +package com.darass.darass.common; + +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.Optional; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.auditing.DateTimeProvider; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; + +@Configuration +@EnableJpaAuditing(dateTimeProviderRef = "utcDateTimeProvider") +public class JpaAuditingConfiguration { + + @Bean + public DateTimeProvider utcDateTimeProvider() { + return () -> Optional.of(LocalDateTime.now(ZoneId.of("JST", ZoneId.SHORT_IDS))); + } +} \ No newline at end of file diff --git a/backend/src/test/java/com/darass/darass/comment/domain/CommentsTest.java b/backend/src/test/java/com/darass/darass/comment/domain/CommentsTest.java index be8dad0c6..0427bf584 100644 --- a/backend/src/test/java/com/darass/darass/comment/domain/CommentsTest.java +++ b/backend/src/test/java/com/darass/darass/comment/domain/CommentsTest.java @@ -3,14 +3,13 @@ import static org.assertj.core.api.Assertions.assertThat; import com.darass.darass.project.domain.Project; -import com.darass.darass.project.domain.RandomSecretKeyFactory; import com.darass.darass.project.service.CustomSecretKeyFactory; import java.util.ArrayList; import java.util.List; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -@DisplayName("") +@DisplayName("Comments 클래스") class CommentsTest { private final List commentList = new ArrayList<>(); diff --git a/backend/src/test/java/com/darass/darass/common/domain/BaseTimeEntityTest.java b/backend/src/test/java/com/darass/darass/common/domain/BaseTimeEntityTest.java index 00f26b863..f212e8613 100644 --- a/backend/src/test/java/com/darass/darass/common/domain/BaseTimeEntityTest.java +++ b/backend/src/test/java/com/darass/darass/common/domain/BaseTimeEntityTest.java @@ -3,6 +3,9 @@ import com.darass.darass.user.domain.OAuthPlatform; import com.darass.darass.user.domain.SocialLoginUser; import com.darass.darass.user.repository.SocialLoginUserRepository; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -22,25 +25,24 @@ class BaseTimeEntityTest { @Autowired SocialLoginUserRepository socialLoginUserRepository; - @DisplayName("BaseTimeEntity을 상속한 Entity는 save될 때 생성시간과, 수정시간이 자동으로 저장된다.") + @DisplayName("BaseTimeEntity을 상속한 Entity는 save될 때 생성시간과, 수정시간이 자동으로 저장된다.(JST 시간으로 저장됨)") @Test - public void saveCreatedDateAndModifiedDate() { - //given - LocalDateTime now = LocalDateTime.now(); + void saveCreatedDateAndModifiedDate() { socialLoginUserRepository.save(SocialLoginUser.builder() - .nickName("병욱") - .email("jujubebat@kakao.com") - .oauthId("241323123") - .oauthPlatform(OAuthPlatform.KAKAO) - .build()); + .nickName("병욱") + .email("jujubebat@kakao.com") + .oauthId("241323123") + .oauthPlatform(OAuthPlatform.KAKAO) + .build()); - //when List socialLoginUsers = socialLoginUserRepository.findAll(); - - //then SocialLoginUser socialLoginUser = socialLoginUsers.get(0); - assertThat(socialLoginUser.getCreatedDate()).isAfter(now); - assertThat(socialLoginUser.getModifiedDate()).isAfter(now); + + LocalDateTime currentSavedLocalDateTime = socialLoginUser.getCreatedDate(); + LocalDateTime currentJapanStandardTime = LocalDateTime.now(ZoneId.of("JST", ZoneId.SHORT_IDS)); + + assertThat(currentSavedLocalDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd-hh-mm-ss"))) + .isEqualTo(currentJapanStandardTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd-hh-mm-ss"))); } } \ No newline at end of file From 9a929d5faab4bc313c7ef2a964d53b1311e63e0d Mon Sep 17 00:00:00 2001 From: jujubebat Date: Sat, 17 Jul 2021 12:56:52 +0900 Subject: [PATCH 2/4] =?UTF-8?q?refactor:=20columnDefinition=20=EC=98=B5?= =?UTF-8?q?=EC=85=98=EC=9D=84=20=EC=82=AC=EC=9A=A9=ED=95=B4=EC=84=9C=20tim?= =?UTF-8?q?e=20zone=EC=97=90=20=EB=94=B0=EB=A5=B8=20=EC=8B=9C=EA=B0=84?= =?UTF-8?q?=EC=9D=B4=20=EC=9E=90=EB=8F=99=20=EC=A0=80=EC=9E=A5=EB=90=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../darass/common/JpaAuditingConfiguration.java | 11 +---------- .../darass/common/domain/BaseTimeEntity.java | 5 ++++- .../common/domain/BaseTimeEntityTest.java | 17 +++++++++-------- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/backend/src/main/java/com/darass/darass/common/JpaAuditingConfiguration.java b/backend/src/main/java/com/darass/darass/common/JpaAuditingConfiguration.java index 2ee2d0435..c1106f6bd 100644 --- a/backend/src/main/java/com/darass/darass/common/JpaAuditingConfiguration.java +++ b/backend/src/main/java/com/darass/darass/common/JpaAuditingConfiguration.java @@ -1,19 +1,10 @@ package com.darass.darass.common; -import java.time.LocalDateTime; -import java.time.ZoneId; -import java.util.Optional; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.data.auditing.DateTimeProvider; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; @Configuration -@EnableJpaAuditing(dateTimeProviderRef = "utcDateTimeProvider") +@EnableJpaAuditing public class JpaAuditingConfiguration { - @Bean - public DateTimeProvider utcDateTimeProvider() { - return () -> Optional.of(LocalDateTime.now(ZoneId.of("JST", ZoneId.SHORT_IDS))); - } } \ No newline at end of file diff --git a/backend/src/main/java/com/darass/darass/common/domain/BaseTimeEntity.java b/backend/src/main/java/com/darass/darass/common/domain/BaseTimeEntity.java index 1d16cba5f..27f28c6ee 100644 --- a/backend/src/main/java/com/darass/darass/common/domain/BaseTimeEntity.java +++ b/backend/src/main/java/com/darass/darass/common/domain/BaseTimeEntity.java @@ -1,5 +1,6 @@ package com.darass.darass.common.domain; +import javax.persistence.Column; import lombok.Getter; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; @@ -15,9 +16,11 @@ public abstract class BaseTimeEntity { @CreatedDate + @Column(columnDefinition = "TIMESTAMP") private LocalDateTime createdDate; - @LastModifiedDate + @LastModifiedDate() + @Column(columnDefinition = "TIMESTAMP") private LocalDateTime modifiedDate; } diff --git a/backend/src/test/java/com/darass/darass/common/domain/BaseTimeEntityTest.java b/backend/src/test/java/com/darass/darass/common/domain/BaseTimeEntityTest.java index f212e8613..985ae9162 100644 --- a/backend/src/test/java/com/darass/darass/common/domain/BaseTimeEntityTest.java +++ b/backend/src/test/java/com/darass/darass/common/domain/BaseTimeEntityTest.java @@ -25,9 +25,11 @@ class BaseTimeEntityTest { @Autowired SocialLoginUserRepository socialLoginUserRepository; - @DisplayName("BaseTimeEntity을 상속한 Entity는 save될 때 생성시간과, 수정시간이 자동으로 저장된다.(JST 시간으로 저장됨)") + @DisplayName("BaseTimeEntity을 상속한 Entity는 save될 때 생성시간과, 수정시간이 자동으로 저장된다.") @Test - void saveCreatedDateAndModifiedDate() { + public void saveCreatedDateAndModifiedDate() { + //given + LocalDateTime now = LocalDateTime.now(); socialLoginUserRepository.save(SocialLoginUser.builder() .nickName("병욱") .email("jujubebat@kakao.com") @@ -35,14 +37,13 @@ void saveCreatedDateAndModifiedDate() { .oauthPlatform(OAuthPlatform.KAKAO) .build()); + //when List socialLoginUsers = socialLoginUserRepository.findAll(); - SocialLoginUser socialLoginUser = socialLoginUsers.get(0); - - LocalDateTime currentSavedLocalDateTime = socialLoginUser.getCreatedDate(); - LocalDateTime currentJapanStandardTime = LocalDateTime.now(ZoneId.of("JST", ZoneId.SHORT_IDS)); - assertThat(currentSavedLocalDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd-hh-mm-ss"))) - .isEqualTo(currentJapanStandardTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd-hh-mm-ss"))); + //then + SocialLoginUser socialLoginUser = socialLoginUsers.get(0); + assertThat(socialLoginUser.getCreatedDate()).isAfter(now); + assertThat(socialLoginUser.getModifiedDate()).isAfter(now); } } \ No newline at end of file From 433d308cd21e907e00bdef291e30def03adbada4 Mon Sep 17 00:00:00 2001 From: jujubebat Date: Sat, 17 Jul 2021 23:11:47 +0900 Subject: [PATCH 3/4] =?UTF-8?q?refactor:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EA=B4=84=ED=98=B8=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/darass/darass/common/domain/BaseTimeEntity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/com/darass/darass/common/domain/BaseTimeEntity.java b/backend/src/main/java/com/darass/darass/common/domain/BaseTimeEntity.java index 27f28c6ee..73bc65145 100644 --- a/backend/src/main/java/com/darass/darass/common/domain/BaseTimeEntity.java +++ b/backend/src/main/java/com/darass/darass/common/domain/BaseTimeEntity.java @@ -19,7 +19,7 @@ public abstract class BaseTimeEntity { @Column(columnDefinition = "TIMESTAMP") private LocalDateTime createdDate; - @LastModifiedDate() + @LastModifiedDate @Column(columnDefinition = "TIMESTAMP") private LocalDateTime modifiedDate; From eb80827bd78e43d7ef17f9d6d360878f1ed22c47 Mon Sep 17 00:00:00 2001 From: jujubebat Date: Sat, 17 Jul 2021 23:17:22 +0900 Subject: [PATCH 4/4] =?UTF-8?q?refactor:=20=EC=97=AC=EB=9F=AC=20=EC=A2=85?= =?UTF-8?q?=EB=A5=98=EC=9D=98=20=EC=9D=B8=EC=A6=9D=20=ED=83=80=EC=9E=85=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=EA=B0=80=20=EB=8B=B4=EA=B2=A8=EC=9E=88?= =?UTF-8?q?=EB=8A=94=20=ED=97=A4=EB=8D=94=EA=B0=80=20=EC=A3=BC=EC=96=B4?= =?UTF-8?q?=EC=A7=88=20=EA=B2=BD=EC=9A=B0=EB=A5=BC=20=EA=B3=A0=EB=A0=A4?= =?UTF-8?q?=ED=95=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AuthorizationExtractorTest.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/backend/src/test/java/com/darass/darass/auth/oauth/infrastructure/AuthorizationExtractorTest.java b/backend/src/test/java/com/darass/darass/auth/oauth/infrastructure/AuthorizationExtractorTest.java index 0f28a1c02..1bc55f987 100644 --- a/backend/src/test/java/com/darass/darass/auth/oauth/infrastructure/AuthorizationExtractorTest.java +++ b/backend/src/test/java/com/darass/darass/auth/oauth/infrastructure/AuthorizationExtractorTest.java @@ -2,6 +2,7 @@ import static org.assertj.core.api.Assertions.assertThat; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.mock.web.MockHttpServletRequest; @@ -10,13 +11,21 @@ class AuthorizationExtractorTest { private final MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest(); - private final String tokenType = "Bearer "; + private final String basicAuthType = "Basic "; + private final String bearerAuthType = "Bearer "; + private final String mutualAuthType = "Mutual "; private final String accessToken = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIiwiaWF0IjoxNjI2NTI2MzI3LCJleHAiOjE2MjY1MzE1MTF9.ByMJIr0G2gLcQs_7N6lLpEWAqWXq4CYdEe-QUfMjWI0"; + @BeforeEach + void setUp(){ + mockHttpServletRequest.addHeader("authorization", mutualAuthType + accessToken); + mockHttpServletRequest.addHeader("authorization", basicAuthType + accessToken); + } + @DisplayName("extract 메서드는 Bearer 타입 토큰 정보가 담긴 Authorization 헤더를 가지는 httpServletRequest가 주어진다면, 엑세스 토큰을 파싱헤서 반환한다.") @Test void extract_success1() { - mockHttpServletRequest.addHeader("Authorization", tokenType + accessToken); + mockHttpServletRequest.addHeader("authorization", bearerAuthType + accessToken); AuthorizationExtractor authorizationExtractor = new AuthorizationExtractor(); assertThat(authorizationExtractor.extract(mockHttpServletRequest)).isEqualTo(accessToken); @@ -25,7 +34,7 @@ void extract_success1() { @DisplayName("extract 메서드는 엑세스 토큰 뒤에 추가 정보가 콤마를 기준으로 붙어 있는 Authorization 헤더를 가지는 httpServletRequest가 주어진다면, 엑세스 토큰을 파싱헤서 반환한다.") @Test void extract_success2() { - mockHttpServletRequest.addHeader("Authorization", tokenType + accessToken + ", Basic YXNkZnNhZGZzYWRmOlZLdDVOMVhk"); + mockHttpServletRequest.addHeader("authorization", bearerAuthType + accessToken + ", Basic YXNkZnNhZGZzYWRmOlZLdDVOMVhk"); AuthorizationExtractor authorizationExtractor = new AuthorizationExtractor(); assertThat(authorizationExtractor.extract(mockHttpServletRequest)).isEqualTo(accessToken);