|
| 1 | +package org.baeldung.web.test; |
| 2 | + |
| 3 | +import static org.hamcrest.Matchers.equalTo; |
| 4 | + |
| 5 | +import org.junit.Test; |
| 6 | + |
| 7 | +import com.jayway.restassured.RestAssured; |
| 8 | + |
| 9 | +public class RequestMappingLiveTest { |
| 10 | + private static String BASE_URI = "http://localhost:8080/spring-rest/ex/"; |
| 11 | + |
| 12 | + @Test |
| 13 | + public void givenSimplePath_whenGetFoos_thenOk() { |
| 14 | + RestAssured.given().accept("text/html").get(BASE_URI + "foos").then().assertThat().body(equalTo("Simple Get some Foos")); |
| 15 | + } |
| 16 | + |
| 17 | + @Test |
| 18 | + public void whenPostFoos_thenOk() { |
| 19 | + RestAssured.given().accept("text/html").post(BASE_URI + "foos").then().assertThat().body(equalTo("Post some Foos")); |
| 20 | + } |
| 21 | + |
| 22 | + @Test |
| 23 | + public void givenOneHeader_whenGetFoos_thenOk() { |
| 24 | + RestAssured.given().accept("text/html").header("key", "val").get(BASE_URI + "foos").then().assertThat().body(equalTo("Get some Foos with Header")); |
| 25 | + } |
| 26 | + |
| 27 | + @Test |
| 28 | + public void givenMultipleHeaders_whenGetFoos_thenOk() { |
| 29 | + RestAssured.given().accept("text/html").headers("key1", "val1", "key2", "val2").get(BASE_URI + "foos").then().assertThat().body(equalTo("Get some Foos with Header")); |
| 30 | + } |
| 31 | + |
| 32 | + @Test |
| 33 | + public void givenAcceptHeader_whenGetFoos_thenOk() { |
| 34 | + RestAssured.given().accept("application/json").get(BASE_URI + "foos").then().assertThat().body(equalTo("Get some Foos with Header New")); |
| 35 | + } |
| 36 | + |
| 37 | + @Test |
| 38 | + public void givenPathVariable_whenGetFoos_thenOk() { |
| 39 | + RestAssured.given().accept("text/html").get(BASE_URI + "foos/1").then().assertThat().body(equalTo("Get a specific Foo with id=1")); |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + public void givenMultiplePathVariable_whenGetFoos_thenOk() { |
| 44 | + RestAssured.given().accept("text/html").get(BASE_URI + "foos/1/bar/2").then().assertThat().body(equalTo("Get a specific Bar with id=2 from a Foo with id=1")); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + public void givenPathVariable_whenGetBars_thenOk() { |
| 49 | + RestAssured.given().accept("text/html").get(BASE_URI + "bars/1").then().assertThat().body(equalTo("Get a specific Bar with id=1")); |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + public void givenParams_whenGetBars_thenOk() { |
| 54 | + RestAssured.given().accept("text/html").get(BASE_URI + "bars?id=100&second=something").then().assertThat().body(equalTo("Get a specific Bar with id=100")); |
| 55 | + } |
| 56 | + |
| 57 | + @Test |
| 58 | + public void whenGetFoosOrBars_thenOk() { |
| 59 | + RestAssured.given().accept("text/html").get(BASE_URI + "advanced/foos").then().assertThat().body(equalTo("Advanced - Get some Foos or Bars")); |
| 60 | + RestAssured.given().accept("text/html").get(BASE_URI + "advanced/bars").then().assertThat().body(equalTo("Advanced - Get some Foos or Bars")); |
| 61 | + } |
| 62 | +} |
0 commit comments