Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit test #45

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
259afad
貸出日のテスト
stgctkm Jul 4, 2023
9d37a60
貸出リストのテスト
stgctkm Jul 4, 2023
61f9dd7
予約制限のテスト
stgctkm Jul 5, 2023
203a583
遅延状態のテスト
stgctkm Jul 5, 2023
db72e9f
遅延状態のテスト,遅延期間のテスト
stgctkm Jul 5, 2023
516e25e
複数のassertを修正
stgctkm Jul 5, 2023
24870c5
所蔵品の貸出可否のテスト
stgctkm Jul 5, 2023
0c6da23
貸出制限のテスト
stgctkm Jul 5, 2023
3c8ff7b
コメント修正
stgctkm Jul 5, 2023
34eafda
コメント削除
stgctkm Jul 5, 2023
73cdb6d
既存のテストをLoadnStatusテストに移動
stgctkm Jul 5, 2023
d847e13
貸出予約と待ち順番のテスト
stgctkm Jul 5, 2023
d19b5ba
貸出予約リスト
stgctkm Jul 5, 2023
402d16a
取置期限のテスト
stgctkm Jul 5, 2023
79fa980
貸出シナリオTest
stgctkm Jul 5, 2023
59b7d6e
コメント修正
stgctkm Jul 5, 2023
86ccd56
予約受付シナリオTest
stgctkm Jul 6, 2023
c3fd71e
テスト実行時のデータに画面動作確認用のデータを使わない
stgctkm Jul 6, 2023
86b28a2
予約取消シナリオTest
stgctkm Jul 6, 2023
b2450c9
`integration-test` profile を追加
stgctkm Jul 6, 2023
2f78d20
Merge branch 'master' into unit-test
stgctkm Jul 6, 2023
402dadb
取置シナリオTest
stgctkm Jul 6, 2023
973ee53
不要なテストを削除
stgctkm Jul 6, 2023
6681376
返却シナリオテスト
stgctkm Jul 6, 2023
28bfd7e
E2Eテスト
stgctkm Jul 7, 2023
3ddbeb7
Arrange, Act, Assertのコメントが不要な箇所は削除
stgctkm Jul 11, 2023
ad9e673
driverの設定を変更
stgctkm Jul 12, 2023
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
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ dependencies {
runtimeOnly 'io.opentelemetry:opentelemetry-exporter-zipkin'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
// testImplementation 'org.seleniumhq.selenium:selenium-java:4.10.0'
testImplementation 'com.codeborne:selenide:6.16.0'


}

tasks.named('test') {
Expand Down
10 changes: 5 additions & 5 deletions src/main/resources/templates/_parts/navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<nav>
<!-- <a></a>-->
<ul>
<li><a th:href="@{/}">ホーム</a></li>
<li><a th:href="@{/}" id="link-to-home">ホーム</a></li>
<li><a th:href="@{/reservation/entries/search}">本を探す</a></li>
<li><a th:href="@{/reservation/register}">本の貸出予約</a></li>
</ul>
Expand All @@ -19,16 +19,16 @@
<header th:fragment="loan">
<nav>
<ul>
<li><a th:href="@{/}">ホーム</a></li>
<li><a th:href="@{/loan/register}">本の貸出</a></li>
<li><a th:href="@{/returns}">本の返却</a></li>
<li><a th:href="@{/}" id="link-to-home">ホーム</a></li>
<li><a th:href="@{/loan/register}" id="link-loan">本の貸出</a></li>
<li><a th:href="@{/returns}" id="link-return">本の返却</a></li>
</ul>
</nav>
</header>
<header th:fragment="retention">
<nav>
<ul>
<li><a th:href="@{/}">ホーム</a></li>
<li><a th:href="@{/}" id="link-to-home">ホーム</a></li>
<li><a th:href="@{/retentions/requests}">予約の管理</a></li>
<li><a th:href="@{/retentions}">取置の管理</a></li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/loan/completed.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<p>会員番号: <span th:text="${loanStatus.memberNumber()}"></span> の貸出を登録しました。
</p>
<h3>貸出状況</h3>
<table>
<table id="loan-list">
<thead>
<tr>
<th>貸出日</th>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/loan/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ <h3>貸出の記録</h3>
<mark><span th:errors="*{loanDate.value}"></span></mark>
</p>

<button>登録</button>
<button id="button-register-loan">登録</button>
</form>
</article>

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/reservation/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ <h4 th:text="${entry.show()}"></h4>

<input type="hidden" name="entry" th:value="${entry.entryNumber()}">

<button>予約する</button>
<button id="button-reserve">予約する</button>
</form>
</article>

Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/templates/reservation/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
<form method="get" action="#" th:action="@{/reservation/entries/search}">
<label>キーワード検索(空白で全件を検索します)</label>
<input class="input" type="text" placeholder="キーワード" th:field="${searchKeyword.value}">
<button>本を探す</button>
<button id="button-search">本を探す</button>
</form>
</article>

<article>
<h4>検索結果:
<h4 id="header-search-result">検索結果:
<span th:text="${entryInStockList.numberOfMaterial().show()}"></span>
</h4>
<table th:if="${entryInStockList.size()} > 0">
<table id="table-search-result" th:if="${entryInStockList.size()} > 0">
<thead>
<tr>
<th></th>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/retention/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h1>取置の登録</h1>
</mark>
</p>
<input type="hidden" name="reservationNumber.value" th:value="${reservation.reservationNumber()}">
<button type="submit" value="取置">取置</button>
<button type="submit" value="取置" id="button-retention">取置</button>
</form>
</article>
</main>
Expand Down
5 changes: 3 additions & 2 deletions src/main/resources/templates/retention/requests.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
<header th:replace="_parts/navigation::retention"></header>
<main>
<article>
<h1>予約の管理</h1>
<h1 id="header-reservation-management">予約の管理</h1>
<p th:text="${reservations.numberOfReservation()}">件</p>
<form>
<table th:unless="${reservations.isEmpty()}">
<table th:unless="${reservations.isEmpty()}" id="table-reservations">
<thead>
<tr>
<th>アクション</th>
Expand All @@ -26,6 +26,7 @@ <h1>予約の管理</h1>

<td>
<button type="submit"
id="button-retention"
th:formmethod="get" th:formaction="@{/retentions/requests/{reservation}(reservation=${reservation.reservationNumber()})}">
取置</button>
<button type="submit" name="notAvailable"
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/retention/retentions.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h1>取置中</h1>
<p th:text="${retainedList.showCount()}">件</p>
<form th:unless="${retainedList.isEmpty()}"
th:action="@{/retentions/loans}" method="post">
<table>
<table id="table-retentions">
<thead>
<tr>
<th>取置期限</th>
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/templates/returns/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<main>
<article>
<h3>本の返却</h3>
<h3 id="title-return">本の返却</h3>
<form method="post" action="#"
th:object="${returned}"
th:action="@{/returns}">
Expand All @@ -34,7 +34,7 @@ <h3>本の返却</h3>
<mark><span th:errors="*{returnDate.value}"></span></mark>
</p>

<button>登録</button>
<button id="button-return">登録</button>
</form>
</article>
</main>
Expand Down
12 changes: 6 additions & 6 deletions src/main/resources/templates/top.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ <h2>図書館サービス</h2>
<h3>利用者向け</h3>
<ul>
<li>一般:<a th:href="@{/}">ご利用案内</a> <small>未実装</small></li>
<li>会員:<a th:href="@{/reservation/entries/search}">本の予約</a></li>
<li>会員:<a th:href="@{/reservation/entries/search}" id="link-reservation-for-member">本の予約</a></li>
</ul>
<h3>図書館スタッフ用</h3>
<ul>
<li><a th:href="@{/loan/register}">貸出と返却</a></li>
<li><a th:href="@{/retentions/requests}">予約の管理</a></li>
<li><a th:href="@{/retentions}">取置の管理</a></li>
<li><a th:href="@{/}">会員の管理</a> <small>未実装</small></li>
<li><a th:href="@{/}">所蔵品の管理</a> <small>未実装</small></li>
<li><a th:href="@{/loan/register}" id="link-loan-return">貸出と返却</a></li>
<li><a th:href="@{/retentions/requests}" id="link-reservations">予約の管理</a></li>
<li><a th:href="@{/retentions}" id="link-retentions">取置の管理</a></li>
<li><a th:href="@{/}" id="link-members">会員の管理</a> <small>未実装</small></li>
<li><a th:href="@{/}" id="link-items">所蔵品の管理</a> <small>未実装</small></li>
</ul>
</article>
</main>
Expand Down
26 changes: 26 additions & 0 deletions src/test/java/library/application/fixture/entry/EntryFixture.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package library.application.fixture.entry;

import library.domain.model.material.entry.Entry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

@Component
public class EntryFixture {

@Autowired
JdbcTemplate jdbcTemplate;

public void 所蔵品目を登録する(Entry entry) {
String sql = """
INSERT INTO 資料_所蔵品目.所蔵品目(所蔵品目番号, タイトル, 著者, 所蔵品目種別)
VALUES (?, ?, ?, ?)
""";

jdbcTemplate.update(sql,
entry.entryNumber().value(),
entry.title().toString(),
entry.workOf().toString(),
entry.所蔵品目種別().name());
}
}
34 changes: 34 additions & 0 deletions src/test/java/library/application/fixture/item/ItemFixture.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package library.application.fixture.item;

import library.domain.model.material.item.Item;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

@Component
public class ItemFixture {

@Autowired
JdbcTemplate jdbcTemplate;

public void 所蔵品を登録する(Item item) {
String sql = """
INSERT INTO 資料_所蔵品.所蔵品(所蔵品番号, 所蔵品目番号)
VALUES(?, ?)
""";

jdbcTemplate.update(sql,
item.所蔵品番号().toString(),
item.所蔵品目().entryNumber().value());
}

public void 貸出可能な状態を登録する(Item item) {
String sql = """
INSERT INTO 資料_所蔵品._貸出可能(所蔵品番号)
VALUES (?)
""";

jdbcTemplate.update(sql,
item.所蔵品番号().toString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package library.application.fixture.member;

import library.domain.model.member.Member;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

@Component
public class MemberFixture {

@Autowired
JdbcTemplate jdbcTemplate;

public void 会員を登録する(Member member) {

String sql = """
INSERT INTO 会員.会員(会員番号, 氏名, 会員種別)
VALUES (?, ?, ?)
""";

jdbcTemplate.update(sql,
member.number().value(),
member.name().toString(),
member.type().name());

}




}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package library.application.scenario.loan;

import library.application.fixture.entry.EntryFixture;
import library.application.fixture.item.ItemFixture;
import library.application.fixture.member.MemberFixture;
import library.application.service.loan.LoanQueryService;
import library.domain.model.loan.LoanDate;
import library.domain.model.loan.LoanRequest;
import library.domain.model.loan.rule.ItemLoanability;
import library.domain.model.loan.rule.LoanStatus;
import library.domain.model.loan.rule.Loanability;
import library.domain.model.material.entry.*;
import library.domain.model.material.item.Item;
import library.domain.model.material.item.ItemNumber;
import library.domain.model.member.Member;
import library.domain.model.member.MemberNumber;
import library.domain.model.member.MemberType;
import library.domain.model.member.Name;
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;
import org.springframework.context.annotation.Profile;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;

import static org.junit.jupiter.api.Assertions.*;

@SpringBootTest
@Transactional
@ActiveProfiles("integration-test")
class 貸出シナリオTest {

@Autowired
LoanScenario sut;

@Autowired
MemberFixture memberFixture;

@Autowired
EntryFixture entryFixture;

@Autowired
ItemFixture itemFixture;

@Autowired
LoanQueryService loanQueryService;

Member 高橋雄一 = new Member(new MemberNumber(1009), new Name("高橋雄一"), MemberType.中学生以上);
Entry entry = new Entry(new EntryNumber(898912), new Title("マイクロサービスアーキテクチャー"), new WorkOf("Sam Newman"), EntryType.図書);
Item item = new Item(new ItemNumber("77878"), entry);

@Test
void 貸出制限を判断する() {
// Arrange
memberFixture.会員を登録する(高橋雄一);
entryFixture.所蔵品目を登録する(entry);
itemFixture.所蔵品を登録する(item);

LoanRequest 貸出依頼 =
new LoanRequest(new MemberNumber(1009), new ItemNumber("77878"), new LoanDate(LocalDate.parse("2023-07-01")));

// Act
Loanability 貸出可否 = sut.loanability(貸出依頼);
// Assert
assertEquals(Loanability.貸出可能, 貸出可否);
}

@Test
void 貸出() {
memberFixture.会員を登録する(高橋雄一);
entryFixture.所蔵品目を登録する(entry);
itemFixture.所蔵品を登録する(item);

sut.loan(new LoanRequest(高橋雄一.number(), item.所蔵品番号(), new LoanDate(LocalDate.parse("2023-07-04"))));

LoanStatus status = loanQueryService.status(高橋雄一.number());
assertEquals(1, status.loans().冊数().value());
}

@Test
@Disabled("LoanScenario#loanStatus()の引数は会員が良いと思う")
void loanStatus() {
fail();
}

@Test
void 所蔵品の貸出可否を提示する() {
entryFixture.所蔵品目を登録する(entry);
itemFixture.所蔵品を登録する(item);
itemFixture.貸出可能な状態を登録する(item);

ItemLoanability 所蔵品の貸出可否 = sut.所蔵品の貸出可否を提示する(item.所蔵品番号());

assertEquals(ItemLoanability.貸出可能, 所蔵品の貸出可否);
}
}
Loading