-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWhenWeekStartedThenProclaimWeekSymbolTest.java
More file actions
108 lines (89 loc) · 3.99 KB
/
WhenWeekStartedThenProclaimWeekSymbolTest.java
File metadata and controls
108 lines (89 loc) · 3.99 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
package com.dddheroes.heroesofddd.astrologers.automation.whenweekstartedthenproclaimweeksymbol;
import com.dddheroes.heroesofddd.TestcontainersConfiguration;
import com.dddheroes.heroesofddd.astrologers.write.proclaimweeksymbol.ProclaimWeekSymbol;
import com.dddheroes.heroesofddd.calendar.events.CalendarEvent;
import com.dddheroes.heroesofddd.calendar.write.CalendarId;
import com.dddheroes.heroesofddd.calendar.events.DayStarted;
import com.dddheroes.heroesofddd.maintenance.write.resetprocessor.StreamProcessorsOperations;
import com.dddheroes.heroesofddd.shared.domain.identifiers.GameId;
import com.dddheroes.heroesofddd.shared.application.GameMetaData;
import com.dddheroes.heroesofddd.shared.domain.identifiers.PlayerId;
import org.axonframework.commandhandling.gateway.CommandGateway;
import org.axonframework.eventhandling.DomainEventMessage;
import org.axonframework.eventhandling.GenericDomainEventMessage;
import org.axonframework.eventhandling.gateway.EventGateway;
import org.axonframework.messaging.MetaData;
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 org.springframework.test.context.bean.override.mockito.MockitoSpyBean;
import java.util.UUID;
import static com.dddheroes.heroesofddd.utils.AwaitilityUtils.awaitUntilAsserted;
import static org.mockito.Mockito.*;
@Import(TestcontainersConfiguration.class)
@SpringBootTest
class WhenWeekStartedThenProclaimWeekSymbolTest {
private static final String GAME_ID = GameId.random().raw();
private static final String PLAYER_ID = PlayerId.random().raw();
@Autowired
private EventGateway eventGateway;
@Autowired
private StreamProcessorsOperations streamProcessorsOperations;
@MockitoSpyBean
private CommandGateway commandGateway;
@Test
void whenDayStartedForFirstDayOfTheWeek_ThenProclaimWeekSymbol() {
// given
var gameId = UUID.randomUUID().toString();
var calendarId = CalendarId.of(gameId);
givenCalendarEvents(
gameId,
new DayStarted(calendarId.raw(), 1, 1, 1)
);
// when
// processed by the automation
// then
awaitUntilAsserted(() -> verify(commandGateway, times(1))
.sendAndWait(ProclaimWeekSymbol.command(gameId, 1, 1, "angel", any()), eq(gameMetaData()))
);
}
@Test
void givenDisallowedReplay_WhenReplayed_ThenShouldNotResendTheCommand() {
// given
var gameId = UUID.randomUUID().toString();
var calendarId = CalendarId.of(gameId);
givenCalendarEvents(
gameId,
new DayStarted(calendarId.raw(), 1, 1, 1)
);
// when
// processed by the automation
// then
awaitUntilAsserted(() -> verify(commandGateway, times(1))
.sendAndWait(ProclaimWeekSymbol.command(gameId, 1, 1, "angel", any()), eq(gameMetaData()))
);
// when
streamProcessorsOperations.reset("Automation_WhenWeekStartedThenProclaimWeekSymbol_Processor");
// then
verify(commandGateway, times(1))
.sendAndWait(ProclaimWeekSymbol.command(gameId, 1, 1, "angel", any()), eq(gameMetaData()));
}
private void givenCalendarEvents(String gameId, CalendarEvent... events) {
for (int i = 0; i < events.length; i++) {
eventGateway.publish(calendarDomainEvent(gameId, i, events[i]));
}
}
private static DomainEventMessage<?> calendarDomainEvent(String identifier, int sequenceNumber,
CalendarEvent payload) {
return new GenericDomainEventMessage<>(
"Calendar",
identifier,
sequenceNumber,
payload
).andMetaData(gameMetaData());
}
private static MetaData gameMetaData() {
return GameMetaData.with(GAME_ID, PLAYER_ID);
}
}