|
3 | 3 | import static edu.harvard.iq.dataverse.api.ApiConstants.DS_VERSION_LATEST_PUBLISHED; |
4 | 4 | import edu.harvard.iq.dataverse.dataset.DatasetType; |
5 | 5 | import edu.harvard.iq.dataverse.util.StringUtil; |
| 6 | +import static io.restassured.path.json.JsonPath.with; |
6 | 7 | import io.restassured.RestAssured; |
7 | 8 | import io.restassured.path.json.JsonPath; |
8 | 9 | import io.restassured.response.Response; |
|
12 | 13 | import static jakarta.ws.rs.core.Response.Status.CREATED; |
13 | 14 | import static jakarta.ws.rs.core.Response.Status.FORBIDDEN; |
14 | 15 | import static jakarta.ws.rs.core.Response.Status.OK; |
| 16 | +import java.util.List; |
| 17 | +import java.util.Map; |
15 | 18 | import java.util.UUID; |
16 | 19 | import org.hamcrest.CoreMatchers; |
17 | 20 | import static org.hamcrest.CoreMatchers.containsString; |
@@ -902,4 +905,66 @@ public void testCreateReview() { |
902 | 905 | UtilIT.publishDatasetViaNativeApi(reviewPid, "major", apiTokenReviewer).then().assertThat().statusCode(OK.getStatusCode()); |
903 | 906 | } |
904 | 907 |
|
| 908 | + @Test |
| 909 | + public void testInternationalization() { |
| 910 | + Response getDatasetType = UtilIT.getDatasetType("software"); |
| 911 | + getDatasetType.prettyPrint(); |
| 912 | + getDatasetType.then().assertThat() |
| 913 | + .statusCode(OK.getStatusCode()) |
| 914 | + .body("data.name", is("software")) |
| 915 | + .body("data.displayName", is("Software")); |
| 916 | + |
| 917 | + // https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Accept-Language |
| 918 | + getDatasetType = UtilIT.getDatasetType("software", "en-US,en;q=0.5"); |
| 919 | + getDatasetType.prettyPrint(); |
| 920 | + getDatasetType.then().assertThat() |
| 921 | + .statusCode(OK.getStatusCode()) |
| 922 | + .body("data.name", is("software")) |
| 923 | + .body("data.displayName", is("Software")); |
| 924 | + |
| 925 | + getDatasetType = UtilIT.getDatasetType("software", "en-US"); |
| 926 | + getDatasetType.prettyPrint(); |
| 927 | + getDatasetType.then().assertThat() |
| 928 | + .statusCode(OK.getStatusCode()) |
| 929 | + .body("data.name", is("software")) |
| 930 | + .body("data.displayName", is("Software")); |
| 931 | + |
| 932 | + getDatasetType = UtilIT.getDatasetType("software", ""); |
| 933 | + getDatasetType.prettyPrint(); |
| 934 | + getDatasetType.then().assertThat() |
| 935 | + .statusCode(OK.getStatusCode()) |
| 936 | + .body("data.name", is("software")) |
| 937 | + .body("data.displayName", is("Software")); |
| 938 | + |
| 939 | + boolean i18nIsConfigured = false; |
| 940 | + if (!i18nIsConfigured) { |
| 941 | + System.out.println("i18n is not configured; skipping test of non-English languages"); |
| 942 | + return; |
| 943 | + } |
| 944 | + |
| 945 | + getDatasetType = UtilIT.getDatasetType("software", "fr-CA,fr;q=0.8,en-US;q=0.6,en;q=0.4"); |
| 946 | + getDatasetType.prettyPrint(); |
| 947 | + getDatasetType.then().assertThat() |
| 948 | + .statusCode(OK.getStatusCode()) |
| 949 | + .body("data.name", is("software")) |
| 950 | + .body("data.displayName", is("Logiciel")); |
| 951 | + |
| 952 | + getDatasetType = UtilIT.getDatasetTypes("fr-CA,fr;q=0.8,en-US;q=0.6,en;q=0.4"); |
| 953 | + getDatasetType.prettyPrint(); |
| 954 | + getDatasetType.then().assertThat() |
| 955 | + .statusCode(OK.getStatusCode()); |
| 956 | + |
| 957 | + // Messy but the only way we've figured out ¯\_(ツ)_/¯ |
| 958 | + List<Map<String, Object>> dataset = with(getDatasetType.body().asString()).param("dataset", "dataset") |
| 959 | + .getList("data.findAll { data -> data.name == dataset }"); |
| 960 | + Map<String, Object> firstDataset = dataset.get(0); |
| 961 | + assertEquals("Ensemble de données", firstDataset.get("displayName")); |
| 962 | + |
| 963 | + List<Map<String, Object>> instrument = with(getDatasetType.body().asString()).param("instrument", "instrument") |
| 964 | + .getList("data.findAll { data -> data.name == instrument }"); |
| 965 | + Map<String, Object> firstInstrument = instrument.get(0); |
| 966 | + // Instrument isn't translated in the French properties file; should fall back to English |
| 967 | + assertEquals("Instrument", firstInstrument.get("displayName")); |
| 968 | + } |
| 969 | + |
905 | 970 | } |
0 commit comments