Skip to content

Commit f9b6750

Browse files
committed
create test methods for getting and setting all settings (and use them) #11639
1 parent b3aea84 commit f9b6750

2 files changed

Lines changed: 22 additions & 31 deletions

File tree

src/test/java/edu/harvard/iq/dataverse/api/AdminIT.java

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ void testSettingsRoundTrip() {
8080
UtilIT.setSetting(harmlessSetting, harmlessL10nValue, language);
8181

8282
// Step 1: Get current settings state
83-
Response getResponse = given()
84-
.when()
85-
.get("/api/admin/settings");
83+
Response getResponse = UtilIT.getSettings();
8684

8785
getResponse.then()
8886
.assertThat()
@@ -111,12 +109,7 @@ void testSettingsRoundTrip() {
111109
.body("data.message", equalTo(harmlessValue));
112110

113111
// Step 4: Put back the original settings (this is what we're testing)
114-
Response putResponse = given()
115-
//.header("X-Dataverse-key", "")
116-
.header("Content-Type", "application/json")
117-
.body(originalSettings.toString())
118-
.when()
119-
.put("/api/admin/settings");
112+
Response putResponse = UtilIT.setSettings(originalSettings.toString());
120113

121114
putResponse.then()
122115
.assertThat()
@@ -125,20 +118,14 @@ void testSettingsRoundTrip() {
125118
.body("message.message", containsString("successfully updated"));
126119

127120
// Step 5: Verify the harmless setting is gone (restored to original state)
128-
Response verifyRestoredResponse = given()
129-
//.header("X-Dataverse-key", "")
130-
.when()
131-
.get("/api/admin/settings" + harmlessSetting.toString());
121+
Response verifyRestoredResponse = UtilIT.getSetting(harmlessSetting);
132122

133123
verifyRestoredResponse.then()
134124
.assertThat()
135125
.statusCode(NOT_FOUND.getStatusCode()); // Should not exist anymore
136126

137127
// Step 6: Verify overall settings state matches original
138-
Response finalGetResponse = given()
139-
//.header("X-Dataverse-key", "")
140-
.when()
141-
.get("/api/admin/settings");
128+
Response finalGetResponse = UtilIT.getSettings();
142129

143130
finalGetResponse.then()
144131
.assertThat()
@@ -165,9 +152,7 @@ void testGetAllSettingsWithLocalization() {
165152
UtilIT.setSetting(harmlessSetting, harmlessL10nValue, language);
166153

167154
// When
168-
Response getResponse = given()
169-
.when()
170-
.get("/api/admin/settings");
155+
Response getResponse = UtilIT.getSettings();
171156

172157
// Then
173158
getResponse.then()
@@ -184,11 +169,7 @@ void testGetAllSettingsWithLocalization() {
184169
@Test
185170
void testPutAllSettingsWithEmptyJson() {
186171
// Test error handling for empty JSON
187-
Response response = given()
188-
.header("Content-Type", "application/json")
189-
.body("{}")
190-
.when()
191-
.put("/api/admin/settings");
172+
Response response = UtilIT.setSettings("{}");
192173

193174
response.then()
194175
.assertThat()
@@ -199,11 +180,7 @@ void testPutAllSettingsWithEmptyJson() {
199180
@Test
200181
void testPutAllSettingsWithInvalidSetting() {
201182
// Test error handling for empty JSON
202-
Response response = given()
203-
.header("Content-Type", "application/json")
204-
.body("{\":Test1\": \"Foobar\", \":Test2\": \"Foobar\" }")
205-
.when()
206-
.put("/api/admin/settings");
183+
Response response = UtilIT.setSettings("{\":Test1\": \"Foobar\", \":Test2\": \"Foobar\" }");
207184

208185
response.then()
209186
.assertThat()
@@ -242,7 +219,7 @@ public void testListAuthenticatedUsers() throws Exception {
242219

243220
Response deleteSuperuser = UtilIT.deleteUser(superuserUsername);
244221
assertEquals(200, deleteSuperuser.getStatusCode());
245-
}
222+
}
246223

247224
@Test
248225
public void testFilterAuthenticatedUsersForbidden() throws Exception {

src/test/java/edu/harvard/iq/dataverse/api/UtilIT.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2505,6 +2505,11 @@ static Response deleteSetting(String settingKey) {
25052505
return response;
25062506
}
25072507

2508+
static Response getSettings() {
2509+
Response response = given().when().get("/api/admin/settings");
2510+
return response;
2511+
}
2512+
25082513
static Response getSetting(SettingsServiceBean.Key settingKey) {
25092514
Response response = given().when().get("/api/admin/settings/" + settingKey);
25102515
return response;
@@ -2533,6 +2538,15 @@ public static Response setSetting(String settingKey, String value) {
25332538
return response;
25342539
}
25352540

2541+
public static Response setSettings(String value) {
2542+
Response response = given()
2543+
.header("Content-Type", "application/json")
2544+
.body(value)
2545+
.when()
2546+
.put("/api/admin/settings");
2547+
return response;
2548+
}
2549+
25362550
static Response getFeatureFlags() {
25372551
Response response = given().when().get("/api/admin/featureFlags");
25382552
return response;

0 commit comments

Comments
 (0)