|
| 1 | +package cwms.cda.api; |
| 2 | + |
| 3 | +import static io.restassured.RestAssured.given; |
| 4 | +import static org.hamcrest.Matchers.equalTo; |
| 5 | +import static org.hamcrest.Matchers.is; |
| 6 | +import static org.hamcrest.Matchers.nullValue; |
| 7 | + |
| 8 | +import javax.servlet.http.HttpServletResponse; |
| 9 | + |
| 10 | +import org.junit.jupiter.api.Tag; |
| 11 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 12 | +import org.junit.jupiter.params.ParameterizedTest; |
| 13 | +import org.junit.jupiter.params.provider.ValueSource; |
| 14 | + |
| 15 | +import fixtures.CwmsDataApiSetupCallback; |
| 16 | +import io.restassured.filter.log.LogDetail; |
| 17 | + |
| 18 | +/** |
| 19 | + * Location for tests that aren't specifically related to a given endpoint. |
| 20 | + */ |
| 21 | +@Tag("integration") |
| 22 | +@ExtendWith(CwmsDataApiSetupCallback.class) |
| 23 | +class BaseLineTestIT extends DataApiTestIT { |
| 24 | + |
| 25 | + @ParameterizedTest |
| 26 | + @ValueSource(strings = {"/blobs/", "/timeseries", "/levels"}) |
| 27 | + void test_options_handling_known_url(String url) throws Exception { |
| 28 | + given() |
| 29 | + .log().ifValidationFails(LogDetail.ALL,true) |
| 30 | + .when() |
| 31 | + .redirects().follow(true) |
| 32 | + .redirects().max(3) |
| 33 | + .options(url) |
| 34 | + .then() |
| 35 | + .log().ifValidationFails(LogDetail.ALL,true) |
| 36 | + .assertThat() |
| 37 | + .statusCode(is(HttpServletResponse.SC_OK)) |
| 38 | + .header("Access-Control-Allow-Methods", equalTo("GET, POST, PUT, DELETE, OPTIONS")) |
| 39 | + .header("Access-Control-Allow-Headers", equalTo("Content-Type, Authorization")); |
| 40 | + } |
| 41 | + |
| 42 | + @ParameterizedTest |
| 43 | + @ValueSource(strings = {"/flurgle/", "/blah/", "/levels-i-do-not-exist"}) |
| 44 | + void test_options_handling_unknown_url(String url) throws Exception { |
| 45 | + given() |
| 46 | + .log().ifValidationFails(LogDetail.ALL,true) |
| 47 | + .when() |
| 48 | + .redirects().follow(true) |
| 49 | + .redirects().max(3) |
| 50 | + .options(url) |
| 51 | + .then() |
| 52 | + .log().ifValidationFails(LogDetail.ALL,true) |
| 53 | + .assertThat() |
| 54 | + .statusCode(is(HttpServletResponse.SC_OK)) |
| 55 | + .header("Access-Control-Allow-Methods", nullValue()) |
| 56 | + .header("Access-Control-Allow-Headers", nullValue()); |
| 57 | + } |
| 58 | +} |
0 commit comments