http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-interpreter/src/main/java/org/apache/zeppelin/user/UsernamePassword.java ---------------------------------------------------------------------- diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/user/UsernamePassword.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/user/UsernamePassword.java index 9be8200..00116a9 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/user/UsernamePassword.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/user/UsernamePassword.java @@ -1,23 +1,25 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +* Licensed to the Apache Software Foundation (ASF) under one or more +* contributor license agreements. See the NOTICE file distributed with +* this work for additional information regarding copyright ownership. +* The ASF licenses this file to You under the Apache License, Version 2.0 +* (the "License"); you may not use this file except in compliance with +* the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ package org.apache.zeppelin.user; -/** Username and Password POJO */ +/** + * Username and Password POJO + */ public class UsernamePassword { private String username; private String password; @@ -45,13 +47,9 @@ public class UsernamePassword { @Override public String toString() { - return "UsernamePassword{" - + "username='" - + username - + '\'' - + ", password='" - + password - + '\'' - + '}'; + return "UsernamePassword{" + + "username='" + username + '\'' + + ", password='" + password + '\'' + + '}'; } }
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-interpreter/src/main/java/org/apache/zeppelin/util/IdHashes.java ---------------------------------------------------------------------- diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/util/IdHashes.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/util/IdHashes.java index 9a34380..9d4e10f 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/util/IdHashes.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/util/IdHashes.java @@ -18,17 +18,17 @@ package org.apache.zeppelin.util; import java.math.BigInteger; -import java.security.SecureRandom; import java.util.ArrayList; import java.util.List; +import java.security.SecureRandom; -/** Generate Tiny ID. */ +/** + * Generate Tiny ID. + */ public class IdHashes { - private static final char[] DICTIONARY = - new char[] { - '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', - 'K', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' - }; + private static final char[] DICTIONARY = new char[] {'1', '2', '3', '4', '5', '6', '7', '8', '9', + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', + 'W', 'X', 'Y', 'Z'}; /** * encodes the given string into the base of the dictionary provided in the constructor. http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-interpreter/src/main/java/org/apache/zeppelin/util/Util.java ---------------------------------------------------------------------- diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/util/Util.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/util/Util.java index 2e189d5..6153f49 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/util/Util.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/util/Util.java @@ -17,11 +17,14 @@ package org.apache.zeppelin.util; +import org.apache.commons.lang.StringUtils; + import java.io.IOException; import java.util.Properties; -import org.apache.commons.lang.StringUtils; -/** TODO(moon) : add description. */ +/** + * TODO(moon) : add description. + */ public class Util { private static final String PROJECT_PROPERTIES_VERSION_KEY = "version"; private static final String GIT_PROPERTIES_COMMIT_ID_KEY = "git.commit.id.abbrev"; @@ -37,7 +40,7 @@ public class Util { projectProperties.load(Util.class.getResourceAsStream("/project.properties")); gitProperties.load(Util.class.getResourceAsStream("/git.properties")); } catch (IOException e) { - // Fail to read project.properties + //Fail to read project.properties } } @@ -47,8 +50,8 @@ public class Util { * @return Current Zeppelin version */ public static String getVersion() { - return StringUtils.defaultIfEmpty( - projectProperties.getProperty(PROJECT_PROPERTIES_VERSION_KEY), StringUtils.EMPTY); + return StringUtils.defaultIfEmpty(projectProperties.getProperty(PROJECT_PROPERTIES_VERSION_KEY), + StringUtils.EMPTY); } /** @@ -57,8 +60,8 @@ public class Util { * @return Latest Zeppelin commit id */ public static String getGitCommitId() { - return StringUtils.defaultIfEmpty( - gitProperties.getProperty(GIT_PROPERTIES_COMMIT_ID_KEY), StringUtils.EMPTY); + return StringUtils.defaultIfEmpty(gitProperties.getProperty(GIT_PROPERTIES_COMMIT_ID_KEY), + StringUtils.EMPTY); } /** @@ -67,7 +70,7 @@ public class Util { * @return Latest Zeppelin commit timestamp */ public static String getGitTimestamp() { - return StringUtils.defaultIfEmpty( - gitProperties.getProperty(GIT_PROPERTIES_COMMIT_TS_KEY), StringUtils.EMPTY); + return StringUtils.defaultIfEmpty(gitProperties.getProperty(GIT_PROPERTIES_COMMIT_TS_KEY), + StringUtils.EMPTY); } } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-interpreter/src/test/java/org/apache/zeppelin/dep/BooterTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/dep/BooterTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/dep/BooterTest.java index 8d74d4c..ffc3c8f 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/dep/BooterTest.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/dep/BooterTest.java @@ -17,13 +17,14 @@ package org.apache.zeppelin.dep; +import org.junit.Test; + +import java.nio.file.Paths; + import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -import java.nio.file.Paths; -import org.junit.Test; - public class BooterTest { @Test @@ -34,7 +35,8 @@ public class BooterTest { @Test public void should_not_change_absolute_path() { - String absolutePath = Paths.get("first", "second").toAbsolutePath().toString(); + String absolutePath + = Paths.get("first", "second").toAbsolutePath().toString(); String resolvedPath = Booter.resolveLocalRepoPath(absolutePath); assertThat(resolvedPath, equalTo(absolutePath)); http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-interpreter/src/test/java/org/apache/zeppelin/dep/DependencyResolverTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/dep/DependencyResolverTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/dep/DependencyResolverTest.java index 80ce490..7ccc7df 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/dep/DependencyResolverTest.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/dep/DependencyResolverTest.java @@ -17,11 +17,6 @@ package org.apache.zeppelin.dep; -import static org.junit.Assert.assertEquals; - -import java.io.File; -import java.io.FileNotFoundException; -import java.util.Collections; import org.apache.commons.io.FileUtils; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -30,19 +25,25 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonatype.aether.RepositoryException; +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Collections; + +import static org.junit.Assert.assertEquals; + public class DependencyResolverTest { private static DependencyResolver resolver; private static String testPath; private static File testCopyPath; private static File tmpDir; - @Rule public ExpectedException expectedException = ExpectedException.none(); + @Rule + public ExpectedException expectedException = ExpectedException.none(); @BeforeClass public static void setUp() throws Exception { - tmpDir = - new File( - System.getProperty("java.io.tmpdir") + "/ZeppelinLTest_" + System.currentTimeMillis()); + tmpDir = new File(System.getProperty("java.io.tmpdir") + "/ZeppelinLTest_" + + System.currentTimeMillis()); testPath = tmpDir.getAbsolutePath() + "/test-repo"; testCopyPath = new File(tmpDir, "test-copy-repo"); resolver = new DependencyResolver(testPath); @@ -53,7 +54,8 @@ public class DependencyResolverTest { FileUtils.deleteDirectory(tmpDir); } - @Rule public final ExpectedException exception = ExpectedException.none(); + @Rule + public final ExpectedException exception = ExpectedException.none(); @Test public void testAddRepo() { @@ -78,16 +80,14 @@ public class DependencyResolverTest { FileUtils.cleanDirectory(testCopyPath); // load with exclusions parameter - resolver.load( - "com.databricks:spark-csv_2.10:1.3.0", - Collections.singletonList("org.scala-lang:scala-library"), - testCopyPath); + resolver.load("com.databricks:spark-csv_2.10:1.3.0", + Collections.singletonList("org.scala-lang:scala-library"), testCopyPath); assertEquals(testCopyPath.list().length, 3); FileUtils.cleanDirectory(testCopyPath); // load from added repository - resolver.addRepo( - "sonatype", "https://oss.sonatype.org/content/repositories/agimatec-releases/", false); + resolver.addRepo("sonatype", + "https://oss.sonatype.org/content/repositories/agimatec-releases/", false); resolver.load("com.agimatec:agimatec-validation:0.9.3", testCopyPath); assertEquals(testCopyPath.list().length, 8); @@ -104,4 +104,5 @@ public class DependencyResolverTest { resolver.load("one.two:1.0", testCopyPath); } + } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-interpreter/src/test/java/org/apache/zeppelin/display/AngularObjectRegistryTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/display/AngularObjectRegistryTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/display/AngularObjectRegistryTest.java index 5b2f6ae..529284f 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/display/AngularObjectRegistryTest.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/display/AngularObjectRegistryTest.java @@ -17,13 +17,14 @@ package org.apache.zeppelin.display; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import java.util.concurrent.atomic.AtomicInteger; import org.apache.thrift.TException; import org.junit.Test; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + public class AngularObjectRegistryTest { @Test @@ -32,27 +33,27 @@ public class AngularObjectRegistryTest { final AtomicInteger onUpdate = new AtomicInteger(0); final AtomicInteger onRemove = new AtomicInteger(0); - AngularObjectRegistry registry = - new AngularObjectRegistry( - "intpId", - new AngularObjectRegistryListener() { + AngularObjectRegistry registry = new AngularObjectRegistry("intpId", + new AngularObjectRegistryListener() { - @Override - public void onAdd(String interpreterGroupId, AngularObject object) { - onAdd.incrementAndGet(); - } + @Override + public void onAdd(String interpreterGroupId, AngularObject object) { + onAdd.incrementAndGet(); + } - @Override - public void onUpdate(String interpreterGroupId, AngularObject object) { - onUpdate.incrementAndGet(); - } + @Override + public void onUpdate(String interpreterGroupId, AngularObject object) { + onUpdate.incrementAndGet(); + } - @Override - public void onRemove( - String interpreterGroupId, String name, String noteId, String paragraphId) { - onRemove.incrementAndGet(); - } - }); + @Override + public void onRemove(String interpreterGroupId, + String name, + String noteId, + String paragraphId) { + onRemove.incrementAndGet(); + } + }); registry.add("name1", "value1", "note1", null); assertEquals(1, registry.getAll("note1", null).size()); @@ -87,6 +88,7 @@ public class AngularObjectRegistryTest { AngularObject ao4 = registry.add("name3", "o4", "noteId1", null); AngularObject ao5 = registry.add("name4", "o5", null, null); + assertNull(registry.get("name3", "noteId1", "paragraphId1")); assertNull(registry.get("name1", "noteId2", null)); assertEquals("o1", registry.get("name1", "noteId1", "paragraphId1").get()); @@ -111,4 +113,5 @@ public class AngularObjectRegistryTest { assertEquals(1, registry.getAll(null, null).size()); assertEquals(5, registry.getAllWithGlobal("noteId1").size()); } + } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-interpreter/src/test/java/org/apache/zeppelin/display/AngularObjectTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/display/AngularObjectTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/display/AngularObjectTest.java index 80acea8..b30439a 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/display/AngularObjectTest.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/display/AngularObjectTest.java @@ -17,71 +17,78 @@ package org.apache.zeppelin.display; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; - -import java.util.concurrent.atomic.AtomicInteger; import org.apache.thrift.TException; import org.apache.zeppelin.interpreter.InterpreterContext; import org.junit.Test; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotSame; + public class AngularObjectTest { @Test public void testEquals() { assertEquals( new AngularObject("name", "value", "note1", null, null), - new AngularObject("name", "value", "note1", null, null)); + new AngularObject("name", "value", "note1", null, null) + ); assertEquals( new AngularObject("name", "value", "note1", "paragraph1", null), - new AngularObject("name", "value", "note1", "paragraph1", null)); + new AngularObject("name", "value", "note1", "paragraph1", null) + ); assertEquals( new AngularObject("name", "value", null, null, null), - new AngularObject("name", "value", null, null, null)); + new AngularObject("name", "value", null, null, null) + ); assertEquals( new AngularObject("name", "value1", null, null, null), - new AngularObject("name", "value2", null, null, null)); + new AngularObject("name", "value2", null, null, null) + ); assertNotSame( new AngularObject("name1", "value", null, null, null), - new AngularObject("name2", "value", null, null, null)); + new AngularObject("name2", "value", null, null, null) + ); assertNotSame( new AngularObject("name1", "value", "note1", null, null), - new AngularObject("name2", "value", "note2", null, null)); + new AngularObject("name2", "value", "note2", null, null) + ); assertNotSame( new AngularObject("name1", "value", "note", null, null), - new AngularObject("name2", "value", null, null, null)); + new AngularObject("name2", "value", null, null, null) + ); assertNotSame( new AngularObject("name", "value", "note", "paragraph1", null), - new AngularObject("name", "value", "note", "paragraph2", null)); + new AngularObject("name", "value", "note", "paragraph2", null) + ); assertNotSame( new AngularObject("name", "value", "note1", null, null), - new AngularObject("name", "value", "note1", "paragraph1", null)); + new AngularObject("name", "value", "note1", "paragraph1", null) + ); + + } @Test public void testListener() throws TException { final AtomicInteger updated = new AtomicInteger(0); - AngularObject ao = - new AngularObject( - "name", - "value", - "note1", - null, - new AngularObjectListener() { - - @Override - public void updated(AngularObject updatedObject) { - updated.incrementAndGet(); - } - }); + AngularObject ao = new AngularObject("name", "value", "note1", null, + new AngularObjectListener() { + + @Override + public void updated(AngularObject updatedObject) { + updated.incrementAndGet(); + } + }); assertEquals(0, updated.get()); ao.set("newValue"); @@ -100,27 +107,21 @@ public class AngularObjectTest { public void testWatcher() throws InterruptedException, TException { final AtomicInteger updated = new AtomicInteger(0); final AtomicInteger onWatch = new AtomicInteger(0); - AngularObject ao = - new AngularObject( - "name", - "value", - "note1", - null, - new AngularObjectListener() { - @Override - public void updated(AngularObject updatedObject) { - updated.incrementAndGet(); - } - }); - - ao.addWatcher( - new AngularObjectWatcher(null) { + AngularObject ao = new AngularObject("name", "value", "note1", null, + new AngularObjectListener() { @Override - public void watch(Object oldObject, Object newObject, InterpreterContext context) { - onWatch.incrementAndGet(); + public void updated(AngularObject updatedObject) { + updated.incrementAndGet(); } }); + ao.addWatcher(new AngularObjectWatcher(null) { + @Override + public void watch(Object oldObject, Object newObject, InterpreterContext context) { + onWatch.incrementAndGet(); + } + }); + assertEquals(0, onWatch.get()); ao.set("newValue"); http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-interpreter/src/test/java/org/apache/zeppelin/display/GUITest.java ---------------------------------------------------------------------- diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/display/GUITest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/display/GUITest.java index 3ab50a9..211c379 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/display/GUITest.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/display/GUITest.java @@ -17,12 +17,6 @@ package org.apache.zeppelin.display; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; import org.apache.zeppelin.display.ui.CheckBox; import org.apache.zeppelin.display.ui.OptionInput.ParamOption; import org.apache.zeppelin.display.ui.Select; @@ -30,10 +24,19 @@ import org.apache.zeppelin.display.ui.TextBox; import org.junit.Before; import org.junit.Test; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + public class GUITest { - private ParamOption[] options = - new ParamOption[] {new ParamOption("1", "value_1"), new ParamOption("2", "value_2")}; + private ParamOption[] options = new ParamOption[]{ + new ParamOption("1", "value_1"), + new ParamOption("2", "value_2") + }; private List<Object> checkedItems; @@ -83,7 +86,8 @@ public class GUITest { GUI gui = new GUI(); gui.forms.put("textbox_1", new OldInput.OldTextBox("textbox_1", "default_text_1")); gui.forms.put("select_1", new OldInput.OldSelect("select_1", "1", options)); - gui.forms.put("checkbox_1", new OldInput.OldCheckBox("checkbox_1", checkedItems, options)); + gui.forms.put("checkbox_1", + new OldInput.OldCheckBox("checkbox_1", checkedItems, options)); // convert to old json format. String json = gui.toJson(); @@ -107,7 +111,8 @@ public class GUITest { GUI gui = new GUI(); gui.forms.put("textbox_1", new OldInput("textbox_1", "default_text_1")); gui.forms.put("select_1", new OldInput("select_1", "1", options)); - gui.forms.put("checkbox_1", new OldInput.OldCheckBox("checkbox_1", checkedItems, options)); + gui.forms.put("checkbox_1", + new OldInput.OldCheckBox("checkbox_1", checkedItems, options)); // convert to old json format. String json = gui.toJson(); @@ -126,48 +131,46 @@ public class GUITest { // load old json file and will convert it into new forms of Input @Test public void testOldGson_3() throws IOException { - String oldJson = - "{\n" - + " \"params\": {\n" - + " \"maxAge\": \"35\"\n" - + " },\n" - + " \"forms\": {\n" - + " \"maxAge\": {\n" - + " \"name\": \"maxAge\",\n" - + " \"defaultValue\": \"30\",\n" - + " \"hidden\": false\n" - + " }\n" - + " }\n" - + " }"; + String oldJson = "{\n" + + " \"params\": {\n" + + " \"maxAge\": \"35\"\n" + + " },\n" + + " \"forms\": {\n" + + " \"maxAge\": {\n" + + " \"name\": \"maxAge\",\n" + + " \"defaultValue\": \"30\",\n" + + " \"hidden\": false\n" + + " }\n" + + " }\n" + + " }"; GUI gui = GUI.fromJson(oldJson); assertEquals(1, gui.forms.size()); assertTrue(gui.forms.get("maxAge") instanceof TextBox); assertEquals("30", gui.forms.get("maxAge").getDefaultValue()); - oldJson = - "{\n" - + " \"params\": {\n" - + " \"marital\": \"single\"\n" - + " },\n" - + " \"forms\": {\n" - + " \"marital\": {\n" - + " \"name\": \"marital\",\n" - + " \"defaultValue\": \"single\",\n" - + " \"options\": [\n" - + " {\n" - + " \"value\": \"single\"\n" - + " },\n" - + " {\n" - + " \"value\": \"divorced\"\n" - + " },\n" - + " {\n" - + " \"value\": \"married\"\n" - + " }\n" - + " ],\n" - + " \"hidden\": false\n" - + " }\n" - + " }\n" - + " }"; + oldJson = "{\n" + + " \"params\": {\n" + + " \"marital\": \"single\"\n" + + " },\n" + + " \"forms\": {\n" + + " \"marital\": {\n" + + " \"name\": \"marital\",\n" + + " \"defaultValue\": \"single\",\n" + + " \"options\": [\n" + + " {\n" + + " \"value\": \"single\"\n" + + " },\n" + + " {\n" + + " \"value\": \"divorced\"\n" + + " },\n" + + " {\n" + + " \"value\": \"married\"\n" + + " }\n" + + " ],\n" + + " \"hidden\": false\n" + + " }\n" + + " }\n" + + " }"; gui = GUI.fromJson(oldJson); assertEquals(1, gui.forms.size()); assertTrue(gui.forms.get("marital") instanceof Select); http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-interpreter/src/test/java/org/apache/zeppelin/display/InputTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/display/InputTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/display/InputTest.java index 789ec49..abe2ac3 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/display/InputTest.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/display/InputTest.java @@ -17,13 +17,6 @@ package org.apache.zeppelin.display; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.util.HashMap; -import java.util.Map; import org.apache.zeppelin.display.ui.CheckBox; import org.apache.zeppelin.display.ui.OptionInput.ParamOption; import org.apache.zeppelin.display.ui.Password; @@ -31,6 +24,14 @@ import org.apache.zeppelin.display.ui.Select; import org.apache.zeppelin.display.ui.TextBox; import org.junit.Test; +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + public class InputTest { @Test @@ -67,12 +68,10 @@ public class InputTest { assertEquals("op1", form.defaultValue); assertEquals("Selection Form", form.getDisplayName()); assertTrue(form instanceof Select); - assertArrayEquals( - new ParamOption[] { - new ParamOption("op1", null), - new ParamOption("op2", "Option 2"), - new ParamOption("op3", null) - }, + assertArrayEquals(new ParamOption[]{ + new ParamOption("op1", null), + new ParamOption("op2", "Option 2"), + new ParamOption("op3", null)}, ((Select) form).getOptions()); // checkbox form @@ -81,11 +80,11 @@ public class InputTest { assertEquals("checkbox_form", form.name); assertTrue(form instanceof CheckBox); - assertArrayEquals(new Object[] {"op1"}, (Object[]) form.defaultValue); - assertArrayEquals( - new ParamOption[] { - new ParamOption("op1", null), new ParamOption("op2", null), new ParamOption("op3", null) - }, + assertArrayEquals(new Object[]{"op1"}, (Object[]) form.defaultValue); + assertArrayEquals(new ParamOption[]{ + new ParamOption("op1", null), + new ParamOption("op2", null), + new ParamOption("op3", null)}, ((CheckBox) form).getOptions()); // checkbox form with multiple default checks @@ -94,13 +93,11 @@ public class InputTest { assertEquals("checkbox_form", form.name); assertEquals("Checkbox Form", form.displayName); assertTrue(form instanceof CheckBox); - assertArrayEquals(new Object[] {"op1", "op3"}, (Object[]) form.defaultValue); - assertArrayEquals( - new ParamOption[] { - new ParamOption("op1", "Option 1"), - new ParamOption("op2", null), - new ParamOption("op3", null) - }, + assertArrayEquals(new Object[]{"op1", "op3"}, (Object[]) form.defaultValue); + assertArrayEquals(new ParamOption[]{ + new ParamOption("op1", "Option 1"), + new ParamOption("op2", null), + new ParamOption("op3", null)}, ((CheckBox) form).getOptions()); // checkbox form with no default check @@ -109,46 +106,42 @@ public class InputTest { assertEquals("checkbox_form", form.name); assertEquals("Checkbox Form", form.displayName); assertTrue(form instanceof CheckBox); - assertArrayEquals(new Object[] {}, (Object[]) form.defaultValue); - assertArrayEquals( - new ParamOption[] { - new ParamOption("op1", "Option 1"), - new ParamOption("op2", "Option 2"), - new ParamOption("op3", "Option 3") - }, + assertArrayEquals(new Object[]{}, (Object[]) form.defaultValue); + assertArrayEquals(new ParamOption[]{ + new ParamOption("op1", "Option 1"), + new ParamOption("op2", "Option 2"), + new ParamOption("op3", "Option 3")}, ((CheckBox) form).getOptions()); } + @Test public void testFormSubstitution() { // test form substitution without new forms - String script = - "INPUT=${input_form=}SELECTED=${select_form(Selection Form)=" - + ",s_op1|s_op2|s_op3}\nCHECKED=${checkbox:checkbox_form=c_op1|c_op2,c_op1|c_op2|c_op3}"; + String script = "INPUT=${input_form=}SELECTED=${select_form(Selection Form)=" + + ",s_op1|s_op2|s_op3}\nCHECKED=${checkbox:checkbox_form=c_op1|c_op2,c_op1|c_op2|c_op3}"; Map<String, Object> params = new HashMap<>(); params.put("input_form", "some_input"); params.put("select_form", "s_op2"); - params.put("checkbox_form", new String[] {"c_op1", "c_op3"}); + params.put("checkbox_form", new String[]{"c_op1", "c_op3"}); String replaced = Input.getSimpleQuery(params, script, false); assertEquals("INPUT=some_inputSELECTED=s_op2\nCHECKED=c_op1,c_op3", replaced); // test form substitution with new forms - script = - "INPUT=${input_form=}SELECTED=${select_form(Selection Form)=,s_op1|s_op2|s_op3}\n" - + "CHECKED=${checkbox:checkbox_form=c_op1|c_op2,c_op1|c_op2|c_op3}\n" - + "NEW_CHECKED=${checkbox( and ):new_check=nc_a|nc_c,nc_a|nc_b|nc_c}"; + script = "INPUT=${input_form=}SELECTED=${select_form(Selection Form)=,s_op1|s_op2|s_op3}\n" + + "CHECKED=${checkbox:checkbox_form=c_op1|c_op2,c_op1|c_op2|c_op3}\n" + + "NEW_CHECKED=${checkbox( and ):new_check=nc_a|nc_c,nc_a|nc_b|nc_c}"; replaced = Input.getSimpleQuery(params, script, false); - assertEquals( - "INPUT=some_inputSELECTED=s_op2\nCHECKED=c_op1,c_op3\n" + "NEW_CHECKED=nc_a and nc_c", - replaced); + assertEquals("INPUT=some_inputSELECTED=s_op2\nCHECKED=c_op1,c_op3\n" + + "NEW_CHECKED=nc_a and nc_c", replaced); // test form substitution with obsoleted values - script = - "INPUT=${input_form=}SELECTED=${select_form(Selection Form)=,s_op1|s_op2|s_op3}\n" - + "CHECKED=${checkbox:checkbox_form=c_op1|c_op2,c_op1|c_op2|c_op3_new}\n" - + "NEW_CHECKED=${checkbox( and ):new_check=nc_a|nc_c,nc_a|nc_b|nc_c}"; + script = "INPUT=${input_form=}SELECTED=${select_form(Selection Form)=,s_op1|s_op2|s_op3}\n" + + "CHECKED=${checkbox:checkbox_form=c_op1|c_op2,c_op1|c_op2|c_op3_new}\n" + + "NEW_CHECKED=${checkbox( and ):new_check=nc_a|nc_c,nc_a|nc_b|nc_c}"; replaced = Input.getSimpleQuery(params, script, false); - assertEquals( - "INPUT=some_inputSELECTED=s_op2\nCHECKED=c_op1\n" + "NEW_CHECKED=nc_a and nc_c", replaced); + assertEquals("INPUT=some_inputSELECTED=s_op2\nCHECKED=c_op1\n" + + "NEW_CHECKED=nc_a and nc_c", replaced); } + } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-interpreter/src/test/java/org/apache/zeppelin/helium/ApplicationLoaderTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/helium/ApplicationLoaderTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/helium/ApplicationLoaderTest.java index 05896f4..490c911 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/helium/ApplicationLoaderTest.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/helium/ApplicationLoaderTest.java @@ -17,12 +17,6 @@ package org.apache.zeppelin.helium; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.io.File; -import java.io.IOException; import org.apache.commons.io.FileUtils; import org.apache.zeppelin.dep.DependencyResolver; import org.apache.zeppelin.interpreter.InterpreterOutput; @@ -31,14 +25,20 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import java.io.File; +import java.io.IOException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + public class ApplicationLoaderTest { private File tmpDir; @Before public void setUp() { - tmpDir = - new File( - System.getProperty("java.io.tmpdir") + "/ZeppelinLTest_" + System.currentTimeMillis()); + tmpDir = new File(System.getProperty("java.io.tmpdir") + "/ZeppelinLTest_" + + System.currentTimeMillis()); tmpDir.mkdirs(); } @@ -58,9 +58,8 @@ public class ApplicationLoaderTest { ApplicationContext context1 = createContext("note1", "paragraph1", "app1"); // when load application - MockApplication1 app = - (MockApplication1) - ((ClassLoaderApplication) appLoader.load(pkg1, context1)).getInnerApplication(); + MockApplication1 app = (MockApplication1) ((ClassLoaderApplication) + appLoader.load(pkg1, context1)).getInnerApplication(); // then assertFalse(app.isUnloaded()); @@ -75,23 +74,25 @@ public class ApplicationLoaderTest { } public HeliumPackage createPackageInfo(String className, String artifact) { - HeliumPackage app1 = - new HeliumPackage( - HeliumType.APPLICATION, - "name1", - "desc1", - artifact, - className, - new String[][] {{}}, - "license", - "icon"); + HeliumPackage app1 = new HeliumPackage( + HeliumType.APPLICATION, + "name1", + "desc1", + artifact, + className, + new String[][]{{}}, + "license", + "icon"); return app1; } public ApplicationContext createContext(String noteId, String paragraphId, String appInstanceId) { - ApplicationContext context1 = - new ApplicationContext( - noteId, paragraphId, appInstanceId, null, new InterpreterOutput(null)); + ApplicationContext context1 = new ApplicationContext( + noteId, + paragraphId, + appInstanceId, + null, + new InterpreterOutput(null)); return context1; } } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-interpreter/src/test/java/org/apache/zeppelin/helium/HeliumPackageTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/helium/HeliumPackageTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/helium/HeliumPackageTest.java index 73fad6e..e810742 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/helium/HeliumPackageTest.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/helium/HeliumPackageTest.java @@ -17,28 +17,28 @@ package org.apache.zeppelin.helium; -import static org.junit.Assert.assertEquals; +import org.junit.Test; import java.util.Map; -import org.junit.Test; + +import static org.junit.Assert.assertEquals; public class HeliumPackageTest { @Test public void parseSpellPackageInfo() { - String examplePackage = - "{\n" - + " \"type\" : \"SPELL\",\n" - + " \"name\" : \"echo-spell\",\n" - + " \"description\" : \"'%echo' - return just what receive (example)\",\n" - + " \"artifact\" : \"./zeppelin-examples/zeppelin-example-spell-echo\",\n" - + " \"license\" : \"Apache-2.0\",\n" - + " \"icon\" : \"<i class='fa fa-repeat'></i>\",\n" - + " \"spell\": {\n" - + " \"magic\": \"%echo\",\n" - + " \"usage\": \"%echo <TEXT>\"\n" - + " }\n" - + "}"; + String examplePackage = "{\n" + + " \"type\" : \"SPELL\",\n" + + " \"name\" : \"echo-spell\",\n" + + " \"description\" : \"'%echo' - return just what receive (example)\",\n" + + " \"artifact\" : \"./zeppelin-examples/zeppelin-example-spell-echo\",\n" + + " \"license\" : \"Apache-2.0\",\n" + + " \"icon\" : \"<i class='fa fa-repeat'></i>\",\n" + + " \"spell\": {\n" + + " \"magic\": \"%echo\",\n" + + " \"usage\": \"%echo <TEXT>\"\n" + + " }\n" + + "}"; HeliumPackage p = HeliumPackage.fromJson(examplePackage); assertEquals(p.getSpellInfo().getMagic(), "%echo"); @@ -47,34 +47,34 @@ public class HeliumPackageTest { @Test public void parseConfig() { - String examplePackage = - "{\n" - + " \"type\" : \"SPELL\",\n" - + " \"name\" : \"translator-spell\",\n" - + " \"description\" : \"Translate langauges using Google API (examaple)\",\n" - + " \"artifact\" : \"./zeppelin-examples/zeppelin-example-spell-translator\",\n" - + " \"license\" : \"Apache-2.0\",\n" - + " \"icon\" : \"<i class='fa fa-globe '></i>\",\n" - + " \"config\": {\n" - + " \"access-token\": {\n" - + " \"type\": \"string\",\n" - + " \"description\": \"access token for Google Translation API\",\n" - + " \"defaultValue\": \"EXAMPLE-TOKEN\"\n" - + " }\n" - + " },\n" - + " \"spell\": {\n" - + " \"magic\": \"%translator\",\n" - + " \"usage\": \"%translator <source>-<target> <access-key> <TEXT>\"\n" - + " }\n" - + "}"; + String examplePackage = "{\n" + + " \"type\" : \"SPELL\",\n" + + " \"name\" : \"translator-spell\",\n" + + " \"description\" : \"Translate langauges using Google API (examaple)\",\n" + + " \"artifact\" : \"./zeppelin-examples/zeppelin-example-spell-translator\",\n" + + " \"license\" : \"Apache-2.0\",\n" + + " \"icon\" : \"<i class='fa fa-globe '></i>\",\n" + + " \"config\": {\n" + + " \"access-token\": {\n" + + " \"type\": \"string\",\n" + + " \"description\": \"access token for Google Translation API\",\n" + + " \"defaultValue\": \"EXAMPLE-TOKEN\"\n" + + " }\n" + + " },\n" + + " \"spell\": {\n" + + " \"magic\": \"%translator\",\n" + + " \"usage\": \"%translator <source>-<target> <access-key> <TEXT>\"\n" + + " }\n" + + "}"; HeliumPackage p = HeliumPackage.fromJson(examplePackage); Map<String, Object> config = p.getConfig(); Map<String, Object> accessToken = (Map<String, Object>) config.get("access-token"); assertEquals((String) accessToken.get("type"), "string"); - assertEquals( - (String) accessToken.get("description"), "access token for Google Translation API"); - assertEquals((String) accessToken.get("defaultValue"), "EXAMPLE-TOKEN"); + assertEquals((String) accessToken.get("description"), + "access token for Google Translation API"); + assertEquals((String) accessToken.get("defaultValue"), + "EXAMPLE-TOKEN"); } } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-interpreter/src/test/java/org/apache/zeppelin/helium/MockApplication1.java ---------------------------------------------------------------------- diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/helium/MockApplication1.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/helium/MockApplication1.java index a581f1e..c962d84 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/helium/MockApplication1.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/helium/MockApplication1.java @@ -18,7 +18,9 @@ package org.apache.zeppelin.helium; import org.apache.zeppelin.resource.ResourceSet; -/** Mock application */ +/** + * Mock application + */ public class MockApplication1 extends Application { boolean unloaded; int run; http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/BaseZeppelinContextTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/BaseZeppelinContextTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/BaseZeppelinContextTest.java index a227adf..985ba4f 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/BaseZeppelinContextTest.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/BaseZeppelinContextTest.java @@ -17,12 +17,14 @@ package org.apache.zeppelin.interpreter; -import static org.junit.Assert.assertEquals; +import org.junit.Test; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.junit.Test; + +import static org.junit.Assert.assertEquals; + public class BaseZeppelinContextTest { @@ -30,118 +32,87 @@ public class BaseZeppelinContextTest { public void testHooks() throws InvalidHookException { InterpreterHookRegistry hookRegistry = new InterpreterHookRegistry(); TestZeppelinContext z = new TestZeppelinContext(hookRegistry, 10); - InterpreterContext context = - InterpreterContext.builder() - .setNoteId("note_1") - .setNoteName("note_name_1") - .setParagraphId("paragraph_1") - .setInterpreterClassName("Test1Interpreter") - .setReplName("test1") - .build(); + InterpreterContext context = InterpreterContext.builder() + .setNoteId("note_1") + .setNoteName("note_name_1") + .setParagraphId("paragraph_1") + .setInterpreterClassName("Test1Interpreter") + .setReplName("test1") + .build(); z.setInterpreterContext(context); // get note name via InterpreterContext String note_name = z.getInterpreterContext().getNoteName(); assertEquals( - String.format("Actual note name: %s, but expected %s", note_name, "note_name_1"), - "note_name_1", - note_name); + String.format("Actual note name: %s, but expected %s", note_name, "note_name_1"), + "note_name_1", + note_name + ); // register global hook for current interpreter z.registerHook(InterpreterHookRegistry.HookType.PRE_EXEC.getName(), "pre_cmd"); z.registerHook(InterpreterHookRegistry.HookType.POST_EXEC.getName(), "post_cmd"); - assertEquals( - "pre_cmd", - hookRegistry.get( - null, "Test1Interpreter", InterpreterHookRegistry.HookType.PRE_EXEC.getName())); - assertEquals( - "post_cmd", - hookRegistry.get( - null, "Test1Interpreter", InterpreterHookRegistry.HookType.POST_EXEC.getName())); + assertEquals("pre_cmd", hookRegistry.get(null, "Test1Interpreter", + InterpreterHookRegistry.HookType.PRE_EXEC.getName())); + assertEquals("post_cmd", hookRegistry.get(null, "Test1Interpreter", + InterpreterHookRegistry.HookType.POST_EXEC.getName())); z.unregisterHook(InterpreterHookRegistry.HookType.PRE_EXEC.getName()); z.unregisterHook(InterpreterHookRegistry.HookType.POST_EXEC.getName()); - assertEquals( - null, - hookRegistry.get( - null, "Test1Interpreter", InterpreterHookRegistry.HookType.PRE_EXEC.getName())); - assertEquals( - null, - hookRegistry.get( - null, "Test1Interpreter", InterpreterHookRegistry.HookType.POST_EXEC.getName())); + assertEquals(null, hookRegistry.get(null, "Test1Interpreter", + InterpreterHookRegistry.HookType.PRE_EXEC.getName())); + assertEquals(null, hookRegistry.get(null, "Test1Interpreter", + InterpreterHookRegistry.HookType.POST_EXEC.getName())); // register global hook for interpreter test2 z.registerHook(InterpreterHookRegistry.HookType.PRE_EXEC.getName(), "pre_cmd2", "test2"); z.registerHook(InterpreterHookRegistry.HookType.POST_EXEC.getName(), "post_cmd2", "test2"); - assertEquals( - "pre_cmd2", - hookRegistry.get( - null, "Test2Interpreter", InterpreterHookRegistry.HookType.PRE_EXEC.getName())); - assertEquals( - "post_cmd2", - hookRegistry.get( - null, "Test2Interpreter", InterpreterHookRegistry.HookType.POST_EXEC.getName())); + assertEquals("pre_cmd2", hookRegistry.get(null, "Test2Interpreter", + InterpreterHookRegistry.HookType.PRE_EXEC.getName())); + assertEquals("post_cmd2", hookRegistry.get(null, "Test2Interpreter", + InterpreterHookRegistry.HookType.POST_EXEC.getName())); z.unregisterHook(InterpreterHookRegistry.HookType.PRE_EXEC.getName(), "test2"); z.unregisterHook(InterpreterHookRegistry.HookType.POST_EXEC.getName(), "test2"); - assertEquals( - null, - hookRegistry.get( - null, "Test2Interpreter", InterpreterHookRegistry.HookType.PRE_EXEC.getName())); - assertEquals( - null, - hookRegistry.get( - null, "Test2Interpreter", InterpreterHookRegistry.HookType.POST_EXEC.getName())); + assertEquals(null, hookRegistry.get(null, "Test2Interpreter", + InterpreterHookRegistry.HookType.PRE_EXEC.getName())); + assertEquals(null, hookRegistry.get(null, "Test2Interpreter", + InterpreterHookRegistry.HookType.POST_EXEC.getName())); // register hook for note_1 and current interpreter z.registerNoteHook(InterpreterHookRegistry.HookType.PRE_EXEC.getName(), "pre_cmd", "note_1"); z.registerNoteHook(InterpreterHookRegistry.HookType.POST_EXEC.getName(), "post_cmd", "note_1"); - assertEquals( - "pre_cmd", - hookRegistry.get( - "note_1", "Test1Interpreter", InterpreterHookRegistry.HookType.PRE_EXEC.getName())); - assertEquals( - "post_cmd", - hookRegistry.get( - "note_1", "Test1Interpreter", InterpreterHookRegistry.HookType.POST_EXEC.getName())); + assertEquals("pre_cmd", hookRegistry.get("note_1", "Test1Interpreter", + InterpreterHookRegistry.HookType.PRE_EXEC.getName())); + assertEquals("post_cmd", hookRegistry.get("note_1", "Test1Interpreter", + InterpreterHookRegistry.HookType.POST_EXEC.getName())); z.unregisterNoteHook("note_1", InterpreterHookRegistry.HookType.PRE_EXEC.getName(), "test1"); z.unregisterNoteHook("note_1", InterpreterHookRegistry.HookType.POST_EXEC.getName(), "test1"); - assertEquals( - null, - hookRegistry.get( - "note_1", "Test1Interpreter", InterpreterHookRegistry.HookType.PRE_EXEC.getName())); - assertEquals( - null, - hookRegistry.get( - "note_1", "Test1Interpreter", InterpreterHookRegistry.HookType.POST_EXEC.getName())); + assertEquals(null, hookRegistry.get("note_1", "Test1Interpreter", + InterpreterHookRegistry.HookType.PRE_EXEC.getName())); + assertEquals(null, hookRegistry.get("note_1", "Test1Interpreter", + InterpreterHookRegistry.HookType.POST_EXEC.getName())); // register hook for note_1 and interpreter test2 - z.registerNoteHook( - InterpreterHookRegistry.HookType.PRE_EXEC.getName(), "pre_cmd2", "note_1", "test2"); - z.registerNoteHook( - InterpreterHookRegistry.HookType.POST_EXEC.getName(), "post_cmd2", "note_1", "test2"); - assertEquals( - "pre_cmd2", - hookRegistry.get( - "note_1", "Test2Interpreter", InterpreterHookRegistry.HookType.PRE_EXEC.getName())); - assertEquals( - "post_cmd2", - hookRegistry.get( - "note_1", "Test2Interpreter", InterpreterHookRegistry.HookType.POST_EXEC.getName())); + z.registerNoteHook(InterpreterHookRegistry.HookType.PRE_EXEC.getName(), + "pre_cmd2", "note_1", "test2"); + z.registerNoteHook(InterpreterHookRegistry.HookType.POST_EXEC.getName(), + "post_cmd2", "note_1", "test2"); + assertEquals("pre_cmd2", hookRegistry.get("note_1", "Test2Interpreter", + InterpreterHookRegistry.HookType.PRE_EXEC.getName())); + assertEquals("post_cmd2", hookRegistry.get("note_1", "Test2Interpreter", + InterpreterHookRegistry.HookType.POST_EXEC.getName())); z.unregisterNoteHook("note_1", InterpreterHookRegistry.HookType.PRE_EXEC.getName(), "test2"); z.unregisterNoteHook("note_1", InterpreterHookRegistry.HookType.POST_EXEC.getName(), "test2"); - assertEquals( - null, - hookRegistry.get( - "note_1", "Test2Interpreter", InterpreterHookRegistry.HookType.PRE_EXEC.getName())); - assertEquals( - null, - hookRegistry.get( - "note_1", "Test2Interpreter", InterpreterHookRegistry.HookType.POST_EXEC.getName())); + assertEquals(null, hookRegistry.get("note_1", "Test2Interpreter", + InterpreterHookRegistry.HookType.PRE_EXEC.getName())); + assertEquals(null, hookRegistry.get("note_1", "Test2Interpreter", + InterpreterHookRegistry.HookType.POST_EXEC.getName())); } + public static class TestZeppelinContext extends BaseZeppelinContext { public TestZeppelinContext(InterpreterHookRegistry hooks, int maxResult) { @@ -166,4 +137,6 @@ public class BaseZeppelinContextTest { return null; } } + + } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterContextTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterContextTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterContextTest.java index ac6a2eb..62b4035 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterContextTest.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterContextTest.java @@ -17,11 +17,11 @@ package org.apache.zeppelin.interpreter; +import org.junit.Test; + import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import org.junit.Test; - public class InterpreterContextTest { @Test @@ -29,10 +29,12 @@ public class InterpreterContextTest { InterpreterContext.remove(); assertNull(InterpreterContext.get()); - InterpreterContext.set(InterpreterContext.builder().build()); + InterpreterContext.set(InterpreterContext.builder() + .build()); assertNotNull(InterpreterContext.get()); InterpreterContext.remove(); assertNull(InterpreterContext.get()); } + } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterHookRegistryTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterHookRegistryTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterHookRegistryTest.java index 52c37e1..2381dc3 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterHookRegistryTest.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterHookRegistryTest.java @@ -17,6 +17,8 @@ package org.apache.zeppelin.interpreter; +import org.junit.Test; + import static org.apache.zeppelin.interpreter.InterpreterHookRegistry.HookType.POST_EXEC; import static org.apache.zeppelin.interpreter.InterpreterHookRegistry.HookType.POST_EXEC_DEV; import static org.apache.zeppelin.interpreter.InterpreterHookRegistry.HookType.PRE_EXEC; @@ -24,8 +26,6 @@ import static org.apache.zeppelin.interpreter.InterpreterHookRegistry.HookType.P import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import org.junit.Test; - public class InterpreterHookRegistryTest { @Test @@ -71,4 +71,5 @@ public class InterpreterHookRegistryTest { // Test that only valid event codes ("pre_exec", "post_exec") are accepted registry.register("foo", "bar", "baz", "whatever"); } + } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterOutputChangeWatcherTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterOutputChangeWatcherTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterOutputChangeWatcherTest.java index 52f1f1c..2dbbbf8 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterOutputChangeWatcherTest.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterOutputChangeWatcherTest.java @@ -16,16 +16,17 @@ */ package org.apache.zeppelin.interpreter; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import org.junit.After; +import org.junit.Before; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.util.concurrent.atomic.AtomicInteger; -import org.junit.After; -import org.junit.Before; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; public class InterpreterOutputChangeWatcherTest implements InterpreterOutputChangeListener { private File tmpDir; @@ -38,9 +39,8 @@ public class InterpreterOutputChangeWatcherTest implements InterpreterOutputChan watcher = new InterpreterOutputChangeWatcher(this); watcher.start(); - tmpDir = - new File( - System.getProperty("java.io.tmpdir") + "/ZeppelinLTest_" + System.currentTimeMillis()); + tmpDir = new File(System.getProperty("java.io.tmpdir") + "/ZeppelinLTest_" + + System.currentTimeMillis()); tmpDir.mkdirs(); fileChanged = null; numChanged = new AtomicInteger(0); @@ -66,6 +66,7 @@ public class InterpreterOutputChangeWatcherTest implements InterpreterOutputChan } } + // @Test public void test() throws IOException, InterruptedException { assertNull(fileChanged); @@ -98,6 +99,7 @@ public class InterpreterOutputChangeWatcherTest implements InterpreterOutputChan assertEquals(1, numChanged.get()); } + @Override public void fileChanged(File file) { fileChanged = file; @@ -107,4 +109,5 @@ public class InterpreterOutputChangeWatcherTest implements InterpreterOutputChan notify(); } } + } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterOutputTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterOutputTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterOutputTest.java index 1d0ea7a..8158151 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterOutputTest.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterOutputTest.java @@ -16,14 +16,16 @@ */ package org.apache.zeppelin.interpreter; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; import org.junit.After; import org.junit.Before; import org.junit.Test; +import java.io.IOException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + + public class InterpreterOutputTest implements InterpreterOutputListener { private InterpreterOutput out; int numAppendEvent; @@ -77,6 +79,7 @@ public class InterpreterOutputTest implements InterpreterOutputListener { assertEquals("div", new String(out.getOutputAt(0).toByteArray())); } + @Test public void testType() throws IOException { // default output stream type is TEXT @@ -150,6 +153,7 @@ public class InterpreterOutputTest implements InterpreterOutputListener { assertEquals("<h3> This is a hack </h3>\t234\n", new String(out.getOutputAt(1).toByteArray())); } + @Test public void testTableCellFormatting() throws IOException { out.write("%table col1\tcol2\n\n%html val1\tval2\n".getBytes()); @@ -188,8 +192,11 @@ public class InterpreterOutputTest implements InterpreterOutputListener { InterpreterOutput.limit = Constants.ZEPPELIN_INTERPRETER_OUTPUT_LIMIT; } + @Override - public void onUpdateAll(InterpreterOutput out) {} + public void onUpdateAll(InterpreterOutput out) { + + } @Override public void onAppend(int index, InterpreterResultMessageOutput out, byte[] line) { http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterResultTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterResultTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterResultTest.java index db069fd..a8ff1bf 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterResultTest.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterResultTest.java @@ -17,17 +17,18 @@ package org.apache.zeppelin.interpreter; +import org.junit.Test; + import static org.junit.Assert.assertEquals; -import org.junit.Test; public class InterpreterResultTest { @Test public void testTextType() { - InterpreterResult result = - new InterpreterResult(InterpreterResult.Code.SUCCESS, "this is a TEXT type"); + InterpreterResult result = new InterpreterResult(InterpreterResult.Code.SUCCESS, + "this is a TEXT type"); assertEquals("No magic", InterpreterResult.Type.TEXT, result.message().get(0).getType()); result = new InterpreterResult(InterpreterResult.Code.SUCCESS, "%this is a TEXT type"); assertEquals("No magic", InterpreterResult.Type.TEXT, result.message().get(0).getType()); @@ -39,15 +40,14 @@ public class InterpreterResultTest { public void testSimpleMagicType() { InterpreterResult result = null; - result = new InterpreterResult(InterpreterResult.Code.SUCCESS, "%table col1\tcol2\naaa\t123\n"); + result = new InterpreterResult(InterpreterResult.Code.SUCCESS, + "%table col1\tcol2\naaa\t123\n"); assertEquals(InterpreterResult.Type.TABLE, result.message().get(0).getType()); - result = - new InterpreterResult(InterpreterResult.Code.SUCCESS, "%table\ncol1\tcol2\naaa\t123\n"); + result = new InterpreterResult(InterpreterResult.Code.SUCCESS, + "%table\ncol1\tcol2\naaa\t123\n"); assertEquals(InterpreterResult.Type.TABLE, result.message().get(0).getType()); - result = - new InterpreterResult( - InterpreterResult.Code.SUCCESS, - "some text before magic word\n%table col1\tcol2\naaa\t123\n"); + result = new InterpreterResult(InterpreterResult.Code.SUCCESS, + "some text before magic word\n%table col1\tcol2\naaa\t123\n"); assertEquals(InterpreterResult.Type.TABLE, result.message().get(1).getType()); } @@ -55,49 +55,29 @@ public class InterpreterResultTest { public void testComplexMagicType() { InterpreterResult result = null; - result = - new InterpreterResult( - InterpreterResult.Code.SUCCESS, "some text before %table col1\tcol2\naaa\t123\n"); - assertEquals( - "some text before magic return magic", - InterpreterResult.Type.TEXT, - result.message().get(0).getType()); - result = - new InterpreterResult( - InterpreterResult.Code.SUCCESS, "some text before\n%table col1\tcol2\naaa\t123\n"); - assertEquals( - "some text before magic return magic", - InterpreterResult.Type.TEXT, - result.message().get(0).getType()); - assertEquals( - "some text before magic return magic", - InterpreterResult.Type.TABLE, - result.message().get(1).getType()); - result = - new InterpreterResult( - InterpreterResult.Code.SUCCESS, - "%html <h3> This is a hack </h3> %table\n col1\tcol2\naaa\t123\n"); - assertEquals( - "magic A before magic B return magic A", - InterpreterResult.Type.HTML, - result.message().get(0).getType()); - result = - new InterpreterResult( - InterpreterResult.Code.SUCCESS, - "some text before magic word %table col1\tcol2\naaa\t123\n %html " - + "<h3> This is a hack </h3>"); - assertEquals( - "text & magic A before magic B return magic A", - InterpreterResult.Type.TEXT, - result.message().get(0).getType()); - result = - new InterpreterResult( - InterpreterResult.Code.SUCCESS, - "%table col1\tcol2\naaa\t123\n %html <h3> This is a hack </h3> %table col1\naaa\n123\n"); - assertEquals( - "magic A, magic B, magic a' return magic A", - InterpreterResult.Type.TABLE, - result.message().get(0).getType()); + result = new InterpreterResult(InterpreterResult.Code.SUCCESS, + "some text before %table col1\tcol2\naaa\t123\n"); + assertEquals("some text before magic return magic", + InterpreterResult.Type.TEXT, result.message().get(0).getType()); + result = new InterpreterResult(InterpreterResult.Code.SUCCESS, + "some text before\n%table col1\tcol2\naaa\t123\n"); + assertEquals("some text before magic return magic", + InterpreterResult.Type.TEXT, result.message().get(0).getType()); + assertEquals("some text before magic return magic", + InterpreterResult.Type.TABLE, result.message().get(1).getType()); + result = new InterpreterResult(InterpreterResult.Code.SUCCESS, + "%html <h3> This is a hack </h3> %table\n col1\tcol2\naaa\t123\n"); + assertEquals("magic A before magic B return magic A", + InterpreterResult.Type.HTML, result.message().get(0).getType()); + result = new InterpreterResult(InterpreterResult.Code.SUCCESS, + "some text before magic word %table col1\tcol2\naaa\t123\n %html " + + "<h3> This is a hack </h3>"); + assertEquals("text & magic A before magic B return magic A", + InterpreterResult.Type.TEXT, result.message().get(0).getType()); + result = new InterpreterResult(InterpreterResult.Code.SUCCESS, + "%table col1\tcol2\naaa\t123\n %html <h3> This is a hack </h3> %table col1\naaa\n123\n"); + assertEquals("magic A, magic B, magic a' return magic A", + InterpreterResult.Type.TABLE, result.message().get(0).getType()); } @Test @@ -105,21 +85,17 @@ public class InterpreterResultTest { InterpreterResult result = null; - result = new InterpreterResult(InterpreterResult.Code.SUCCESS, "%table col1\tcol2\naaa\t123\n"); - assertEquals( - "%table col1\tcol2\naaa\t123\n", + result = new InterpreterResult(InterpreterResult.Code.SUCCESS, + "%table col1\tcol2\naaa\t123\n"); + assertEquals("%table col1\tcol2\naaa\t123\n", "col1\tcol2\naaa\t123\n", result.message().get(0).getData()); - result = - new InterpreterResult(InterpreterResult.Code.SUCCESS, "%table\ncol1\tcol2\naaa\t123\n"); - assertEquals( - "%table\ncol1\tcol2\naaa\t123\n", + result = new InterpreterResult(InterpreterResult.Code.SUCCESS, + "%table\ncol1\tcol2\naaa\t123\n"); + assertEquals("%table\ncol1\tcol2\naaa\t123\n", "col1\tcol2\naaa\t123\n", result.message().get(0).getData()); - result = - new InterpreterResult( - InterpreterResult.Code.SUCCESS, - "some text before magic word\n%table col1\tcol2\naaa\t123\n"); - assertEquals( - "some text before magic word\n%table col1\tcol2\naaa\t123\n", + result = new InterpreterResult(InterpreterResult.Code.SUCCESS, + "some text before magic word\n%table col1\tcol2\naaa\t123\n"); + assertEquals("some text before magic word\n%table col1\tcol2\naaa\t123\n", "col1\tcol2\naaa\t123\n", result.message().get(1).getData()); } @@ -127,40 +103,31 @@ public class InterpreterResultTest { InterpreterResult result = null; - result = - new InterpreterResult( - InterpreterResult.Code.SUCCESS, "some text before\n%table col1\tcol2\naaa\t123\n"); + result = new InterpreterResult(InterpreterResult.Code.SUCCESS, + "some text before\n%table col1\tcol2\naaa\t123\n"); assertEquals("text before %table", "some text before\n", result.message().get(0).getData()); assertEquals("text after %table", "col1\tcol2\naaa\t123\n", result.message().get(1).getData()); - result = - new InterpreterResult( - InterpreterResult.Code.SUCCESS, - "%html <h3> This is a hack </h3>\n%table\ncol1\tcol2\naaa\t123\n"); + result = new InterpreterResult(InterpreterResult.Code.SUCCESS, + "%html <h3> This is a hack </h3>\n%table\ncol1\tcol2\naaa\t123\n"); assertEquals(" <h3> This is a hack </h3>\n", result.message().get(0).getData()); assertEquals("col1\tcol2\naaa\t123\n", result.message().get(1).getData()); - result = - new InterpreterResult( - InterpreterResult.Code.SUCCESS, - "some text before magic word\n%table col1\tcol2\naaa\t123\n\n%html " - + "<h3> This is a hack </h3>"); + result = new InterpreterResult(InterpreterResult.Code.SUCCESS, + "some text before magic word\n%table col1\tcol2\naaa\t123\n\n%html " + + "<h3> This is a hack </h3>"); assertEquals("<h3> This is a hack </h3>", result.message().get(2).getData()); - result = - new InterpreterResult( - InterpreterResult.Code.SUCCESS, - "%table col1\tcol2\naaa\t123\n\n%html <h3> This is a hack </h3>\n%table col1\naaa\n123\n"); + result = new InterpreterResult(InterpreterResult.Code.SUCCESS, + "%table col1\tcol2\naaa\t123\n\n%html <h3> This is a hack </h3>\n%table col1\naaa\n123\n"); assertEquals("col1\naaa\n123\n", result.message().get(2).getData()); - result = - new InterpreterResult( - InterpreterResult.Code.SUCCESS, - "%table " + "col1\tcol2\naaa\t123\n\n%table col1\naaa\n123\n"); + result = new InterpreterResult(InterpreterResult.Code.SUCCESS, + "%table " + "col1\tcol2\naaa\t123\n\n%table col1\naaa\n123\n"); assertEquals("col1\tcol2\naaa\t123\n", result.message().get(0).getData()); assertEquals("col1\naaa\n123\n", result.message().get(1).getData()); } @Test public void testToString() { - assertEquals( - "%html hello", - new InterpreterResult(InterpreterResult.Code.SUCCESS, "%html hello").toString()); + assertEquals("%html hello", new InterpreterResult(InterpreterResult.Code.SUCCESS, + "%html hello").toString()); } + } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterTest.java index 11e9750..72b9f58 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterTest.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterTest.java @@ -17,12 +17,13 @@ package org.apache.zeppelin.interpreter; -import static org.junit.Assert.assertEquals; +import org.junit.Test; import java.util.Properties; -import org.junit.Test; -// TODO(zjffdu) add more test for Interpreter which is a very important class +import static org.junit.Assert.assertEquals; + +//TODO(zjffdu) add more test for Interpreter which is a very important class public class InterpreterTest { @Test @@ -66,22 +67,20 @@ public class InterpreterTest { .build()); Properties p = new Properties(); - p.put( - "p1", - "replName #{noteId}, #{paragraphTitle}, #{paragraphId}, #{paragraphText}, " - + "#{replName}, #{noteId}, #{user}," - + " #{authenticationInfo}"); + p.put("p1", "replName #{noteId}, #{paragraphTitle}, #{paragraphId}, #{paragraphText}, " + + "#{replName}, #{noteId}, #{user}," + + " #{authenticationInfo}"); Interpreter intp = new DummyInterpreter(p); intp.setUserName(user); String actual = intp.getProperty("p1"); InterpreterContext.remove(); assertEquals( - String.format( - "replName %s, #{paragraphTitle}, #{paragraphId}, #{paragraphText}, , " - + "%s, %s, #{authenticationInfo}", - noteId, noteId, user), - actual); + String.format("replName %s, #{paragraphTitle}, #{paragraphId}, #{paragraphText}, , " + + "%s, %s, #{authenticationInfo}", noteId, + noteId, user), + actual + ); } public static class DummyInterpreter extends Interpreter { @@ -91,10 +90,14 @@ public class InterpreterTest { } @Override - public void open() {} + public void open() { + + } @Override - public void close() {} + public void close() { + + } @Override public InterpreterResult interpret(String st, InterpreterContext context) { @@ -102,7 +105,9 @@ public class InterpreterTest { } @Override - public void cancel(InterpreterContext context) {} + public void cancel(InterpreterContext context) { + + } @Override public FormType getFormType() { @@ -114,4 +119,5 @@ public class InterpreterTest { return 0; } } + } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/LazyOpenInterpreterTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/LazyOpenInterpreterTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/LazyOpenInterpreterTest.java index 272e9ed..417b72c 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/LazyOpenInterpreterTest.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/LazyOpenInterpreterTest.java @@ -17,14 +17,14 @@ package org.apache.zeppelin.interpreter; +import org.junit.Test; + import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import org.junit.Test; - public class LazyOpenInterpreterTest { Interpreter interpreter = mock(Interpreter.class); http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/ZeppCtxtVariableTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/ZeppCtxtVariableTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/ZeppCtxtVariableTest.java index e517b46..14b4b6b 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/ZeppCtxtVariableTest.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/ZeppCtxtVariableTest.java @@ -17,15 +17,16 @@ package org.apache.zeppelin.interpreter; -import static org.junit.Assert.assertTrue; - -import java.util.Properties; import org.apache.zeppelin.resource.LocalResourcePool; import org.apache.zeppelin.resource.ResourcePool; import org.junit.After; import org.junit.Before; import org.junit.Test; +import java.util.Properties; + +import static org.junit.Assert.assertTrue; + public class ZeppCtxtVariableTest { public static class TestInterpreter extends Interpreter { @@ -35,10 +36,12 @@ public class ZeppCtxtVariableTest { } @Override - public void open() {} + public void open() { + } @Override - public void close() {} + public void close() { + } @Override public InterpreterResult interpret(String st, InterpreterContext context) { @@ -46,7 +49,8 @@ public class ZeppCtxtVariableTest { } @Override - public void cancel(InterpreterContext context) {} + public void cancel(InterpreterContext context) { + } @Override public FormType getFormType() { @@ -67,17 +71,17 @@ public class ZeppCtxtVariableTest { resourcePool = new LocalResourcePool("ZeppelinContextVariableInterpolationTest"); - InterpreterContext context = - InterpreterContext.builder() - .setNoteId("noteId") - .setParagraphId("paragraphId") - .setResourcePool(resourcePool) - .build(); + InterpreterContext context = InterpreterContext.builder() + .setNoteId("noteId") + .setParagraphId("paragraphId") + .setResourcePool(resourcePool) + .build(); InterpreterContext.set(context); interpreter = new TestInterpreter(new Properties()); resourcePool.put("PI", "3.1415"); + } @After @@ -109,24 +113,28 @@ public class ZeppCtxtVariableTest { assertTrue("multiLineSubstitutionSuccessful1", "{PI}\n3.1415\n{PI}\n3.1415".equals(result)); } + @Test public void multiLineSubstitutionSuccessful2() { String result = interpreter.interpolate("prefix {PI} {{PI\n}} suffix", resourcePool); assertTrue("multiLineSubstitutionSuccessful2", "prefix 3.1415 {PI\n} suffix".equals(result)); } + @Test public void multiLineSubstitutionSuccessful3() { String result = interpreter.interpolate("prefix {{\nPI}} {PI} suffix", resourcePool); assertTrue("multiLineSubstitutionSuccessful3", "prefix {\nPI} 3.1415 suffix".equals(result)); } + @Test public void multiLineSubstitutionFailure2() { String result = interpreter.interpolate("prefix {PI\n} suffix", resourcePool); assertTrue("multiLineSubstitutionFailure2", "prefix {PI\n} suffix".equals(result)); } + @Test public void multiLineSubstitutionFailure3() { String result = interpreter.interpolate("prefix {\nPI} suffix", resourcePool); @@ -192,4 +200,5 @@ public class ZeppCtxtVariableTest { String result = interpreter.interpolate("Paired } end an escaped sequence", resourcePool); assertTrue("Random braces - four", "Paired } end an escaped sequence".equals(result)); } + } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterServerTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterServerTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterServerTest.java index fa16ace..9719717 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterServerTest.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterServerTest.java @@ -17,16 +17,6 @@ package org.apache.zeppelin.interpreter.remote; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; -import java.util.concurrent.atomic.AtomicBoolean; import org.apache.thrift.TException; import org.apache.zeppelin.interpreter.Interpreter; import org.apache.zeppelin.interpreter.InterpreterContext; @@ -37,17 +27,23 @@ import org.apache.zeppelin.interpreter.thrift.RemoteInterpreterContext; import org.apache.zeppelin.interpreter.thrift.RemoteInterpreterResult; import org.junit.Test; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import java.util.concurrent.atomic.AtomicBoolean; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; + public class RemoteInterpreterServerTest { @Test public void testStartStop() throws InterruptedException, IOException, TException { - RemoteInterpreterServer server = - new RemoteInterpreterServer( - "localhost", - RemoteInterpreterUtils.findRandomAvailablePortOnAllLocalInterfaces(), - ":", - "groupId", - true); + RemoteInterpreterServer server = new RemoteInterpreterServer("localhost", + RemoteInterpreterUtils.findRandomAvailablePortOnAllLocalInterfaces(), ":", "groupId", true); startRemoteInterpreterServer(server, 10 * 1000); stopRemoteInterpreterServer(server, 10 * 10000); @@ -55,13 +51,8 @@ public class RemoteInterpreterServerTest { @Test public void testStartStopWithQueuedEvents() throws InterruptedException, IOException, TException { - RemoteInterpreterServer server = - new RemoteInterpreterServer( - "localhost", - RemoteInterpreterUtils.findRandomAvailablePortOnAllLocalInterfaces(), - ":", - "groupId", - true); + RemoteInterpreterServer server = new RemoteInterpreterServer("localhost", + RemoteInterpreterUtils.findRandomAvailablePortOnAllLocalInterfaces(), ":", "groupId", true); server.intpEventClient = mock(RemoteInterpreterEventClient.class); startRemoteInterpreterServer(server, 10 * 1000); @@ -81,9 +72,8 @@ public class RemoteInterpreterServerTest { Thread.sleep(200); } assertEquals(true, server.isRunning()); - assertEquals( - true, - RemoteInterpreterUtils.checkIfRemoteEndpointAccessible("localhost", server.getPort())); + assertEquals(true, RemoteInterpreterUtils.checkIfRemoteEndpointAccessible("localhost", + server.getPort())); } private void stopRemoteInterpreterServer(RemoteInterpreterServer server, int timeout) @@ -98,20 +88,14 @@ public class RemoteInterpreterServerTest { Thread.sleep(200); } assertEquals(false, server.isRunning()); - assertEquals( - false, - RemoteInterpreterUtils.checkIfRemoteEndpointAccessible("localhost", server.getPort())); + assertEquals(false, RemoteInterpreterUtils.checkIfRemoteEndpointAccessible("localhost", + server.getPort())); } @Test public void testInterpreter() throws IOException, TException, InterruptedException { - final RemoteInterpreterServer server = - new RemoteInterpreterServer( - "localhost", - RemoteInterpreterUtils.findRandomAvailablePortOnAllLocalInterfaces(), - ":", - "groupId", - true); + final RemoteInterpreterServer server = new RemoteInterpreterServer("localhost", + RemoteInterpreterUtils.findRandomAvailablePortOnAllLocalInterfaces(), ":", "groupId", true); server.intpEventClient = mock(RemoteInterpreterEventClient.class); Map<String, String> intpProperties = new HashMap<>(); @@ -119,25 +103,24 @@ public class RemoteInterpreterServerTest { intpProperties.put("zeppelin.interpreter.localRepo", "/tmp"); // create Test1Interpreter in session_1 - server.createInterpreter( - "group_1", "session_1", Test1Interpreter.class.getName(), intpProperties, "user_1"); - Test1Interpreter interpreter1 = - (Test1Interpreter) - ((LazyOpenInterpreter) server.getInterpreterGroup().get("session_1").get(0)) - .getInnerInterpreter(); + server.createInterpreter("group_1", "session_1", Test1Interpreter.class.getName(), + intpProperties, "user_1"); + Test1Interpreter interpreter1 = (Test1Interpreter) + ((LazyOpenInterpreter) server.getInterpreterGroup().get("session_1").get(0)) + .getInnerInterpreter(); assertEquals(1, server.getInterpreterGroup().getSessionNum()); assertEquals(1, server.getInterpreterGroup().get("session_1").size()); assertEquals(2, interpreter1.getProperties().size()); assertEquals("value_1", interpreter1.getProperty("property_1")); // create Test2Interpreter in session_1 - server.createInterpreter( - "group_1", "session_1", Test1Interpreter.class.getName(), intpProperties, "user_1"); + server.createInterpreter("group_1", "session_1", Test1Interpreter.class.getName(), + intpProperties, "user_1"); assertEquals(2, server.getInterpreterGroup().get("session_1").size()); // create Test1Interpreter in session_2 - server.createInterpreter( - "group_1", "session_2", Test1Interpreter.class.getName(), intpProperties, "user_1"); + server.createInterpreter("group_1", "session_2", Test1Interpreter.class.getName(), + intpProperties, "user_1"); assertEquals(2, server.getInterpreterGroup().getSessionNum()); assertEquals(2, server.getInterpreterGroup().get("session_1").size()); assertEquals(1, server.getInterpreterGroup().get("session_2").size()); @@ -149,26 +132,23 @@ public class RemoteInterpreterServerTest { intpContext.setNoteGui("{}"); // single output of SUCCESS - RemoteInterpreterResult result = - server.interpret( - "session_1", Test1Interpreter.class.getName(), "SINGLE_OUTPUT_SUCCESS", intpContext); + RemoteInterpreterResult result = server.interpret("session_1", Test1Interpreter.class.getName(), + "SINGLE_OUTPUT_SUCCESS", intpContext); assertEquals("SUCCESS", result.code); assertEquals(1, result.getMsg().size()); assertEquals("SINGLE_OUTPUT_SUCCESS", result.getMsg().get(0).getData()); // combo output of SUCCESS - result = - server.interpret( - "session_1", Test1Interpreter.class.getName(), "COMBO_OUTPUT_SUCCESS", intpContext); + result = server.interpret("session_1", Test1Interpreter.class.getName(), "COMBO_OUTPUT_SUCCESS", + intpContext); assertEquals("SUCCESS", result.code); assertEquals(2, result.getMsg().size()); assertEquals("INTERPRETER_OUT", result.getMsg().get(0).getData()); assertEquals("SINGLE_OUTPUT_SUCCESS", result.getMsg().get(1).getData()); // single output of ERROR - result = - server.interpret( - "session_1", Test1Interpreter.class.getName(), "SINGLE_OUTPUT_ERROR", intpContext); + result = server.interpret("session_1", Test1Interpreter.class.getName(), "SINGLE_OUTPUT_ERROR", + intpContext); assertEquals("ERROR", result.code); assertEquals(1, result.getMsg().size()); assertEquals("SINGLE_OUTPUT_ERROR", result.getMsg().get(0).getData()); @@ -178,17 +158,16 @@ public class RemoteInterpreterServerTest { assertEquals("NATIVE", formType); // cancel - Thread sleepThread = - new Thread() { - @Override - public void run() { - try { - server.interpret("session_1", Test1Interpreter.class.getName(), "SLEEP", intpContext); - } catch (TException e) { - e.printStackTrace(); - } - } - }; + Thread sleepThread = new Thread() { + @Override + public void run() { + try { + server.interpret("session_1", Test1Interpreter.class.getName(), "SLEEP", intpContext); + } catch (TException e) { + e.printStackTrace(); + } + } + }; sleepThread.start(); Thread.sleep(1000); @@ -197,8 +176,8 @@ public class RemoteInterpreterServerTest { assertTrue(interpreter1.cancelled.get()); // getProgress - assertEquals( - 10, server.getProgress("session_1", Test1Interpreter.class.getName(), intpContext)); + assertEquals(10, server.getProgress("session_1", Test1Interpreter.class.getName(), + intpContext)); // close server.close("session_1", Test1Interpreter.class.getName()); @@ -215,7 +194,9 @@ public class RemoteInterpreterServerTest { } @Override - public void open() {} + public void open() { + + } @Override public InterpreterResult interpret(String st, InterpreterContext context) { @@ -260,16 +241,20 @@ public class RemoteInterpreterServerTest { public void close() { closed.set(true); } + } public static class Test2Interpreter extends Interpreter { + public Test2Interpreter(Properties properties) { super(properties); } @Override - public void open() {} + public void open() { + + } @Override public InterpreterResult interpret(String st, InterpreterContext context) { @@ -277,7 +262,9 @@ public class RemoteInterpreterServerTest { } @Override - public void cancel(InterpreterContext context) throws InterpreterException {} + public void cancel(InterpreterContext context) throws InterpreterException { + + } @Override public FormType getFormType() throws InterpreterException { @@ -290,6 +277,9 @@ public class RemoteInterpreterServerTest { } @Override - public void close() {} + public void close() { + + } + } }
