use of com.twosigma.beakerx.kernel.magic.command.MagicCommand 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");
}
use of com.twosigma.beakerx.kernel.magic.command.MagicCommand 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");
}
use of com.twosigma.beakerx.kernel.magic.command.MagicCommand in project beakerx by twosigma.
the class CodeTest method shouldReadAllMagicCommands.
@Test
public void shouldReadAllMagicCommands() throws Exception {
// give
String allCode = "" + CLASSPATH_ADD_JAR + " lib1.jar\n" + CLASSPATH_ADD_JAR + " lib2.jar\n" + CLASSPATH_ADD_JAR + " lib3.jar\n" + "code code code";
// when
Code code = CodeFactory.create(allCode, new Message(), kernel);
// then
assertThat(code.getCodeFrames().size()).isEqualTo(4);
assertThat(((MagicCommand) code.getCodeFrames().get(0)).getCommand()).isEqualTo("%classpath add jar lib1.jar");
assertThat(((MagicCommand) code.getCodeFrames().get(1)).getCommand()).isEqualTo("%classpath add jar lib2.jar");
assertThat(((MagicCommand) code.getCodeFrames().get(2)).getCommand()).isEqualTo("%classpath add jar lib3.jar");
assertThat(((PlainCode) code.getCodeFrames().get(3)).getPlainCode()).isEqualTo("code code code");
}
use of com.twosigma.beakerx.kernel.magic.command.MagicCommand in project beakerx by twosigma.
the class CodeTest method shouldReadJavaScriptCommand.
@Test
public void shouldReadJavaScriptCommand() {
// give
String jsCode = "require.config({\n" + " paths: {\n" + " d3: '//cdnjs.cloudflare.com/ajax/libs/d3/3.4.8/d3.min'\n" + " }});";
// when
Code code = CodeFactory.create(JAVASCRIPT + "\n" + jsCode, new Message(), kernel);
// then
assertThat(code.getCodeFrames().size()).isEqualTo(1);
MagicCommand magicCommand = (MagicCommand) code.getCodeFrames().get(0);
assertThat(magicCommand.getCommand()).isEqualTo(JAVASCRIPT);
String toCompare = magicCommand.getCommandCodeBlock().replaceAll("\\s+", "");
jsCode = jsCode.replaceAll("\\s+", "");
assertThat(toCompare).isEqualTo(jsCode);
// assertThat(result.takeCodeWithoutCommand()).isEqualTo(new Code(jsCode));
}
Aggregations