Instantly share code, notes, and snippets.

Embed
What would you like to do?
final version of ReservationEndToEndTest
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class ReservationEndToEndTest {
@Autowired
TestRestTemplate testRestTemplate;
@Test
public void getReservation_shouldReturnReservationDetails() {
// Arrange
// Act
ResponseEntity<Reservation> response = testRestTemplate.getForEntity("/reservation/{name}",
// Assert
Assertions.assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
Assertions.assertThat(response.getBody().getFirstName()).isEqualTo("Dhaval");
Assertions.assertThat(response.getBody().getLastName()).isEqualTo("Shah");
Assertions.assertThat(response.getBody().getId()).isNotNull();
}
}
@Component
class SampleDataCLR implements CommandLineRunner {
private ReservationRepository reservationRepository;
public SampleDataCLR(ReservationRepository reservationRepository) {
this.reservationRepository = reservationRepository;
}
@Override
public void run(String... args) throws Exception {
System.out.println("@@@@@@@@@@@@@@ Entering SampleDataCLR : run");
reservationRepository.save(new Reservation("Dhaval","Shah"));
reservationRepository.save(new Reservation("Yatharth","Shah"));
reservationRepository.findAll().forEach(System.out :: println);
System.out.println("@@@@@@@@@@@@@@ Leaving SampleDataCLR : run");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment