diff --git a/test/notebooks/groovy/KernelAPITest.ipynb b/test/notebooks/groovy/KernelAPITest.ipynb new file mode 100644 index 0000000000..7c75325487 --- /dev/null +++ b/test/notebooks/groovy/KernelAPITest.ipynb @@ -0,0 +1,135 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Load Magic Command" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "%classpath add jar ../../../doc/resources/jar/loadMagicJarDemo.jar" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "%load_magic com.twosigma.beakerx.custom.magic.command.ShowEnvsCustomMagicCommand" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "%showEnvs" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Show Null Execution Result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "com.twosigma.beakerx.kernel.Kernel.showNullExecutionResult" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "com.twosigma.beakerx.kernel.Kernel.showNullExecutionResult = true;\n", + "String seeNullString = null;\n", + "seeNullString" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "com.twosigma.beakerx.kernel.Kernel.showNullExecutionResult = false;\n", + "String noNullString = null;\n", + "noNullString" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# JVM Repr" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import jupyter.Displayer;\n", + "import jupyter.Displayers;\n", + "Displayers.register(Integer.class, new Displayer() {\n", + " @Override\n", + " public Map display(Integer value) {\n", + " return new HashMap() {{\n", + " put(MIMEContainer.MIME.TEXT_HTML, \"

\" + value + \"

\");\n", + "\n", + " }};\n", + " }\n", + "});" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "1+1" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Groovy", + "language": "groovy", + "name": "groovy" + }, + "language_info": { + "codemirror_mode": "groovy", + "file_extension": ".groovy", + "mimetype": "", + "name": "Groovy", + "nbconverter_exporter": "", + "version": "2.4.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/test/tests/groovy/kernelAPITest.js b/test/tests/groovy/kernelAPITest.js new file mode 100644 index 0000000000..bb8876ac4c --- /dev/null +++ b/test/tests/groovy/kernelAPITest.js @@ -0,0 +1,108 @@ +/* + * Copyright 2017 TWO SIGMA OPEN SOURCE, LLC + * + * Licensed 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. + */ + +var BeakerXPageObject = require('../beakerx.po.js'); +var beakerxPO; + +describe('(Groovy) Testing of Kernel API', function () { + + beforeAll(function () { + beakerxPO = new BeakerXPageObject(); + beakerxPO.runNotebookByUrl('/notebooks/test/notebooks/groovy/KernelAPITest.ipynb'); + }, 2); + + afterAll(function () { + beakerxPO.closeAndHaltNotebook(); + }); + + var cellIndex; + + describe('(Groovy) Adding jar file', function () { + + var testValues = { + loadJarSuccess: 'Added jar: [loadMagicJarDemo.jar]', + magicCommandSuccess: 'Magic command %showEnvs was successfully added.', + envs: '{PATH=' + }; + + it('Jar file is loaded correctly', function () { + cellIndex = 0; + var output = beakerxPO.runCellToGetOutputTextElement(cellIndex); + expect(output.isEnabled()).toBeTruthy(); + expect(output.getText()).toBe(testValues.loadJarSuccess); + }); + + it('Magic command is added successfully', function () { + cellIndex += 1; + var output = beakerxPO.runCellToGetOutputTextElement(cellIndex); + expect(output.isEnabled()).toBeTruthy(); + expect(output.getText()).toBe(testValues.magicCommandSuccess); + }); + + it('Envs are displayed correctly', function () { + cellIndex += 1; + var output = beakerxPO.runCellToGetOutputTextElement(cellIndex); + expect(output.isEnabled()).toBeTruthy(); + expect(output.getText()).toContain(testValues.envs); + }); + }); + + describe('(Groovy) Show null execution result as true', function() { + it('Cell displays true output', function () { + cellIndex += 1; + var codeCell = beakerxPO.runCodeCellByIndex(cellIndex); + + expect(codeCell.$('div.output_result').isEnabled()).toBeTruthy(); + expect(codeCell.$('div.output_result').getText()).toBe('true'); + }); + }); + + describe('(Groovy) Show null execution result as null', function() { + it('Cell displays null output', function () { + cellIndex += 1; + var codeCell = beakerxPO.runCodeCellByIndex(cellIndex); + + expect(codeCell.$('div.output_result').isEnabled()).toBeTruthy(); + expect(codeCell.$('div.output_result').getText()).toBe('null'); + }); + }); + + describe('(Groovy) Do not show null execution result', function() { + it('Cell displays no output', function () { + cellIndex += 1; + var codeCell = beakerxPO.runCodeCellByIndex(cellIndex); + + expect(codeCell.$('div.output').getText()).toBe(''); + }); + }); + + describe('(Groovy) Jvm Repr', function() { + it('Displayer is properly loaded', function() { + cellIndex += 1; + var codeCell = beakerxPO.runCodeCellByIndex(cellIndex); + + expect(codeCell.$('div.output').getText()).toBe(''); + }); + + it('Cell displays proper output', function() { + cellIndex += 1; + var codeCell = beakerxPO.runCodeCellByIndex(cellIndex); + + expect(codeCell.$('div.output_result').getText()).toBe('2'); + + }); + }); +}); \ No newline at end of file