|
4 | 4 | import static jakarta.ws.rs.core.Response.Status.OK; |
5 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; |
6 | 6 |
|
| 7 | +import org.hamcrest.Matchers; |
7 | 8 | import org.junit.jupiter.api.AfterAll; |
8 | 9 | import org.junit.jupiter.api.BeforeAll; |
9 | 10 | import org.junit.jupiter.api.Test; |
10 | 11 |
|
11 | 12 | import edu.harvard.iq.dataverse.metrics.MetricsUtil; |
12 | 13 | import edu.harvard.iq.dataverse.util.FileUtil; |
13 | 14 | import io.restassured.RestAssured; |
| 15 | +import io.restassured.http.ContentType; |
14 | 16 | import io.restassured.response.Response; |
15 | 17 | import jakarta.ws.rs.core.MediaType; |
16 | 18 |
|
@@ -381,4 +383,41 @@ public void testGetDatasetsBySubjectToMonth() { |
381 | 383 | response.then().assertThat() |
382 | 384 | .statusCode(OK.getStatusCode()); |
383 | 385 | } |
384 | | -} |
| 386 | + |
| 387 | + @Test |
| 388 | + public void testUnsupportedQueryParam() { |
| 389 | + Response response = UtilIT.makeDataCountMetricTimeSeries("viewCount", "unsupportedParam=value"); |
| 390 | + |
| 391 | + response.then().assertThat() |
| 392 | + .statusCode(BAD_REQUEST.getStatusCode()) |
| 393 | + .body("message", Matchers.containsString("queryParameter unsupportedParam not supported for this endpoint")); |
| 394 | + } |
| 395 | + |
| 396 | + @Test |
| 397 | + public void testInvalidMetric() { |
| 398 | + Response response = UtilIT.makeDataCountMetricTimeSeries("invalidMetric", null); |
| 399 | + |
| 400 | + response.then().assertThat() |
| 401 | + .statusCode(BAD_REQUEST.getStatusCode()) |
| 402 | + .body("message", Matchers.containsString("MetricType must be one of these values")); |
| 403 | + } |
| 404 | + |
| 405 | + @Test |
| 406 | + public void testInvalidCountryCode() { |
| 407 | + Response response = UtilIT.makeDataCountMetricTimeSeries("viewCount", "country=INVALID"); |
| 408 | + |
| 409 | + response.then().assertThat() |
| 410 | + .statusCode(BAD_REQUEST.getStatusCode()) |
| 411 | + .body("message", Matchers.containsString("Country must be one of the ISO 1366 Country Codes")); |
| 412 | + } |
| 413 | + |
| 414 | + @Test |
| 415 | + public void testValidRequest() { |
| 416 | + Response response = UtilIT.makeDataCountMetricTimeSeries("viewCount", "country=us"); |
| 417 | + |
| 418 | + response.then().assertThat() |
| 419 | + .statusCode(OK.getStatusCode()) |
| 420 | + .contentType(ContentType.JSON); |
| 421 | + } |
| 422 | + |
| 423 | + } |
0 commit comments