Skip to content

Instantly share code, notes, and snippets.

@dhaval201279
Last active March 11, 2018 05:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhaval201279/2814acadde6985264229c13466eb97c5 to your computer and use it in GitHub Desktop.
Save dhaval201279/2814acadde6985264229c13466eb97c5 to your computer and use it in GitHub Desktop.
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