Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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