Search in sources :

Example 26 with Code

use of com.twosigma.beakerx.kernel.Code in project beakerx by twosigma.

the class GroovyKernelTest method shouldImportStaticFieldDemoClassByMagicCommand.

@Test
public void shouldImportStaticFieldDemoClassByMagicCommand() throws Exception {
    // given
    addDemoJar();
    String path = pathToDemoClassFromAddedDemoJar() + ".STATIC_TEST_123";
    // when
    Code code = CodeFactory.create(ADD_STATIC_IMPORT + " " + path, new Message(), getKernel());
    code.execute(kernel, 1);
    // then
    verifyStaticImportedDemoClassByMagicCommand(pathToDemoClassFromAddedDemoJar() + ".STATIC_TEST_123");
}
Also used : MessageFactoryTest.getExecuteRequestMessage(com.twosigma.beakerx.MessageFactoryTest.getExecuteRequestMessage) EvaluatorResultTestWatcher.waitForIdleMessage(com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForIdleMessage) Message(com.twosigma.beakerx.message.Message) EvaluatorResultTestWatcher.waitForUpdateMessage(com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForUpdateMessage) Code(com.twosigma.beakerx.kernel.Code) KernelExecutionTest(com.twosigma.beakerx.KernelExecutionTest) Test(org.junit.Test)

Example 27 with Code

use of com.twosigma.beakerx.kernel.Code in project beakerx by twosigma.

the class GroovyKernelTest method shouldImportStaticWildcardDemoClassByMagicCommand.

@Test
public void shouldImportStaticWildcardDemoClassByMagicCommand() throws Exception {
    // given
    addDemoJar();
    String path = pathToDemoClassFromAddedDemoJar() + ".*";
    // when
    Code code = CodeFactory.create(ADD_STATIC_IMPORT + " " + path, new Message(), getKernel());
    code.execute(kernel, 1);
    // then
    verifyStaticImportedDemoClassByMagicCommand(pathToDemoClassFromAddedDemoJar() + ".staticTest()");
    verifyStaticImportedDemoClassByMagicCommand(pathToDemoClassFromAddedDemoJar() + ".STATIC_TEST_123");
}
Also used : MessageFactoryTest.getExecuteRequestMessage(com.twosigma.beakerx.MessageFactoryTest.getExecuteRequestMessage) EvaluatorResultTestWatcher.waitForIdleMessage(com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForIdleMessage) Message(com.twosigma.beakerx.message.Message) EvaluatorResultTestWatcher.waitForUpdateMessage(com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForUpdateMessage) Code(com.twosigma.beakerx.kernel.Code) KernelExecutionTest(com.twosigma.beakerx.KernelExecutionTest) Test(org.junit.Test)

Example 28 with Code

use of com.twosigma.beakerx.kernel.Code in project beakerx by twosigma.

the class SQLMagicCommandTest method handleDefaultDatasourceMagicCommand.

@Test
public void handleDefaultDatasourceMagicCommand() throws Exception {
    // given
    String codeAsString = DEFAULT_DATASOURCE + " jdbc:h2:mem:db1";
    MagicCommand command = new MagicCommand(new DefaultDataSourcesMagicCommand(kernel), codeAsString);
    Code code = Code.createCode(codeAsString, singletonList(command), NO_ERRORS, new Message());
    // when
    code.execute(kernel, 1);
    // then
    assertThat(getDefaultDatasource().get()).isEqualTo("jdbc:h2:mem:db1");
}
Also used : Message(com.twosigma.beakerx.message.Message) MagicCommand(com.twosigma.beakerx.kernel.magic.command.MagicCommand) Code(com.twosigma.beakerx.kernel.Code) Test(org.junit.Test) EvaluatorTest(com.twosigma.beakerx.evaluator.EvaluatorTest)

Example 29 with Code

use of com.twosigma.beakerx.kernel.Code in project beakerx by twosigma.

the class SQLMagicCommandTest method handleDatasourceMagicCommand.

@Test
public void handleDatasourceMagicCommand() throws Exception {
    // given
    String codeAsString = DATASOURCES + " jdbc:h2:mem:db2";
    MagicCommand command = new MagicCommand(new DataSourcesMagicCommand(kernel), codeAsString);
    Code code = Code.createCode(codeAsString, singletonList(command), NO_ERRORS, new Message());
    // when
    code.execute(kernel, 1);
    // then
    assertThat(getDatasource().get()).isEqualTo("jdbc:h2:mem:db2");
}
Also used : Message(com.twosigma.beakerx.message.Message) MagicCommand(com.twosigma.beakerx.kernel.magic.command.MagicCommand) Code(com.twosigma.beakerx.kernel.Code) Test(org.junit.Test) EvaluatorTest(com.twosigma.beakerx.evaluator.EvaluatorTest)

Example 30 with Code

use of com.twosigma.beakerx.kernel.Code in project beakerx by twosigma.

the class ClasspathAddMvnDepsCellMagicCommandTest method handleUnresolvedDep.

@Test
public void handleUnresolvedDep() throws Exception {
    String allCode = "%%classpath add mvn\n" + "com.google.code.XXXX:gson:2.6.2";
    // given
    MagicCommand command = new MagicCommand(new ClassPathAddMvnCellMagicCommand(kernel.mavenResolverParam, kernel), allCode);
    Code code = Code.createCode(allCode, Collections.singletonList(command), NO_ERRORS, new Message());
    // when
    code.execute(kernel, 1);
    // then
    List<Message> stderr = EvaluatorResultTestWatcher.getStderr(kernel.getPublishedMessages());
    String text = (String) stderr.get(0).getContent().get("text");
    Assertions.assertThat(text).contains("Could not resolve dependencies for:");
    Assertions.assertThat(text).contains("com.google.code.XXXX : gson : 2.6.2");
}
Also used : ClassPathAddMvnCellMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.ClassPathAddMvnCellMagicCommand) Message(com.twosigma.beakerx.message.Message) ClassPathAddMvnCellMagicCommand(com.twosigma.beakerx.kernel.magic.command.functionality.ClassPathAddMvnCellMagicCommand) Code(com.twosigma.beakerx.kernel.Code) EvaluatorTest(com.twosigma.beakerx.evaluator.EvaluatorTest) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest)

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