-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGetDwellingByIdTest.java
More file actions
135 lines (115 loc) · 4.85 KB
/
GetDwellingByIdTest.java
File metadata and controls
135 lines (115 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package com.dddheroes.heroesofddd.creaturerecruitment.read.getdwellingbyid;
import com.dddheroes.heroesofddd.TestcontainersConfiguration;
import com.dddheroes.heroesofddd.creaturerecruitment.read.DwellingReadModel;
import com.dddheroes.heroesofddd.creaturerecruitment.read.DwellingReadModelTest;
import com.dddheroes.heroesofddd.creaturerecruitment.write.DwellingId;
import com.dddheroes.heroesofddd.creaturerecruitment.events.DwellingBuilt;
import com.dddheroes.heroesofddd.creaturerecruitment.events.AvailableCreaturesChanged;
import com.dddheroes.heroesofddd.creaturerecruitment.events.CreatureRecruited;
import com.dddheroes.heroesofddd.shared.domain.identifiers.ArmyId;
import com.dddheroes.heroesofddd.shared.CreatureIds;
import org.axonframework.eventhandling.gateway.EventGateway;
import org.axonframework.queryhandling.QueryGateway;
import org.junit.jupiter.api.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Import;
import static com.dddheroes.heroesofddd.utils.AwaitilityUtils.*;
import static org.assertj.core.api.Assertions.*;
@Import(TestcontainersConfiguration.class)
@SpringBootTest
class GetDwellingByIdTest extends DwellingReadModelTest {
private final QueryGateway queryGateway;
@Autowired
GetDwellingByIdTest(
EventGateway eventGateway,
QueryGateway queryGateway
) {
super(eventGateway);
this.queryGateway = queryGateway;
}
@Test
void projectingDwellingReadModel_TestCase1() {
// given
var dwellingId = DwellingId.random().raw();
// when
var query = getDwellingById(dwellingId);
// then
awaitUntilAsserted(() -> {
var result = getDwellingReadModel(query);
assertThat(result).isNull();
});
}
@Test
void projectingDwellingReadModel_TestCase2() {
// given
var dwellingId = DwellingId.random().raw();
var creatureId = CreatureIds.phoenix().raw();
givenDwellingEvents(
dwellingId,
new DwellingBuilt(dwellingId, creatureId, PHOENIX_COST)
);
// when
var query = getDwellingById(dwellingId);
// then
awaitUntilAsserted(() -> {
var result = getDwellingReadModel(query);
assertThat(result).isNotNull();
assertThat(result.getDwellingId()).isEqualTo(dwellingId);
assertThat(result.getCreatureId()).isEqualTo(creatureId);
assertThat(result.getCostPerTroop()).isEqualTo(PHOENIX_COST);
assertThat(result.getAvailableCreatures()).isEqualTo(0);
});
}
@Test
void projectingDwellingReadModel_TestCase3() {
// given
var dwellingId = DwellingId.random().raw();
var creatureId = CreatureIds.phoenix().raw();
givenDwellingEvents(
dwellingId,
new DwellingBuilt(dwellingId, creatureId, PHOENIX_COST),
new AvailableCreaturesChanged(dwellingId, creatureId, 3)
);
// when
var query = getDwellingById(dwellingId);
// then
awaitUntilAsserted(() -> {
var result = getDwellingReadModel(query);
assertThat(result).isNotNull();
assertThat(result.getDwellingId()).isEqualTo(dwellingId);
assertThat(result.getCreatureId()).isEqualTo(creatureId);
assertThat(result.getCostPerTroop()).isEqualTo(PHOENIX_COST);
assertThat(result.getAvailableCreatures()).isEqualTo(3);
});
}
@Test
void projectingDwellingReadModel_TestCase4() {
// given
var dwellingId = DwellingId.random().raw();
var creatureId = CreatureIds.phoenix().raw();
givenDwellingEvents(
dwellingId,
new DwellingBuilt(dwellingId, creatureId, PHOENIX_COST),
new AvailableCreaturesChanged(dwellingId, creatureId, 3),
new CreatureRecruited(dwellingId, creatureId, ArmyId.random().raw(), 1, PHOENIX_COST)
);
// when
var query = getDwellingById(dwellingId);
// then
awaitUntilAsserted(() -> {
var result = getDwellingReadModel(query);
assertThat(result).isNotNull();
assertThat(result.getDwellingId()).isEqualTo(dwellingId);
assertThat(result.getCreatureId()).isEqualTo(creatureId);
assertThat(result.getCostPerTroop()).isEqualTo(PHOENIX_COST);
assertThat(result.getAvailableCreatures()).isEqualTo(2);
});
}
private GetDwellingById getDwellingById(String dwellingId) {
return GetDwellingById.query(GAME_ID, dwellingId);
}
private DwellingReadModel getDwellingReadModel(GetDwellingById query) {
return queryGateway.query(query, DwellingReadModel.class).join();
}
}