Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions .github/workflow/ci.yml

This file was deleted.

53 changes: 53 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: pr-test
on: pull_request

env:
SPRING_DATASOURCE_URL: ${{ secrets.SPRING_DATASOURCE_URL }}
DB_PASSWORD: root
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

jobs:
pr-test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@main

- name: Start Redis
uses: supercharge/redis-github-action@1.1.0
with:
redis-version: 6

- name: Start Mysql Service
run: |
sudo /etc/init.d/mysql start
mysql -e 'CREATE DATABASE shoppingtest;' -uroot -proot

- name: Set up JDK 21
uses: actions/setup-java@main
with:
java-version: '21'
cache: 'gradle'
distribution: 'temurin'

- name: Setup Gradle
uses: gradle/gradle-build-action@v3
with:
gradle-version: 8.5

- name: Run Test
uses: gradle/gradle-build-action@v3
with:
gradle-version: wrapper
arguments: test

- name: send slack notification
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
fields: repo,commit,author,ref,workflow,job,took
author_name: GitHub Actions
if: always()



3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ out/

### VS Code ###
.vscode/

/mysql_data
/config
2 changes: 1 addition & 1 deletion src/main/java/com/kt/common/profile/LocalProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import org.springframework.context.annotation.Profile;

@Profile({"local", "test"})
@Profile("local")
@Retention(RetentionPolicy.RUNTIME)
public @interface LocalProfile {
}
11 changes: 11 additions & 0 deletions src/main/java/com/kt/common/profile/ProdProfile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.kt.common.profile;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

import org.springframework.context.annotation.Profile;

@Profile("prod")
@Retention(RetentionPolicy.RUNTIME)
public @interface ProdProfile {
}
11 changes: 11 additions & 0 deletions src/main/java/com/kt/common/profile/TestProfile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.kt.common.profile;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

import org.springframework.context.annotation.Profile;

@Profile("test")
@Retention(RetentionPolicy.RUNTIME)
public @interface TestProfile {
}
12 changes: 7 additions & 5 deletions src/main/java/com/kt/config/ActiveProfileConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;

import lombok.RequiredArgsConstructor;

@Profile("dev")
@Configuration
@RequiredArgsConstructor
public class ActiveProfileConfig {

private final Environment environment;
private final TestProperties testProperties;

private final CommonProperties commonProperties;

@Bean
public String init() {
System.out.println("Active Profile : " + environment.getActiveProfiles()[0]);
System.out.println(commonProperties.commonValue());
System.out.println(commonProperties.commonValueParam());
System.out.println(testProperties.myValue());
System.out.println(testProperties.myValueParam());
return "";
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/kt/config/CommonProperties.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.kt.config;

import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties(prefix = "common")
public record CommonProperties(
String commonValue,
String commonValueParam
) {
}
9 changes: 8 additions & 1 deletion src/main/java/com/kt/config/RedisConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import lombok.RequiredArgsConstructor;

@Configuration
@RequiredArgsConstructor
public class RedisConfiguration {

private final RedisProperties redisProperties;

@Bean
public RedissonClient redisClient() {
Config config = new Config();
config.useSingleServer().setAddress("redis://localhost:6379");
String redisUrl = String.format("redis://%s:%d", redisProperties.getHost(), redisProperties.getPort());
config.useSingleServer().setAddress(redisUrl);
return Redisson.create(config);
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/kt/config/TestProperties.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.kt.config;

import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties(prefix = "test")
public record TestProperties(
String myValue,
String myValueParam
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,12 @@ jwt:

slack:
bot-token: ${slack.token}
log-channel: ${slack.channel}
log-channel: ${slack.channel}

common:
common-value: this is common value
common-value-param: this is common value with param - ${COMMON_PARAM:공통}

test:
my-value: this is test value in local
my-value-param: this is test value with param - ${TEST_PARAM:terry}
32 changes: 0 additions & 32 deletions src/main/resources/application-test.yml

This file was deleted.

45 changes: 24 additions & 21 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
spring:
### h2 설정 ###
# h2:
# console:
# enabled: true
# datasource:
# url: jdbc:h2:~/test
# username: sa
# password:
# driver-class-name: org.h2.Driver
### mysql 드라이버 설정 ###
datasource:
url: jdbc:mysql://localhost:3306/shopping-sehyeon
username: root
password: 1234
password: ${db.password:1234}
driver-class-name: com.mysql.cj.jdbc.Driver
### jpa 설정 ###
jpa:
hibernate:
# create = 테이블을 만들기만
# update = 테이블 없으면 만들고, entity랑 다르면 수정 -> 삭제는 안해줌
# validate = 테이블이랑 entity랑 맞는지 확인만
# none = 아무것도 안함
# create-drop = create랑 똑같은데, 애플리케이션 종료시점에 테이블 drop => 테스트코드에서만 쓰세요
ddl-auto: update
#create = 테이블을 만들기만
#update = 테이블 없으면 만들고 있지만 entity랑 다르면 수정 -> 삭제는 안해줌
#validate = 테이블이랑 entity랑 맞는지 확인만
#none = 아무것도 안함
#create-drop = create랑 똑같은데 애플리케이션 종료시점에 테이블을 drop함 => 테스트코드에서만 쓰세요
ddl-auto: create-drop
properties:
hibernate:
format_sql: true # SQL문을 보기 좋게 출력
# dialect: org.hibernate.dialect.MySQL5InnoDBDialect
format_sql: true
dialect: org.hibernate.dialect.MySQLDialect
jdbc:
time_zone: Asia/Seoul
show_sql: true #로컬에서만
# default_batch_fetch_size: 2
show-sql: true
data:
redis:
host: ${redis.host:localhost}
port: ${redis.port:6379}

jwt:
secret: ${kt.jwt.secret:kt-cloud-shopping-kt-cloud-shopping-kt-cloud-shopping-kt-cloud-shopping}
Expand All @@ -38,4 +33,12 @@ jwt:

slack:
bot-token: ${slack.token}
log-channel: ${slack.channel}
log-channel: ${slack.channel}

common:
common-value: this is common value
common-value-param: this is common value with param - ${COMMON_PARAM}

test:
my-value: this is test value in normal
my-value-param: this is test value with param - ${TEST_PARAM:default}
30 changes: 30 additions & 0 deletions src/test/java/com/kt/ConfigTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.kt;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

import com.kt.config.CommonProperties;
import com.kt.config.TestProperties;

@ActiveProfiles("test")
@SpringBootTest
public class ConfigTest {

@Autowired
CommonProperties commonProperties

@Autowired
TestProperties testProperties;

@Test
public void test() {

System.out.println(commonProperties.commonValue());
System.out.println(commonProperties.commonValueParam());

System.out.println(testProperties.myValue());
System.out.println(testProperties.myValueParam());
}
}
2 changes: 2 additions & 0 deletions src/test/java/com/kt/ShoppingApplicationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

@ActiveProfiles("test")
@SpringBootTest
class ShoppingApplicationTests {

Expand Down
2 changes: 2 additions & 0 deletions src/test/java/com/kt/domain/product/ProductTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Test;
import org.springframework.test.context.ActiveProfiles;

import com.kt.common.exception.CustomException;

@ActiveProfiles("test")
class ProductTest {

@Test
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/com/kt/repository/ProductRepositoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
Expand Down Expand Up @@ -46,6 +47,7 @@ class ProductRepositoryTest {
}

@Test
@Disabled
void 동시에_100명_주문() throws InterruptedException {
var userList = new ArrayList<User>();
for (int i = 0; i < 100; i++) {
Expand Down
Loading
Loading