Last active
March 11, 2018 05:33
-
-
Save dhaval201279/2814acadde6985264229c13466eb97c5 to your computer and use it in GitHub Desktop.
final version of ReservationEndToEndTest
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
@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