mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
feat: Add /interpreter/setting/id API and test
This commit is contained in:
parent
31f584cfee
commit
9bc24fd5e3
2 changed files with 47 additions and 0 deletions
|
|
@ -80,6 +80,28 @@ public class InterpreterRestApi {
|
|||
return new JsonResponse<>(Status.OK, "", interpreterFactory.get()).build();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a setting
|
||||
*/
|
||||
@GET
|
||||
@Path("setting/{settingId}")
|
||||
@ZeppelinApi
|
||||
public Response getSetting(@PathParam("settingId") String settingId) {
|
||||
try {
|
||||
InterpreterSetting setting = interpreterFactory.get(settingId);
|
||||
if (setting == null) {
|
||||
return new JsonResponse<>(Status.NOT_FOUND).build();
|
||||
} else {
|
||||
return new JsonResponse<>(Status.OK, "", setting).build();
|
||||
}
|
||||
} catch (NullPointerException e){
|
||||
logger.error("Exception in InterpreterRestApi while creating ", e);
|
||||
return new JsonResponse<>(Status.INTERNAL_SERVER_ERROR, e.getMessage(),
|
||||
ExceptionUtils.getStackTrace(e)) .build();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new interpreter setting
|
||||
*
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ import java.io.IOException;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.apache.commons.httpclient.methods.DeleteMethod;
|
||||
import org.apache.commons.httpclient.methods.GetMethod;
|
||||
import org.apache.commons.httpclient.methods.PostMethod;
|
||||
|
|
@ -93,6 +95,17 @@ public class InterpreterRestApiTest extends AbstractTestRestApi {
|
|||
get.releaseConnection();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNonExistInterpreterSetting() throws IOException {
|
||||
// when
|
||||
String nonExistInterpreterSettingId = "apache_.zeppelin_1s_.aw3some$";
|
||||
GetMethod get = httpGet("/interpreter/setting/" + nonExistInterpreterSettingId);
|
||||
get.releaseConnection();
|
||||
|
||||
// when
|
||||
assertThat("Test get method:", get, isNotFound());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSettingsCRUD() throws IOException {
|
||||
// Call Create Setting REST API
|
||||
|
|
@ -111,6 +124,18 @@ public class InterpreterRestApiTest extends AbstractTestRestApi {
|
|||
String newSettingId = body.toString().split(",")[0].split("=")[1];
|
||||
post.releaseConnection();
|
||||
|
||||
// Call Read Setting API
|
||||
GetMethod get = httpGet("/interpreter/setting/" + newSettingId);
|
||||
String rawResponse = get.getResponseBodyAsString();
|
||||
LOG.info("testSettingCRUD get response\n" + rawResponse);
|
||||
get.releaseConnection();
|
||||
JsonObject response = gson.fromJson(rawResponse, JsonElement.class)
|
||||
.getAsJsonObject();
|
||||
assertThat("Test get method:", get, isAllowed());
|
||||
InterpreterSetting created = gson.fromJson(response.getAsJsonObject("body"),
|
||||
InterpreterSetting.class);
|
||||
assertEquals(newSettingId, created.getId());
|
||||
|
||||
// Call Update Setting REST API
|
||||
jsonRequest = "{\"name\":\"md2\",\"group\":\"md\",\"properties\":{\"propname\":\"Otherpropvalue\"}," +
|
||||
"\"interpreterGroup\":[{\"class\":\"org.apache.zeppelin.markdown.Markdown\",\"name\":\"md\"}]," +
|
||||
|
|
|
|||
Loading…
Reference in a new issue