You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by fe...@apache.org on 2018/04/05 06:09:58 UTC
[2/5] zeppelin git commit: ZEPPELIN-3140. Fixed Checkstyle issues in
zeppelin-server
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/1add74b4/zeppelin-server/src/test/java/org/apache/zeppelin/rest/AbstractTestRestApi.java
----------------------------------------------------------------------
diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/AbstractTestRestApi.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/AbstractTestRestApi.java
index dfb5ac2..172f117 100644
--- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/AbstractTestRestApi.java
+++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/AbstractTestRestApi.java
@@ -14,22 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.zeppelin.rest;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonParser;
-import java.io.File;
-import java.io.IOException;
-import java.lang.ref.WeakReference;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.regex.Pattern;
+
import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.PumpStreamHandler;
@@ -45,24 +35,32 @@ import org.apache.commons.httpclient.methods.PutMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
-import org.apache.zeppelin.conf.ZeppelinConfiguration;
-import org.apache.zeppelin.interpreter.InterpreterProperty;
-import org.apache.zeppelin.interpreter.InterpreterPropertyType;
-import org.apache.zeppelin.interpreter.InterpreterSetting;
-import org.apache.zeppelin.server.ZeppelinServer;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public abstract class AbstractTestRestApi {
+import java.io.File;
+import java.io.IOException;
+import java.lang.ref.WeakReference;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.regex.Pattern;
+
+import org.apache.zeppelin.conf.ZeppelinConfiguration;
+import org.apache.zeppelin.interpreter.InterpreterSetting;
+import org.apache.zeppelin.server.ZeppelinServer;
+public abstract class AbstractTestRestApi {
protected static final Logger LOG = LoggerFactory.getLogger(AbstractTestRestApi.class);
- static final String restApiUrl = "/api";
- static final String url = getUrlToTest();
- protected static final boolean wasRunning = checkIfServerIsRunning();
+ static final String REST_API_URL = "/api";
+ static final String URL = getUrlToTest();
+ protected static final boolean WAS_RUNNING = checkIfServerIsRunning();
static boolean isRunningWithAuth = false;
private static File shiroIni = null;
@@ -110,7 +108,7 @@ public abstract class AbstractTestRestApi {
"/** = authc";
private static File knoxSsoPem = null;
- private static String KNOX_SSO_PEM =
+ private static String knoxSsoPemCertificate =
"-----BEGIN CERTIFICATE-----\n"
+ "MIIChjCCAe+gAwIBAgIJALYrdDEXKwcqMA0GCSqGSIb3DQEBBQUAMIGEMQswCQYD\n"
+ "VQQGEwJVUzENMAsGA1UECBMEVGVzdDENMAsGA1UEBxMEVGVzdDEPMA0GA1UEChMG\n"
@@ -138,14 +136,16 @@ public abstract class AbstractTestRestApi {
} else {
url = "http://localhost:8080";
}
- url += restApiUrl;
- if (path != null)
+ url += REST_API_URL;
+ if (path != null) {
url += path;
+ }
+
return url;
}
protected static String getUrlToTest() {
- String url = "http://localhost:8080" + restApiUrl;
+ String url = "http://localhost:8080" + REST_API_URL;
if (System.getProperty("url") != null) {
url = System.getProperty("url");
}
@@ -153,7 +153,7 @@ public abstract class AbstractTestRestApi {
}
static ExecutorService executor;
- protected static final Runnable server = new Runnable() {
+ protected static final Runnable SERVER = new Runnable() {
@Override
public void run() {
try {
@@ -165,17 +165,21 @@ public abstract class AbstractTestRestApi {
}
};
- private static void start(boolean withAuth, String testClassName, boolean withKnox) throws Exception {
- if (!wasRunning) {
+ private static void start(boolean withAuth, String testClassName, boolean withKnox)
+ throws Exception {
+ if (!WAS_RUNNING) {
// copy the resources files to a temp folder
zeppelinHome = new File("..");
LOG.info("ZEPPELIN_HOME: " + zeppelinHome.getAbsolutePath());
confDir = new File(zeppelinHome, "conf_" + testClassName);
confDir.mkdirs();
- System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_HOME.getVarName(), zeppelinHome.getAbsolutePath());
- System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_WAR.getVarName(), new File("../zeppelin-web/dist").getAbsolutePath());
- System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_CONF_DIR.getVarName(), confDir.getAbsolutePath());
+ System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_HOME.getVarName(),
+ zeppelinHome.getAbsolutePath());
+ System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_WAR.getVarName(),
+ new File("../zeppelin-web/dist").getAbsolutePath());
+ System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_CONF_DIR.getVarName(),
+ confDir.getAbsolutePath());
// some test profile does not build zeppelin-web.
// to prevent zeppelin starting up fail, create zeppelin-web/dist directory
@@ -187,7 +191,8 @@ public abstract class AbstractTestRestApi {
if (withAuth) {
isRunningWithAuth = true;
// Set Anonymous session to false.
- System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_ANONYMOUS_ALLOWED.getVarName(), "false");
+ System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_ANONYMOUS_ALLOWED.getVarName(),
+ "false");
// Create a shiro env test.
shiroIni = new File(confDir, "shiro.ini");
@@ -201,7 +206,7 @@ public abstract class AbstractTestRestApi {
if (!knoxSsoPem.exists()) {
knoxSsoPem.createNewFile();
}
- FileUtils.writeStringToFile(knoxSsoPem, KNOX_SSO_PEM);
+ FileUtils.writeStringToFile(knoxSsoPem, knoxSsoPemCertificate);
} else {
FileUtils.writeStringToFile(shiroIni, zeppelinShiro);
}
@@ -228,9 +233,8 @@ public abstract class AbstractTestRestApi {
ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETERS.getVarName(),
interpretersCompatibleWithScala211Test);
-
executor = Executors.newSingleThreadExecutor();
- executor.submit(server);
+ executor.submit(SERVER);
long s = System.currentTimeMillis();
boolean started = false;
while (System.currentTimeMillis() - s < 1000 * 60 * 3) { // 3 minutes
@@ -247,7 +251,6 @@ public abstract class AbstractTestRestApi {
}
}
-
protected static void startUpWithKnoxEnable(String testClassName) throws Exception {
start(true, testClassName, true);
}
@@ -274,9 +277,10 @@ public abstract class AbstractTestRestApi {
}
protected static void shutDown(final boolean deleteConfDir) throws Exception {
- if (!wasRunning && ZeppelinServer.notebook != null) {
+ if (!WAS_RUNNING && ZeppelinServer.notebook != null) {
// restart interpreter to stop all interpreter processes
- List<InterpreterSetting> settingList = ZeppelinServer.notebook.getInterpreterSettingManager().get();
+ List<InterpreterSetting> settingList = ZeppelinServer.notebook.getInterpreterSettingManager()
+ .get();
if (!ZeppelinServer.notebook.getConf().isRecoveryEnabled()) {
for (InterpreterSetting setting : settingList) {
ZeppelinServer.notebook.getInterpreterSettingManager().restart(setting.getId());
@@ -322,12 +326,13 @@ public abstract class AbstractTestRestApi {
protected static boolean checkIfServerIsRunning() {
GetMethod request = null;
- boolean isRunning = true;
+ boolean isRunning;
try {
request = httpGet("/version");
isRunning = request.getStatusCode() == 200;
} catch (IOException e) {
- LOG.error("AbstractTestRestApi.checkIfServerIsRunning() fails .. ZeppelinServer is not running");
+ LOG.error("AbstractTestRestApi.checkIfServerIsRunning() fails .. ZeppelinServer is not " +
+ "running");
isRunning = false;
} finally {
if (request != null) {
@@ -345,13 +350,14 @@ public abstract class AbstractTestRestApi {
return httpGet(path, user, pwd, StringUtils.EMPTY);
}
- protected static GetMethod httpGet(String path, String user, String pwd, String cookies) throws IOException {
- LOG.info("Connecting to {}", url + path);
+ protected static GetMethod httpGet(String path, String user, String pwd, String cookies)
+ throws IOException {
+ LOG.info("Connecting to {}", URL + path);
HttpClient httpClient = new HttpClient();
- GetMethod getMethod = new GetMethod(url + path);
- getMethod.addRequestHeader("Origin", url);
+ GetMethod getMethod = new GetMethod(URL + path);
+ getMethod.addRequestHeader("Origin", URL);
if (userAndPasswordAreNotBlank(user, pwd)) {
- getMethod.setRequestHeader("Cookie", "JSESSIONID="+ getCookie(user, pwd));
+ getMethod.setRequestHeader("Cookie", "JSESSIONID=" + getCookie(user, pwd));
}
if (!StringUtils.isBlank(cookies)) {
getMethod.setRequestHeader("Cookie", getMethod.getResponseHeader("Cookie") + ";" + cookies);
@@ -365,13 +371,14 @@ public abstract class AbstractTestRestApi {
return httpDelete(path, StringUtils.EMPTY, StringUtils.EMPTY);
}
- protected static DeleteMethod httpDelete(String path, String user, String pwd) throws IOException {
- LOG.info("Connecting to {}", url + path);
+ protected static DeleteMethod httpDelete(String path, String user, String pwd)
+ throws IOException {
+ LOG.info("Connecting to {}", URL + path);
HttpClient httpClient = new HttpClient();
- DeleteMethod deleteMethod = new DeleteMethod(url + path);
- deleteMethod.addRequestHeader("Origin", url);
+ DeleteMethod deleteMethod = new DeleteMethod(URL + path);
+ deleteMethod.addRequestHeader("Origin", URL);
if (userAndPasswordAreNotBlank(user, pwd)) {
- deleteMethod.setRequestHeader("Cookie", "JSESSIONID="+ getCookie(user, pwd));
+ deleteMethod.setRequestHeader("Cookie", "JSESSIONID=" + getCookie(user, pwd));
}
httpClient.executeMethod(deleteMethod);
LOG.info("{} - {}", deleteMethod.getStatusCode(), deleteMethod.getStatusText());
@@ -383,14 +390,14 @@ public abstract class AbstractTestRestApi {
}
protected static PostMethod httpPost(String path, String request, String user, String pwd)
- throws IOException {
- LOG.info("Connecting to {}", url + path);
+ throws IOException {
+ LOG.info("Connecting to {}", URL + path);
HttpClient httpClient = new HttpClient();
- PostMethod postMethod = new PostMethod(url + path);
+ PostMethod postMethod = new PostMethod(URL + path);
postMethod.setRequestBody(request);
postMethod.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
if (userAndPasswordAreNotBlank(user, pwd)) {
- postMethod.setRequestHeader("Cookie", "JSESSIONID="+ getCookie(user, pwd));
+ postMethod.setRequestHeader("Cookie", "JSESSIONID=" + getCookie(user, pwd));
}
httpClient.executeMethod(postMethod);
LOG.info("{} - {}", postMethod.getStatusCode(), postMethod.getStatusText());
@@ -401,15 +408,16 @@ public abstract class AbstractTestRestApi {
return httpPut(path, body, StringUtils.EMPTY, StringUtils.EMPTY);
}
- protected static PutMethod httpPut(String path, String body, String user, String pwd) throws IOException {
- LOG.info("Connecting to {}", url + path);
+ protected static PutMethod httpPut(String path, String body, String user, String pwd)
+ throws IOException {
+ LOG.info("Connecting to {}", URL + path);
HttpClient httpClient = new HttpClient();
- PutMethod putMethod = new PutMethod(url + path);
- putMethod.addRequestHeader("Origin", url);
+ PutMethod putMethod = new PutMethod(URL + path);
+ putMethod.addRequestHeader("Origin", URL);
RequestEntity entity = new ByteArrayRequestEntity(body.getBytes("UTF-8"));
putMethod.setRequestEntity(entity);
if (userAndPasswordAreNotBlank(user, pwd)) {
- putMethod.setRequestHeader("Cookie", "JSESSIONID="+ getCookie(user, pwd));
+ putMethod.setRequestHeader("Cookie", "JSESSIONID=" + getCookie(user, pwd));
}
httpClient.executeMethod(putMethod);
LOG.info("{} - {}", putMethod.getStatusCode(), putMethod.getStatusText());
@@ -418,8 +426,8 @@ public abstract class AbstractTestRestApi {
private static String getCookie(String user, String password) throws IOException {
HttpClient httpClient = new HttpClient();
- PostMethod postMethod = new PostMethod(url + "/login");
- postMethod.addRequestHeader("Origin", url);
+ PostMethod postMethod = new PostMethod(URL + "/login");
+ postMethod.addRequestHeader("Origin", URL);
postMethod.setParameter("password", password);
postMethod.setParameter("userName", user);
httpClient.executeMethod(postMethod);
@@ -538,7 +546,6 @@ public abstract class AbstractTestRestApi {
};
}
-
public static void ps() {
DefaultExecutor executor = new DefaultExecutor();
executor.setStreamHandler(new PumpStreamHandler(System.out, System.err));
@@ -553,22 +560,30 @@ public abstract class AbstractTestRestApi {
}
}
-
- /** Status code matcher */
- protected Matcher<? super HttpMethodBase> isForbidden() { return responsesWith(403); }
+ /**
+ * Status code matcher.
+ */
+ protected Matcher<? super HttpMethodBase> isForbidden() {
+ return responsesWith(403);
+ }
protected Matcher<? super HttpMethodBase> isAllowed() {
return responsesWith(200);
}
- protected Matcher<? super HttpMethodBase> isCreated() { return responsesWith(201); }
+ protected Matcher<? super HttpMethodBase> isCreated() {
+ return responsesWith(201);
+ }
- protected Matcher<? super HttpMethodBase> isBadRequest() { return responsesWith(400); }
+ protected Matcher<? super HttpMethodBase> isBadRequest() {
+ return responsesWith(400);
+ }
- protected Matcher<? super HttpMethodBase> isNotFound() { return responsesWith(404); }
+ protected Matcher<? super HttpMethodBase> isNotFound() {
+ return responsesWith(404);
+ }
protected Matcher<? super HttpMethodBase> isNotAllowed() {
return responsesWith(405);
}
-
}
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/1add74b4/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ConfigurationsRestApiTest.java
----------------------------------------------------------------------
diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ConfigurationsRestApiTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ConfigurationsRestApiTest.java
index f85d519..bd489b5 100644
--- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ConfigurationsRestApiTest.java
+++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ConfigurationsRestApiTest.java
@@ -14,13 +14,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.zeppelin.rest;
+import static org.junit.Assert.assertTrue;
+
import com.google.common.base.Predicate;
import com.google.common.collect.Iterators;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
+
import org.apache.commons.httpclient.methods.GetMethod;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -29,8 +31,6 @@ import org.junit.Test;
import java.io.IOException;
import java.util.Map;
-import static org.junit.Assert.assertTrue;
-
public class ConfigurationsRestApiTest extends AbstractTestRestApi {
Gson gson = new Gson();
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/1add74b4/zeppelin-server/src/test/java/org/apache/zeppelin/rest/CredentialsRestApiTest.java
----------------------------------------------------------------------
diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/CredentialsRestApiTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/CredentialsRestApiTest.java
index 1737324..2225c39 100644
--- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/CredentialsRestApiTest.java
+++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/CredentialsRestApiTest.java
@@ -14,18 +14,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.zeppelin.rest;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
+
import org.apache.commons.httpclient.methods.DeleteMethod;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PutMethod;
-import org.apache.zeppelin.notebook.Note;
-import org.apache.zeppelin.server.ZeppelinServer;
-import org.apache.zeppelin.user.UserCredentials;
-import org.apache.zeppelin.utils.SecurityUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -35,7 +36,7 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.Map;
-import static org.junit.Assert.*;
+import org.apache.zeppelin.user.UserCredentials;
public class CredentialsRestApiTest extends AbstractTestRestApi {
protected static final Logger LOG = LoggerFactory.getLogger(CredentialsRestApiTest.class);
@@ -53,10 +54,14 @@ public class CredentialsRestApiTest extends AbstractTestRestApi {
@Test
public void testInvalidRequest() throws IOException {
- String jsonInvalidRequestEntityNull = "{\"entity\" : null, \"username\" : \"test\", \"password\" : \"testpass\"}";
- String jsonInvalidRequestNameNull = "{\"entity\" : \"test\", \"username\" : null, \"password\" : \"testpass\"}";
- String jsonInvalidRequestPasswordNull = "{\"entity\" : \"test\", \"username\" : \"test\", \"password\" : null}";
- String jsonInvalidRequestAllNull = "{\"entity\" : null, \"username\" : null, \"password\" : null}";
+ String jsonInvalidRequestEntityNull = "{\"entity\" : null, \"username\" : \"test\", " +
+ "\"password\" : \"testpass\"}";
+ String jsonInvalidRequestNameNull = "{\"entity\" : \"test\", \"username\" : null, " +
+ "\"password\" : \"testpass\"}";
+ String jsonInvalidRequestPasswordNull = "{\"entity\" : \"test\", \"username\" : \"test\", " +
+ "\"password\" : null}";
+ String jsonInvalidRequestAllNull = "{\"entity\" : null, \"username\" : null, " +
+ "\"password\" : null}";
PutMethod entityNullPut = httpPut("/credential", jsonInvalidRequestEntityNull);
entityNullPut.addRequestHeader("Origin", "http://localhost");
@@ -85,7 +90,8 @@ public class CredentialsRestApiTest extends AbstractTestRestApi {
Map<String, Object> resp = gson.fromJson(getMethod.getResponseBodyAsString(),
new TypeToken<Map<String, Object>>(){}.getType());
Map<String, Object> body = (Map<String, Object>) resp.get("body");
- Map<String, UserCredentials> credentialMap = (Map<String, UserCredentials>)body.get("userCredentials");
+ Map<String, UserCredentials> credentialMap =
+ (Map<String, UserCredentials>) body.get("userCredentials");
getMethod.releaseConnection();
return credentialMap;
}
@@ -111,7 +117,8 @@ public class CredentialsRestApiTest extends AbstractTestRestApi {
@Test
public void testCredentialsAPIs() throws IOException {
- String requestData1 = "{\"entity\" : \"entityname\", \"username\" : \"myuser\", \"password\" : \"mypass\"}";
+ String requestData1 = "{\"entity\" : \"entityname\", \"username\" : \"myuser\", \"password\" " +
+ ": \"mypass\"}";
String entity = "entityname";
Map<String, UserCredentials> credentialMap;
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/1add74b4/zeppelin-server/src/test/java/org/apache/zeppelin/rest/HeliumRestApiTest.java
----------------------------------------------------------------------
diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/HeliumRestApiTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/HeliumRestApiTest.java
index 7d29dcb..6f8edfd 100644
--- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/HeliumRestApiTest.java
+++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/HeliumRestApiTest.java
@@ -14,17 +14,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.zeppelin.rest;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
import com.google.gson.Gson;
import com.google.gson.internal.StringMap;
import com.google.gson.reflect.TypeToken;
+
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
-import org.apache.zeppelin.helium.*;
-import org.apache.zeppelin.server.ZeppelinServer;
-import org.junit.*;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
import java.io.IOException;
import java.util.LinkedList;
@@ -32,28 +38,31 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-import static org.junit.Assert.*;
+import org.apache.zeppelin.helium.HeliumPackage;
+import org.apache.zeppelin.helium.HeliumRegistry;
+import org.apache.zeppelin.helium.HeliumType;
+import org.apache.zeppelin.server.ZeppelinServer;
public class HeliumRestApiTest extends AbstractTestRestApi {
- Gson gson = new Gson();
+ Gson gson = new Gson();
- @BeforeClass
- public static void init() throws Exception {
- AbstractTestRestApi.startUp(HeliumRestApi.class.getSimpleName());
- }
+ @BeforeClass
+ public static void init() throws Exception {
+ AbstractTestRestApi.startUp(HeliumRestApi.class.getSimpleName());
+ }
- @AfterClass
- public static void destroy() throws Exception {
- AbstractTestRestApi.shutDown();
- }
+ @AfterClass
+ public static void destroy() throws Exception {
+ AbstractTestRestApi.shutDown();
+ }
- @Before
- public void setUp() throws IOException {
- HeliumTestRegistry registry = new HeliumTestRegistry("r1", "r1");
- ZeppelinServer.helium.clear();
- ZeppelinServer.helium.addRegistry(registry);
+ @Before
+ public void setUp() throws IOException {
+ HeliumTestRegistry registry = new HeliumTestRegistry("r1", "r1");
+ ZeppelinServer.helium.clear();
+ ZeppelinServer.helium.addRegistry(registry);
- registry.add(new HeliumPackage(
+ registry.add(new HeliumPackage(
HeliumType.APPLICATION,
"name1",
"desc1",
@@ -63,7 +72,7 @@ public class HeliumRestApiTest extends AbstractTestRestApi {
"",
""));
- registry.add(new HeliumPackage(
+ registry.add(new HeliumPackage(
HeliumType.APPLICATION,
"name2",
"desc2",
@@ -72,152 +81,152 @@ public class HeliumRestApiTest extends AbstractTestRestApi {
new String[][]{},
"",
""));
- }
-
- @After
- public void tearDown() throws Exception {
- ZeppelinServer.helium.clear();
- }
-
- @Test
- public void testGetAllPackageInfo() throws IOException {
- GetMethod get = httpGet("/helium/package");
- assertThat(get, isAllowed());
- Map<String, Object> resp = gson.fromJson(get.getResponseBodyAsString(),
- new TypeToken<Map<String, Object>>() { }.getType());
- Map<String, Set<String>> body = (Map<String, Set<String>>) resp.get("body");
-
- assertEquals(body.size(), 2);
- assertTrue(body.containsKey("name1"));
- assertTrue(body.containsKey("name2"));
- }
-
- @Test
- public void testGetAllEnabledPackageInfo() throws IOException {
- // No enabled packages initially
- GetMethod get1 = httpGet("/helium/enabledPackage");
- assertThat(get1, isAllowed());
- Map<String, Object> resp1 = gson.fromJson(get1.getResponseBodyAsString(),
- new TypeToken<Map<String, Object>>() { }.getType());
- List<StringMap<Object>> body1 = (List<StringMap<Object>>) resp1.get("body");
- assertEquals(body1.size(), 0);
-
- // Enable "name1" package
- ZeppelinServer.helium.enable("name1","artifact1");
-
- GetMethod get2 = httpGet("/helium/enabledPackage");
- assertThat(get2, isAllowed());
- Map<String, Object> resp2 = gson.fromJson(get2.getResponseBodyAsString(),
- new TypeToken<Map<String, Object>>() { }.getType());
- List<StringMap<Object>> body2 = (List<StringMap<Object>>) resp2.get("body");
-
- assertEquals(body2.size(), 1);
- StringMap<Object> pkg = (StringMap<Object>) body2.get(0).get("pkg");
- assertEquals(pkg.get("name"), "name1");
- }
-
- @Test
- public void testGetSinglePackageInfo() throws IOException {
- String packageName = "name1";
- GetMethod get = httpGet("/helium/package/" + packageName);
- assertThat(get, isAllowed());
- Map<String, Object> resp = gson.fromJson(get.getResponseBodyAsString(),
- new TypeToken<Map<String, Object>>() { }.getType());
- List<StringMap<Object>> body = (List<StringMap<Object>>) resp.get("body");
-
- assertEquals(body.size(), 1);
- StringMap<Object> pkg = (StringMap<Object>) body.get(0).get("pkg");
- assertEquals(pkg.get("name"), "name1");
- }
-
- @Test
- public void testGetAllPackageConfigs() throws IOException {
- GetMethod get = httpGet("/helium/config/");
- assertThat(get, isAllowed());
- Map<String, Object> resp = gson.fromJson(get.getResponseBodyAsString(),
- new TypeToken<Map<String, Object>>() { }.getType());
- StringMap<Object> body = (StringMap<Object>) resp.get("body");
- // ToDo: Apply config with POST command and check update
- assertEquals(body.size(), 0);
- }
-
- @Test
- public void testGetPackageConfig() throws IOException {
- String packageName = "name1";
- String artifact = "artifact1";
- GetMethod get = httpGet("/helium/config/" + packageName + "/" + artifact);
- assertThat(get, isAllowed());
- Map<String, Object> resp = gson.fromJson(get.getResponseBodyAsString(),
- new TypeToken<Map<String, Object>>() { }.getType());
- StringMap<Object> body = (StringMap<Object>) resp.get("body");
- assertTrue(body.containsKey("confPersisted"));
- }
-
- @Test
- public void testEnableDisablePackage() throws IOException {
- String packageName = "name1";
- PostMethod post1 = httpPost("/helium/enable/" + packageName, "");
- assertThat(post1, isAllowed());
- post1.releaseConnection();
-
- GetMethod get1 = httpGet("/helium/package/" + packageName);
- Map<String, Object> resp1 = gson.fromJson(get1.getResponseBodyAsString(),
- new TypeToken<Map<String, Object>>() { }.getType());
- List<StringMap<Object>> body1 = (List<StringMap<Object>>) resp1.get("body");
- assertEquals(body1.get(0).get("enabled"), true);
-
- PostMethod post2 = httpPost("/helium/disable/" + packageName, "");
- assertThat(post2, isAllowed());
- post2.releaseConnection();
-
- GetMethod get2 = httpGet("/helium/package/" + packageName);
- Map<String, Object> resp2 = gson.fromJson(get2.getResponseBodyAsString(),
- new TypeToken<Map<String, Object>>() { }.getType());
- List<StringMap<Object>> body2 = (List<StringMap<Object>>) resp2.get("body");
- assertEquals(body2.get(0).get("enabled"), false);
- }
-
- @Test
- public void testVisualizationPackageOrder() throws IOException {
- GetMethod get1 = httpGet("/helium/order/visualization");
- assertThat(get1, isAllowed());
- Map<String, Object> resp1 = gson.fromJson(get1.getResponseBodyAsString(),
- new TypeToken<Map<String, Object>>() { }.getType());
- List<Object> body1 = (List<Object>) resp1.get("body");
- assertEquals(body1.size(), 0);
-
- //We assume allPackages list has been refreshed before sorting
- ZeppelinServer.helium.getAllPackageInfo();
-
- String postRequestJson = "[name2, name1]";
- PostMethod post = httpPost("/helium/order/visualization", postRequestJson);
- assertThat(post, isAllowed());
- post.releaseConnection();
-
- GetMethod get2 = httpGet("/helium/order/visualization");
- assertThat(get2, isAllowed());
- Map<String, Object> resp2 = gson.fromJson(get2.getResponseBodyAsString(),
+ }
+
+ @After
+ public void tearDown() {
+ ZeppelinServer.helium.clear();
+ }
+
+ @Test
+ public void testGetAllPackageInfo() throws IOException {
+ GetMethod get = httpGet("/helium/package");
+ assertThat(get, isAllowed());
+ Map<String, Object> resp = gson.fromJson(get.getResponseBodyAsString(),
+ new TypeToken<Map<String, Object>>() { }.getType());
+ Map<String, Set<String>> body = (Map<String, Set<String>>) resp.get("body");
+
+ assertEquals(body.size(), 2);
+ assertTrue(body.containsKey("name1"));
+ assertTrue(body.containsKey("name2"));
+ }
+
+ @Test
+ public void testGetAllEnabledPackageInfo() throws IOException {
+ // No enabled packages initially
+ GetMethod get1 = httpGet("/helium/enabledPackage");
+ assertThat(get1, isAllowed());
+ Map<String, Object> resp1 = gson.fromJson(get1.getResponseBodyAsString(),
new TypeToken<Map<String, Object>>() { }.getType());
- List<Object> body2 = (List<Object>) resp2.get("body");
- assertEquals(body2.size(), 2);
- assertEquals(body2.get(0), "name2");
- assertEquals(body2.get(1), "name1");
- }
+ List<StringMap<Object>> body1 = (List<StringMap<Object>>) resp1.get("body");
+ assertEquals(body1.size(), 0);
+
+ // Enable "name1" package
+ ZeppelinServer.helium.enable("name1", "artifact1");
+
+ GetMethod get2 = httpGet("/helium/enabledPackage");
+ assertThat(get2, isAllowed());
+ Map<String, Object> resp2 = gson.fromJson(get2.getResponseBodyAsString(),
+ new TypeToken<Map<String, Object>>() { }.getType());
+ List<StringMap<Object>> body2 = (List<StringMap<Object>>) resp2.get("body");
+
+ assertEquals(body2.size(), 1);
+ StringMap<Object> pkg = (StringMap<Object>) body2.get(0).get("pkg");
+ assertEquals(pkg.get("name"), "name1");
+ }
+
+ @Test
+ public void testGetSinglePackageInfo() throws IOException {
+ String packageName = "name1";
+ GetMethod get = httpGet("/helium/package/" + packageName);
+ assertThat(get, isAllowed());
+ Map<String, Object> resp = gson.fromJson(get.getResponseBodyAsString(),
+ new TypeToken<Map<String, Object>>() { }.getType());
+ List<StringMap<Object>> body = (List<StringMap<Object>>) resp.get("body");
+
+ assertEquals(body.size(), 1);
+ StringMap<Object> pkg = (StringMap<Object>) body.get(0).get("pkg");
+ assertEquals(pkg.get("name"), "name1");
+ }
+
+ @Test
+ public void testGetAllPackageConfigs() throws IOException {
+ GetMethod get = httpGet("/helium/config/");
+ assertThat(get, isAllowed());
+ Map<String, Object> resp = gson.fromJson(get.getResponseBodyAsString(),
+ new TypeToken<Map<String, Object>>() { }.getType());
+ StringMap<Object> body = (StringMap<Object>) resp.get("body");
+ // ToDo: Apply config with POST command and check update
+ assertEquals(body.size(), 0);
+ }
+
+ @Test
+ public void testGetPackageConfig() throws IOException {
+ String packageName = "name1";
+ String artifact = "artifact1";
+ GetMethod get = httpGet("/helium/config/" + packageName + "/" + artifact);
+ assertThat(get, isAllowed());
+ Map<String, Object> resp = gson.fromJson(get.getResponseBodyAsString(),
+ new TypeToken<Map<String, Object>>() { }.getType());
+ StringMap<Object> body = (StringMap<Object>) resp.get("body");
+ assertTrue(body.containsKey("confPersisted"));
+ }
+
+ @Test
+ public void testEnableDisablePackage() throws IOException {
+ String packageName = "name1";
+ PostMethod post1 = httpPost("/helium/enable/" + packageName, "");
+ assertThat(post1, isAllowed());
+ post1.releaseConnection();
+
+ GetMethod get1 = httpGet("/helium/package/" + packageName);
+ Map<String, Object> resp1 = gson.fromJson(get1.getResponseBodyAsString(),
+ new TypeToken<Map<String, Object>>() { }.getType());
+ List<StringMap<Object>> body1 = (List<StringMap<Object>>) resp1.get("body");
+ assertEquals(body1.get(0).get("enabled"), true);
+
+ PostMethod post2 = httpPost("/helium/disable/" + packageName, "");
+ assertThat(post2, isAllowed());
+ post2.releaseConnection();
+
+ GetMethod get2 = httpGet("/helium/package/" + packageName);
+ Map<String, Object> resp2 = gson.fromJson(get2.getResponseBodyAsString(),
+ new TypeToken<Map<String, Object>>() { }.getType());
+ List<StringMap<Object>> body2 = (List<StringMap<Object>>) resp2.get("body");
+ assertEquals(body2.get(0).get("enabled"), false);
+ }
+
+ @Test
+ public void testVisualizationPackageOrder() throws IOException {
+ GetMethod get1 = httpGet("/helium/order/visualization");
+ assertThat(get1, isAllowed());
+ Map<String, Object> resp1 = gson.fromJson(get1.getResponseBodyAsString(),
+ new TypeToken<Map<String, Object>>() { }.getType());
+ List<Object> body1 = (List<Object>) resp1.get("body");
+ assertEquals(body1.size(), 0);
+
+ //We assume allPackages list has been refreshed before sorting
+ ZeppelinServer.helium.getAllPackageInfo();
+
+ String postRequestJson = "[name2, name1]";
+ PostMethod post = httpPost("/helium/order/visualization", postRequestJson);
+ assertThat(post, isAllowed());
+ post.releaseConnection();
+
+ GetMethod get2 = httpGet("/helium/order/visualization");
+ assertThat(get2, isAllowed());
+ Map<String, Object> resp2 = gson.fromJson(get2.getResponseBodyAsString(),
+ new TypeToken<Map<String, Object>>() { }.getType());
+ List<Object> body2 = (List<Object>) resp2.get("body");
+ assertEquals(body2.size(), 2);
+ assertEquals(body2.get(0), "name2");
+ assertEquals(body2.get(1), "name1");
+ }
}
class HeliumTestRegistry extends HeliumRegistry {
- private List<HeliumPackage> infos = new LinkedList<>();
+ private List<HeliumPackage> infos = new LinkedList<>();
- public HeliumTestRegistry(String name, String uri) {
- super(name, uri);
- }
+ HeliumTestRegistry(String name, String uri) {
+ super(name, uri);
+ }
- @Override
- public List<HeliumPackage> getAll() throws IOException {
- return infos;
- }
+ @Override
+ public List<HeliumPackage> getAll() throws IOException {
+ return infos;
+ }
- public void add(HeliumPackage info) {
- infos.add(info);
- }
+ public void add(HeliumPackage info) {
+ infos.add(info);
+ }
}
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/1add74b4/zeppelin-server/src/test/java/org/apache/zeppelin/rest/InterpreterRestApiTest.java
----------------------------------------------------------------------
diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/InterpreterRestApiTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/InterpreterRestApiTest.java
index 7de4dc6..e870442 100644
--- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/InterpreterRestApiTest.java
+++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/InterpreterRestApiTest.java
@@ -14,29 +14,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.zeppelin.rest;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
+
import org.apache.commons.httpclient.methods.DeleteMethod;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.PutMethod;
-import org.apache.zeppelin.interpreter.InterpreterOption;
-import org.apache.zeppelin.interpreter.InterpreterSetting;
-import org.apache.zeppelin.notebook.Note;
-import org.apache.zeppelin.notebook.Paragraph;
-import org.apache.zeppelin.scheduler.Job.Status;
-import org.apache.zeppelin.server.ZeppelinServer;
-import org.apache.zeppelin.user.AuthenticationInfo;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -44,13 +37,21 @@ import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
-import com.google.gson.Gson;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
-import static org.junit.Assert.*;
-import static org.hamcrest.MatcherAssert.assertThat;
+import org.apache.zeppelin.interpreter.InterpreterOption;
+import org.apache.zeppelin.interpreter.InterpreterSetting;
+import org.apache.zeppelin.notebook.Note;
+import org.apache.zeppelin.notebook.Paragraph;
+import org.apache.zeppelin.scheduler.Job.Status;
+import org.apache.zeppelin.server.ZeppelinServer;
+import org.apache.zeppelin.user.AuthenticationInfo;
/**
- * Zeppelin interpreter rest api tests
+ * Zeppelin interpreter rest api tests.
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class InterpreterRestApiTest extends AbstractTestRestApi {
@@ -80,8 +81,8 @@ public class InterpreterRestApiTest extends AbstractTestRestApi {
// then
assertThat(get, isAllowed());
- assertEquals(ZeppelinServer.notebook.getInterpreterSettingManager().getInterpreterSettingTemplates().size(),
- body.entrySet().size());
+ assertEquals(ZeppelinServer.notebook.getInterpreterSettingManager()
+ .getInterpreterSettingTemplates().size(), body.entrySet().size());
get.releaseConnection();
}
@@ -111,10 +112,11 @@ public class InterpreterRestApiTest extends AbstractTestRestApi {
public void testSettingsCRUD() throws IOException {
// when: call create setting API
String rawRequest = "{\"name\":\"md3\",\"group\":\"md\"," +
- "\"properties\":{\"propname\": {\"value\": \"propvalue\", \"name\": \"propname\", \"type\": \"textarea\"}}," +
- "\"interpreterGroup\":[{\"class\":\"org.apache.zeppelin.markdown.Markdown\",\"name\":\"md\"}]," +
- "\"dependencies\":[]," +
- "\"option\": { \"remote\": true, \"session\": false }}";
+ "\"properties\":{\"propname\": {\"value\": \"propvalue\", \"name\": \"propname\", " +
+ "\"type\": \"textarea\"}}," +
+ "\"interpreterGroup\":[{\"class\":\"org.apache.zeppelin.markdown.Markdown\"," +
+ "\"name\":\"md\"}],\"dependencies\":[]," +
+ "\"option\": { \"remote\": true, \"session\": false }}";
JsonObject jsonRequest = gson.fromJson(rawRequest, JsonElement.class).getAsJsonObject();
PostMethod post = httpPost("/interpreter/setting/", jsonRequest.toString());
String postResponse = post.getResponseBodyAsString();
@@ -158,7 +160,6 @@ public class InterpreterRestApiTest extends AbstractTestRestApi {
@Test
public void testCreatedInterpreterDependencies() throws IOException {
// when: Create 2 interpreter settings `md1` and `md2` which have different dep.
-
String md1Name = "md1";
String md2Name = "md2";
@@ -166,25 +167,29 @@ public class InterpreterRestApiTest extends AbstractTestRestApi {
String md2Dep = "org.apache.drill.exec:drill-jdbc:jar:1.6.0";
String reqBody1 = "{\"name\":\"" + md1Name + "\",\"group\":\"md\"," +
- "\"properties\":{\"propname\": {\"value\": \"propvalue\", \"name\": \"propname\", \"type\": \"textarea\"}}," +
- "\"interpreterGroup\":[{\"class\":\"org.apache.zeppelin.markdown.Markdown\",\"name\":\"md\"}]," +
- "\"dependencies\":[ {\n" +
- " \"groupArtifactVersion\": \"" + md1Dep + "\",\n" +
- " \"exclusions\":[]\n" +
- " }]," +
- "\"option\": { \"remote\": true, \"session\": false }}";
+ "\"properties\":{\"propname\": {\"value\": \"propvalue\", \"name\": \"propname\", " +
+ "\"type\": \"textarea\"}}," +
+ "\"interpreterGroup\":[{\"class\":\"org.apache.zeppelin.markdown.Markdown\"," +
+ "\"name\":\"md\"}]," +
+ "\"dependencies\":[ {\n" +
+ " \"groupArtifactVersion\": \"" + md1Dep + "\",\n" +
+ " \"exclusions\":[]\n" +
+ " }]," +
+ "\"option\": { \"remote\": true, \"session\": false }}";
PostMethod post = httpPost("/interpreter/setting", reqBody1);
assertThat("test create method:", post, isAllowed());
post.releaseConnection();
String reqBody2 = "{\"name\":\"" + md2Name + "\",\"group\":\"md\"," +
- "\"properties\": {\"propname\": {\"value\": \"propvalue\", \"name\": \"propname\", \"type\": \"textarea\"}}," +
- "\"interpreterGroup\":[{\"class\":\"org.apache.zeppelin.markdown.Markdown\",\"name\":\"md\"}]," +
- "\"dependencies\":[ {\n" +
- " \"groupArtifactVersion\": \"" + md2Dep + "\",\n" +
- " \"exclusions\":[]\n" +
- " }]," +
- "\"option\": { \"remote\": true, \"session\": false }}";
+ "\"properties\": {\"propname\": {\"value\": \"propvalue\", \"name\": \"propname\", " +
+ "\"type\": \"textarea\"}}," +
+ "\"interpreterGroup\":[{\"class\":\"org.apache.zeppelin.markdown.Markdown\"," +
+ "\"name\":\"md\"}]," +
+ "\"dependencies\":[ {\n" +
+ " \"groupArtifactVersion\": \"" + md2Dep + "\",\n" +
+ " \"exclusions\":[]\n" +
+ " }]," +
+ "\"option\": { \"remote\": true, \"session\": false }}";
post = httpPost("/interpreter/setting", reqBody2);
assertThat("test create method:", post, isAllowed());
post.releaseConnection();
@@ -265,7 +270,8 @@ public class InterpreterRestApiTest extends AbstractTestRestApi {
assertEquals(p.getResult().message().get(0).getData(), getSimulatedMarkdownResult("markdown"));
// when: restart interpreter
- for (InterpreterSetting setting : ZeppelinServer.notebook.getInterpreterSettingManager().getInterpreterSettings(note.getId())) {
+ for (InterpreterSetting setting : ZeppelinServer.notebook.getInterpreterSettingManager()
+ .getInterpreterSettings(note.getId())) {
if (setting.getName().equals("md")) {
// call restart interpreter API
PutMethod put = httpPut("/interpreter/setting/restart/" + setting.getId(), "");
@@ -286,7 +292,8 @@ public class InterpreterRestApiTest extends AbstractTestRestApi {
}
// then
- assertEquals(p.getResult().message().get(0).getData(), getSimulatedMarkdownResult("markdown restarted"));
+ assertEquals(p.getResult().message().get(0).getData(),
+ getSimulatedMarkdownResult("markdown restarted"));
ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
}
@@ -311,7 +318,8 @@ public class InterpreterRestApiTest extends AbstractTestRestApi {
// when: get md interpreter
InterpreterSetting mdIntpSetting = null;
- for (InterpreterSetting setting : ZeppelinServer.notebook.getInterpreterSettingManager().getInterpreterSettings(note.getId())) {
+ for (InterpreterSetting setting : ZeppelinServer.notebook.getInterpreterSettingManager()
+ .getInterpreterSettings(note.getId())) {
if (setting.getName().equals("md")) {
mdIntpSetting = setting;
break;
@@ -368,12 +376,14 @@ public class InterpreterRestApiTest extends AbstractTestRestApi {
@Test
public void testGetMetadataInfo() throws IOException {
String jsonRequest = "{\"name\":\"spark_new\",\"group\":\"spark\"," +
- "\"properties\":{\"propname\": {\"value\": \"propvalue\", \"name\": \"propname\", \"type\": \"textarea\"}}," +
- "\"interpreterGroup\":[{\"class\":\"org.apache.zeppelin.markdown.Markdown\",\"name\":\"md\"}]," +
- "\"dependencies\":[]," +
+ "\"properties\":{\"propname\": {\"value\": \"propvalue\", \"name\": \"propname\", " +
+ "\"type\": \"textarea\"}}," +
+ "\"interpreterGroup\":[{\"class\":\"org.apache.zeppelin.markdown.Markdown\"," +
+ "\"name\":\"md\"}],\"dependencies\":[]," +
"\"option\": { \"remote\": true, \"session\": false }}";
PostMethod post = httpPost("/interpreter/setting/", jsonRequest);
- InterpreterSetting created = convertResponseToInterpreterSetting(post.getResponseBodyAsString());
+ InterpreterSetting created = convertResponseToInterpreterSetting(
+ post.getResponseBodyAsString());
String settingId = created.getId();
Map<String, String> infos = new java.util.HashMap<>();
infos.put("key1", "value1");
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/1add74b4/zeppelin-server/src/test/java/org/apache/zeppelin/rest/KnoxRestApiTest.java
----------------------------------------------------------------------
diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/KnoxRestApiTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/KnoxRestApiTest.java
index e3034e4..9459317 100644
--- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/KnoxRestApiTest.java
+++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/KnoxRestApiTest.java
@@ -17,8 +17,7 @@
package org.apache.zeppelin.rest;
import com.google.gson.Gson;
-import java.io.IOException;
-import java.util.Map;
+
import org.apache.commons.httpclient.methods.GetMethod;
import org.hamcrest.CoreMatchers;
import org.junit.AfterClass;
@@ -30,9 +29,14 @@ import org.junit.rules.ErrorCollector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class KnoxRestApiTest extends AbstractTestRestApi {
+import java.io.IOException;
+import java.util.Map;
- private String KNOX_COOKIE = "hadoop-jwt=eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJhZG1pbiIsImlzcyI6IktOT1hTU08iLCJleHAiOjE1MTM3NDU1MDd9.E2cWQo2sq75h0G_9fc9nWkL0SFMI5x_-Z0Zzr0NzQ86X4jfxliWYjr0M17Bm9GfPHRRR66s7YuYXa6DLbB4fHE0cyOoQnkfJFpU_vr1xhy0_0URc5v-Gb829b9rxuQfjKe-37hqbUdkwww2q6QQETVMvzp0rQKprUClZujyDvh0;";
+public class KnoxRestApiTest extends AbstractTestRestApi {
+ private final String knoxCookie = "hadoop-jwt=eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJhZG1pbiIsImlzcyI" +
+ "6IktOT1hTU08iLCJleHAiOjE1MTM3NDU1MDd9.E2cWQo2sq75h0G_9fc9nWkL0SFMI5x_-Z0Zzr0NzQ86X4jfx" +
+ "liWYjr0M17Bm9GfPHRRR66s7YuYXa6DLbB4fHE0cyOoQnkfJFpU_vr1xhy0_0URc5v-Gb829b9rxuQfjKe-37h" +
+ "qbUdkwww2q6QQETVMvzp0rQKprUClZujyDvh0;";
@Rule
public ErrorCollector collector = new ErrorCollector();
@@ -55,7 +59,6 @@ public class KnoxRestApiTest extends AbstractTestRestApi {
public void setUp() {
}
-
@Test
public void testThatOtherUserCanAccessNoteIfPermissionNotSet() throws IOException {
GetMethod loginWithoutCookie = httpGet("/api/security/ticket");
@@ -70,7 +73,7 @@ public class KnoxRestApiTest extends AbstractTestRestApi {
((Map) result.get("body")).get("redirectURL").toString(), CoreMatchers.equalTo(
"https://domain.example.com/gateway/knoxsso/knoxauth/login.html?originalUrl="));
- GetMethod loginWithCookie = httpGet("/api/security/ticket", "", "", KNOX_COOKIE);
+ GetMethod loginWithCookie = httpGet("/api/security/ticket", "", "", knoxCookie);
result = gson.fromJson(loginWithCookie.getResponseBodyAsString(), Map.class);
collector.checkThat("User logged in as admin",
@@ -78,5 +81,4 @@ public class KnoxRestApiTest extends AbstractTestRestApi {
System.out.println(result);
}
-
}
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/1add74b4/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRepoRestApiTest.java
----------------------------------------------------------------------
diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRepoRestApiTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRepoRestApiTest.java
index b852d6e..34b85ae 100644
--- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRepoRestApiTest.java
+++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRepoRestApiTest.java
@@ -16,19 +16,17 @@
*/
package org.apache.zeppelin.rest;
+import static org.hamcrest.CoreMatchers.anyOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.CoreMatchers.anyOf;
import static org.junit.Assert.assertThat;
-import java.io.IOException;
-import java.util.List;
-import java.util.Map;
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PutMethod;
import org.apache.commons.lang.StringUtils;
-import org.apache.zeppelin.user.AuthenticationInfo;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -36,15 +34,17 @@ import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
-import com.google.gson.Gson;
-import com.google.gson.reflect.TypeToken;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.zeppelin.user.AuthenticationInfo;
/**
* NotebookRepo rest api test.
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class NotebookRepoRestApiTest extends AbstractTestRestApi {
-
Gson gson = new Gson();
AuthenticationInfo anonymous;
@@ -65,7 +65,8 @@ public class NotebookRepoRestApiTest extends AbstractTestRestApi {
private List<Map<String, Object>> getListOfReposotiry() throws IOException {
GetMethod get = httpGet("/notebook-repositories");
- Map<String, Object> responce = gson.fromJson(get.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {}.getType());
+ Map<String, Object> responce = gson.fromJson(get.getResponseBodyAsString(),
+ new TypeToken<Map<String, Object>>() {}.getType());
get.releaseConnection();
return (List<Map<String, Object>>) responce.get("body");
}
@@ -77,26 +78,31 @@ public class NotebookRepoRestApiTest extends AbstractTestRestApi {
assertThat(status, is(200));
}
- @Test public void ThatCanGetNotebookRepositoiesSettings() throws IOException {
+ @Test
+ public void thatCanGetNotebookRepositoiesSettings() throws IOException {
List<Map<String, Object>> listOfRepositories = getListOfReposotiry();
assertThat(listOfRepositories.size(), is(not(0)));
}
- @Test public void reloadRepositories() throws IOException {
+ @Test
+ public void reloadRepositories() throws IOException {
GetMethod get = httpGet("/notebook-repositories/reload");
int status = get.getStatusCode();
get.releaseConnection();
assertThat(status, is(200));
}
- @Test public void setNewDirectoryForLocalDirectory() throws IOException {
+ @Test
+ public void setNewDirectoryForLocalDirectory() throws IOException {
List<Map<String, Object>> listOfRepositories = getListOfReposotiry();
String localVfs = StringUtils.EMPTY;
String className = StringUtils.EMPTY;
for (int i = 0; i < listOfRepositories.size(); i++) {
if (listOfRepositories.get(i).get("name").equals("VFSNotebookRepo")) {
- localVfs = (String) ((List<Map<String, Object>>)listOfRepositories.get(i).get("settings")).get(0).get("selected");
+ localVfs =
+ (String) ((List<Map<String, Object>>) listOfRepositories.get(i).get("settings"))
+ .get(0).get("selected");
className = (String) listOfRepositories.get(i).get("className");
break;
}
@@ -107,7 +113,8 @@ public class NotebookRepoRestApiTest extends AbstractTestRestApi {
return;
}
- String payload = "{ \"name\": \"" + className + "\", \"settings\" : { \"Notebook Path\" : \"/tmp/newDir\" } }";
+ String payload = "{ \"name\": \"" + className + "\", \"settings\" : " +
+ "{ \"Notebook Path\" : \"/tmp/newDir\" } }";
updateNotebookRepoWithNewSetting(payload);
// Verify
@@ -115,14 +122,17 @@ public class NotebookRepoRestApiTest extends AbstractTestRestApi {
String updatedPath = StringUtils.EMPTY;
for (int i = 0; i < listOfRepositories.size(); i++) {
if (listOfRepositories.get(i).get("name").equals("VFSNotebookRepo")) {
- updatedPath = (String) ((List<Map<String, Object>>)listOfRepositories.get(i).get("settings")).get(0).get("selected");
+ updatedPath =
+ (String) ((List<Map<String, Object>>) listOfRepositories.get(i).get("settings"))
+ .get(0).get("selected");
break;
}
}
- assertThat(updatedPath, anyOf(is("/tmp/newDir"),is("/tmp/newDir/")));
+ assertThat(updatedPath, anyOf(is("/tmp/newDir"), is("/tmp/newDir/")));
// go back to normal
- payload = "{ \"name\": \"" + className + "\", \"settings\" : { \"Notebook Path\" : \"" + localVfs + "\" } }";
+ payload = "{ \"name\": \"" + className + "\", \"settings\" : { \"Notebook Path\" : \"" +
+ localVfs + "\" } }";
updateNotebookRepoWithNewSetting(payload);
}
}
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/1add74b4/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java
----------------------------------------------------------------------
diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java
index d5c29c9..f131ed1 100644
--- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java
+++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java
@@ -14,21 +14,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.zeppelin.rest;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.PutMethod;
-import org.apache.zeppelin.interpreter.InterpreterResult;
-import org.apache.zeppelin.notebook.Note;
-import org.apache.zeppelin.notebook.Paragraph;
-import org.apache.zeppelin.scheduler.Job;
-import org.apache.zeppelin.server.ZeppelinServer;
-import org.apache.zeppelin.user.AuthenticationInfo;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -40,14 +39,15 @@ import java.io.IOException;
import java.util.Map;
import java.util.Set;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
+import org.apache.zeppelin.interpreter.InterpreterResult;
+import org.apache.zeppelin.notebook.Note;
+import org.apache.zeppelin.notebook.Paragraph;
+import org.apache.zeppelin.scheduler.Job;
+import org.apache.zeppelin.server.ZeppelinServer;
+import org.apache.zeppelin.user.AuthenticationInfo;
/**
- * Zeppelin notebook rest api tests
+ * Zeppelin notebook rest api tests.
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class NotebookRestApiTest extends AbstractTestRestApi {
@@ -78,8 +78,8 @@ public class NotebookRestApiTest extends AbstractTestRestApi {
GetMethod get = httpGet("/notebook/job/" + note1.getId() + "/" + paragraphId);
assertThat(get, isAllowed());
- Map<String, Object> resp = gson.fromJson(get.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
- }.getType());
+ Map<String, Object> resp = gson.fromJson(get.getResponseBodyAsString(),
+ new TypeToken<Map<String, Object>>() {}.getType());
Map<String, Set<String>> paragraphStatus = (Map<String, Set<String>>) resp.get("body");
// Check id and status have proper value
@@ -88,7 +88,6 @@ public class NotebookRestApiTest extends AbstractTestRestApi {
//cleanup
ZeppelinServer.notebook.removeNote(note1.getId(), anonymous);
-
}
@Test
@@ -101,8 +100,8 @@ public class NotebookRestApiTest extends AbstractTestRestApi {
// run blank paragraph
PostMethod post = httpPost("/notebook/job/" + note1.getId() + "/" + p.getId(), "");
assertThat(post, isAllowed());
- Map<String, Object> resp = gson.fromJson(post.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
- }.getType());
+ Map<String, Object> resp = gson.fromJson(post.getResponseBodyAsString(),
+ new TypeToken<Map<String, Object>>() {}.getType());
assertEquals(resp.get("status"), "OK");
post.releaseConnection();
assertEquals(p.getStatus(), Job.Status.FINISHED);
@@ -111,8 +110,8 @@ public class NotebookRestApiTest extends AbstractTestRestApi {
p.setText("test");
post = httpPost("/notebook/job/" + note1.getId() + "/" + p.getId(), "");
assertThat(post, isAllowed());
- resp = gson.fromJson(post.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
- }.getType());
+ resp = gson.fromJson(post.getResponseBodyAsString(),
+ new TypeToken<Map<String, Object>>() {}.getType());
assertEquals(resp.get("status"), "OK");
post.releaseConnection();
assertNotEquals(p.getStatus(), Job.Status.READY);
@@ -142,8 +141,8 @@ public class NotebookRestApiTest extends AbstractTestRestApi {
PostMethod post = httpPost("/notebook/job/" + note1.getId(), "");
assertThat(post, isAllowed());
- Map<String, Object> resp = gson.fromJson(post.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
- }.getType());
+ Map<String, Object> resp = gson.fromJson(post.getResponseBodyAsString(),
+ new TypeToken<Map<String, Object>>() {}.getType());
assertEquals(resp.get("status"), "OK");
post.releaseConnection();
@@ -173,8 +172,8 @@ public class NotebookRestApiTest extends AbstractTestRestApi {
PostMethod post = httpPost("/notebook/job/" + note1.getId(), "");
assertThat(post, isAllowed());
- Map<String, Object> resp = gson.fromJson(post.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
- }.getType());
+ Map<String, Object> resp = gson.fromJson(post.getResponseBodyAsString(),
+ new TypeToken<Map<String, Object>>() {}.getType());
assertEquals(resp.get("status"), "OK");
post.releaseConnection();
@@ -189,15 +188,15 @@ public class NotebookRestApiTest extends AbstractTestRestApi {
PostMethod post = httpPost("/notebook/" + note1.getId(), "");
LOG.info("testCloneNote response\n" + post.getResponseBodyAsString());
assertThat(post, isAllowed());
- Map<String, Object> resp = gson.fromJson(post.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
- }.getType());
+ Map<String, Object> resp = gson.fromJson(post.getResponseBodyAsString(),
+ new TypeToken<Map<String, Object>>() {}.getType());
String clonedNoteId = (String) resp.get("body");
post.releaseConnection();
GetMethod get = httpGet("/notebook/" + clonedNoteId);
assertThat(get, isAllowed());
- Map<String, Object> resp2 = gson.fromJson(get.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
- }.getType());
+ Map<String, Object> resp2 = gson.fromJson(get.getResponseBodyAsString(),
+ new TypeToken<Map<String, Object>>() {}.getType());
Map<String, Object> resp2Body = (Map<String, Object>) resp2.get("body");
assertEquals(resp2Body.get("name"), "Note " + clonedNoteId);
@@ -217,11 +216,12 @@ public class NotebookRestApiTest extends AbstractTestRestApi {
String paragraphId = p.getId();
String jsonRequest = "{\"colWidth\": 6.0}";
- PutMethod put = httpPut("/notebook/" + noteId + "/paragraph/" + paragraphId +"/config", jsonRequest);
+ PutMethod put = httpPut("/notebook/" + noteId + "/paragraph/" + paragraphId + "/config",
+ jsonRequest);
assertThat("test testUpdateParagraphConfig:", put, isAllowed());
- Map<String, Object> resp = gson.fromJson(put.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
- }.getType());
+ Map<String, Object> resp = gson.fromJson(put.getResponseBodyAsString(),
+ new TypeToken<Map<String, Object>>() {}.getType());
Map<String, Object> respBody = (Map<String, Object>) resp.get("body");
Map<String, Object> config = (Map<String, Object>) respBody.get("config");
put.releaseConnection();
@@ -239,7 +239,8 @@ public class NotebookRestApiTest extends AbstractTestRestApi {
// Create note and set result explicitly
Note note = ZeppelinServer.notebook.createNote(anonymous);
Paragraph p1 = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
- InterpreterResult result = new InterpreterResult(InterpreterResult.Code.SUCCESS, InterpreterResult.Type.TEXT, "result");
+ InterpreterResult result = new InterpreterResult(InterpreterResult.Code.SUCCESS,
+ InterpreterResult.Type.TEXT, "result");
p1.setResult(result);
Paragraph p2 = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
@@ -254,15 +255,15 @@ public class NotebookRestApiTest extends AbstractTestRestApi {
// check if paragraph results are cleared
GetMethod get = httpGet("/notebook/" + note.getId() + "/paragraph/" + p1.getId());
assertThat(get, isAllowed());
- Map<String, Object> resp1 = gson.fromJson(get.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
- }.getType());
+ Map<String, Object> resp1 = gson.fromJson(get.getResponseBodyAsString(),
+ new TypeToken<Map<String, Object>>() {}.getType());
Map<String, Object> resp1Body = (Map<String, Object>) resp1.get("body");
assertNull(resp1Body.get("result"));
get = httpGet("/notebook/" + note.getId() + "/paragraph/" + p2.getId());
assertThat(get, isAllowed());
- Map<String, Object> resp2 = gson.fromJson(get.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
- }.getType());
+ Map<String, Object> resp2 = gson.fromJson(get.getResponseBodyAsString(),
+ new TypeToken<Map<String, Object>>() {}.getType());
Map<String, Object> resp2Body = (Map<String, Object>) resp2.get("body");
assertNull(resp2Body.get("result"));
get.releaseConnection();
@@ -317,6 +318,5 @@ public class NotebookRestApiTest extends AbstractTestRestApi {
assertEquals(Job.Status.FINISHED, p2.getStatus());
assertNotNull(p2.getResult());
assertEquals("abc\n", p2.getResult().message().get(0).getData());
-
}
}
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/1add74b4/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookSecurityRestApiTest.java
----------------------------------------------------------------------
diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookSecurityRestApiTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookSecurityRestApiTest.java
index 808cfd8..209a272 100644
--- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookSecurityRestApiTest.java
+++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookSecurityRestApiTest.java
@@ -17,36 +17,39 @@
package org.apache.zeppelin.rest;
import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Map;
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
import org.apache.commons.httpclient.HttpMethodBase;
import org.apache.commons.httpclient.methods.DeleteMethod;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.PutMethod;
-import org.apache.zeppelin.notebook.Note;
-import org.apache.zeppelin.server.ZeppelinServer;
import org.hamcrest.Matcher;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
-import com.google.gson.Gson;
-import com.google.gson.reflect.TypeToken;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Map;
-public class NotebookSecurityRestApiTest extends AbstractTestRestApi {
+import org.apache.zeppelin.notebook.Note;
+import org.apache.zeppelin.server.ZeppelinServer;
+public class NotebookSecurityRestApiTest extends AbstractTestRestApi {
Gson gson = new Gson();
@BeforeClass
public static void init() throws Exception {
- AbstractTestRestApi.startUpWithAuthenticationEnable(NotebookSecurityRestApiTest.class.getSimpleName());
+ AbstractTestRestApi.startUpWithAuthenticationEnable(
+ NotebookSecurityRestApiTest.class.getSimpleName());
}
@AfterClass
@@ -56,7 +59,6 @@ public class NotebookSecurityRestApiTest extends AbstractTestRestApi {
@Before
public void setUp() {}
-
@Test
public void testThatUserCanCreateAndRemoveNote() throws IOException {
@@ -81,7 +83,8 @@ public class NotebookSecurityRestApiTest extends AbstractTestRestApi {
String noteId = createNoteForUser("test", "admin", "password1");
//set permission
- String payload = "{ \"owners\": [\"admin\"], \"readers\": [\"user2\"], \"runners\": [\"user2\"], \"writers\": [\"user2\"] }";
+ String payload = "{ \"owners\": [\"admin\"], \"readers\": [\"user2\"], " +
+ "\"runners\": [\"user2\"], \"writers\": [\"user2\"] }";
PutMethod put = httpPut("/notebook/" + noteId + "/permissions", payload , "admin", "password1");
assertThat("test set note permission method:", put, isAllowed());
put.releaseConnection();
@@ -98,7 +101,8 @@ public class NotebookSecurityRestApiTest extends AbstractTestRestApi {
String noteId = createNoteForUser("test", "admin", "password1");
//set permission
- String payload = "{ \"owners\": [\"admin\", \"user1\"], \"readers\": [\"user2\"], \"runners\": [\"user2\"], \"writers\": [\"user2\"] }";
+ String payload = "{ \"owners\": [\"admin\", \"user1\"], \"readers\": [\"user2\"], " +
+ "\"runners\": [\"user2\"], \"writers\": [\"user2\"] }";
PutMethod put = httpPut("/notebook/" + noteId + "/permissions", payload , "admin", "password1");
assertThat("test set note permission method:", put, isAllowed());
put.releaseConnection();
@@ -113,10 +117,12 @@ public class NotebookSecurityRestApiTest extends AbstractTestRestApi {
@Test
public void testThatUserCanSearchNote() throws IOException {
String noteId1 = createNoteForUser("test1", "admin", "password1");
- createParagraphForUser(noteId1, "admin", "password1", "title1", "ThisIsToTestSearchMethodWithPermissions 1");
+ createParagraphForUser(noteId1, "admin", "password1", "title1",
+ "ThisIsToTestSearchMethodWithPermissions 1");
String noteId2 = createNoteForUser("test2", "user1", "password2");
- createParagraphForUser(noteId1, "admin", "password1", "title2", "ThisIsToTestSearchMethodWithPermissions 2");
+ createParagraphForUser(noteId1, "admin", "password1", "title2",
+ "ThisIsToTestSearchMethodWithPermissions 2");
//set permission for each note
setPermissionForNote(noteId1, "admin", "password1");
@@ -128,13 +134,15 @@ public class NotebookSecurityRestApiTest extends AbstractTestRestApi {
deleteNoteForUser(noteId2, "user1", "password2");
}
- private void userTryRemoveNote(String noteId, String user, String pwd, Matcher<? super HttpMethodBase> m) throws IOException {
+ private void userTryRemoveNote(String noteId, String user, String pwd,
+ Matcher<? super HttpMethodBase> m) throws IOException {
DeleteMethod delete = httpDelete(("/notebook/" + noteId), user, pwd);
assertThat(delete, m);
delete.releaseConnection();
}
- private void userTryGetNote(String noteId, String user, String pwd, Matcher<? super HttpMethodBase> m) throws IOException {
+ private void userTryGetNote(String noteId, String user, String pwd,
+ Matcher<? super HttpMethodBase> m) throws IOException {
GetMethod get = httpGet("/notebook/" + noteId, user, pwd);
assertThat(get, m);
get.releaseConnection();
@@ -143,18 +151,18 @@ public class NotebookSecurityRestApiTest extends AbstractTestRestApi {
private String getNoteIdForUser(String noteId, String user, String pwd) throws IOException {
GetMethod get = httpGet("/notebook/" + noteId, user, pwd);
assertThat("test note create method:", get, isAllowed());
- Map<String, Object> resp = gson.fromJson(get.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
- }.getType());
+ Map<String, Object> resp = gson.fromJson(get.getResponseBodyAsString(),
+ new TypeToken<Map<String, Object>>() {}.getType());
get.releaseConnection();
- return (String) ((Map<String, Object>)resp.get("body")).get("id");
+ return (String) ((Map<String, Object>) resp.get("body")).get("id");
}
private String createNoteForUser(String noteName, String user, String pwd) throws IOException {
String jsonRequest = "{\"name\":\"" + noteName + "\"}";
PostMethod post = httpPost("/notebook/", jsonRequest, user, pwd);
assertThat("test note create method:", post, isAllowed());
- Map<String, Object> resp = gson.fromJson(post.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
- }.getType());
+ Map<String, Object> resp = gson.fromJson(post.getResponseBodyAsString(),
+ new TypeToken<Map<String, Object>>() {}.getType());
post.releaseConnection();
String newNoteId = (String) resp.get("body");
Note newNote = ZeppelinServer.notebook.getNote(newNoteId);
@@ -173,24 +181,25 @@ public class NotebookSecurityRestApiTest extends AbstractTestRestApi {
}
}
- private void createParagraphForUser(String noteId, String user, String pwd, String title, String text) throws IOException {
+ private void createParagraphForUser(String noteId, String user, String pwd,
+ String title, String text) throws IOException {
String payload = "{\"title\": \"" + title + "\",\"text\": \"" + text + "\"}";
PostMethod post = httpPost(("/notebook/" + noteId + "/paragraph"), payload, user, pwd);
post.releaseConnection();
}
private void setPermissionForNote(String noteId, String user, String pwd) throws IOException {
- String payload = "{\"owners\":[\"" + user + "\"],\"readers\":[\"" + user + "\"],\"runners\":[\"" + user + "\"],\"writers\":[\"" + user + "\"]}";
+ String payload = "{\"owners\":[\"" + user + "\"],\"readers\":[\"" + user +
+ "\"],\"runners\":[\"" + user + "\"],\"writers\":[\"" + user + "\"]}";
PutMethod put = httpPut(("/notebook/" + noteId + "/permissions"), payload, user, pwd);
put.releaseConnection();
}
-
- private void searchNoteBasedOnPermission(String searchText, String user, String pwd) throws IOException{
+ private void searchNoteBasedOnPermission(String searchText, String user, String pwd)
+ throws IOException{
GetMethod searchNote = httpGet(("/notebook/search?q=" + searchText), user, pwd);
Map<String, Object> respSearchResult = gson.fromJson(searchNote.getResponseBodyAsString(),
- new TypeToken<Map<String, Object>>() {
- }.getType());
+ new TypeToken<Map<String, Object>>() {}.getType());
ArrayList searchBody = (ArrayList) respSearchResult.get("body");
assertEquals("At-least one search results is there", true, searchBody.size() >= 1);
@@ -200,8 +209,7 @@ public class NotebookSecurityRestApiTest extends AbstractTestRestApi {
GetMethod getPermission = httpGet(("/notebook/" + userId + "/permissions"), user, pwd);
Map<String, Object> resp = gson.fromJson(getPermission.getResponseBodyAsString(),
- new TypeToken<Map<String, Object>>() {
- }.getType());
+ new TypeToken<Map<String, Object>>() {}.getType());
Map<String, ArrayList> permissions = (Map<String, ArrayList>) resp.get("body");
ArrayList owners = permissions.get("owners");
ArrayList readers = permissions.get("readers");
@@ -209,8 +217,8 @@ public class NotebookSecurityRestApiTest extends AbstractTestRestApi {
ArrayList runners = permissions.get("runners");
if (owners.size() != 0 && readers.size() != 0 && writers.size() != 0 && runners.size() != 0) {
- assertEquals("User has permissions ", true, (owners.contains(user) || readers.contains(user) ||
- writers.contains(user) || runners.contains(user)));
+ assertEquals("User has permissions ", true, (owners.contains(user) ||
+ readers.contains(user) || writers.contains(user) || runners.contains(user)));
}
getPermission.releaseConnection();
}
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/1add74b4/zeppelin-server/src/test/java/org/apache/zeppelin/rest/SecurityRestApiTest.java
----------------------------------------------------------------------
diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/SecurityRestApiTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/SecurityRestApiTest.java
index 9df2e7f..a127b06 100644
--- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/SecurityRestApiTest.java
+++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/SecurityRestApiTest.java
@@ -14,12 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.zeppelin.rest;
-import java.io.IOException;
-import java.util.List;
-import java.util.Map;
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
import org.apache.commons.httpclient.methods.GetMethod;
import org.hamcrest.CoreMatchers;
@@ -29,8 +27,9 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ErrorCollector;
-import com.google.gson.Gson;
-import com.google.gson.reflect.TypeToken;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
public class SecurityRestApiTest extends AbstractTestRestApi {
Gson gson = new Gson();
@@ -86,4 +85,3 @@ public class SecurityRestApiTest extends AbstractTestRestApi {
notUser.releaseConnection();
}
}
-