Skip to content

extact-io/person-multi-module-app

Repository files navigation

Person Multi Module App

豆蔵デベロッパーサイトのブログ記事で利用しているサンプルアプリ

利用している記事

記事 利用内容
ArchUnitで考えるアーキテクチャ構造とその検証 ArchUnitのサンプル
JUnit5のExtension実装 - テストライフサイクルコールバックと引数の解決 JUnit5のExtension実装サンプル

ArchUnitのサンプルテストクラス

クラス 実装内容
全体 LayerDependencyArchUnitTest レイヤー間の依存関係の定義
物理モジュール間の依存関係の定義
アプリが依存してOKなライブラリの定義
レイヤ別 CoreDependencyArchUnitTest coreパッケージで依存してOKなライブラリの定義
EntityDependencyArchUnitTest entityパッケージで依存してOKなライブラリの定義
WebApiDependencyArchUnitTest webapiパッケージで依存してOKなライブラリの定義
ServiceDependencyArchUnitTest serviceパッケージで依存してOKなライブラリの定義
persistenceパッケージ直下で依存してOKなライブラリの定義
persistenceの実装パッケージへの依存がないことの定義
JpaDependencyArchUnitTest jpaパッケージで依存してOKなライブラリの定義
FileDependencyArchUnitTest fileパッケージで依存してOKなライブラリの定義

JUnit5のExtension実装サンプルクラス

クラス 実装内容
JpaPersonRepository テスト対象クラス
JpaPersonRepositoryTest Extensionを使ったテストクラス
JpaTransactionalExtension Extension実装
TransactionalForTest トランザクション対象を表すアノテーション

ビルドと実行

サンプルアプリのビルドにはJava11以上とMavenが必要です

  1. moduleのローカルインストール
# Clone this repository
git clone https://github.com/extact-io/person-multi-module-app.git
# Go into the repository
cd person-multi-module-app
# Install dependencies
mvn clean install -DskipTests=true
  1. サーバ側(RESTリソースアプリ)のビルドと起動
# Go into the app directory
cd person-server
# Build the app
mvn -Prunnable,jpa clean package -DskipTests=true
# Run the app
java -jar target/person-server.jar

動作確認

# Invoke PersonResource#get(id)
curl -X GET http://localhost:7001/api/persons/1 -w ':%{http_code}\n'
{"age":18,"id":1,"name":"soramame"}:200

# Invoke PersonResource#getAll()
curl -X GET http://localhost:7001/api/persons -w ':%{http_code}\n'
[{"age":18,"id":1,"name":"soramame"},{"age":32,"id":2,"name":"edamame"}]:200

# Invoke PersonResource#add(person)
curl -X POST -H "Content-Type: application/json" -d '{"id":null,"name":"daizu","age":20}' http://localhost:7001/api/persons -w ':%{http_code}\n'
{"age":20,"id":3,"name":"daizu"}:200

About

Sample app used in the blog article on the Mamezou developer site

Topics

Resources

Stars

Watchers

Forks

Languages