forked from IQSS/dataverse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2935cde
commit 072fb3e
Showing
3 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package edu.harvard.iq.dataverse.api; | ||
|
||
import edu.harvard.iq.dataverse.settings.SettingsServiceBean; | ||
import javax.ejb.EJB; | ||
import javax.json.Json; | ||
import javax.json.JsonObjectBuilder; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.core.Response; | ||
|
||
/** | ||
* API endpoint that returns JSON representations of particular database | ||
* settings. | ||
* | ||
* @author jackson | ||
*/ | ||
@Path("system") | ||
public class Sys extends AbstractApiBean { | ||
|
||
@EJB | ||
SettingsServiceBean settingsService; | ||
|
||
@GET | ||
@Path("settings/:DatasetPublishPopupCustomText") | ||
public Response getDatasetPublishPopupCustomText() { | ||
|
||
String setting = settingsService.getValueForKey( | ||
SettingsServiceBean.Key.DatasetPublishPopupCustomText); | ||
|
||
JsonObjectBuilder response = Json.createObjectBuilder(); | ||
|
||
if (setting != null) { | ||
return okResponse(response.add( | ||
"message", setting)); | ||
} else { | ||
return notFound("Setting " | ||
+ SettingsServiceBean.Key.DatasetPublishPopupCustomText | ||
+ " not found"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package edu.harvard.iq.dataverse.api; | ||
|
||
import static com.jayway.restassured.RestAssured.given; | ||
import com.jayway.restassured.response.Response; | ||
import edu.harvard.iq.dataverse.settings.SettingsServiceBean; | ||
import org.junit.Test; | ||
import static org.hamcrest.CoreMatchers.equalTo; | ||
|
||
/** | ||
* | ||
* @author jacksonokuhn | ||
*/ | ||
public class SysIT { | ||
|
||
/** | ||
* Test of getDatasetPublishPopupCustomText method, of class Sys. | ||
*/ | ||
@Test | ||
public void testGetDatasetPublishPopupCustomText() { | ||
|
||
System.out.println("checking getDatasetPublishPopupCustomText"); | ||
|
||
given().urlEncodingEnabled(false) | ||
.body("Hello world!") | ||
.put("/api/admin/settings/" | ||
+ SettingsServiceBean.Key.DatasetPublishPopupCustomText); | ||
|
||
Response response = given().urlEncodingEnabled(false) | ||
.get("/api/system/settings/" + SettingsServiceBean.Key.DatasetPublishPopupCustomText); | ||
response.prettyPrint(); | ||
response.then().assertThat().statusCode(200) | ||
.body("data.message", equalTo("Hello world!")); | ||
|
||
given().urlEncodingEnabled(false) | ||
.delete("/api/admin/settings/" | ||
+ SettingsServiceBean.Key.DatasetPublishPopupCustomText); | ||
|
||
response = given().urlEncodingEnabled(false) | ||
.get("/api/system/settings/" + SettingsServiceBean.Key.DatasetPublishPopupCustomText); | ||
response.prettyPrint(); | ||
response.then().assertThat().statusCode(404) | ||
.body("message", equalTo("Setting " | ||
+ SettingsServiceBean.Key.DatasetPublishPopupCustomText | ||
+ " not found")); | ||
} | ||
} |