From f8c498710fa3475d14c34b9948bd6d13fb8254c9 Mon Sep 17 00:00:00 2001 From: averak Date: Thu, 1 Feb 2024 01:43:00 +0900 Subject: [PATCH 1/2] =?UTF-8?q?refs=20#130=20=E4=BE=9D=E5=AD=98=E9=96=A2?= =?UTF-8?q?=E4=BF=82=E3=82=92=E3=82=A2=E3=83=83=E3=83=97=E3=83=87=E3=83=BC?= =?UTF-8?q?=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 1 - gradle/libs.versions.toml | 19 ++++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 26fcbbf..dc28141 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -53,7 +53,6 @@ allprojects { } // 現時点で K2 compiler はベータ版なので、導入を見送っている - // K2 コンパイラはまだ試験的なものなので、 // sourceSets { // all { // languageSettings { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 8cabe59..de22bb6 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,11 +1,12 @@ [versions] -easy-random = "6.2.1" -flyway = "10.4.1" +easy-random = "7.0.0" +flyway = "10.7.1" groovy = "4.0.18" -mybatis-generator = "1.4.2" grpc = "1.61.0" +mybatis-generator = "1.4.2" +protobuf = "3.25.2" spock = "2.4-M1-groovy-4.0" -spring-boot = "3.2.1" +spring-boot = "3.2.2" [libraries] commons-lang3 = "org.apache.commons:commons-lang3:3.14.0" @@ -15,8 +16,8 @@ flyway-gradle-plugin = { module = "org.flywaydb:flyway-gradle-plugin", version.r flyway-spanner = { module = "org.flywaydb:flyway-gcp-spanner", version.ref = "flyway" } google-cloud-spanner-jdbc = "com.google.cloud:google-cloud-spanner-jdbc:2.15.0" google-cloud-spanner-spring = "com.google.cloud:spring-cloud-gcp-starter-data-spanner:5.0.0" -google-protobuf = "com.google.protobuf:protobuf-java:3.25.2" -google-protobuf-util = "com.google.protobuf:protobuf-java-util:3.25.2" +google-protobuf = { module = "com.google.protobuf:protobuf-java", version.ref = "protobuf" } +google-protobuf-util = { module = "com.google.protobuf:protobuf-java-util", version.ref = "protobuf" } groovy = { module = "org.apache.groovy:groovy", version.ref = "groovy" } groovy-sql = { module = "org.apache.groovy:groovy-sql", version.ref = "groovy" } guava = "com.google.guava:guava:33.0.0-jre" @@ -47,7 +48,7 @@ spring-boot-starter-webflux = { module = "org.springframework.boot:spring-boot-s flyway = { id = "org.flywaydb.flyway", version.ref = "flyway" } gradle-git-properties = "com.gorylenko.gradle-git-properties:2.4.1" sonarqube = "org.sonarqube:4.4.1.3373" -spotless = "com.diffplug.spotless:6.23.3" +spotless = "com.diffplug.spotless:6.25.0" springboot = { id = "org.springframework.boot", version.ref = "spring-boot" } -version-catalog-update = "nl.littlerobots.version-catalog-update:0.8.3" -versions = "com.github.ben-manes.versions:0.50.0" +version-catalog-update = "nl.littlerobots.version-catalog-update:0.8.4" +versions = "com.github.ben-manes.versions:0.51.0" From 1ad4057a51b880cf3816197ef57f733c3901f94b Mon Sep 17 00:00:00 2001 From: averak Date: Thu, 1 Feb 2024 01:43:03 +0900 Subject: [PATCH 2/2] =?UTF-8?q?refs=20#130=20=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=83=95=E3=82=A3=E3=82=AF=E3=82=B9=E3=83=81=E3=83=A3=E3=82=92?= =?UTF-8?q?builder=E7=B5=8C=E7=94=B1=E3=81=A7=E4=BD=9C=E6=88=90=E3=81=99?= =?UTF-8?q?=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../player_api/PlayerStorageHandler_IT.groovy | 116 ++++++------------ .../ClientVersionInterceptor_UT.groovy | 2 +- .../utils/MasterVersionUtils_UT.groovy | 2 +- .../repository/EchoRepository_UT.groovy | 2 +- .../repository/FriendRepository_UT.groovy | 2 +- .../repository/GameRepository_UT.groovy | 2 +- .../repository/OperatorRepository_UT.groovy | 2 +- .../repository/PlayerRepository_UT.groovy | 2 +- .../PlayerStorageRepository_UT.groovy | 2 +- .../gsync/testkit/AbstractDatabaseSpec.groovy | 11 ++ .../gsync/testkit/api/grpc/GrpcTester.kt | 11 ++ .../gsync/testkit/{ => fixture}/Fixture.kt | 4 +- .../builder/master/FriendSettingBuilder.kt | 29 +++++ .../fixture/builder/master/Registry.kt | 7 ++ .../fixture/builder/player/PlayerBuilder.kt | 33 +++++ .../builder/player/PlayerStorageBuilder.kt | 42 +++++++ .../fixture/builder/player/Registry.kt | 13 ++ .../testkit/fixture/setupper/MasterUp.kt | 27 ++++ .../testkit/fixture/setupper/PlayerUp.kt | 33 +++++ 19 files changed, 253 insertions(+), 89 deletions(-) rename testkit/src/main/kotlin/net/averak/gsync/testkit/{ => fixture}/Fixture.kt (96%) create mode 100644 testkit/src/main/kotlin/net/averak/gsync/testkit/fixture/builder/master/FriendSettingBuilder.kt create mode 100644 testkit/src/main/kotlin/net/averak/gsync/testkit/fixture/builder/master/Registry.kt create mode 100644 testkit/src/main/kotlin/net/averak/gsync/testkit/fixture/builder/player/PlayerBuilder.kt create mode 100644 testkit/src/main/kotlin/net/averak/gsync/testkit/fixture/builder/player/PlayerStorageBuilder.kt create mode 100644 testkit/src/main/kotlin/net/averak/gsync/testkit/fixture/builder/player/Registry.kt create mode 100644 testkit/src/main/kotlin/net/averak/gsync/testkit/fixture/setupper/MasterUp.kt create mode 100644 testkit/src/main/kotlin/net/averak/gsync/testkit/fixture/setupper/PlayerUp.kt diff --git a/app/adapter/src/test/groovy/net/averak/gsync/adapter/handler/player_api/PlayerStorageHandler_IT.groovy b/app/adapter/src/test/groovy/net/averak/gsync/adapter/handler/player_api/PlayerStorageHandler_IT.groovy index 44c8f97..4230661 100644 --- a/app/adapter/src/test/groovy/net/averak/gsync/adapter/handler/player_api/PlayerStorageHandler_IT.groovy +++ b/app/adapter/src/test/groovy/net/averak/gsync/adapter/handler/player_api/PlayerStorageHandler_IT.groovy @@ -1,9 +1,7 @@ package net.averak.gsync.adapter.handler.player_api -import net.averak.gsync.adapter.dao.dto.base.PlayerDto -import net.averak.gsync.adapter.dao.dto.base.PlayerStorageEntryDto -import net.averak.gsync.adapter.dao.dto.base.PlayerStorageRevisionDto import net.averak.gsync.adapter.handler.player_api.pbconv.PlayerStorageConverter +import net.averak.gsync.core.game_context.GameContext import net.averak.gsync.domain.model.PlayerStorageEntry import net.averak.gsync.schema.protobuf.player_api.PlayerStorageClearV1 import net.averak.gsync.schema.protobuf.player_api.PlayerStorageSearchV1 @@ -11,42 +9,24 @@ import net.averak.gsync.schema.protobuf.player_api.PlayerStorageSetV1 import net.averak.gsync.schema.protobuf.resource.player_storage.Criteria import net.averak.gsync.testkit.AbstractDatabaseSpec import net.averak.gsync.testkit.Faker -import net.averak.gsync.testkit.Fixture +import net.averak.gsync.testkit.fixture.builder.player.PlayerBuilder +import net.averak.gsync.testkit.fixture.builder.player.PlayerStorageBuilder class PlayerStorageHandler_SearchV1_IT extends AbstractDatabaseSpec { def "正常系: パターンにマッチしたエントリを取得できる"() { given: - Fixture.setup( - Faker.fake(PlayerDto, [ - "playerId": Faker.uuidv5("p1").toString(), - ]), - ) - Fixture.setup( - Faker.fake(PlayerStorageRevisionDto, [ - "playerId": Faker.uuidv5("p1").toString(), - "gameId" : Faker.uuidv5("g1").toString(), - ]), - ) - Fixture.setup( - Faker.fake(PlayerStorageEntryDto, [ - "playerId": Faker.uuidv5("p1").toString(), - "gameId" : Faker.uuidv5("g1").toString(), - "key" : "group1#key1", - "value" : "value1".bytes, - ]), - Faker.fake(PlayerStorageEntryDto, [ - "playerId": Faker.uuidv5("p1").toString(), - "gameId" : Faker.uuidv5("g1").toString(), - "key" : "group1#key2", - "value" : "value2".bytes, - ]), - Faker.fake(PlayerStorageEntryDto, [ - "playerId": Faker.uuidv5("p1").toString(), - "gameId" : Faker.uuidv5("g1").toString(), - "key" : "group2#key1", - "value" : "value3".bytes, - ]), + final gctx = Faker.fake(GameContext) + playerUp.setup( + gctx, + new PlayerBuilder(Faker.uuidv5("p1")).build(), + new PlayerStorageBuilder(Faker.uuidv5("p1"), Faker.uuidv5("g1")) + .entries( + new PlayerStorageEntry("group1#key1", "value1".bytes), + new PlayerStorageEntry("group1#key2", "value2".bytes), + new PlayerStorageEntry("group2#key1", "value3".bytes), + ) + .build(), ) when: @@ -60,7 +40,7 @@ class PlayerStorageHandler_SearchV1_IT extends AbstractDatabaseSpec { ).build(), ) { it.session(Faker.uuidv5("p1"), Faker.uuidv5("g1")) - it.spoofingMasterVersion(Faker.uuidv4()) + it.spoofingMasterVersion(gctx.masterVersion) } then: @@ -73,17 +53,14 @@ class PlayerStorageHandler_SetV1_IT extends AbstractDatabaseSpec { def "正常系: パターンにマッチしたエントリを作成できる"() { given: - Fixture.setup( - Faker.fake(PlayerDto, [ - "playerId": Faker.uuidv5("p1").toString(), - ]), - ) - Fixture.setup( - Faker.fake(PlayerStorageRevisionDto, [ - "playerId" : Faker.uuidv5("p1").toString(), - "gameId" : Faker.uuidv5("g1").toString(), - "playerStorageRevisionId": Faker.uuidv5("r1").toString(), - ]), + final gctx = Faker.fake(GameContext) + playerUp.setup( + gctx, + new PlayerBuilder(Faker.uuidv5("p1")).build(), + new PlayerStorageBuilder(Faker.uuidv5("p1"), Faker.uuidv5("g1")) + .revision(Faker.uuidv5("r1")) + .entries() + .build(), ) final entry = Faker.fake(PlayerStorageEntry) @@ -97,7 +74,7 @@ class PlayerStorageHandler_SetV1_IT extends AbstractDatabaseSpec { .build(), ) { it.session(Faker.uuidv5("p1"), Faker.uuidv5("g1")) - it.spoofingMasterVersion(Faker.uuidv4()) + it.spoofingMasterVersion(gctx.masterVersion) } then: @@ -120,37 +97,18 @@ class PlayerStorageHandler_ClearV1_IT extends AbstractDatabaseSpec { def "正常系: パターンにマッチしたエントリを削除できる"() { given: - Fixture.setup( - Faker.fake(PlayerDto, [ - "playerId": Faker.uuidv5("p1").toString(), - ]), - ) - Fixture.setup( - Faker.fake(PlayerStorageRevisionDto, [ - "playerId" : Faker.uuidv5("p1").toString(), - "gameId" : Faker.uuidv5("g1").toString(), - "playerStorageRevisionId": Faker.uuidv5("current revision").toString(), - ]), - ) - Fixture.setup( - Faker.fake(PlayerStorageEntryDto, [ - "playerId": Faker.uuidv5("p1").toString(), - "gameId" : Faker.uuidv5("g1").toString(), - "key" : "group1#key1", - "value" : "value1".bytes, - ]), - Faker.fake(PlayerStorageEntryDto, [ - "playerId": Faker.uuidv5("p1").toString(), - "gameId" : Faker.uuidv5("g1").toString(), - "key" : "group1#key2", - "value" : "value2".bytes, - ]), - Faker.fake(PlayerStorageEntryDto, [ - "playerId": Faker.uuidv5("p1").toString(), - "gameId" : Faker.uuidv5("g1").toString(), - "key" : "group2#key1", - "value" : "value3".bytes, - ]), + final gctx = Faker.fake(GameContext) + playerUp.setup( + gctx, + new PlayerBuilder(Faker.uuidv5("p1")).build(), + new PlayerStorageBuilder(Faker.uuidv5("p1"), Faker.uuidv5("g1")) + .revision(Faker.uuidv5("current revision")) + .entries( + new PlayerStorageEntry("group1#key1", "value1".bytes), + new PlayerStorageEntry("group1#key2", "value2".bytes), + new PlayerStorageEntry("group2#key1", "value3".bytes), + ) + .build(), ) when: @@ -165,7 +123,7 @@ class PlayerStorageHandler_ClearV1_IT extends AbstractDatabaseSpec { ).build(), ) { it.session(Faker.uuidv5("p1"), Faker.uuidv5("g1")) - it.spoofingMasterVersion(Faker.uuidv4()) + it.spoofingMasterVersion(gctx.masterVersion) } then: diff --git a/app/adapter/src/test/groovy/net/averak/gsync/adapter/handler/player_api/interceptor/ClientVersionInterceptor_UT.groovy b/app/adapter/src/test/groovy/net/averak/gsync/adapter/handler/player_api/interceptor/ClientVersionInterceptor_UT.groovy index 96b7167..c73e4f8 100644 --- a/app/adapter/src/test/groovy/net/averak/gsync/adapter/handler/player_api/interceptor/ClientVersionInterceptor_UT.groovy +++ b/app/adapter/src/test/groovy/net/averak/gsync/adapter/handler/player_api/interceptor/ClientVersionInterceptor_UT.groovy @@ -8,7 +8,7 @@ import net.averak.gsync.schema.protobuf.player_api.EchoEchoV1 import net.averak.gsync.testkit.AbstractDatabaseSpec import net.averak.gsync.testkit.Assert import net.averak.gsync.testkit.Faker -import net.averak.gsync.testkit.Fixture +import net.averak.gsync.testkit.fixture.Fixture import org.springframework.beans.factory.annotation.Autowired class ClientVersionInterceptor_UT extends AbstractDatabaseSpec { diff --git a/app/adapter/src/test/groovy/net/averak/gsync/adapter/handler/utils/MasterVersionUtils_UT.groovy b/app/adapter/src/test/groovy/net/averak/gsync/adapter/handler/utils/MasterVersionUtils_UT.groovy index 4eadae7..35417d5 100644 --- a/app/adapter/src/test/groovy/net/averak/gsync/adapter/handler/utils/MasterVersionUtils_UT.groovy +++ b/app/adapter/src/test/groovy/net/averak/gsync/adapter/handler/utils/MasterVersionUtils_UT.groovy @@ -6,7 +6,7 @@ import net.averak.gsync.core.exception.GsyncException import net.averak.gsync.testkit.AbstractDatabaseSpec import net.averak.gsync.testkit.Assert import net.averak.gsync.testkit.Faker -import net.averak.gsync.testkit.Fixture +import net.averak.gsync.testkit.fixture.Fixture import org.springframework.beans.factory.annotation.Autowired class MasterVersionUtils_UT extends AbstractDatabaseSpec { diff --git a/app/adapter/src/test/groovy/net/averak/gsync/adapter/repository/EchoRepository_UT.groovy b/app/adapter/src/test/groovy/net/averak/gsync/adapter/repository/EchoRepository_UT.groovy index 981f2ce..eeeeb66 100644 --- a/app/adapter/src/test/groovy/net/averak/gsync/adapter/repository/EchoRepository_UT.groovy +++ b/app/adapter/src/test/groovy/net/averak/gsync/adapter/repository/EchoRepository_UT.groovy @@ -6,7 +6,7 @@ import net.averak.gsync.domain.model.Echo import net.averak.gsync.testkit.AbstractDatabaseSpec import net.averak.gsync.testkit.Assert import net.averak.gsync.testkit.Faker -import net.averak.gsync.testkit.Fixture +import net.averak.gsync.testkit.fixture.Fixture import org.springframework.beans.factory.annotation.Autowired import spock.lang.Shared diff --git a/app/adapter/src/test/groovy/net/averak/gsync/adapter/repository/FriendRepository_UT.groovy b/app/adapter/src/test/groovy/net/averak/gsync/adapter/repository/FriendRepository_UT.groovy index 0df5fb8..4bc2a5d 100644 --- a/app/adapter/src/test/groovy/net/averak/gsync/adapter/repository/FriendRepository_UT.groovy +++ b/app/adapter/src/test/groovy/net/averak/gsync/adapter/repository/FriendRepository_UT.groovy @@ -10,7 +10,7 @@ import net.averak.gsync.domain.repository.exception.MasterDataNotFoundException import net.averak.gsync.testkit.AbstractDatabaseSpec import net.averak.gsync.testkit.Assert import net.averak.gsync.testkit.Faker -import net.averak.gsync.testkit.Fixture +import net.averak.gsync.testkit.fixture.Fixture import org.springframework.beans.factory.annotation.Autowired import java.time.LocalDateTime diff --git a/app/adapter/src/test/groovy/net/averak/gsync/adapter/repository/GameRepository_UT.groovy b/app/adapter/src/test/groovy/net/averak/gsync/adapter/repository/GameRepository_UT.groovy index f42c376..07d3f0d 100644 --- a/app/adapter/src/test/groovy/net/averak/gsync/adapter/repository/GameRepository_UT.groovy +++ b/app/adapter/src/test/groovy/net/averak/gsync/adapter/repository/GameRepository_UT.groovy @@ -5,7 +5,7 @@ import net.averak.gsync.core.game_context.GameContext import net.averak.gsync.domain.model.Game import net.averak.gsync.testkit.AbstractDatabaseSpec import net.averak.gsync.testkit.Faker -import net.averak.gsync.testkit.Fixture +import net.averak.gsync.testkit.fixture.Fixture import org.springframework.beans.factory.annotation.Autowired class GameRepository_UT extends AbstractDatabaseSpec { diff --git a/app/adapter/src/test/groovy/net/averak/gsync/adapter/repository/OperatorRepository_UT.groovy b/app/adapter/src/test/groovy/net/averak/gsync/adapter/repository/OperatorRepository_UT.groovy index 8baadab..d3a228a 100644 --- a/app/adapter/src/test/groovy/net/averak/gsync/adapter/repository/OperatorRepository_UT.groovy +++ b/app/adapter/src/test/groovy/net/averak/gsync/adapter/repository/OperatorRepository_UT.groovy @@ -6,7 +6,7 @@ import net.averak.gsync.core.game_context.GameContext import net.averak.gsync.domain.model.Operator import net.averak.gsync.testkit.AbstractDatabaseSpec import net.averak.gsync.testkit.Faker -import net.averak.gsync.testkit.Fixture +import net.averak.gsync.testkit.fixture.Fixture import org.springframework.beans.factory.annotation.Autowired class OperatorRepository_UT extends AbstractDatabaseSpec { diff --git a/app/adapter/src/test/groovy/net/averak/gsync/adapter/repository/PlayerRepository_UT.groovy b/app/adapter/src/test/groovy/net/averak/gsync/adapter/repository/PlayerRepository_UT.groovy index caebbe8..f9761ca 100644 --- a/app/adapter/src/test/groovy/net/averak/gsync/adapter/repository/PlayerRepository_UT.groovy +++ b/app/adapter/src/test/groovy/net/averak/gsync/adapter/repository/PlayerRepository_UT.groovy @@ -10,7 +10,7 @@ import net.averak.gsync.domain.model.PlayerProfile import net.averak.gsync.testkit.AbstractDatabaseSpec import net.averak.gsync.testkit.Assert import net.averak.gsync.testkit.Faker -import net.averak.gsync.testkit.Fixture +import net.averak.gsync.testkit.fixture.Fixture import org.springframework.beans.factory.annotation.Autowired import spock.lang.Shared diff --git a/app/adapter/src/test/groovy/net/averak/gsync/adapter/repository/PlayerStorageRepository_UT.groovy b/app/adapter/src/test/groovy/net/averak/gsync/adapter/repository/PlayerStorageRepository_UT.groovy index 62d96da..961f3fa 100644 --- a/app/adapter/src/test/groovy/net/averak/gsync/adapter/repository/PlayerStorageRepository_UT.groovy +++ b/app/adapter/src/test/groovy/net/averak/gsync/adapter/repository/PlayerStorageRepository_UT.groovy @@ -10,7 +10,7 @@ import net.averak.gsync.domain.repository.IPlayerStorageRepository import net.averak.gsync.domain.repository.exception.AlreadyDoneException import net.averak.gsync.testkit.AbstractDatabaseSpec import net.averak.gsync.testkit.Faker -import net.averak.gsync.testkit.Fixture +import net.averak.gsync.testkit.fixture.Fixture import org.springframework.beans.factory.annotation.Autowired import spock.lang.Shared diff --git a/testkit/src/main/groovy/net/averak/gsync/testkit/AbstractDatabaseSpec.groovy b/testkit/src/main/groovy/net/averak/gsync/testkit/AbstractDatabaseSpec.groovy index d723a70..cb90661 100644 --- a/testkit/src/main/groovy/net/averak/gsync/testkit/AbstractDatabaseSpec.groovy +++ b/testkit/src/main/groovy/net/averak/gsync/testkit/AbstractDatabaseSpec.groovy @@ -3,6 +3,9 @@ package net.averak.gsync.testkit import groovy.sql.Sql import jakarta.annotation.PostConstruct import net.averak.gsync.infrastructure.redis.RedisClient +import net.averak.gsync.testkit.fixture.Fixture +import net.averak.gsync.testkit.fixture.setupper.MasterUp +import net.averak.gsync.testkit.fixture.setupper.PlayerUp import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.autoconfigure.EnableAutoConfiguration import spock.lang.Shared @@ -18,6 +21,14 @@ abstract class AbstractDatabaseSpec extends AbstractSpec { @Shared RedisClient redis + @Autowired + @Shared + MasterUp masterUp + + @Autowired + @Shared + PlayerUp playerUp + @PostConstruct private void init() { Fixture.init(sql) diff --git a/testkit/src/main/kotlin/net/averak/gsync/testkit/api/grpc/GrpcTester.kt b/testkit/src/main/kotlin/net/averak/gsync/testkit/api/grpc/GrpcTester.kt index 62c2e7f..90613b5 100644 --- a/testkit/src/main/kotlin/net/averak/gsync/testkit/api/grpc/GrpcTester.kt +++ b/testkit/src/main/kotlin/net/averak/gsync/testkit/api/grpc/GrpcTester.kt @@ -4,6 +4,7 @@ import com.google.protobuf.AbstractMessage import io.grpc.* import jakarta.annotation.PostConstruct import net.averak.gsync.core.config.Config +import net.averak.gsync.core.game_context.GameContext import net.averak.gsync.domain.model.Os import net.averak.gsync.infrastructure.grpc.player_api.metadata.IncomingHeaderKey import net.averak.gsync.schema.protobuf.player_api.EchoGrpc @@ -74,6 +75,10 @@ class GrpcTester( metadata[IncomingHeaderKey.GAME_ID] = value.toString() } + fun idempotencyKey(value: UUID) { + metadata[IncomingHeaderKey.IDEMPOTENCY_KEY] = value.toString() + } + fun spoofingPlayerID(value: UUID) { metadata[IncomingHeaderKey.DEBUG_SPOOFING_PLAYER_ID] = value.toString() } @@ -85,6 +90,12 @@ class GrpcTester( fun spoofingCurrentTime(value: LocalDateTime) { metadata[IncomingHeaderKey.DEBUG_SPOOFING_CURRENT_TIME] = value.toString() } + + fun gameContext(gctx: GameContext) { + idempotencyKey(gctx.idempotencyKey) + spoofingMasterVersion(gctx.masterVersion) + spoofingCurrentTime(gctx.currentTime) + } } private class MetadataInterceptor : ClientInterceptor { diff --git a/testkit/src/main/kotlin/net/averak/gsync/testkit/Fixture.kt b/testkit/src/main/kotlin/net/averak/gsync/testkit/fixture/Fixture.kt similarity index 96% rename from testkit/src/main/kotlin/net/averak/gsync/testkit/Fixture.kt rename to testkit/src/main/kotlin/net/averak/gsync/testkit/fixture/Fixture.kt index 7b5557b..45314eb 100644 --- a/testkit/src/main/kotlin/net/averak/gsync/testkit/Fixture.kt +++ b/testkit/src/main/kotlin/net/averak/gsync/testkit/fixture/Fixture.kt @@ -1,4 +1,4 @@ -package net.averak.gsync.testkit +package net.averak.gsync.testkit.fixture import com.google.common.base.CaseFormat import groovy.sql.Sql @@ -19,7 +19,7 @@ class Fixture { */ @JvmStatic fun init(sql: Sql) { - Fixture.sql = sql + Companion.sql = sql } /** diff --git a/testkit/src/main/kotlin/net/averak/gsync/testkit/fixture/builder/master/FriendSettingBuilder.kt b/testkit/src/main/kotlin/net/averak/gsync/testkit/fixture/builder/master/FriendSettingBuilder.kt new file mode 100644 index 0000000..5638811 --- /dev/null +++ b/testkit/src/main/kotlin/net/averak/gsync/testkit/fixture/builder/master/FriendSettingBuilder.kt @@ -0,0 +1,29 @@ +package net.averak.gsync.testkit.fixture.builder.master + +import net.averak.gsync.domain.model.FriendSetting + +class FriendSettingBuilder( + private var data: FriendSetting, +) { + + constructor() : this( + FriendSetting( + maxFriendCount = 100, + maxFriendRequestCount = 100, + ), + ) + + fun maxFriendCount(maxFriendCount: Int): FriendSettingBuilder { + data = data.copy(maxFriendCount = maxFriendCount) + return this + } + + fun maxFriendRequestCount(maxFriendRequestCount: Int): FriendSettingBuilder { + data = data.copy(maxFriendRequestCount = maxFriendRequestCount) + return this + } + + fun build(): Registry { + return Registry(friendSetting = data) + } +} diff --git a/testkit/src/main/kotlin/net/averak/gsync/testkit/fixture/builder/master/Registry.kt b/testkit/src/main/kotlin/net/averak/gsync/testkit/fixture/builder/master/Registry.kt new file mode 100644 index 0000000..1611598 --- /dev/null +++ b/testkit/src/main/kotlin/net/averak/gsync/testkit/fixture/builder/master/Registry.kt @@ -0,0 +1,7 @@ +package net.averak.gsync.testkit.fixture.builder.master + +import net.averak.gsync.domain.model.FriendSetting + +data class Registry( + val friendSetting: FriendSetting? = null, +) diff --git a/testkit/src/main/kotlin/net/averak/gsync/testkit/fixture/builder/player/PlayerBuilder.kt b/testkit/src/main/kotlin/net/averak/gsync/testkit/fixture/builder/player/PlayerBuilder.kt new file mode 100644 index 0000000..1281197 --- /dev/null +++ b/testkit/src/main/kotlin/net/averak/gsync/testkit/fixture/builder/player/PlayerBuilder.kt @@ -0,0 +1,33 @@ +package net.averak.gsync.testkit.fixture.builder.player + +import net.averak.gsync.domain.model.Player +import net.averak.gsync.domain.model.PlayerProfile +import net.averak.gsync.testkit.Faker +import java.util.* + +class PlayerBuilder( + private var data: Player, +) { + + constructor(playerID: UUID) : this( + Player( + id = playerID, + friendID = UUID.randomUUID(), + isBanned = false, + profile = PlayerProfile( + nickname = Faker.alphanumeric(10), + iconID = Faker.uuidv4().toString(), + ), + login = null, + ), + ) + + fun profile(profile: PlayerProfile): PlayerBuilder { + data = data.copy(profile = profile) + return this + } + + fun build(): Registry { + return Registry(player = data) + } +} diff --git a/testkit/src/main/kotlin/net/averak/gsync/testkit/fixture/builder/player/PlayerStorageBuilder.kt b/testkit/src/main/kotlin/net/averak/gsync/testkit/fixture/builder/player/PlayerStorageBuilder.kt new file mode 100644 index 0000000..b02cc31 --- /dev/null +++ b/testkit/src/main/kotlin/net/averak/gsync/testkit/fixture/builder/player/PlayerStorageBuilder.kt @@ -0,0 +1,42 @@ +package net.averak.gsync.testkit.fixture.builder.player + +import net.averak.gsync.domain.model.PlayerStorage +import net.averak.gsync.domain.model.PlayerStorageEntry +import java.util.* + +class PlayerStorageBuilder( + private var data: PlayerStorage, +) { + + constructor(playerID: UUID, gameID: UUID) : this( + PlayerStorage( + playerID = playerID, + gameID = gameID, + revision = UUID.randomUUID(), + entries = mutableListOf( + PlayerStorageEntry( + key = "key1", + value = "value1".toByteArray(), + ), + PlayerStorageEntry( + key = "key2", + value = "value2".toByteArray(), + ), + ), + ), + ) + + fun revision(revision: UUID): PlayerStorageBuilder { + data = data.copy(revision = revision) + return this + } + + fun entries(vararg entries: PlayerStorageEntry): PlayerStorageBuilder { + data = data.copy(entries = entries.toMutableList()) + return this + } + + fun build(): Registry { + return Registry(playerStorage = data) + } +} diff --git a/testkit/src/main/kotlin/net/averak/gsync/testkit/fixture/builder/player/Registry.kt b/testkit/src/main/kotlin/net/averak/gsync/testkit/fixture/builder/player/Registry.kt new file mode 100644 index 0000000..ebdbdda --- /dev/null +++ b/testkit/src/main/kotlin/net/averak/gsync/testkit/fixture/builder/player/Registry.kt @@ -0,0 +1,13 @@ +package net.averak.gsync.testkit.fixture.builder.player + +import net.averak.gsync.domain.model.FriendRequest +import net.averak.gsync.domain.model.Friendship +import net.averak.gsync.domain.model.Player +import net.averak.gsync.domain.model.PlayerStorage + +data class Registry( + val player: Player? = null, + val playerStorage: PlayerStorage? = null, + val friendships: List = emptyList(), + val friendRequests: List = emptyList(), +) diff --git a/testkit/src/main/kotlin/net/averak/gsync/testkit/fixture/setupper/MasterUp.kt b/testkit/src/main/kotlin/net/averak/gsync/testkit/fixture/setupper/MasterUp.kt new file mode 100644 index 0000000..9c7b98e --- /dev/null +++ b/testkit/src/main/kotlin/net/averak/gsync/testkit/fixture/setupper/MasterUp.kt @@ -0,0 +1,27 @@ +package net.averak.gsync.testkit.fixture.setupper + +import net.averak.gsync.adapter.dao.dto.base.FriendSettingMasterDto +import net.averak.gsync.adapter.dao.mapper.base.FriendSettingMasterBaseMapper +import net.averak.gsync.core.game_context.GameContext +import net.averak.gsync.testkit.fixture.builder.master.Registry +import org.springframework.stereotype.Component + +@Component +class MasterUp( + private val friendSettingMasterMapper: FriendSettingMasterBaseMapper, +) { + + fun setup(gctx: GameContext, vararg registry: Registry) { + registry.forEach { data -> + if (data.friendSetting != null) { + friendSettingMasterMapper.insert( + FriendSettingMasterDto( + gctx.masterVersion.toString(), + data.friendSetting.maxFriendCount.toLong(), + data.friendSetting.maxFriendRequestCount.toLong(), + ), + ) + } + } + } +} diff --git a/testkit/src/main/kotlin/net/averak/gsync/testkit/fixture/setupper/PlayerUp.kt b/testkit/src/main/kotlin/net/averak/gsync/testkit/fixture/setupper/PlayerUp.kt new file mode 100644 index 0000000..5d7ee4e --- /dev/null +++ b/testkit/src/main/kotlin/net/averak/gsync/testkit/fixture/setupper/PlayerUp.kt @@ -0,0 +1,33 @@ +package net.averak.gsync.testkit.fixture.setupper + +import net.averak.gsync.core.game_context.GameContext +import net.averak.gsync.domain.repository.IFriendRepository +import net.averak.gsync.domain.repository.IPlayerRepository +import net.averak.gsync.domain.repository.IPlayerStorageRepository +import net.averak.gsync.testkit.fixture.builder.player.Registry +import org.springframework.stereotype.Component + +@Component +class PlayerUp( + private val playerRepository: IPlayerRepository, + private val playerStorageRepository: IPlayerStorageRepository, + private val friendRepository: IFriendRepository, +) { + + fun setup(gctx: GameContext, vararg registry: Registry) { + registry.forEach { data -> + if (data.player != null) { + playerRepository.save(gctx, data.player) + } + if (data.playerStorage != null) { + playerStorageRepository.save(gctx, data.playerStorage) + } + data.friendships.forEach { friendship -> + friendRepository.saveFriendship(gctx, friendship) + } + data.friendRequests.forEach { friendRequest -> + friendRepository.saveFriendRequest(gctx, friendRequest) + } + } + } +}