Search in sources :

Example 51 with Code

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);
}
Also used : Message(com.twosigma.beakerx.message.Message) Code(com.twosigma.beakerx.kernel.Code) Map(java.util.Map) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest)

Example 52 with Code

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");
}
Also used : Message(com.twosigma.beakerx.message.Message) Code(com.twosigma.beakerx.kernel.Code) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest)

Example 53 with Code

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");
}
Also used : MessageAssertions.verifyExecuteReplyMessage(com.twosigma.MessageAssertions.verifyExecuteReplyMessage) EvaluatorResultTestWatcher.waitForIdleMessage(com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForIdleMessage) Message(com.twosigma.beakerx.message.Message) MessageFactoryTest.getExecuteRequestMessage(com.twosigma.beakerx.MessageFactoryTest.getExecuteRequestMessage) EvaluatorResultTestWatcher.waitForErrorMessage(com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForErrorMessage) EvaluatorResultTestWatcher.waitForSentMessage(com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForSentMessage) Code(com.twosigma.beakerx.kernel.Code) Test(org.junit.Test)

Example 54 with Code

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");
}
Also used : MessageAssertions.verifyExecuteReplyMessage(com.twosigma.MessageAssertions.verifyExecuteReplyMessage) EvaluatorResultTestWatcher.waitForIdleMessage(com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForIdleMessage) Message(com.twosigma.beakerx.message.Message) MessageFactoryTest.getExecuteRequestMessage(com.twosigma.beakerx.MessageFactoryTest.getExecuteRequestMessage) EvaluatorResultTestWatcher.waitForErrorMessage(com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForErrorMessage) EvaluatorResultTestWatcher.waitForSentMessage(com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForSentMessage) Code(com.twosigma.beakerx.kernel.Code) Test(org.junit.Test)

Example 55 with Code

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]");
}
Also used : MessageAssertions.verifyExecuteReplyMessage(com.twosigma.MessageAssertions.verifyExecuteReplyMessage) EvaluatorResultTestWatcher.waitForIdleMessage(com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForIdleMessage) Message(com.twosigma.beakerx.message.Message) MessageFactoryTest.getExecuteRequestMessage(com.twosigma.beakerx.MessageFactoryTest.getExecuteRequestMessage) EvaluatorResultTestWatcher.waitForErrorMessage(com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForErrorMessage) EvaluatorResultTestWatcher.waitForSentMessage(com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForSentMessage) Code(com.twosigma.beakerx.kernel.Code)

Aggregations

Code (com.twosigma.beakerx.kernel.Code)55 Message (com.twosigma.beakerx.message.Message)54 Test (org.junit.Test)47 KernelTest (com.twosigma.beakerx.KernelTest)33 EvaluatorTest (com.twosigma.beakerx.evaluator.EvaluatorTest)29 MessageFactoryTest.getExecuteRequestMessage (com.twosigma.beakerx.MessageFactoryTest.getExecuteRequestMessage)16 EvaluatorResultTestWatcher.waitForIdleMessage (com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForIdleMessage)16 PlainCode (com.twosigma.beakerx.kernel.PlainCode)14 MessageAssertions.verifyExecuteReplyMessage (com.twosigma.MessageAssertions.verifyExecuteReplyMessage)9 EvaluatorResultTestWatcher.waitForErrorMessage (com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForErrorMessage)9 EvaluatorResultTestWatcher.waitForSentMessage (com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForSentMessage)9 KernelExecutionTest (com.twosigma.beakerx.KernelExecutionTest)7 EvaluatorResultTestWatcher.waitForUpdateMessage (com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForUpdateMessage)7 ClasspathAddMvnMagicCommand (com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathAddMvnMagicCommand)4 ClasspathResetMagicCommand (com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathResetMagicCommand)4 ImportPath (com.twosigma.beakerx.kernel.ImportPath)3 PathToJar (com.twosigma.beakerx.kernel.PathToJar)2 MagicCommand (com.twosigma.beakerx.kernel.magic.command.MagicCommand)2 ClassPathAddMvnCellMagicCommand (com.twosigma.beakerx.kernel.magic.command.functionality.ClassPathAddMvnCellMagicCommand)2 EvaluatorResultTestWatcher (com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher)1