Skip to content

Commit

Permalink
Fixed: response message string formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
GPortas committed Jan 13, 2025
1 parent 998cc6c commit e265ae8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/main/java/propertyFiles/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3126,5 +3126,5 @@ authenticationServiceBean.errors.invalidBearerToken=Could not parse bearer token
authenticationServiceBean.errors.bearerTokenDetectedNoOIDCProviderConfigured=Bearer token detected, no OIDC provider configured.

#DataverseFeaturedItems.java
dataverseFeaturedItems.errors.notFound=Can't find dataverse featured item with identifier='{0}'
dataverseFeaturedItems.delete.successful=Successfully deleted dataverse featured item with identifier='{0}'
dataverseFeaturedItems.errors.notFound=Can't find dataverse featured item with identifier {0}
dataverseFeaturedItems.delete.successful=Successfully deleted dataverse featured item with identifier {0}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package edu.harvard.iq.dataverse.api;

import edu.harvard.iq.dataverse.util.BundleUtil;
import io.restassured.RestAssured;
import io.restassured.path.json.JsonPath;
import io.restassured.response.Response;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.text.MessageFormat;

import static jakarta.ws.rs.core.Response.Status.*;
import static org.hamcrest.CoreMatchers.equalTo;

Expand All @@ -24,7 +27,9 @@ public void testDeleteFeaturedItem() {

// Should return not found when passing incorrect item id
Response deleteFeatureItemResponse = UtilIT.deleteDataverseFeaturedItem(100000L, apiToken);
deleteFeatureItemResponse.then().assertThat().statusCode(NOT_FOUND.getStatusCode());
deleteFeatureItemResponse.then()
.body("message", equalTo(MessageFormat.format(BundleUtil.getStringFromBundle("dataverseFeaturedItems.errors.notFound"), featuredItemId)))
.assertThat().statusCode(NOT_FOUND.getStatusCode());

// Should return unauthorized when passing correct id and user does not have permissions
String randomUserApiToken = createUserAndGetApiToken();
Expand All @@ -33,7 +38,9 @@ public void testDeleteFeaturedItem() {

// Should delete featured item when passing correct id and user has permissions
deleteFeatureItemResponse = UtilIT.deleteDataverseFeaturedItem(featuredItemId, apiToken);
deleteFeatureItemResponse.then().assertThat().statusCode(OK.getStatusCode());
deleteFeatureItemResponse.then()
.body("data.message", equalTo(MessageFormat.format(BundleUtil.getStringFromBundle("dataverseFeaturedItems.delete.successful"), featuredItemId)))
.assertThat().statusCode(OK.getStatusCode());

Response listFeaturedItemsResponse = UtilIT.listDataverseFeaturedItems(dataverseAlias, apiToken);
listFeaturedItemsResponse.then()
Expand All @@ -49,7 +56,9 @@ public void testUpdateFeaturedItem() {

// Should return not found when passing incorrect item id
Response updateFeatureItemResponse = UtilIT.updateDataverseFeaturedItem(100000L, "updatedTitle", 1, false, null, apiToken);
updateFeatureItemResponse.then().assertThat().statusCode(NOT_FOUND.getStatusCode());
updateFeatureItemResponse.then()
.body("message", equalTo(MessageFormat.format(BundleUtil.getStringFromBundle("dataverseFeaturedItems.errors.notFound"), featuredItemId)))
.assertThat().statusCode(NOT_FOUND.getStatusCode());

// Should return unauthorized when passing correct id and user does not have permissions
String randomUserApiToken = createUserAndGetApiToken();
Expand Down

0 comments on commit e265ae8

Please sign in to comment.