Skip to content

Instantly share code, notes, and snippets.

@dhaval201279
Last active March 11, 2018 01:41
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/c53ad63b95b9f59b7e29d10906ec7739 to your computer and use it in GitHub Desktop.
Save dhaval201279/c53ad63b95b9f59b7e29d10906ec7739 to your computer and use it in GitHub Desktop.
Reservation end to end test
package com.its.reservation;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;
import com.its.reservation.repository.Reservation;
/**
* @author Dhaval
*
*/
@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}", Reservation.class, "Dhaval");
// Assert
Assertions.assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
Assertions.assertThat(response.getBody().getName()).isEqualTo("Dhaval");
Assertions.assertThat(response.getBody().getId()).isNotNull();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment