use of com.twosigma.beakerx.kernel.Code in project beakerx by twosigma.
the class JavaScriptMagicCommandTest method handleJavaScriptMagicCommand.
@Test
public void handleJavaScriptMagicCommand() throws Exception {
// given
String jsCode = "require.config({\n" + " paths: {\n" + " d3: '//cdnjs.cloudflare.com/ajax/libs/d3/3.4.8/d3.min'\n" + " }});";
Code code = CodeFactory.create(JAVASCRIPT + System.lineSeparator() + jsCode, new Message(), kernel);
// when
code.execute(this.kernel, 1);
// MagicCommandOutcome result = executeMagicCommands(code, 1, kernel);
// then
Map data = (Map) kernel.getPublishedMessages().get(0).getContent().get("data");
String toCompare = (String) data.get(MIMEContainer.MIME.APPLICATION_JAVASCRIPT);
toCompare = toCompare.replaceAll("\\s+", "");
jsCode = jsCode.replaceAll("\\s+", "");
assertThat(toCompare.trim()).isEqualTo(jsCode);
}
use of com.twosigma.beakerx.kernel.Code in project beakerx by twosigma.
the class JavaScriptMagicCommandTest method shouldCreateMsgWithWrongMagic.
@Test
public void shouldCreateMsgWithWrongMagic() {
// given
String jsCode = System.lineSeparator() + "alert()";
Code code = CodeFactory.create(JAVASCRIPT + "wrong" + jsCode, new Message(), kernel);
// when
code.execute(kernel, 1);
// then
List<Message> std = EvaluatorResultTestWatcher.getStderr(kernel.getPublishedMessages());
String text = (String) std.get(0).getContent().get("text");
assertThat(text).isEqualTo("Cell magic " + JAVASCRIPT + "wrong" + " not found\n");
}
use of com.twosigma.beakerx.kernel.Code in project beakerx by twosigma.
the class KernelExecutionTest method shouldNotImportClassesFromUnknownPackageWithWildcardByMagicCommand.
@Test
public void shouldNotImportClassesFromUnknownPackageWithWildcardByMagicCommand() throws Exception {
// given
String path = pathToDemoClassFromAddedDemoJar();
String allCode = IMPORT + " " + (path.substring(0, path.lastIndexOf(".")) + "Unknown.*");
addDemoJar();
// when
Code code = CodeFactory.create(allCode, new Message(), getKernel());
code.execute(kernel, 1);
// then
List<Message> std = waitForStderr(getKernelSocketsService().getKernelSockets());
String text = (String) std.get(0).getContent().get("text");
assertThat(text).contains("Could not import");
}
use of com.twosigma.beakerx.kernel.Code in project beakerx by twosigma.
the class KernelExecutionTest method shouldNotImportUnknownClassByMagicCommand.
@Test
public void shouldNotImportUnknownClassByMagicCommand() throws Exception {
// given
String allCode = IMPORT + " " + pathToDemoClassFromAddedDemoJar() + "UnknownClass";
// when
Code code = CodeFactory.create(allCode, new Message(), getKernel());
code.execute(kernel, 1);
// then
List<Message> std = waitForStderr(getKernelSocketsService().getKernelSockets());
String text = (String) std.get(0).getContent().get("text");
assertThat(text).contains("Could not import");
}
use of com.twosigma.beakerx.kernel.Code in project beakerx by twosigma.
the class KernelExecutionTest method addDemoJar.
protected void addDemoJar() throws InterruptedException {
String allCode = CLASSPATH_ADD_JAR + " " + DEMO_JAR;
Code code = CodeFactory.create(allCode, new Message(), getKernel());
code.execute(getKernel(), 1);
List<Message> std = waitForStdouts(getKernelSocketsService().getKernelSockets());
String text = (String) std.get(0).getContent().get("text");
assertThat(text).contains("Added jar: [demo.jar]");
}
Aggregations