From b9be6de485bbb5baf05d50d58ca2c48fa9a13254 Mon Sep 17 00:00:00 2001 From: jonghun Date: Sun, 1 Sep 2024 11:59:35 +0900 Subject: [PATCH 01/10] =?UTF-8?q?#117=20gradle:=20test=20=EB=B9=8C?= =?UTF-8?q?=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/docker-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-ci.yml b/.github/workflows/docker-ci.yml index db3602f..abfbd2c 100644 --- a/.github/workflows/docker-ci.yml +++ b/.github/workflows/docker-ci.yml @@ -35,7 +35,7 @@ jobs: run: chmod +x gradlew - name: Build With Gradle - run: ./gradlew build -x test + run: ./gradlew build - name: Publish Unit Test Results uses: EnricoMi/publish-unit-test-result-action@v1 From b2356a56a93da033223bdbce828ed4f4bec35e24 Mon Sep 17 00:00:00 2001 From: jonghun Date: Tue, 3 Sep 2024 09:59:13 +0900 Subject: [PATCH 02/10] =?UTF-8?q?#117=20gradle:=20test=20=EB=B9=8C?= =?UTF-8?q?=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/docker-ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/docker-ci.yml b/.github/workflows/docker-ci.yml index abfbd2c..6decd68 100644 --- a/.github/workflows/docker-ci.yml +++ b/.github/workflows/docker-ci.yml @@ -37,6 +37,10 @@ jobs: - name: Build With Gradle run: ./gradlew build + # build test + - name: Run Tests with Gradle + run: ./gradlew --info test + - name: Publish Unit Test Results uses: EnricoMi/publish-unit-test-result-action@v1 if: ${{ always() }} From 2f69b1289eb6ad49af287af6d132cf042db76452 Mon Sep 17 00:00:00 2001 From: jonghun Date: Tue, 3 Sep 2024 12:30:32 +0900 Subject: [PATCH 03/10] =?UTF-8?q?#117=20gradle:=20refreshToken=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - refreshtoken 이 없는 경우 - refreshtoken이 유효한 경우 - refreshtoken이 유효하지 않은 경우 --- .../domain/idtest/IdGenerateTest.java | 176 +++++++++--------- .../domain/post/PostGeneratorTest.java | 74 ++++---- .../domain/user/UserServiceTest.java | 98 ++++++++-- 3 files changed, 211 insertions(+), 137 deletions(-) diff --git a/src/test/java/com/seoultech/synergybe/domain/idtest/IdGenerateTest.java b/src/test/java/com/seoultech/synergybe/domain/idtest/IdGenerateTest.java index 742ee10..cdb55f1 100644 --- a/src/test/java/com/seoultech/synergybe/domain/idtest/IdGenerateTest.java +++ b/src/test/java/com/seoultech/synergybe/domain/idtest/IdGenerateTest.java @@ -1,88 +1,88 @@ -package com.seoultech.synergybe.domain.idtest; - -import com.seoultech.synergybe.domain.common.generator.IdGenerator; -import com.seoultech.synergybe.domain.common.generator.IdPrefix; -import com.seoultech.synergybe.domain.common.generator.TokenGenerator; -import com.seoultech.synergybe.domain.user.IdTest; -import com.seoultech.synergybe.domain.user.IdTestRepository; -import com.seoultech.synergybe.domain.user.UUIDTest; -import com.seoultech.synergybe.domain.user.UUIDTestRepository; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; - -import java.util.ArrayList; -import java.util.List; - -@SpringBootTest -public class IdGenerateTest { - @Autowired - IdGenerator idGenerator; - - @Autowired - TokenGenerator tokenGenerator; - - @Autowired - IdTestRepository idTestRepository; - - @Autowired - UUIDTestRepository uuidTestRepository; - - @Test - void generateLongId() { - // test start - long startTime = System.currentTimeMillis(); - - - - for (int j = 0; j < 100; j++) { - List idTestList = new ArrayList<>(); - - for (int i = 0; i < 10000; i++) { - Long id = idGenerator.generateId(); - IdTest idTest = IdTest.builder() - .id(id) - .text("text") - .build(); - - idTestList.add(idTest); - } - System.out.println("longId : " + j + " 번째 : "); - idTestRepository.saveAll(idTestList); - } - - // test end - long endTime = System.currentTimeMillis(); - System.out.println("longId Total execution time: " + (endTime - startTime) + " milliseconds"); - - } - - @Test - void generateStringId() { - // test start - long startTime = System.currentTimeMillis(); - - - - for (int j = 0; j < 100; j++) { - List uuidTestList = new ArrayList<>(); - - for (int i = 0; i < 10000; i++) { - String id = tokenGenerator.generateToken(IdPrefix.POST_LIKE); - UUIDTest idTest = UUIDTest.builder() - .id(id) - .text("text") - .build(); - - uuidTestList.add(idTest); - } - System.out.println("StringId : " + j + " 번째 : "); - uuidTestRepository.saveAll(uuidTestList); - } - - // test end - long endTime = System.currentTimeMillis(); - System.out.println("StringId Total execution time: " + (endTime - startTime) + " milliseconds"); - - } -} +//package com.seoultech.synergybe.domain.idtest; +// +//import com.seoultech.synergybe.domain.common.generator.IdGenerator; +//import com.seoultech.synergybe.domain.common.generator.IdPrefix; +//import com.seoultech.synergybe.domain.common.generator.TokenGenerator; +//import com.seoultech.synergybe.domain.user.IdTest; +//import com.seoultech.synergybe.domain.user.IdTestRepository; +//import com.seoultech.synergybe.domain.user.UUIDTest; +//import com.seoultech.synergybe.domain.user.UUIDTestRepository; +//import org.junit.jupiter.api.Test; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.boot.test.context.SpringBootTest; +// +//import java.util.ArrayList; +//import java.util.List; +// +//@SpringBootTest +//public class IdGenerateTest { +// @Autowired +// IdGenerator idGenerator; +// +// @Autowired +// TokenGenerator tokenGenerator; +// +// @Autowired +// IdTestRepository idTestRepository; +// +// @Autowired +// UUIDTestRepository uuidTestRepository; +// +// @Test +// void generateLongId() { +// // test start +// long startTime = System.currentTimeMillis(); +// +// +// +// for (int j = 0; j < 100; j++) { +// List idTestList = new ArrayList<>(); +// +// for (int i = 0; i < 10000; i++) { +// Long id = idGenerator.generateId(); +// IdTest idTest = IdTest.builder() +// .id(id) +// .text("text") +// .build(); +// +// idTestList.add(idTest); +// } +// System.out.println("longId : " + j + " 번째 : "); +// idTestRepository.saveAll(idTestList); +// } +// +// // test end +// long endTime = System.currentTimeMillis(); +// System.out.println("longId Total execution time: " + (endTime - startTime) + " milliseconds"); +// +// } +// +// @Test +// void generateStringId() { +// // test start +// long startTime = System.currentTimeMillis(); +// +// +// +// for (int j = 0; j < 100; j++) { +// List uuidTestList = new ArrayList<>(); +// +// for (int i = 0; i < 10000; i++) { +// String id = tokenGenerator.generateToken(IdPrefix.POST_LIKE); +// UUIDTest idTest = UUIDTest.builder() +// .id(id) +// .text("text") +// .build(); +// +// uuidTestList.add(idTest); +// } +// System.out.println("StringId : " + j + " 번째 : "); +// uuidTestRepository.saveAll(uuidTestList); +// } +// +// // test end +// long endTime = System.currentTimeMillis(); +// System.out.println("StringId Total execution time: " + (endTime - startTime) + " milliseconds"); +// +// } +//} diff --git a/src/test/java/com/seoultech/synergybe/domain/post/PostGeneratorTest.java b/src/test/java/com/seoultech/synergybe/domain/post/PostGeneratorTest.java index b321dfb..43ef84e 100644 --- a/src/test/java/com/seoultech/synergybe/domain/post/PostGeneratorTest.java +++ b/src/test/java/com/seoultech/synergybe/domain/post/PostGeneratorTest.java @@ -36,41 +36,41 @@ public class PostGeneratorTest { UserRepository userRepository; - @Test - void generatePost() { - Long userId = idGenerator.generateId(); - String userToken = tokenGenerator.generateToken(IdPrefix.USER); - - User user = User.builder() - .id(userId) - .userToken(userToken) - .password("3e4r5t6y6y7u") - .passwordEncoder(passwordEncoder) - .email("email@email.com") - .name("jonghun") - .major("cs") - .build(); - userRepository.save(user); - - assertThat("email@email.com").isEqualTo(user.getEmail().getEmail()); - - List postList = new ArrayList<>(); - - - for (int i = 0; i < 10; i++) { - Long postId = idGenerator.generateId(); - String postToken = tokenGenerator.generateToken(IdPrefix.POST); - - Post post = Post.builder() - .id(postId) - .postToken(postToken) - .user(user) - .title("title") - .content("content") - .build(); - postList.add(post); - - } - postManager.saveAll(postList); - } +// @Test +// void generatePost() { +// Long userId = idGenerator.generateId(); +// String userToken = tokenGenerator.generateToken(IdPrefix.USER); +// +// User user = User.builder() +// .id(userId) +// .userToken(userToken) +// .password("3e4r5t6y6y7u") +// .passwordEncoder(passwordEncoder) +// .email("email@email.com") +// .name("jonghun") +// .major("cs") +// .build(); +// userRepository.save(user); +// +// assertThat("email@email.com").isEqualTo(user.getEmail().getEmail()); +// +// List postList = new ArrayList<>(); +// +// +// for (int i = 0; i < 10; i++) { +// Long postId = idGenerator.generateId(); +// String postToken = tokenGenerator.generateToken(IdPrefix.POST); +// +// Post post = Post.builder() +// .id(postId) +// .postToken(postToken) +// .user(user) +// .title("title") +// .content("content") +// .build(); +// postList.add(post); +// +// } +// postManager.saveAll(postList); +// } } diff --git a/src/test/java/com/seoultech/synergybe/domain/user/UserServiceTest.java b/src/test/java/com/seoultech/synergybe/domain/user/UserServiceTest.java index b59eadc..853ffba 100644 --- a/src/test/java/com/seoultech/synergybe/domain/user/UserServiceTest.java +++ b/src/test/java/com/seoultech/synergybe/domain/user/UserServiceTest.java @@ -8,25 +8,25 @@ import com.seoultech.synergybe.domain.user.dto.request.CreateUserRequest; import com.seoultech.synergybe.domain.user.dto.request.ValidateNumberRequest; import com.seoultech.synergybe.domain.user.exception.UserBadRequestException; +import com.seoultech.synergybe.domain.user.repository.UserRefreshTokenFactory; import com.seoultech.synergybe.domain.user.repository.UserRepository; import com.seoultech.synergybe.domain.user.service.UserService; -import com.seoultech.synergybe.system.utils.CookieUtil; import com.seoultech.synergybe.system.utils.RedisUtil; import jakarta.annotation.PostConstruct; import jakarta.servlet.http.Cookie; -import jakarta.servlet.http.HttpServletRequest; import org.junit.jupiter.api.*; -import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.transaction.annotation.Transactional; -import java.util.Optional; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import static org.junit.jupiter.api.Assertions.assertThrows; + @SpringBootTest @Transactional @TestMethodOrder(MethodOrderer.OrderAnnotation.class) @@ -51,6 +51,11 @@ class UserServiceTest { private final String TRUE = "true"; private final String FALSE = "false"; + private MockHttpServletRequest request; + private MockHttpServletResponse response; + + @Autowired + private UserRefreshTokenFactory userRefreshTokenFactory; @PostConstruct public void setAuthNumber() { @@ -174,17 +179,86 @@ void checkEmailDuplicate() { .isInstanceOf(UserBadRequestException.class) .hasMessage("checkEmailDuplicate >> 유저 email: " + email + "은 이미 존재합니다."); } + @DisplayName("RefreshToken이 없는 경우 예외를 발생시킨다") + @Test + void EmptyRefreshTokengenerateAccessTokenByRefreshToken() { + // given + request = new MockHttpServletRequest(); + response = new MockHttpServletResponse(); + Cookie mockCookie = new Cookie("refreshToken", null); + request.setCookies(mockCookie); + + // when & then + assertThrows(UserBadRequestException.class, + () -> userService.generateAccessTokenByRefreshToken(request, response)); + } - @DisplayName("RefreshToken 으로 AccessToken 재발급한다") + @DisplayName("RefreshToken이 유효한 경우 AccessToken을 재발급한다") @Test - void generateAccessTokenByRefreshToken() { - HttpServletRequest request = new MockHttpServletRequest(); + void generateAccessTokenByRefreshToken_V1() { + // given + String email = "jonghuncu@gmail.com"; + String password = "password"; + String name = "name"; + String major = "major"; + CreateUserRequest createUserRequest = new CreateUserRequest(email, password, name, major, authNumber); + redisUtil.setDataExpire(email+authNumber, TRUE, 60*5L); + + String userToken = userService.createUser(createUserRequest); + User user = userRepository.findByUserToken(userToken).orElseThrow(); + Long userId = user.getId(); + + // refresh token + UserRefreshToken userRefreshToken = new UserRefreshToken(userId); + userRefreshTokenFactory.save(userRefreshToken); + + String refreshToken = userRefreshToken.getRefreshToken().getRefreshToken(); + + // cookie 세팅 + request = new MockHttpServletRequest(); + response = new MockHttpServletResponse(); + Cookie mockCookie = new Cookie("refreshToken", refreshToken); + request.setCookies(mockCookie); + + // when + userService.generateAccessTokenByRefreshToken(request, response); + + // then + String accessToken = response.getHeader("Authorization"); // Assuming the token is in the "Authorization" header + assertThat(accessToken).isNotNull(); + assertThat(accessToken).startsWith("Bearer "); + } + + @DisplayName("유효하지 않은 RefreshToken인 경우 예외를 발생시킨다") + @Test + void invalidRefreshTokengenerateAccessTokenByRefreshToken() { + // given + String email = "jonghuncu@gmail.com"; + String password = "password"; + String name = "name"; + String major = "major"; + CreateUserRequest createUserRequest = new CreateUserRequest(email, password, name, major, authNumber); + redisUtil.setDataExpire(email+authNumber, TRUE, 60*5L); + + String userToken = userService.createUser(createUserRequest); + User user = userRepository.findByUserToken(userToken).orElseThrow(); + Long userId = user.getId(); + + // refresh token + UserRefreshToken userRefreshToken = new UserRefreshToken(userId); + userRefreshTokenFactory.save(userRefreshToken); - String mockRefreshTokenValue = "mockRefreshToken"; - String mockAccessTokenValue = "mockAccessToken"; + String refreshToken = userRefreshToken.getRefreshToken().getRefreshToken(); + String invalidRefreshToken = refreshToken + "invalid"; - Cookie mockCookie = new Cookie("refreshToken", mockRefreshTokenValue); - Mockito.when(CookieUtil.getCookie(request, "refreshToken")).thenReturn(Optional.of(mockCookie)); + // cookie 세팅 + request = new MockHttpServletRequest(); + response = new MockHttpServletResponse(); + Cookie mockCookie = new Cookie("refreshToken", invalidRefreshToken); + request.setCookies(mockCookie); + // when & then + assertThrows(UserBadRequestException.class, + () -> userService.generateAccessTokenByRefreshToken(request, response)); } -} +} \ No newline at end of file From 83a106b1215032f7edfd49c361307afcbcbd772f Mon Sep 17 00:00:00 2001 From: jonghun Date: Tue, 3 Sep 2024 12:44:30 +0900 Subject: [PATCH 04/10] =?UTF-8?q?#117=20fix:=20ci=20mongodb=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/docker-ci.yml | 159 ++++++++++++++++++++++++-------- 1 file changed, 120 insertions(+), 39 deletions(-) diff --git a/.github/workflows/docker-ci.yml b/.github/workflows/docker-ci.yml index 6decd68..a000ec7 100644 --- a/.github/workflows/docker-ci.yml +++ b/.github/workflows/docker-ci.yml @@ -9,46 +9,127 @@ on: branches: [ "develop" ] # 테스트 결과 작성을 위해 쓰기권한 추가 -permissions: write-all +permissions: + checks: write + pull-requests: write + + +# Job 실행 jobs: build: + runs-on: ubuntu-latest + + services: + redis: + image: redis:latest + ports: + - 6379:6379 + mongodb: + image: mongodb:latest + env: + MONGO_INITDB_ROOT_USERNAME: rivkode + MONGO_INITDB_ROOT_PASSWORD: ${{ secrets.MONGO_DB_PASSWORD }} + MONGO_INITDB_DATABASE: synergy_db + ports: + - 27017:27017 + options: >- + --health-cmd mongo + --health-interval 10s + --health-timeout 5s + --health-retries 5 + steps: - - uses: actions/checkout@v3 - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'adopt' - - - name: Gradle Caching - uses: actions/cache@v3 - with: - path: | - ~/.gradle/caches - ~/.gradle/wrapper - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} - restore-keys: | - ${{ runner.os }}-gradle- - - - name: Grant Execute Permission For Gradlew - run: chmod +x gradlew - - - name: Build With Gradle - run: ./gradlew build - - # build test - - name: Run Tests with Gradle - run: ./gradlew --info test - - - name: Publish Unit Test Results - uses: EnricoMi/publish-unit-test-result-action@v1 - if: ${{ always() }} - with: - files: build/test-results/**/*.xml - - - name: Publish Test Report - uses: mikepenz/action-junit-report@v3 - if: success() || failure() # always run even if the previous step fails - with: - report_paths: '**/build/test-results/test/TEST-*.xml' + + - name: 레포지토리 체크아웃 + uses: actions/checkout@v4 + + - name: 기본 MySQL 종료 (SUDO 필요) + run: sudo service mysql stop # 기본 MySQL 종료 + + - name: JDK 17 설치 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'adopt' + + - name: Gradle Caching + uses: actions/cache@v3 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + + - name: MySQL 설치 + uses: mirromutth/mysql-action@v1 + with: + mysql version: '8.0' # Optional, default value is "latest". The version of the MySQL + mysql database: synergy_db # Optional, default value is "test". The specified database which will be create + mysql user: rivkode # Required if "mysql root password" is empty, default is empty. The superuser for the specified database. Of course you can use secrets, too + mysql password: ${{ secrets.MYSQL_DB_PASSWORD }} + + - name: Wait for MySQL + run: | + while ! mysqladmin ping --host=127.0.0.1 --password=$DB_PASSWORD --silent; do + sleep 1 + done + + - name: Install mongosh + run: | + sudo apt-get install gnupg + wget -qO- https://www.mongodb.org/static/pgp/server-7.0.asc | sudo tee /etc/apt/trusted.gpg.d/server-7.0.asc + echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list + sudo apt-get update + sudo apt-get install -y mongodb-mongosh + mongosh --version + + - name: Initalize MongoDB + run: | + mongosh --host localhost:27017 -u rivkode -p ${{ secrets.MONGO_DB_PASSWORD }} --authenticationDatabase admin < ./application.properties + + - name: Verify application.properties + run: cat ./src/main/resources/application.properties + shell: bash + + - name: Verify MySQL is running + run: sudo netstat -tlnp | grep 3306 + + # gradle 실행 허가 + - name: Run chmod to make gradlew executable + run: chmod +x ./gradlew + + - name: 빌드 진행 + run: ./gradlew build -x test + + - name: 테스트 코드 실행 + run: ./gradlew --info test + + - name: 테스트 결과 PR에 코멘트 작성 + uses: EnricoMi/publish-unit-test-result-action@v2 + if: always() # 테스트가 실패했을때만 or 테스트가 성공했을때만 알려주기(여기선 둘다!) + with: + files: | + **/build/test-results/**/*.xml + + # Files changed에서 어디에서 잘못되었는지 가르쳐준다. + - name: Publish Test Report + uses: mikepenz/action-junit-report@v3 + if: success() || failure() # always run even if the previous step fails + with: + report_paths: '**/build/test-results/test/TEST-*.xml' \ No newline at end of file From 0f6f4c1b836ea1ff0e87afbeb7611489c8046fe3 Mon Sep 17 00:00:00 2001 From: jonghun Date: Tue, 3 Sep 2024 12:53:16 +0900 Subject: [PATCH 05/10] #117 fix: ci mongo version --- .github/workflows/docker-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker-ci.yml b/.github/workflows/docker-ci.yml index a000ec7..3a378b2 100644 --- a/.github/workflows/docker-ci.yml +++ b/.github/workflows/docker-ci.yml @@ -18,7 +18,7 @@ permissions: jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 services: redis: @@ -26,7 +26,7 @@ jobs: ports: - 6379:6379 mongodb: - image: mongodb:latest + image: mongo:4.4.6 env: MONGO_INITDB_ROOT_USERNAME: rivkode MONGO_INITDB_ROOT_PASSWORD: ${{ secrets.MONGO_DB_PASSWORD }} From 10c5aa0404ec3a9f836008f76385e94ea8769b83 Mon Sep 17 00:00:00 2001 From: jonghun Date: Tue, 3 Sep 2024 13:02:21 +0900 Subject: [PATCH 06/10] #117 fix: ci mysql --- .github/workflows/docker-ci.yml | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/.github/workflows/docker-ci.yml b/.github/workflows/docker-ci.yml index 3a378b2..91d0b85 100644 --- a/.github/workflows/docker-ci.yml +++ b/.github/workflows/docker-ci.yml @@ -21,6 +21,15 @@ jobs: runs-on: ubuntu-22.04 services: + mysql: + image: mysql:8.0 + env: + MYSQL_DATABASE: synergy_db + MYSQL_USER: rivkode + MYSQL_PASSWORD: ${{ secrets.MYSQL_DB_PASSWORD }} + MYSQL_ROOT_PASSWORD: ${{ secrets.MYSQL_DB_PASSWORD }} + ports: + - 3306:3306 redis: image: redis:latest ports: @@ -63,13 +72,13 @@ jobs: restore-keys: | ${{ runner.os }}-gradle- - - name: MySQL 설치 - uses: mirromutth/mysql-action@v1 - with: - mysql version: '8.0' # Optional, default value is "latest". The version of the MySQL - mysql database: synergy_db # Optional, default value is "test". The specified database which will be create - mysql user: rivkode # Required if "mysql root password" is empty, default is empty. The superuser for the specified database. Of course you can use secrets, too - mysql password: ${{ secrets.MYSQL_DB_PASSWORD }} +# - name: MySQL 설치 +# uses: mirromutth/mysql-action@v1 +# with: +# mysql version: '8.0' # Optional, default value is "latest". The version of the MySQL +# mysql database: synergy_db # Optional, default value is "test". The specified database which will be create +# mysql user: rivkode # Required if "mysql root password" is empty, default is empty. The superuser for the specified database. Of course you can use secrets, too +# mysql password: ${{ secrets.MYSQL_DB_PASSWORD }} - name: Wait for MySQL run: | From 3d4b23690ddbd5537321c39d47bc5abab3d02f1f Mon Sep 17 00:00:00 2001 From: jonghun Date: Tue, 3 Sep 2024 13:15:55 +0900 Subject: [PATCH 07/10] #117 fix: ci mysql --- .github/workflows/docker-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker-ci.yml b/.github/workflows/docker-ci.yml index 91d0b85..b04b8ff 100644 --- a/.github/workflows/docker-ci.yml +++ b/.github/workflows/docker-ci.yml @@ -53,8 +53,8 @@ jobs: - name: 레포지토리 체크아웃 uses: actions/checkout@v4 - - name: 기본 MySQL 종료 (SUDO 필요) - run: sudo service mysql stop # 기본 MySQL 종료 +# - name: 기본 MySQL 종료 (SUDO 필요) +# run: sudo service mysql stop # 기본 MySQL 종료 - name: JDK 17 설치 uses: actions/setup-java@v3 From 115f62680b942a56288ecf16003c31b612af99f5 Mon Sep 17 00:00:00 2001 From: jonghun Date: Tue, 3 Sep 2024 13:43:55 +0900 Subject: [PATCH 08/10] =?UTF-8?q?#117=20remove:=20=EB=B6=88=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/idtest/IdGenerateTest.java | 88 ------------------- .../domain/post/PostGeneratorTest.java | 76 ---------------- 2 files changed, 164 deletions(-) delete mode 100644 src/test/java/com/seoultech/synergybe/domain/idtest/IdGenerateTest.java delete mode 100644 src/test/java/com/seoultech/synergybe/domain/post/PostGeneratorTest.java diff --git a/src/test/java/com/seoultech/synergybe/domain/idtest/IdGenerateTest.java b/src/test/java/com/seoultech/synergybe/domain/idtest/IdGenerateTest.java deleted file mode 100644 index cdb55f1..0000000 --- a/src/test/java/com/seoultech/synergybe/domain/idtest/IdGenerateTest.java +++ /dev/null @@ -1,88 +0,0 @@ -//package com.seoultech.synergybe.domain.idtest; -// -//import com.seoultech.synergybe.domain.common.generator.IdGenerator; -//import com.seoultech.synergybe.domain.common.generator.IdPrefix; -//import com.seoultech.synergybe.domain.common.generator.TokenGenerator; -//import com.seoultech.synergybe.domain.user.IdTest; -//import com.seoultech.synergybe.domain.user.IdTestRepository; -//import com.seoultech.synergybe.domain.user.UUIDTest; -//import com.seoultech.synergybe.domain.user.UUIDTestRepository; -//import org.junit.jupiter.api.Test; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.boot.test.context.SpringBootTest; -// -//import java.util.ArrayList; -//import java.util.List; -// -//@SpringBootTest -//public class IdGenerateTest { -// @Autowired -// IdGenerator idGenerator; -// -// @Autowired -// TokenGenerator tokenGenerator; -// -// @Autowired -// IdTestRepository idTestRepository; -// -// @Autowired -// UUIDTestRepository uuidTestRepository; -// -// @Test -// void generateLongId() { -// // test start -// long startTime = System.currentTimeMillis(); -// -// -// -// for (int j = 0; j < 100; j++) { -// List idTestList = new ArrayList<>(); -// -// for (int i = 0; i < 10000; i++) { -// Long id = idGenerator.generateId(); -// IdTest idTest = IdTest.builder() -// .id(id) -// .text("text") -// .build(); -// -// idTestList.add(idTest); -// } -// System.out.println("longId : " + j + " 번째 : "); -// idTestRepository.saveAll(idTestList); -// } -// -// // test end -// long endTime = System.currentTimeMillis(); -// System.out.println("longId Total execution time: " + (endTime - startTime) + " milliseconds"); -// -// } -// -// @Test -// void generateStringId() { -// // test start -// long startTime = System.currentTimeMillis(); -// -// -// -// for (int j = 0; j < 100; j++) { -// List uuidTestList = new ArrayList<>(); -// -// for (int i = 0; i < 10000; i++) { -// String id = tokenGenerator.generateToken(IdPrefix.POST_LIKE); -// UUIDTest idTest = UUIDTest.builder() -// .id(id) -// .text("text") -// .build(); -// -// uuidTestList.add(idTest); -// } -// System.out.println("StringId : " + j + " 번째 : "); -// uuidTestRepository.saveAll(uuidTestList); -// } -// -// // test end -// long endTime = System.currentTimeMillis(); -// System.out.println("StringId Total execution time: " + (endTime - startTime) + " milliseconds"); -// -// } -//} diff --git a/src/test/java/com/seoultech/synergybe/domain/post/PostGeneratorTest.java b/src/test/java/com/seoultech/synergybe/domain/post/PostGeneratorTest.java deleted file mode 100644 index 43ef84e..0000000 --- a/src/test/java/com/seoultech/synergybe/domain/post/PostGeneratorTest.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.seoultech.synergybe.domain.post; - -import com.seoultech.synergybe.domain.common.CustomPasswordEncoder; -import com.seoultech.synergybe.domain.common.generator.IdGenerator; -import com.seoultech.synergybe.domain.common.generator.IdPrefix; -import com.seoultech.synergybe.domain.common.generator.TokenGenerator; -import com.seoultech.synergybe.domain.post.implement.PostManager; -import com.seoultech.synergybe.domain.user.User; -import com.seoultech.synergybe.domain.user.repository.UserRepository; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; - -import java.util.ArrayList; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest -public class PostGeneratorTest { - private static final int TEST_COUNT = 10000; - - @Autowired - CustomPasswordEncoder passwordEncoder; - - @Autowired - IdGenerator idGenerator; - - @Autowired - TokenGenerator tokenGenerator; - - @Autowired - PostManager postManager; - - @Autowired - UserRepository userRepository; - - -// @Test -// void generatePost() { -// Long userId = idGenerator.generateId(); -// String userToken = tokenGenerator.generateToken(IdPrefix.USER); -// -// User user = User.builder() -// .id(userId) -// .userToken(userToken) -// .password("3e4r5t6y6y7u") -// .passwordEncoder(passwordEncoder) -// .email("email@email.com") -// .name("jonghun") -// .major("cs") -// .build(); -// userRepository.save(user); -// -// assertThat("email@email.com").isEqualTo(user.getEmail().getEmail()); -// -// List postList = new ArrayList<>(); -// -// -// for (int i = 0; i < 10; i++) { -// Long postId = idGenerator.generateId(); -// String postToken = tokenGenerator.generateToken(IdPrefix.POST); -// -// Post post = Post.builder() -// .id(postId) -// .postToken(postToken) -// .user(user) -// .title("title") -// .content("content") -// .build(); -// postList.add(post); -// -// } -// postManager.saveAll(postList); -// } -} From 28c60a8df6952e730857edc8f38cf6650c881d92 Mon Sep 17 00:00:00 2001 From: jonghun Date: Tue, 3 Sep 2024 13:44:14 +0900 Subject: [PATCH 09/10] =?UTF-8?q?#117=20test:=20=EA=B0=9D=EC=B2=B4=20ID=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=EA=B8=B0=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../generator/TokenGeneratorUUIDTest.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/test/java/com/seoultech/synergybe/domain/common/generator/TokenGeneratorUUIDTest.java b/src/test/java/com/seoultech/synergybe/domain/common/generator/TokenGeneratorUUIDTest.java index 4f2f8a8..0d75ad6 100644 --- a/src/test/java/com/seoultech/synergybe/domain/common/generator/TokenGeneratorUUIDTest.java +++ b/src/test/java/com/seoultech/synergybe/domain/common/generator/TokenGeneratorUUIDTest.java @@ -18,6 +18,7 @@ public class TokenGeneratorUUIDTest { @Autowired TokenGenerator tokenGenerator; + @DisplayName("객체 ID 1만개 생성시 1초 이내로 실행된다.") @Test void generateLongId() { List longList = new ArrayList<>(); @@ -27,18 +28,18 @@ void generateLongId() { for (int i = 0; i < 10000; i++) { Long longId = idGenerator.generateId(); - System.out.println("longId : " + i + " 번째 : "+ longId); longList.add(longId); - } - // test end long endTime = System.currentTimeMillis(); - System.out.println("longId Total execution time: " + (endTime - startTime) + " milliseconds"); + long elapsedTime = endTime - startTime; - assertThat(longList.size()).isEqualTo(10000); + // test end + assertThat(longList).hasSize(10000); + assertThat(elapsedTime).isLessThanOrEqualTo(1000); } + @DisplayName("대체키 ID 1만개 생성시 3초 이내로 실행된다.") @Test void generateStringId() { List stringList = new ArrayList<>(); @@ -48,16 +49,14 @@ void generateStringId() { for (int i = 0; i < 10000; i++) { String stringId = tokenGenerator.generateToken(IdPrefix.POST); - System.out.println("stringId : " + i + " 번째 : "+ stringId); stringList.add(stringId); } // test end long endTime = System.currentTimeMillis(); - System.out.println("stringId Total execution time: " + (endTime - startTime) + " milliseconds"); + long elapsedTime = endTime - startTime; - assertThat(stringList.size()).isEqualTo(10000); + assertThat(stringList).hasSize(10000); + assertThat(elapsedTime).isLessThanOrEqualTo(3000); } - - } \ No newline at end of file From 474a32b6efc94fd5500abaf1157feddbbb3da74c Mon Sep 17 00:00:00 2001 From: jonghun Date: Tue, 3 Sep 2024 13:49:06 +0900 Subject: [PATCH 10/10] =?UTF-8?q?#117=20rename:=20V1=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/common/generator/TokenGeneratorUUIDTest.java | 2 +- .../com/seoultech/synergybe/domain/user/UserServiceTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/seoultech/synergybe/domain/common/generator/TokenGeneratorUUIDTest.java b/src/test/java/com/seoultech/synergybe/domain/common/generator/TokenGeneratorUUIDTest.java index 0d75ad6..ff0969a 100644 --- a/src/test/java/com/seoultech/synergybe/domain/common/generator/TokenGeneratorUUIDTest.java +++ b/src/test/java/com/seoultech/synergybe/domain/common/generator/TokenGeneratorUUIDTest.java @@ -11,7 +11,7 @@ import static org.assertj.core.api.Assertions.assertThat; @SpringBootTest -public class TokenGeneratorUUIDTest { +class TokenGeneratorUUIDTest { @Autowired IdGenerator idGenerator; diff --git a/src/test/java/com/seoultech/synergybe/domain/user/UserServiceTest.java b/src/test/java/com/seoultech/synergybe/domain/user/UserServiceTest.java index 853ffba..b9df14d 100644 --- a/src/test/java/com/seoultech/synergybe/domain/user/UserServiceTest.java +++ b/src/test/java/com/seoultech/synergybe/domain/user/UserServiceTest.java @@ -195,7 +195,7 @@ void EmptyRefreshTokengenerateAccessTokenByRefreshToken() { @DisplayName("RefreshToken이 유효한 경우 AccessToken을 재발급한다") @Test - void generateAccessTokenByRefreshToken_V1() { + void generateAccessTokenByRefreshToken() { // given String email = "jonghuncu@gmail.com"; String password = "password";