|
15 | 15 | import java.util.ArrayList;
|
16 | 16 | import java.util.HashMap;
|
17 | 17 | import java.util.List;
|
18 |
| -import static jakarta.ws.rs.core.Response.Status.FORBIDDEN; |
19 |
| -import static jakarta.ws.rs.core.Response.Status.BAD_REQUEST; |
20 | 18 |
|
21 | 19 | import org.junit.jupiter.api.Disabled;
|
22 | 20 | import org.junit.jupiter.api.Test;
|
23 | 21 | import org.junit.jupiter.api.BeforeAll;
|
24 | 22 | import org.junit.jupiter.params.ParameterizedTest;
|
25 | 23 | import org.junit.jupiter.params.provider.ValueSource;
|
| 24 | + |
| 25 | + |
| 26 | + |
26 | 27 | import java.util.Map;
|
27 | 28 | import java.util.UUID;
|
| 29 | +import java.util.logging.Level; |
28 | 30 | import java.util.logging.Logger;
|
29 | 31 |
|
30 |
| -import static jakarta.ws.rs.core.Response.Status.CREATED; |
31 |
| -import static jakarta.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR; |
32 |
| -import static jakarta.ws.rs.core.Response.Status.OK; |
33 |
| -import static jakarta.ws.rs.core.Response.Status.UNAUTHORIZED; |
| 32 | +import static jakarta.ws.rs.core.Response.Status.*; |
34 | 33 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
35 | 34 | import static org.hamcrest.CoreMatchers.equalTo;
|
36 | 35 | import static org.hamcrest.CoreMatchers.notNullValue;
|
@@ -832,36 +831,47 @@ public void testClearThumbnailFailureFlag(){
|
832 | 831 |
|
833 | 832 | @Test
|
834 | 833 | public void testBannerMessages(){
|
835 |
| - |
836 |
| - String pathToJsonFile = "scripts/api/data/bannerMessageError.json"; |
837 |
| - Response addBannerMessageErrorResponse = UtilIT.addBannerMessage(pathToJsonFile); |
| 834 | + |
| 835 | + //We check for existing banner messages and get the number of existing messages |
| 836 | + Response getBannerMessageResponse = UtilIT.getBannerMessages(); |
| 837 | + getBannerMessageResponse.prettyPrint(); |
| 838 | + getBannerMessageResponse.then().assertThat() |
| 839 | + .statusCode(OK.getStatusCode()); |
| 840 | + Integer numBannerMessages = |
| 841 | + JsonPath.from(getBannerMessageResponse.getBody().asString()).getInt("data.size()"); |
| 842 | + |
| 843 | + //We add a banner message with an error in the json file |
| 844 | + String pathToJsonFile = "scripts/api/data/bannerMessageError.json"; |
| 845 | + Response addBannerMessageErrorResponse = UtilIT.addBannerMessage(pathToJsonFile); |
838 | 846 | addBannerMessageErrorResponse.prettyPrint();
|
839 |
| - String body = addBannerMessageErrorResponse.getBody().asString(); |
840 |
| - String status = JsonPath.from(body).getString("status"); |
841 |
| - assertEquals("ERROR", status); |
| 847 | + addBannerMessageErrorResponse.then().assertThat() |
| 848 | + .statusCode(BAD_REQUEST.getStatusCode()) |
| 849 | + .body("status", equalTo("ERROR")); |
842 | 850 |
|
| 851 | + //We add a banner message with a correct json file |
843 | 852 | pathToJsonFile = "scripts/api/data/bannerMessageTest.json";
|
844 |
| - |
845 | 853 | Response addBannerMessageResponse = UtilIT.addBannerMessage(pathToJsonFile);
|
846 | 854 | addBannerMessageResponse.prettyPrint();
|
847 |
| - body = addBannerMessageResponse.getBody().asString(); |
848 |
| - status = JsonPath.from(body).getString("status"); |
849 |
| - assertEquals("OK", status); |
| 855 | + addBannerMessageResponse.then().assertThat() |
| 856 | + .statusCode(OK.getStatusCode()) |
| 857 | + .body("status", equalTo("OK")) |
| 858 | + .body("data.message", equalTo("Banner Message added successfully.")); |
| 859 | + Long addedBanner = Long.valueOf( |
| 860 | + JsonPath.from(addBannerMessageResponse.getBody().asString()).getLong("data.id")); |
850 | 861 |
|
851 |
| - Response getBannerMessageResponse = UtilIT.getBannerMessages(); |
| 862 | + //We get the banner messages and check that the number of messages has increased by 1 |
| 863 | + getBannerMessageResponse = UtilIT.getBannerMessages(); |
852 | 864 | getBannerMessageResponse.prettyPrint();
|
853 |
| - body = getBannerMessageResponse.getBody().asString(); |
854 |
| - status = JsonPath.from(body).getString("status"); |
855 |
| - assertEquals("OK", status); |
856 |
| - String deleteId = UtilIT.getBannerMessageIdFromResponse(getBannerMessageResponse.getBody().asString()); |
857 |
| - |
858 |
| - System.out.print("delete id: " + deleteId); |
859 |
| - |
860 |
| - Response deleteBannerMessageResponse = UtilIT.deleteBannerMessage(new Long (deleteId)); |
| 865 | + getBannerMessageResponse.then().assertThat() |
| 866 | + .statusCode(OK.getStatusCode()) |
| 867 | + .body("data.size()", equalTo(numBannerMessages + 1)); |
| 868 | + |
| 869 | + //We delete the banner message |
| 870 | + Response deleteBannerMessageResponse = UtilIT.deleteBannerMessage(addedBanner); |
861 | 871 | deleteBannerMessageResponse.prettyPrint();
|
862 |
| - body = deleteBannerMessageResponse.getBody().asString(); |
863 |
| - status = JsonPath.from(body).getString("status"); |
864 |
| - assertEquals("OK", status); |
| 872 | + deleteBannerMessageResponse.then().assertThat() |
| 873 | + .statusCode(OK.getStatusCode()) |
| 874 | + .body("status", equalTo("OK")); |
865 | 875 |
|
866 | 876 | }
|
867 | 877 |
|
|
0 commit comments