1+ package org .soujava .demos .mongodb ;
2+
3+
4+ import io .cucumber .java .en .*;
5+ import org .assertj .core .api .Assertions ;
6+ import org .soujava .demos .mongodb .document .*;
7+
8+ import jakarta .inject .Inject ;
9+ import java .util .List ;
10+ import java .util .Optional ;
11+
12+ public class HotelRoomSteps {
13+
14+
15+ @ Inject
16+ RoomService roomService ;
17+
18+ @ Inject
19+ RoomRepository roomRepository ;
20+
21+ @ Given ("the hotel management system is operational" )
22+ public void the_hotel_management_system_is_operational () {
23+ Assertions .assertThat (roomService ).as ("RoomService should be initialized" ).isNotNull ();
24+ Assertions .assertThat (roomRepository ).as ("RoomRepository should be initialized" ).isNotNull ();
25+ }
26+
27+ @ When ("I register a room with number {int}" )
28+ public void i_register_a_room_with_number (Integer number ) {
29+ Room room = Room .builder ()
30+ .number (number )
31+ .type (RoomType .STANDARD )
32+ .status (RoomStatus .AVAILABLE )
33+ .cleanStatus (CleanStatus .CLEAN )
34+ .build ();
35+ roomService .save (room );
36+ }
37+
38+ @ Then ("the room with number {int} should appear in the room list" )
39+ public void the_room_with_number_should_appear_in_the_room_list (Integer number ) {
40+ List <Room > rooms = roomRepository .findAll ();
41+ Assertions .assertThat (rooms )
42+ .extracting (Room ::getNumber )
43+ .contains (number );
44+ }
45+
46+ @ When ("I register the following rooms:" )
47+ public void i_register_the_following_rooms (List <Room > rooms ) {
48+ rooms .forEach (roomService ::save );
49+ }
50+
51+ @ Then ("there should be {int} rooms available in the system" )
52+ public void there_should_be_rooms_available_in_the_system (int expectedCount ) {
53+ List <Room > rooms = roomRepository .findAll ();
54+ Assertions .assertThat (rooms ).hasSize (expectedCount );
55+ }
56+
57+ @ Given ("a room with number {int} is registered as {word}" )
58+ public void a_room_with_number_is_registered_as (Integer number , String statusName ) {
59+ RoomStatus status = RoomStatus .valueOf (statusName );
60+ Room room = Room .builder ()
61+ .number (number )
62+ .type (RoomType .STANDARD )
63+ .status (status )
64+ .cleanStatus (CleanStatus .CLEAN )
65+ .build ();
66+ roomService .save (room );
67+ }
68+
69+ @ When ("I mark the room {int} as {word}" )
70+ public void i_mark_the_room_as (Integer number , String newStatusName ) {
71+ RoomStatus newStatus = RoomStatus .valueOf (newStatusName );
72+ Optional <Room > roomOpt = roomRepository .findAll ()
73+ .stream ()
74+ .filter (r -> r .getNumber () == number )
75+ .findFirst ();
76+
77+ Assertions .assertThat (roomOpt )
78+ .as ("Room %s should exist" , number )
79+ .isPresent ();
80+
81+ Room updatedRoom = roomOpt .orElseThrow ();
82+ updatedRoom .update (newStatus );
83+
84+ roomService .save (updatedRoom );
85+ }
86+
87+ @ Then ("the room {int} should be marked as {word}" )
88+ public void the_room_should_be_marked_as (Integer number , String expectedStatusName ) {
89+ RoomStatus expectedStatus = RoomStatus .valueOf (expectedStatusName );
90+ Optional <Room > roomOpt = roomRepository .findAll ()
91+ .stream ()
92+ .filter (r -> r .getNumber () == number )
93+ .findFirst ();
94+
95+ Assertions .assertThat (roomOpt )
96+ .as ("Room %s should exist" , number )
97+ .isPresent ()
98+ .get ()
99+ .extracting (Room ::getStatus )
100+ .isEqualTo (expectedStatus );
101+ }
102+ }
0 commit comments