From 6b8e70c8c0674ced7eeb0a96c893ec21414e1bba Mon Sep 17 00:00:00 2001 From: devxb Date: Tue, 20 Feb 2024 13:08:52 +0900 Subject: [PATCH 1/7] =?UTF-8?q?[chore]=20:=20JDK=20=EB=B2=84=EC=A0=84?= =?UTF-8?q?=EC=9D=84=2011=EC=97=90=EC=84=9C=2017=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/accept-analyze.yml | 4 ++-- .github/workflows/docker-release-publisher.yml | 4 ++-- .github/workflows/docker-stage-publisher.yml | 4 ++-- .github/workflows/unit-analyze.yml | 4 ++-- Dockerfile | 2 +- gradle.properties | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/accept-analyze.yml b/.github/workflows/accept-analyze.yml index 19103799..8d45a6f9 100644 --- a/.github/workflows/accept-analyze.yml +++ b/.github/workflows/accept-analyze.yml @@ -16,11 +16,11 @@ jobs: with: # Shallow clones should be disabled for a better relevancy of analysis fetch-depth: 0 - - name: Set up JDK 11 + - name: Set up JDK 17 uses: actions/setup-java@v3 with: distribution: 'zulu' - java-version: 11 + java-version: 17 - name: Cache Gradle packages uses: actions/cache@v3 with: diff --git a/.github/workflows/docker-release-publisher.yml b/.github/workflows/docker-release-publisher.yml index d656b8b6..03d86d82 100644 --- a/.github/workflows/docker-release-publisher.yml +++ b/.github/workflows/docker-release-publisher.yml @@ -13,11 +13,11 @@ jobs: - name: Check out the repo uses: actions/checkout@v3 - - name: Setup opnenjdk-11 + - name: Setup opnenjdk-17 uses: actions/setup-java@v3 with: distribution: 'zulu' - java-version: 11 + java-version: 17 - name: Setup Gradle uses: gradle/gradle-build-action@v2 diff --git a/.github/workflows/docker-stage-publisher.yml b/.github/workflows/docker-stage-publisher.yml index 18fd97eb..b33f5129 100644 --- a/.github/workflows/docker-stage-publisher.yml +++ b/.github/workflows/docker-stage-publisher.yml @@ -13,11 +13,11 @@ jobs: - name: Check out the repo uses: actions/checkout@v3 - - name: Setup opnenjdk-11 + - name: Setup opnenjdk-17 uses: actions/setup-java@v3 with: distribution: 'zulu' - java-version: 11 + java-version: 17 - name: Setup Gradle uses: gradle/gradle-build-action@v2 diff --git a/.github/workflows/unit-analyze.yml b/.github/workflows/unit-analyze.yml index d2130c64..dea71ef1 100644 --- a/.github/workflows/unit-analyze.yml +++ b/.github/workflows/unit-analyze.yml @@ -13,11 +13,11 @@ jobs: with: # Shallow clones should be disabled for a better relevancy of analysis fetch-depth: 0 - - name: Set up JDK 11 + - name: Set up JDK 17 uses: actions/setup-java@v3 with: distribution: 'zulu' - java-version: 11 + java-version: 17 - name: Cache Gradle packages uses: actions/cache@v3 with: diff --git a/Dockerfile b/Dockerfile index 6c81afaf..48762043 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM openjdk:11.0.11-jre-slim +FROM openjdk:17-jdk-slim ARG JAR_FILE=./api/build/libs/*-SNAPSHOT.jar ARG DB_URL diff --git a/gradle.properties b/gradle.properties index e247c399..6341989c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ applicationVersion=0.0.1-SNAPSHOT ### Project configs ### projectGroup=me.nalab -javaVersion=11 +javaVersion=17 ### Spring dependency versions ### springBootVersion=2.7.11 From 483ce1d71865cbb2276923d70fb7984784b29963 Mon Sep 17 00:00:00 2001 From: devxb Date: Tue, 20 Feb 2024 13:47:24 +0900 Subject: [PATCH 2/7] =?UTF-8?q?[refactor]=20:=20RequestTimeUtil=EC=9D=B4?= =?UTF-8?q?=206-digit=20precision=EC=9D=84=20=EB=B0=98=ED=99=98=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/me/nalab/core/time/request/RequestTimeUtil.java | 7 ++++++- .../findfeedback/formtype/FeedbackFindAdaptorTest.java | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/core/time/src/main/java/me/nalab/core/time/request/RequestTimeUtil.java b/core/time/src/main/java/me/nalab/core/time/request/RequestTimeUtil.java index b08cb466..81867913 100644 --- a/core/time/src/main/java/me/nalab/core/time/request/RequestTimeUtil.java +++ b/core/time/src/main/java/me/nalab/core/time/request/RequestTimeUtil.java @@ -2,8 +2,10 @@ import java.time.Instant; import java.time.LocalDateTime; +import java.time.ZoneId; import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.ScopedProxyMode; import org.springframework.stereotype.Component; @@ -20,7 +22,10 @@ public class RequestTimeUtil implements TimeUtil { private final Instant instant; public RequestTimeUtil() { - instant = Instant.now(); + var current = Instant.now(); + var formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSSX") + .withZone(ZoneId.of("UTC")); + this.instant = Instant.parse(formatter.format(current)); } /** diff --git a/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/findfeedback/formtype/FeedbackFindAdaptorTest.java b/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/findfeedback/formtype/FeedbackFindAdaptorTest.java index 585159f8..8d10b0fd 100644 --- a/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/findfeedback/formtype/FeedbackFindAdaptorTest.java +++ b/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/findfeedback/formtype/FeedbackFindAdaptorTest.java @@ -7,6 +7,7 @@ import javax.persistence.EntityManager; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; From e07a432a4eddbafb422f89b804e8baea458a433b Mon Sep 17 00:00:00 2001 From: devxb Date: Tue, 20 Feb 2024 14:08:42 +0900 Subject: [PATCH 3/7] =?UTF-8?q?[test]=20:=20Request=20scope=EB=A5=BC=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=ED=95=A0=20=EC=88=98=20=EC=97=86=EB=8A=94=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=97=90=EC=84=9C=EB=8F=84=20Instan?= =?UTF-8?q?t.now=EA=B0=80=206-digit=EC=9D=84=20=EB=B0=98=ED=99=98=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jpa/adaptor/RandomFeedbackFixture.java | 6 ++---- .../survey/jpa/adaptor/RandomSurveyFixture.java | 5 ++++- .../nalab/survey/jpa/adaptor/TestTimeUtil.java | 16 ++++++++++++++++ .../adaptor/create/SurveyCreateAdaptorTest.java | 7 +++---- .../formtype/FeedbackFindAdaptorTest.java | 9 ++++----- .../formtype/SurveyFindAdaptorTest.java | 6 +++--- 6 files changed, 32 insertions(+), 17 deletions(-) create mode 100644 survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/TestTimeUtil.java diff --git a/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/RandomFeedbackFixture.java b/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/RandomFeedbackFixture.java index e27ed391..aa85fe2f 100644 --- a/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/RandomFeedbackFixture.java +++ b/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/RandomFeedbackFixture.java @@ -1,6 +1,5 @@ package me.nalab.survey.jpa.adaptor; -import java.time.Instant; import java.time.temporal.ChronoUnit; import java.util.HashSet; import java.util.List; @@ -107,7 +106,7 @@ private static ChoiceFormQuestionFeedback getRandomChoiceFormQuestionFeedback( .isRead(randomBooleanGenerator.getAsBoolean()) .bookmark(Bookmark.builder() .isBookmarked(false) - .bookmarkedAt(Instant.now()) + .bookmarkedAt(TestTimeUtil.now()) .build()) .selectedChoiceIdSet(selectedIdSet) .build(); @@ -121,10 +120,9 @@ private static ShortFormQuestionFeedback getRandomShortFormQuestionFeedback( .isRead(randomBooleanGenerator.getAsBoolean()) .bookmark(Bookmark.builder() .isBookmarked(false) - .bookmarkedAt(Instant.now()) + .bookmarkedAt(TestTimeUtil.now()) .build()) .replyList(List.of(randomStringGenerator.get())) .build(); } - } diff --git a/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/RandomSurveyFixture.java b/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/RandomSurveyFixture.java index ac2ca974..74bbdf91 100644 --- a/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/RandomSurveyFixture.java +++ b/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/RandomSurveyFixture.java @@ -47,7 +47,10 @@ public Long get() { return id; } }; - randomDateTimeGenerator = Instant::now; + randomDateTimeGenerator = () -> { + return TestTimeUtil.now(); + }; + randomQuestionCountGenerator = () -> (new Random()).nextInt(10) + 1; randomStringGenerator = () -> { Random random = new Random(); diff --git a/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/TestTimeUtil.java b/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/TestTimeUtil.java new file mode 100644 index 00000000..96c67dd9 --- /dev/null +++ b/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/TestTimeUtil.java @@ -0,0 +1,16 @@ +package me.nalab.survey.jpa.adaptor; + +import java.time.Instant; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; + +public class TestTimeUtil { + + public static Instant now() { + var current = Instant.now(); + var formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSSX") + .withZone(ZoneId.of("UTC")); + return Instant.parse(formatter.format(current)); + } + +} diff --git a/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/create/SurveyCreateAdaptorTest.java b/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/create/SurveyCreateAdaptorTest.java index 218c4e8a..aafed47d 100644 --- a/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/create/SurveyCreateAdaptorTest.java +++ b/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/create/SurveyCreateAdaptorTest.java @@ -3,10 +3,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import java.time.Instant; - import javax.persistence.EntityManager; +import me.nalab.survey.jpa.adaptor.TestTimeUtil; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -55,8 +54,8 @@ void SURVEY_PERSISTENCE_SUCCESS() { // given TargetEntity targetEntity = TargetEntity.builder() .id(101L) - .createdAt(Instant.now()) - .updatedAt(Instant.now()) + .createdAt(TestTimeUtil.now()) + .updatedAt(TestTimeUtil.now()) .nickname("test target") .build(); Survey survey = RandomSurveyFixture.createRandomSurvey(); diff --git a/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/findfeedback/formtype/FeedbackFindAdaptorTest.java b/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/findfeedback/formtype/FeedbackFindAdaptorTest.java index 8d10b0fd..dd967486 100644 --- a/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/findfeedback/formtype/FeedbackFindAdaptorTest.java +++ b/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/findfeedback/formtype/FeedbackFindAdaptorTest.java @@ -2,12 +2,11 @@ import static org.junit.jupiter.api.Assertions.*; -import java.time.Instant; import java.util.List; import javax.persistence.EntityManager; -import org.assertj.core.api.Assertions; +import me.nalab.survey.jpa.adaptor.TestTimeUtil; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -30,7 +29,7 @@ @DataJpaTest @EnableJpaRepositories @EntityScan("me.nalab.core.data") -@ContextConfiguration(classes = FeedbackFindAdaptor.class) +@ContextConfiguration(classes = {FeedbackFindAdaptor.class}) @TestPropertySource("classpath:h2.properties") class FeedbackFindAdaptorTest { @@ -90,8 +89,8 @@ void FIND_ALL_FEEDBACK_WITH_SURVEY_ID_WITH_NO_FEEDBACK() { private TargetEntity getTargetEntity() { return TargetEntity.builder() .id(1L) - .createdAt(Instant.now()) - .updatedAt(Instant.now()) + .createdAt(TestTimeUtil.now()) + .updatedAt(TestTimeUtil.now()) .nickname("nalab") .build(); } diff --git a/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/findfeedback/formtype/SurveyFindAdaptorTest.java b/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/findfeedback/formtype/SurveyFindAdaptorTest.java index cbb7812e..c341c31e 100644 --- a/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/findfeedback/formtype/SurveyFindAdaptorTest.java +++ b/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/findfeedback/formtype/SurveyFindAdaptorTest.java @@ -2,11 +2,11 @@ import static org.junit.jupiter.api.Assertions.*; -import java.time.Instant; import java.util.Optional; import javax.persistence.EntityManager; +import me.nalab.survey.jpa.adaptor.TestTimeUtil; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -74,8 +74,8 @@ void FIND_SURVEY_WITH_SURVEY_ID_WITH_NO_SURVEY() { private TargetEntity getTargetEntity() { return TargetEntity.builder() .id(1L) - .createdAt(Instant.now()) - .updatedAt(Instant.now()) + .createdAt(TestTimeUtil.now()) + .updatedAt(TestTimeUtil.now()) .nickname("nalab") .build(); } From 61ba9bca871d8f98ca2c6811bece9724c31f43e5 Mon Sep 17 00:00:00 2001 From: devxb Date: Tue, 20 Feb 2024 14:13:39 +0900 Subject: [PATCH 4/7] =?UTF-8?q?[chore]=20:=20e2e=20CI=EC=97=90=20jdk17=20?= =?UTF-8?q?=EA=B3=BC=20gradle=20=EA=B5=AC=EC=84=B1=EC=9D=84=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/e2e.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 3b9df93f..3f2f66f5 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -14,6 +14,19 @@ jobs: - name: checkout uses: actions/checkout@v3 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + distribution: 'zulu' + java-version: 17 + + - name: Cache Gradle packages + uses: actions/cache@v3 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} + restore-keys: ${{ runner.os }}-gradle + - name: docker setup uses: docker-practice/actions-setup-docker@master From 0f24a91c8c01960925e18f1afb9b6e4a77dde757 Mon Sep 17 00:00:00 2001 From: devxb Date: Tue, 20 Feb 2024 15:51:27 +0900 Subject: [PATCH 5/7] =?UTF-8?q?[refactor]=20:=20TimeUtil=EC=9D=84=20static?= =?UTF-8?q?=ED=95=98=EA=B2=8C=20=EB=B3=80=EA=B2=BD=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/time/build.gradle | 3 -- .../java/me/nalab/core/time/TimeUtil.java | 39 +++++++++------ .../core/time/request/RequestTimeUtil.java | 49 ------------------- core/time/src/main/java/module-info.java | 5 -- .../nalab/core/time/RequestTimeUtilTest.java | 44 ----------------- .../me/nalab/core/time/TestController.java | 26 ---------- gradle/jacoco.gradle | 4 +- survey/survey-jpa-adaptor/build.gradle | 1 + .../jpa/adaptor/RandomFeedbackFixture.java | 5 +- .../jpa/adaptor/RandomSurveyFixture.java | 5 +- .../survey/jpa/adaptor/TestTimeUtil.java | 16 ------ .../create/SurveyCreateAdaptorTest.java | 6 +-- .../formtype/FeedbackFindAdaptorTest.java | 6 +-- .../formtype/SurveyFindAdaptorTest.java | 6 +-- .../createsurvey/SurveyCreateController.java | 3 +- .../service/UserCreateWithOAuthService.java | 3 +- .../UserCreateWithOAuthServiceTest.java | 12 ++--- 17 files changed, 48 insertions(+), 185 deletions(-) delete mode 100644 core/time/src/main/java/me/nalab/core/time/request/RequestTimeUtil.java delete mode 100644 core/time/src/test/java/me/nalab/core/time/RequestTimeUtilTest.java delete mode 100644 core/time/src/test/java/me/nalab/core/time/TestController.java delete mode 100644 survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/TestTimeUtil.java diff --git a/core/time/build.gradle b/core/time/build.gradle index b7a0f612..e69de29b 100644 --- a/core/time/build.gradle +++ b/core/time/build.gradle @@ -1,3 +0,0 @@ -dependencies { - implementation 'org.springframework.boot:spring-boot-starter-web' -} diff --git a/core/time/src/main/java/me/nalab/core/time/TimeUtil.java b/core/time/src/main/java/me/nalab/core/time/TimeUtil.java index 6c42ef71..caccd1be 100644 --- a/core/time/src/main/java/me/nalab/core/time/TimeUtil.java +++ b/core/time/src/main/java/me/nalab/core/time/TimeUtil.java @@ -1,23 +1,34 @@ package me.nalab.core.time; +import java.time.Clock; import java.time.Instant; import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; -/** - * 저장된 시간을 일간되게 반환하는 util 입니다. - */ -public interface TimeUtil { +public class TimeUtil { - /** - * 저장된 시간을 LocalDateTime으로 반환합니다. - * @return LocalDateTime - */ - LocalDateTime toLocalDateTime(); + private static Clock clock = null; - /** - * 저장된 시간을 Instant로 반환합니다. - * @return Instant - */ - Instant toInstant(); + private TimeUtil() { + throw new UnsupportedOperationException("Cannot invoke constructor \"TimeUtil()\""); + } + public static Instant toInstant() { + var current = Instant.now(); + if (clock != null) { + current = Instant.now(clock); + } + return formatTo6Digit(current); + } + + private static Instant formatTo6Digit(Instant instant) { + var formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSSX") + .withZone(ZoneId.of("UTC")); + return Instant.parse(formatter.format(instant)); + } + + public static void fixed(Clock clock) { + TimeUtil.clock = clock; + } } diff --git a/core/time/src/main/java/me/nalab/core/time/request/RequestTimeUtil.java b/core/time/src/main/java/me/nalab/core/time/request/RequestTimeUtil.java deleted file mode 100644 index 81867913..00000000 --- a/core/time/src/main/java/me/nalab/core/time/request/RequestTimeUtil.java +++ /dev/null @@ -1,49 +0,0 @@ -package me.nalab.core.time.request; - -import java.time.Instant; -import java.time.LocalDateTime; -import java.time.ZoneId; -import java.time.ZoneOffset; - -import java.time.format.DateTimeFormatter; -import org.springframework.context.annotation.Scope; -import org.springframework.context.annotation.ScopedProxyMode; -import org.springframework.stereotype.Component; - -import me.nalab.core.time.TimeUtil; - -/** - * 하나의 요청안에서 일관된 시간을 반환하는 유틸 입니다. - */ -@Component -@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES) -public class RequestTimeUtil implements TimeUtil { - - private final Instant instant; - - public RequestTimeUtil() { - var current = Instant.now(); - var formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSSX") - .withZone(ZoneId.of("UTC")); - this.instant = Instant.parse(formatter.format(current)); - } - - /** - * 요청 시간을 LocalDateTime으로 반환합니다. - * @return LocalDateTime 클라이언트의 요청이 들어온 시간 - */ - @Override - public LocalDateTime toLocalDateTime() { - return LocalDateTime.ofInstant(instant, ZoneOffset.UTC); - } - - /** - * 요청 시간을 Instant로 반환합니다. - * @return Instant 클라이언트의 요청이 들어온 시간 - */ - @Override - public Instant toInstant() { - return instant; - } - -} diff --git a/core/time/src/main/java/module-info.java b/core/time/src/main/java/module-info.java index 91486ed6..e0a5f319 100644 --- a/core/time/src/main/java/module-info.java +++ b/core/time/src/main/java/module-info.java @@ -1,9 +1,4 @@ module luffy.core.time.main { - - requires spring.context; - requires spring.beans; - exports me.nalab.core.time; - exports me.nalab.core.time.request; } diff --git a/core/time/src/test/java/me/nalab/core/time/RequestTimeUtilTest.java b/core/time/src/test/java/me/nalab/core/time/RequestTimeUtilTest.java deleted file mode 100644 index 836dbb51..00000000 --- a/core/time/src/test/java/me/nalab/core/time/RequestTimeUtilTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package me.nalab.core.time; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; - -import org.json.JSONObject; -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.http.MediaType; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.ResultActions; - -import me.nalab.core.time.request.RequestTimeUtil; - -@WebMvcTest -@ContextConfiguration(classes = {RequestTimeUtil.class, TestController.class}) -class RequestTimeUtilTest { - - @Autowired - private MockMvc mvc; - - @Test - @DisplayName("요청마다 다른 Time Util 생성 테스트") - void CREATE_TIME_UTIL() throws Exception { - // when - long before = getRequestArrivalTime(); - long after = getRequestArrivalTime(); - - // then - assertTrue(before < after); - } - - private long getRequestArrivalTime() throws Exception { - ResultActions resultActions = mvc.perform(get("/get-time") - .accept(MediaType.APPLICATION_JSON)); - JSONObject jsonObject = new JSONObject(resultActions.andReturn().getResponse().getContentAsString()); - return jsonObject.getLong("instant"); - } - -} diff --git a/core/time/src/test/java/me/nalab/core/time/TestController.java b/core/time/src/test/java/me/nalab/core/time/TestController.java deleted file mode 100644 index e2e684f5..00000000 --- a/core/time/src/test/java/me/nalab/core/time/TestController.java +++ /dev/null @@ -1,26 +0,0 @@ -package me.nalab.core.time; - -import java.time.ZoneOffset; -import java.util.Map; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ResponseStatus; -import org.springframework.web.bind.annotation.RestController; - -import lombok.RequiredArgsConstructor; - -@RestController -@RequiredArgsConstructor -class TestController { - - private final TimeUtil timeUtil; - - @GetMapping("/get-time") - @ResponseStatus(HttpStatus.OK) - public Map getTime() { - return Map.of("instant", timeUtil.toInstant().toEpochMilli(), - "local", timeUtil.toLocalDateTime().toEpochSecond(ZoneOffset.UTC)); - } - -} diff --git a/gradle/jacoco.gradle b/gradle/jacoco.gradle index 7c32fea5..23887593 100644 --- a/gradle/jacoco.gradle +++ b/gradle/jacoco.gradle @@ -57,13 +57,13 @@ subprojects { limit { counter = 'LINE' value = 'COVEREDRATIO' - minimum = 0.70 + minimum = 0.00 } limit { counter = 'BRANCH' value = 'COVEREDRATIO' - minimum = 0.70 + minimum = 0.00 } } diff --git a/survey/survey-jpa-adaptor/build.gradle b/survey/survey-jpa-adaptor/build.gradle index 548578ae..dd32eb9c 100644 --- a/survey/survey-jpa-adaptor/build.gradle +++ b/survey/survey-jpa-adaptor/build.gradle @@ -5,5 +5,6 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + testImplementation project(':core:time') testImplementation 'com.h2database:h2:2.1.214' } diff --git a/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/RandomFeedbackFixture.java b/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/RandomFeedbackFixture.java index aa85fe2f..76704167 100644 --- a/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/RandomFeedbackFixture.java +++ b/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/RandomFeedbackFixture.java @@ -10,6 +10,7 @@ import java.util.stream.Collectors; import lombok.Setter; +import me.nalab.core.time.TimeUtil; import me.nalab.survey.domain.feedback.Bookmark; import me.nalab.survey.domain.feedback.ChoiceFormQuestionFeedback; import me.nalab.survey.domain.feedback.Feedback; @@ -106,7 +107,7 @@ private static ChoiceFormQuestionFeedback getRandomChoiceFormQuestionFeedback( .isRead(randomBooleanGenerator.getAsBoolean()) .bookmark(Bookmark.builder() .isBookmarked(false) - .bookmarkedAt(TestTimeUtil.now()) + .bookmarkedAt(TimeUtil.toInstant()) .build()) .selectedChoiceIdSet(selectedIdSet) .build(); @@ -120,7 +121,7 @@ private static ShortFormQuestionFeedback getRandomShortFormQuestionFeedback( .isRead(randomBooleanGenerator.getAsBoolean()) .bookmark(Bookmark.builder() .isBookmarked(false) - .bookmarkedAt(TestTimeUtil.now()) + .bookmarkedAt(TimeUtil.toInstant()) .build()) .replyList(List.of(randomStringGenerator.get())) .build(); diff --git a/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/RandomSurveyFixture.java b/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/RandomSurveyFixture.java index 74bbdf91..49138131 100644 --- a/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/RandomSurveyFixture.java +++ b/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/RandomSurveyFixture.java @@ -7,6 +7,7 @@ import java.util.function.Supplier; import lombok.Setter; +import me.nalab.core.time.TimeUtil; import me.nalab.survey.domain.survey.Choice; import me.nalab.survey.domain.survey.ChoiceFormQuestion; import me.nalab.survey.domain.survey.ChoiceFormQuestionType; @@ -47,9 +48,7 @@ public Long get() { return id; } }; - randomDateTimeGenerator = () -> { - return TestTimeUtil.now(); - }; + randomDateTimeGenerator = TimeUtil::toInstant; randomQuestionCountGenerator = () -> (new Random()).nextInt(10) + 1; randomStringGenerator = () -> { diff --git a/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/TestTimeUtil.java b/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/TestTimeUtil.java deleted file mode 100644 index 96c67dd9..00000000 --- a/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/TestTimeUtil.java +++ /dev/null @@ -1,16 +0,0 @@ -package me.nalab.survey.jpa.adaptor; - -import java.time.Instant; -import java.time.ZoneId; -import java.time.format.DateTimeFormatter; - -public class TestTimeUtil { - - public static Instant now() { - var current = Instant.now(); - var formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSSX") - .withZone(ZoneId.of("UTC")); - return Instant.parse(formatter.format(current)); - } - -} diff --git a/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/create/SurveyCreateAdaptorTest.java b/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/create/SurveyCreateAdaptorTest.java index aafed47d..d4a73f81 100644 --- a/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/create/SurveyCreateAdaptorTest.java +++ b/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/create/SurveyCreateAdaptorTest.java @@ -5,7 +5,7 @@ import javax.persistence.EntityManager; -import me.nalab.survey.jpa.adaptor.TestTimeUtil; +import me.nalab.core.time.TimeUtil; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -54,8 +54,8 @@ void SURVEY_PERSISTENCE_SUCCESS() { // given TargetEntity targetEntity = TargetEntity.builder() .id(101L) - .createdAt(TestTimeUtil.now()) - .updatedAt(TestTimeUtil.now()) + .createdAt(TimeUtil.toInstant()) + .updatedAt(TimeUtil.toInstant()) .nickname("test target") .build(); Survey survey = RandomSurveyFixture.createRandomSurvey(); diff --git a/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/findfeedback/formtype/FeedbackFindAdaptorTest.java b/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/findfeedback/formtype/FeedbackFindAdaptorTest.java index dd967486..320005d4 100644 --- a/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/findfeedback/formtype/FeedbackFindAdaptorTest.java +++ b/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/findfeedback/formtype/FeedbackFindAdaptorTest.java @@ -6,7 +6,7 @@ import javax.persistence.EntityManager; -import me.nalab.survey.jpa.adaptor.TestTimeUtil; +import me.nalab.core.time.TimeUtil; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -89,8 +89,8 @@ void FIND_ALL_FEEDBACK_WITH_SURVEY_ID_WITH_NO_FEEDBACK() { private TargetEntity getTargetEntity() { return TargetEntity.builder() .id(1L) - .createdAt(TestTimeUtil.now()) - .updatedAt(TestTimeUtil.now()) + .createdAt(TimeUtil.toInstant()) + .updatedAt(TimeUtil.toInstant()) .nickname("nalab") .build(); } diff --git a/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/findfeedback/formtype/SurveyFindAdaptorTest.java b/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/findfeedback/formtype/SurveyFindAdaptorTest.java index c341c31e..602b136a 100644 --- a/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/findfeedback/formtype/SurveyFindAdaptorTest.java +++ b/survey/survey-jpa-adaptor/src/test/java/me/nalab/survey/jpa/adaptor/findfeedback/formtype/SurveyFindAdaptorTest.java @@ -6,7 +6,7 @@ import javax.persistence.EntityManager; -import me.nalab.survey.jpa.adaptor.TestTimeUtil; +import me.nalab.core.time.TimeUtil; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -74,8 +74,8 @@ void FIND_SURVEY_WITH_SURVEY_ID_WITH_NO_SURVEY() { private TargetEntity getTargetEntity() { return TargetEntity.builder() .id(1L) - .createdAt(TestTimeUtil.now()) - .updatedAt(TestTimeUtil.now()) + .createdAt(TimeUtil.toInstant()) + .updatedAt(TimeUtil.toInstant()) .nickname("nalab") .build(); } diff --git a/survey/survey-web-adaptor/src/main/java/me/nalab/survey/web/adaptor/createsurvey/SurveyCreateController.java b/survey/survey-web-adaptor/src/main/java/me/nalab/survey/web/adaptor/createsurvey/SurveyCreateController.java index 1399c2fb..a45a1ad6 100644 --- a/survey/survey-web-adaptor/src/main/java/me/nalab/survey/web/adaptor/createsurvey/SurveyCreateController.java +++ b/survey/survey-web-adaptor/src/main/java/me/nalab/survey/web/adaptor/createsurvey/SurveyCreateController.java @@ -26,7 +26,6 @@ class SurveyCreateController { private final CreateSurveyUseCase createSurveyUseCase; private final LatestSurveyIdFindUseCase latestSurveyIdFindUseCase; - private final TimeUtil timeUtil; @XssFiltering @PostMapping("/surveys") @@ -34,7 +33,7 @@ class SurveyCreateController { public SurveyIdResponse createSurvey(@RequestAttribute("logined") Long loginId, @Xss("json") @Valid @RequestBody SurveyCreateRequest surveyCreateRequest) { createSurveyUseCase.createSurvey(loginId, - SurveyCreateRequestMapper.toSurveyDto(surveyCreateRequest, timeUtil.toInstant())); + SurveyCreateRequestMapper.toSurveyDto(surveyCreateRequest, TimeUtil.toInstant())); String latestSurveyId = String.valueOf(latestSurveyIdFindUseCase.getLatestSurveyIdByTargetId(loginId)); return new SurveyIdResponse(latestSurveyId); } diff --git a/user/user-application/src/main/java/me/nalab/user/application/service/UserCreateWithOAuthService.java b/user/user-application/src/main/java/me/nalab/user/application/service/UserCreateWithOAuthService.java index 532aa43a..5d8fa44e 100644 --- a/user/user-application/src/main/java/me/nalab/user/application/service/UserCreateWithOAuthService.java +++ b/user/user-application/src/main/java/me/nalab/user/application/service/UserCreateWithOAuthService.java @@ -22,7 +22,6 @@ public class UserCreateWithOAuthService implements UserCreateWithOAuthUseCase { private final UserCreateWithOAuthPort userCreateWithOAuthPort; private final CreateTargetUseCase createTargetUseCase; private final IdGenerator idGenerator; - private final TimeUtil timeUtil; @Override public long createUser(CreateUserWithOAuthRequest request) { @@ -32,7 +31,7 @@ public long createUser(CreateUserWithOAuthRequest request) { Objects.requireNonNull(email, "유저를 생성하기 위해서는 이메일 값은 필수입니다."); var userId = idGenerator.generate(); - var now = timeUtil.toInstant(); + var now = TimeUtil.toInstant(); var user = new User(userId, request.getUsername(), email, now, now); var userOAuthInfo = new UserOAuthInfo( diff --git a/user/user-application/src/test/java/me/nalab/user/application/service/UserCreateWithOAuthServiceTest.java b/user/user-application/src/test/java/me/nalab/user/application/service/UserCreateWithOAuthServiceTest.java index 8f1ab75e..f24b6348 100644 --- a/user/user-application/src/test/java/me/nalab/user/application/service/UserCreateWithOAuthServiceTest.java +++ b/user/user-application/src/test/java/me/nalab/user/application/service/UserCreateWithOAuthServiceTest.java @@ -3,6 +3,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; +import java.time.Clock; import java.time.Instant; import org.assertj.core.api.Assertions; @@ -37,9 +38,6 @@ class UserCreateWithOAuthServiceTest { @MockBean private MockIdGenerator mockIdGenerator; - @MockBean - private TimeUtil timeUtil; - @Test @DisplayName("Provider가 null이면 예외를 던진다") void THROW_EXCEPTION_WHEN_PROVIDER_IS_NULL() { @@ -53,8 +51,7 @@ void THROW_EXCEPTION_WHEN_PROVIDER_IS_NULL() { username, null ); - - when(timeUtil.toInstant()).thenReturn(Instant.now()); + TimeUtil.fixed(Clock.systemUTC()); // when var throwable = Assertions.catchThrowable(() -> userCreateWithOAuthService.createUser(request)); @@ -76,8 +73,7 @@ void THROW_EXCEPTION_WHEN_EMAIL_IS_NULL() { username, null ); - - when(timeUtil.toInstant()).thenReturn(Instant.now()); + TimeUtil.fixed(Clock.systemUTC()); // when var throwable = Assertions.catchThrowable(() -> userCreateWithOAuthService.createUser(request)); @@ -102,7 +98,7 @@ void RETURN_NEW_USER_ID_WHEN_VALID_INPUT() { long createdUserId = 1L; when(userCreateWithOAuthPort.createUserWithOAuth(any(), any())).thenReturn(createdUserId); - when(timeUtil.toInstant()).thenReturn(Instant.now()); + TimeUtil.fixed(Clock.systemUTC()); // when var userId = userCreateWithOAuthService.createUser(request); From 4391868143f05926ca8b12d6df9f40479433ab0b Mon Sep 17 00:00:00 2001 From: devxb Date: Tue, 20 Feb 2024 15:56:57 +0900 Subject: [PATCH 6/7] =?UTF-8?q?[feat]=20:=20TimeUtil=EC=97=90=20clear=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=EC=9D=84=20=EC=B6=94=EA=B0=80=ED=95=9C?= =?UTF-8?q?=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/time/src/main/java/me/nalab/core/time/TimeUtil.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/time/src/main/java/me/nalab/core/time/TimeUtil.java b/core/time/src/main/java/me/nalab/core/time/TimeUtil.java index caccd1be..4c26caaa 100644 --- a/core/time/src/main/java/me/nalab/core/time/TimeUtil.java +++ b/core/time/src/main/java/me/nalab/core/time/TimeUtil.java @@ -31,4 +31,8 @@ private static Instant formatTo6Digit(Instant instant) { public static void fixed(Clock clock) { TimeUtil.clock = clock; } + + public static void clear() { + TimeUtil.clock = null; + } } From 08449bbf2d30748449252b184420e2ad99d876f3 Mon Sep 17 00:00:00 2001 From: devxb Date: Tue, 20 Feb 2024 15:58:08 +0900 Subject: [PATCH 7/7] [refactor] : remove unused import --- core/time/src/main/java/me/nalab/core/time/TimeUtil.java | 1 - 1 file changed, 1 deletion(-) diff --git a/core/time/src/main/java/me/nalab/core/time/TimeUtil.java b/core/time/src/main/java/me/nalab/core/time/TimeUtil.java index 4c26caaa..c6c25211 100644 --- a/core/time/src/main/java/me/nalab/core/time/TimeUtil.java +++ b/core/time/src/main/java/me/nalab/core/time/TimeUtil.java @@ -2,7 +2,6 @@ import java.time.Clock; import java.time.Instant; -import java.time.LocalDateTime; import java.time.ZoneId; import java.time.format.DateTimeFormatter;