-
Notifications
You must be signed in to change notification settings - Fork 3
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 #614 from codecentric/add-events-to-habit-service
Add events to habit service
- Loading branch information
Showing
47 changed files
with
693 additions
and
432 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
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
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
67 changes: 67 additions & 0 deletions
67
...ces/habit/src/intTest/java/de/codecentric/hc/habit/habits/HabitModuleIntegrationTest.java
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,67 @@ | ||
package de.codecentric.hc.habit.habits; | ||
|
||
import static de.codecentric.hc.habit.habits.Habit.Schedule.Frequency.WEEKLY; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import de.codecentric.hc.habit.auth.UserIdArgumentResolver; | ||
import de.codecentric.hc.habit.habits.Habit.ModificationRequest; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.modulith.test.ApplicationModuleTest; | ||
import org.springframework.modulith.test.Scenario; | ||
import org.springframework.test.context.ActiveProfiles; | ||
|
||
@ActiveProfiles("intTest") | ||
@ApplicationModuleTest | ||
@MockBean(UserIdArgumentResolver.class) | ||
public class HabitModuleIntegrationTest { | ||
|
||
@Autowired private HabitController habitController; | ||
@Autowired private HabitRepository habitRepository; | ||
|
||
@AfterEach | ||
void tearDown() { | ||
habitRepository.deleteAll(); | ||
} | ||
|
||
@Test | ||
void shouldPublishHabitCreatedEventWhenHabitIsCreated(Scenario scenario) { | ||
ModificationRequest createJoggingHabitRequest = | ||
ModificationRequest.builder() | ||
.name("Jogging") | ||
.schedule(Habit.Schedule.builder().frequency(WEEKLY).repetitions(3).build()) | ||
.build(); | ||
|
||
scenario | ||
.stimulate(() -> habitController.createHabit(createJoggingHabitRequest, "userId")) | ||
.andWaitForEventOfType(Habit.HabitCreated.class) | ||
.toArriveAndVerify( | ||
event -> { | ||
assertThat(event.name()).isEqualTo("Jogging"); | ||
assertThat(event.frequency()).isEqualTo(WEEKLY); | ||
assertThat(event.repetitions()).isEqualTo(3); | ||
}); | ||
} | ||
|
||
@Test | ||
void shouldPublishHabitDeletedEventWhenHabitIsDeleted(Scenario scenario) { | ||
Habit habit = | ||
Habit.from( | ||
ModificationRequest.builder() | ||
.name("Jogging") | ||
.schedule(Habit.Schedule.builder().frequency(WEEKLY).repetitions(3).build()) | ||
.build(), | ||
"userId"); | ||
habitRepository.save(habit); | ||
|
||
scenario | ||
.stimulate(() -> habitController.deleteHabit(habit.getId().toString(), "userId")) | ||
.andWaitForEventOfType(Habit.HabitDeleted.class) | ||
.toArriveAndVerify( | ||
event -> { | ||
assertThat(event.habitId()).isEqualTo(habit.getId()); | ||
}); | ||
} | ||
} |
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
Oops, something went wrong.