-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from averak/feature/16-setup-testtuils
refs #16 testkitサブモジュールを作成
- Loading branch information
Showing
22 changed files
with
463 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
rootProject.name = "gsync" | ||
include(":testkit") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 6 additions & 2 deletions
8
src/main/kotlin/net/averak/gsync/adapter/handler/exception/NotFoundExceptionMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,19 @@ | ||
package net.averak.gsync.adapter.handler.exception | ||
|
||
import jakarta.ws.rs.NotFoundException | ||
import jakarta.ws.rs.core.MediaType | ||
import jakarta.ws.rs.core.Response | ||
import jakarta.ws.rs.ext.ExceptionMapper | ||
import jakarta.ws.rs.ext.Provider | ||
import net.averak.gsync.core.exception.ErrorCode | ||
import org.apache.http.HttpStatus | ||
|
||
@Provider | ||
class NotFoundExceptionMapper : ExceptionMapper<NotFoundException> { | ||
override fun toResponse(exception: NotFoundException?): Response { | ||
return Response.status(HttpStatus.SC_NOT_FOUND).entity(ErrorResponse(ErrorCode.NOT_FOUND_API)).build() | ||
return Response | ||
.status(Response.Status.NOT_FOUND) | ||
.type(MediaType.APPLICATION_JSON_TYPE) | ||
.entity(ErrorResponse(ErrorCode.NOT_FOUND_API)) | ||
.build() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/main/kotlin/net/averak/gsync/core/exception/GsyncException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package net.averak.gsync.core.exception | ||
|
||
class GsyncException(val errorCode: ErrorCode, val causedBy: Throwable?) : RuntimeException(errorCode.summary, causedBy) { | ||
constructor(errorCode: ErrorCode) : this(errorCode, null) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package net.averak.gsync.domain.model | ||
|
||
import net.averak.gsync.domain.primitive.common.ID | ||
import java.time.LocalDateTime | ||
|
||
data class Echo( | ||
val id: ID, | ||
val message: String, | ||
val timestamp: LocalDateTime, | ||
) { | ||
constructor(message: String) : this( | ||
ID(), | ||
message, | ||
LocalDateTime.now(), | ||
) | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/kotlin/net/averak/gsync/domain/primitive/common/ID.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package net.averak.gsync.domain.primitive.common | ||
|
||
import net.averak.gsync.core.exception.ErrorCode | ||
import net.averak.gsync.core.exception.GsyncException | ||
import java.util.UUID | ||
|
||
data class ID(val value: String) { | ||
init { | ||
try { | ||
UUID.fromString(value) | ||
} catch (_: IllegalArgumentException) { | ||
throw GsyncException(ErrorCode.ID_FORMAT_IS_INVALID) | ||
} | ||
} | ||
|
||
constructor() : this(UUID.randomUUID().toString()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package net.averak.gsync.usecase | ||
|
||
import jakarta.inject.Singleton | ||
import net.averak.gsync.domain.model.Echo | ||
|
||
@Singleton | ||
class EchoUsecase { | ||
fun echo(message: String): Echo { | ||
return Echo(message) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,31 @@ | ||
package net.averak.gsync | ||
|
||
import io.quarkus.arc.All | ||
import io.quarkus.test.junit.QuarkusTest | ||
import jakarta.annotation.PostConstruct | ||
import jakarta.inject.Inject | ||
import net.averak.gsync.core.exception.GsyncException | ||
import net.averak.gsync.testkit.Faker | ||
import net.averak.gsync.testkit.IRandomizer | ||
import spock.lang.Specification | ||
|
||
@QuarkusTest | ||
abstract class AbstractSpec extends Specification { | ||
|
||
@Inject | ||
@All | ||
List<IRandomizer> randomizers | ||
|
||
@PostConstruct | ||
void init() { | ||
Faker.init(randomizers) | ||
} | ||
|
||
/** | ||
* 例外を検証 | ||
*/ | ||
static void verify(final GsyncException actual, final GsyncException expected) { | ||
assert actual.errorCode == expected.errorCode | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/test/groovy/net/averak/gsync/domain/primitive/common/ID_UT.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package net.averak.gsync.domain.primitive.common | ||
|
||
import net.averak.gsync.AbstractSpec | ||
import net.averak.gsync.core.exception.ErrorCode | ||
import net.averak.gsync.core.exception.GsyncException | ||
import net.averak.gsync.testkit.Faker | ||
|
||
class ID_UT extends AbstractSpec { | ||
|
||
def "constructor: 正常に作成できる"() { | ||
when: | ||
new ID(value) | ||
|
||
then: | ||
noExceptionThrown() | ||
|
||
where: | ||
value << [ | ||
Faker.uuidv4(), | ||
Faker.uuidv5("1"), | ||
] | ||
} | ||
|
||
def "ID: 制約違反の場合は例外を返す"() { | ||
when: | ||
new ID(value) | ||
|
||
then: | ||
final exception = thrown(GsyncException) | ||
verify(exception, new GsyncException(ErrorCode.ID_FORMAT_IS_INVALID)) | ||
|
||
where: | ||
value << [ | ||
Faker.alphanumeric(36), | ||
Faker.uuidv4() + "A", | ||
] | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
src/test/groovy/net/averak/gsync/randomizer/domain/primitive/common/IDRandomizer.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package net.averak.gsync.randomizer.domain.primitive.common | ||
|
||
import net.averak.gsync.domain.primitive.common.ID | ||
import net.averak.gsync.testkit.IRandomizer | ||
|
||
@Singleton | ||
class IDRandomizer implements IRandomizer { | ||
|
||
final Class typeToGenerate = ID.class | ||
|
||
@Override | ||
Object getRandomValue() { | ||
return new ID() | ||
} | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
src/test/groovy/net/averak/gsync/usecase/AbstractUsecase_UT.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package net.averak.gsync.usecase | ||
|
||
import net.averak.gsync.AbstractSpec | ||
|
||
abstract class AbstractUsecase_UT extends AbstractSpec { | ||
} |
21 changes: 21 additions & 0 deletions
21
src/test/groovy/net/averak/gsync/usecase/EchoUsecase_UT.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package net.averak.gsync.usecase | ||
|
||
import jakarta.inject.Inject | ||
import net.averak.gsync.testkit.Faker | ||
|
||
class EchoUsecase_Echo_UT extends AbstractUsecase_UT { | ||
|
||
@Inject | ||
EchoUsecase sut | ||
|
||
def "echo: 正常系 Echoを作成できる"() { | ||
given: | ||
final message = Faker.alphanumeric() | ||
|
||
when: | ||
final result = sut.echo(message) | ||
|
||
then: | ||
result.message == message | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
plugins { | ||
kotlin("jvm") version libs.versions.kotlin | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation(libs.groovy.sql) | ||
implementation(libs.easy.random) | ||
implementation(libs.commons.lang3) | ||
implementation(libs.guava) | ||
} | ||
|
||
kotlin { | ||
sourceSets { | ||
all { | ||
languageSettings { | ||
languageVersion = "2.0" | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.