Skip to content

Commit d09e1f1

Browse files
committed
test: 테스트 수정
1 parent b1b0d29 commit d09e1f1

File tree

7 files changed

+44
-23
lines changed

7 files changed

+44
-23
lines changed

src/main/kotlin/co/yappuworld/operation/client/application/GenerationActiveStateManager.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import co.yappuworld.global.exception.BusinessException
44
import co.yappuworld.operation.client.dto.param.GenerationActivationControlResult
55
import co.yappuworld.operation.domain.GenerationEntity
66
import co.yappuworld.operation.domain.OperationError
7+
import co.yappuworld.operation.infrastructure.GenerationFindService
78
import co.yappuworld.operation.infrastructure.GenerationRepository
89
import io.github.oshai.kotlinlogging.KotlinLogging
910
import org.springframework.data.repository.findByIdOrNull
@@ -14,6 +15,7 @@ private val logger = KotlinLogging.logger { }
1415

1516
@Component
1617
class GenerationActiveStateManager(
18+
private val generationFindService: GenerationFindService,
1719
private val generationRepository: GenerationRepository
1820
) {
1921

@@ -39,9 +41,9 @@ class GenerationActiveStateManager(
3941
fun getActiveGenerationOrNull(): Int? = generationRepository.getGenerationOrNullByIsActiveIsTrue()?.value
4042

4143
private fun deactivateGeneration(targetGenerationValue: Int? = null): Int? {
42-
if (!generationRepository.existsGenerationByIsActiveIsTrue()) return null
44+
if (!generationFindService.existsActiveGeneration()) return null
4345

44-
val activeGenerations = generationRepository.findAllByIsActiveIsTrue()
46+
val activeGenerations = generationFindService.findAllActiveGeneration()
4547
checkDeactivatingConsistency(activeGenerations, targetGenerationValue)
4648

4749
return activeGenerations

src/main/kotlin/co/yappuworld/operation/infrastructure/GenerationFindService.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,21 @@ class GenerationFindService(
2020

2121
fun existsGeneration(value: Int): Boolean = generationRepository.existsById(value)
2222

23+
fun existsActiveGeneration(): Boolean =
24+
generationRepository
25+
.findAll(limit = 1) {
26+
select(intLiteral(1))
27+
.from(entity(GenerationEntity::class))
28+
.where(path(GenerationEntity::isActive).equal(true))
29+
}.isNotEmpty()
30+
2331
fun findGenerations(values: List<Int>): List<GenerationEntity> = generationRepository.findAllByValueIn(values)
32+
33+
fun findAllActiveGeneration(): List<GenerationEntity> =
34+
generationRepository
35+
.findAll {
36+
select(entity(GenerationEntity::class))
37+
.from(entity(GenerationEntity::class))
38+
.where(path(GenerationEntity::isActive).equal(true))
39+
}.filterNotNull()
2440
}

src/main/kotlin/co/yappuworld/operation/infrastructure/GenerationRepository.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package co.yappuworld.operation.infrastructure
22

33
import co.yappuworld.operation.domain.GenerationEntity
4+
import com.linecorp.kotlinjdsl.support.spring.data.jpa.repository.KotlinJdslJpqlExecutor
45
import org.springframework.data.jpa.repository.JpaRepository
56

6-
interface GenerationRepository : JpaRepository<GenerationEntity, Int> {
7-
8-
fun existsGenerationByIsActiveIsTrue(): Boolean
7+
interface GenerationRepository :
8+
JpaRepository<GenerationEntity, Int>,
9+
KotlinJdslJpqlExecutor {
910

1011
fun getGenerationOrNullByIsActiveIsTrue(): GenerationEntity?
1112

src/main/resources/application-local.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ spring:
1616

1717
sql:
1818
init:
19-
mode: never
19+
mode: always
2020

2121
jpa:
2222
open-in-view: false
2323
database-platform: org.hibernate.dialect.OracleDialect
2424
hibernate:
25-
ddl-auto: create-drop
25+
ddl-auto: none
2626
show-sql: true
2727

2828
h2:

src/main/resources/application-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ spring:
1717
jpa:
1818
database-platform: org.hibernate.dialect.OracleDialect
1919
hibernate:
20-
ddl-auto: create-drop
20+
ddl-auto: none
2121
show-sql: true
2222

2323
jwt:

src/main/resources/schema.sql

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ CREATE TABLE users
2121
role varchar(16) NOT NULL,
2222
gender varchar(8),
2323
phone_number varchar(16),
24-
is_active BOOLEAN NOT NULL
24+
is_active NUMBER(1) NOT NULL
2525
);
2626

2727
DROP TABLE IF EXISTS sign_up_application;
@@ -54,8 +54,8 @@ CREATE TABLE user_alarm_settings
5454
created_at TIMESTAMP,
5555
updated_at TIMESTAMP,
5656
user_id binary(16) NOT NULL,
57-
device BOOLEAN NOT NULL,
58-
master BOOLEAN NOT NULL
57+
device NUMBER(1) NOT NULL,
58+
master NUMBER(1) NOT NULL
5959
);
6060

6161
DROP TABLE IF EXISTS user_devices;
@@ -74,18 +74,18 @@ CREATE TABLE schedules
7474
id binary(16) PRIMARY KEY,
7575
created_at TIMESTAMP,
7676
updated_at TIMESTAMP,
77-
is_deleted BOOLEAN NOT NULL,
77+
is_deleted NUMBER(1) NOT NULL,
7878
name varchar(32) NOT NULL,
7979
description varchar(256),
8080
place varchar(32),
8181
address varchar(64),
8282
longitude double,
8383
latitude double,
84-
date date NOT NULL,
85-
end_date date NOT NULL,
86-
time varchar(32),
84+
start_date varchar(10) NOT NULL,
85+
end_date varchar(10) NOT NULL,
86+
start_time varchar(32),
8787
end_time varchar(32),
88-
is_all_day BOOLEAN NOT NULL,
88+
is_all_day NUMBER(1) NOT NULL,
8989
generation int,
9090
type varchar(32) NOT NULL,
9191
session_type varchar(32)
@@ -104,17 +104,17 @@ CREATE TABLE posts
104104
content_summary varchar(255),
105105
display_target varchar(255),
106106
writer_id binary(16) NOT NULL,
107-
is_active BOOLEAN NOT NULL,
107+
is_active NUMBER(1) NOT NULL,
108108
session_id binary(16)
109109
);
110110

111111
DROP TABLE IF EXISTS generations;
112112
CREATE TABLE generations
113113
(
114114
value int PRIMARY KEY,
115-
start_date date,
116-
end_date date,
117-
is_active BOOLEAN NOT NULL
115+
start_date varchar(10),
116+
end_date varchar(10),
117+
is_active NUMBER(1) NOT NULL
118118
);
119119

120120
drop table if exists attendances;
@@ -156,8 +156,8 @@ CREATE TABLE team_services
156156
id binary(16) PRIMARY KEY,
157157
created_at TIMESTAMP,
158158
updated_at TIMESTAMP,
159-
has_app BOOLEAN NOT NULL DEFAULT 0,
160-
has_web BOOLEAN NOT NULL DEFAULT 0,
159+
has_app NUMBER(1) NOT NULL DEFAULT 0,
160+
has_web NUMBER(1) NOT NULL DEFAULT 0,
161161
name varchar(255) DEFAULT NULL,
162162
service_links json DEFAULT NULL,
163163
team_id binary(16) NOT NULL

src/test/kotlin/co/yappuworld/operation/client/application/GenerationActiveStateManagerTest.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package co.yappuworld.operation.client.application
22

33
import co.yappuworld.global.exception.BusinessException
44
import co.yappuworld.operation.domain.GenerationEntity
5+
import co.yappuworld.operation.infrastructure.GenerationFindService
56
import co.yappuworld.operation.infrastructure.GenerationRepository
67
import co.yappuworld.support.environment.CustomDataJpaTestFeatureSpec
78
import io.kotest.assertions.throwables.shouldThrow
@@ -17,7 +18,8 @@ class GenerationActiveStateManagerTest @Autowired constructor(
1718
private val repository: GenerationRepository
1819
) : CustomDataJpaTestFeatureSpec({
1920

20-
val generationActiveStateManager = GenerationActiveStateManager(repository)
21+
val generationFindService = GenerationFindService(repository)
22+
val generationActiveStateManager = GenerationActiveStateManager(generationFindService, repository)
2123

2224
beforeEach {
2325
fun saveNotExist(generation: GenerationEntity) {

0 commit comments

Comments
 (0)