org.mozilla.javascript.JavaScriptException Java Examples
The following examples show how to use
org.mozilla.javascript.JavaScriptException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StackTraceTest.java From rhino-android with Apache License 2.0 | 6 votes |
private void runWithExpectedStackTrace(final String _source, final String _expectedStackTrace) { final ContextAction action = new ContextAction() { public Object run(Context cx) { final Scriptable scope = cx.initStandardObjects(); try { cx.evaluateString(scope, _source, "test.js", 0, null); } catch (final JavaScriptException e) { assertEquals(_expectedStackTrace, e.getScriptStackTrace()); return null; } throw new RuntimeException("Exception expected!"); } }; Utils.runWithOptimizationLevel(action, -1); }
Example #2
Source File: TestConfigurationParserTest.java From celos with Apache License 2.0 | 6 votes |
@Test(expected = JavaScriptException.class) public void testAddTestCaseNoSampleTimeEnd() throws IOException { String configJS = "ci.addTestCase({\n" + " name: \"wordcount test case 1\",\n" + " sampleTimeStart: \"2013-11-20T18:00Z\",\n" + " inputs: [\n" + " ci.hdfsInput(ci.fixDirFromResource(\"src/test/celos-ci/test-1/input/plain/input/wordcount1\"), \"input/wordcount1\"),\n" + " ci.hdfsInput(ci.fixDirFromResource(\"src/test/celos-ci/test-1/input/plain/input/wordcount11\"), \"input/wordcount11\")\n" + " ],\n" + " outputs: [\n" + " ci.plainCompare(ci.fixDirFromResource(\"src/test/celos-ci/test-1/output/plain/output/wordcount1\"), \"output/wordcount1\")\n" + " ]\n" + "})\n"; TestConfigurationParser parser = new TestConfigurationParser(); parser.evaluateTestConfig(new StringReader(configJS), "string"); }
Example #3
Source File: TestConfigurationParserTest.java From celos with Apache License 2.0 | 6 votes |
@Test(expected = JavaScriptException.class) public void testAddTestCaseNoSampleTimeStart() throws IOException { String configJS = "ci.addTestCase({\n" + " name: \"wordcount test case 1\",\n" + " sampleTimeEnd: \"2013-11-20T18:00Z\",\n" + " inputs: [\n" + " ci.hdfsInput(ci.fixDirFromResource(\"src/test/celos-ci/test-1/input/plain/input/wordcount1\"), \"input/wordcount1\"),\n" + " ci.hdfsInput(ci.fixDirFromResource(\"src/test/celos-ci/test-1/input/plain/input/wordcount11\"), \"input/wordcount11\")\n" + " ],\n" + " outputs: [\n" + " ci.plainCompare(ci.fixDirFromResource(\"src/test/celos-ci/test-1/output/plain/output/wordcount1\"), \"output/wordcount1\")\n" + " ]\n" + "})\n"; TestConfigurationParser parser = new TestConfigurationParser(); parser.evaluateTestConfig(new StringReader(configJS), "string"); }
Example #4
Source File: TestConfigurationParserTest.java From celos with Apache License 2.0 | 6 votes |
@Test(expected = JavaScriptException.class) public void testAddTestCaseNoInput() throws IOException { String configJS = "ci.addTestCase({\n" + " name: \"wordcount test case 1\",\n" + " sampleTimeStart: \"2013-11-20T11:00Z\",\n" + " sampleTimeEnd: \"2013-11-20T18:00Z\",\n" + " outputs: [\n" + " ci.plainCompare(ci.fixDirFromResource(\"src/test/celos-ci/test-1/output/plain/output/wordcount1\"), \"output/wordcount1\")\n" + " ]\n" + "})\n"; TestConfigurationParser parser = new TestConfigurationParser(); parser.evaluateTestConfig(new StringReader(configJS), "string"); }
Example #5
Source File: TestConfigurationParserTest.java From celos with Apache License 2.0 | 6 votes |
@Test(expected = JavaScriptException.class) public void testAddTestCaseNoOutput() throws IOException { String configJS = "ci.addTestCase({\n" + " name: \"wordcount test case 1\",\n" + " sampleTimeStart: \"2013-11-20T11:00Z\",\n" + " sampleTimeEnd: \"2013-11-20T18:00Z\",\n" + " inputs: [\n" + " ci.hdfsInput(ci.fixDirFromResource(\"src/test/celos-ci/test-1/input/plain/input/wordcount1\"), \"input/wordcount1\"),\n" + " ci.hdfsInput(ci.fixDirFromResource(\"src/test/celos-ci/test-1/input/plain/input/wordcount11\"), \"input/wordcount11\")\n" + " ]\n" + "})\n"; TestConfigurationParser parser = new TestConfigurationParser(); parser.evaluateTestConfig(new StringReader(configJS), "string"); }
Example #6
Source File: JavascriptTestUtilities.java From cxf with Apache License 2.0 | 6 votes |
/** * Call a Javascript function, identified by name, on a set of arguments. Optionally, expect it to throw * an exception. * * @param expectingException * @param functionName * @param args * @return */ public Object rhinoCallExpectingException(final Object expectingException, final String functionName, final Object... args) { Object fObj = rhinoScope.get(functionName, rhinoScope); if (!(fObj instanceof Function)) { throw new RuntimeException("Missing test function " + functionName); } Function function = (Function)fObj; try { return function.call(rhinoContext, rhinoScope, rhinoScope, args); } catch (RhinoException angryRhino) { if (expectingException != null && angryRhino instanceof JavaScriptException) { JavaScriptException jse = (JavaScriptException)angryRhino; Assert.assertEquals(jse.getValue(), expectingException); return null; } String trace = angryRhino.getScriptStackTrace(); Assert.fail("JavaScript error: " + angryRhino.toString() + " " + trace); } catch (JavaScriptAssertionFailed assertion) { Assert.fail(assertion.getMessage()); } return null; }
Example #7
Source File: ScriptablePageVariables.java From birt with Eclipse Public License 1.0 | 6 votes |
/** * Support setting parameter value by following methods: */ public void put( String name, Scriptable start, Object value ) { PageVariable variable = variables.get( name ); if ( variable != null ) { if ( value instanceof Wrapper ) { value = ( (Wrapper) value ).unwrap( ); } variable.setValue( value ); return; } String errorMessage = "Report variable\"" + name + "\" does not exist"; throw new JavaScriptException( errorMessage, "<unknown>", -1 ); }
Example #8
Source File: StackTraceTest.java From astor with GNU General Public License v2.0 | 6 votes |
private void runWithExpectedStackTrace(final String _source, final String _expectedStackTrace) { final ContextAction action = new ContextAction() { public Object run(Context cx) { final Scriptable scope = cx.initStandardObjects(); try { cx.evaluateString(scope, _source, "test.js", 0, null); } catch (final JavaScriptException e) { assertEquals(_expectedStackTrace, e.getScriptStackTrace()); return null; } throw new RuntimeException("Exception expected!"); } }; Utils.runWithOptimizationLevel(action, -1); }
Example #9
Source File: DomBasedScriptingEngineFactory.java From lams with GNU General Public License v2.0 | 6 votes |
/** * load * @param response */ public void load( WebResponse response ) { Function onLoadEvent=null; try { Context context = Context.enter(); context.initStandardObjects( null ); HTMLDocument htmlDocument = ((DomWindow) response.getScriptingHandler()).getDocument(); if (!(htmlDocument instanceof HTMLDocumentImpl)) return; HTMLBodyElementImpl body = (HTMLBodyElementImpl) htmlDocument.getBody(); if (body == null) return; onLoadEvent = body.getOnloadEvent(); if (onLoadEvent == null) return; onLoadEvent.call( context, body, body, new Object[0] ); } catch (JavaScriptException e) { ScriptingEngineImpl.handleScriptException(e, onLoadEvent.toString()); // HttpUnitUtils.handleException(e); } catch (EcmaError ee) { //throw ee; ScriptingEngineImpl.handleScriptException(ee, onLoadEvent.toString()); } finally { Context.exit(); } }
Example #10
Source File: NativeJavaMap.java From birt with Eclipse Public License 1.0 | 5 votes |
public Object get( int index, Scriptable start ) { String key = Integer.valueOf( index ).toString( ); if ( has( key, start ) ) { return ( (Map) javaObject ).get( key ); } String errorMessage = CoreMessages.getFormattedString( ResourceConstants.JAVASCRIPT_NATIVE_NOT_FOUND, index ); throw new JavaScriptException( errorMessage, "<unknown>", -1 ); //$NON-NLS-1$ }
Example #11
Source File: JavaScriptFunctionsTest.java From celos with Apache License 2.0 | 5 votes |
@Test(expected = JavaScriptException.class) public void testHdfsCheckWrongType() throws Exception { String js = "var CELOS_DEFAULT_HDFS = ''; " + "var schTime = new Packages.com.collective.celos.ScheduledTime('2014-05-12T19:33:01Z');" + "var workflowId = new Packages.com.collective.celos.WorkflowID('id');" + "var slotId = 'slot';" + "celos.hdfsCheck('file:///tmp', slotId)"; Boolean s = (Boolean) runJS(js); Assert.assertEquals(s, true); }
Example #12
Source File: TestConfigurationParserTest.java From celos with Apache License 2.0 | 5 votes |
@Test (expected = JavaScriptException.class) public void testFixTableComparerFails2() throws IOException { String js = "ci.fixTableCompare();"; TestConfigurationParser parser = new TestConfigurationParser(); parser.evaluateTestConfig(new StringReader(js), "string"); }
Example #13
Source File: TestConfigurationParserTest.java From celos with Apache License 2.0 | 5 votes |
@Test (expected = JavaScriptException.class) public void testFixTableComparerFails1() throws IOException { String js = "var table1 = ci.fixTable([\"col1\", \"col2\"], [[\"row1\", \"row2\"],[\"row11\", \"row22\"]]);" + "ci.fixTableCompare(table1);"; TestConfigurationParser parser = new TestConfigurationParser(); parser.evaluateTestConfig(new StringReader(js), "string"); }
Example #14
Source File: TestConfigurationParserTest.java From celos with Apache License 2.0 | 5 votes |
@Test (expected = JavaScriptException.class) public void testExpandJsonNoParams() throws IOException { String js = "ci.expandJson()"; TestConfigurationParser parser = new TestConfigurationParser(); parser.evaluateTestConfig(new StringReader(js), "string"); }
Example #15
Source File: TestConfigurationParserTest.java From celos with Apache License 2.0 | 5 votes |
@Test (expected = JavaScriptException.class) public void testTableToTSVNoCreator() throws IOException { String js = "ci.tableToTSV()"; TestConfigurationParser parser = new TestConfigurationParser(); parser.evaluateTestConfig(new StringReader(js), "string"); }
Example #16
Source File: TestConfigurationParserTest.java From celos with Apache License 2.0 | 5 votes |
@Test (expected = JavaScriptException.class) public void testTableToJsonNoCreator() throws IOException { String js = "ci.tableToJson()"; TestConfigurationParser parser = new TestConfigurationParser(); parser.evaluateTestConfig(new StringReader(js), "string"); }
Example #17
Source File: TestConfigurationParserTest.java From celos with Apache License 2.0 | 5 votes |
@Test (expected = JavaScriptException.class) public void testHiveTableNoDb() throws IOException { String js = "ci.hiveTable()"; TestConfigurationParser parser = new TestConfigurationParser(); parser.evaluateTestConfig(new StringReader(js), "string"); }
Example #18
Source File: TestConfigurationParserTest.java From celos with Apache License 2.0 | 5 votes |
@Test (expected = JavaScriptException.class) public void testHiveTableNoTable() throws IOException { String js = "ci.hiveTable(\"dbname\")"; TestConfigurationParser parser = new TestConfigurationParser(); parser.evaluateTestConfig(new StringReader(js), "string"); }
Example #19
Source File: TestConfigurationParserTest.java From celos with Apache License 2.0 | 5 votes |
@Test(expected = JavaScriptException.class) public void testHiveInputFails() throws IOException { String js = "ci.hiveInput(\"tablename\", [[\"1\",\"2\",\"3\"],[\"11\",\"22\",\"33\"]])"; TestConfigurationParser parser = new TestConfigurationParser(); parser.evaluateTestConfig(new StringReader(js), "string"); }
Example #20
Source File: TestConfigurationParserTest.java From celos with Apache License 2.0 | 5 votes |
@Test(expected = JavaScriptException.class) public void testJsonCompareFails() throws IOException { TestConfigurationParser parser = new TestConfigurationParser(); NativeJavaObject creatorObj = (NativeJavaObject) parser.evaluateTestConfig(new StringReader("ci.jsonCompare(ci.fixDirFromResource(\"stuff\"))"), "string"); JsonContentsComparer comparer = (JsonContentsComparer) creatorObj.unwrap(); Assert.assertEquals(comparer.getIgnorePaths(), new HashSet(Lists.newArrayList("path1", "path2"))); }
Example #21
Source File: ScriptablePageVariables.java From birt with Eclipse Public License 1.0 | 5 votes |
public Object get( String name, Scriptable start ) { PageVariable variable = variables.get( name ); if ( variable != null ) { return variable.getValue( ); } String errorMessage = "Report variable\"" + name + "\" does not exist"; throw new JavaScriptException( errorMessage, "<unknown>", -1 ); }
Example #22
Source File: TestConfigurationParserTest.java From celos with Apache License 2.0 | 5 votes |
@Test(expected = JavaScriptException.class) public void testRecursiveFsObjectComparer3() throws IOException { TestConfigurationParser parser = new TestConfigurationParser(); NativeJavaObject creatorObj = (NativeJavaObject) parser.evaluateTestConfig(new StringReader("ci.plainCompare(ci.fixFileFromResource(\"stuff\"))"), "string"); RecursiveFsObjectComparer creator = (RecursiveFsObjectComparer) creatorObj.unwrap(); }
Example #23
Source File: TestConfigurationParserTest.java From celos with Apache License 2.0 | 5 votes |
@Test(expected = JavaScriptException.class) public void testRecursiveFsObjectComparer1() throws IOException { TestConfigurationParser parser = new TestConfigurationParser(); NativeJavaObject creatorObj = (NativeJavaObject) parser.evaluateTestConfig(new StringReader("ci.plainCompare()"), "string"); RecursiveFsObjectComparer creator = (RecursiveFsObjectComparer) creatorObj.unwrap(); }
Example #24
Source File: TestConfigurationParserTest.java From celos with Apache License 2.0 | 5 votes |
@Test(expected = JavaScriptException.class) public void testHdfsInputDeployerCall1() throws IOException { TestConfigurationParser parser = new TestConfigurationParser(); NativeJavaObject creatorObj = (NativeJavaObject) parser.evaluateTestConfig(new StringReader("ci.hdfsInput()"), "string"); HdfsInputDeployer creator = (HdfsInputDeployer) creatorObj.unwrap(); Assert.assertEquals(new File("stuff"), creator.getPath()); }
Example #25
Source File: TestConfigurationParserTest.java From celos with Apache License 2.0 | 5 votes |
@Test(expected = JavaScriptException.class) public void fixFileFromResourceFails() throws IOException { TestConfigurationParser parser = new TestConfigurationParser(); NativeJavaObject creatorObj = (NativeJavaObject) parser.evaluateTestConfig(new StringReader("ci.fixFileFromResource()"), "string"); FixFileFromResourceCreator creator = (FixFileFromResourceCreator) creatorObj.unwrap(); Assert.assertEquals(new File("stuff"), creator.getPath(testRun)); }
Example #26
Source File: TestConfigurationParserTest.java From celos with Apache License 2.0 | 5 votes |
@Test(expected = JavaScriptException.class) public void fixDirFromResourceFails() throws IOException { TestConfigurationParser parser = new TestConfigurationParser(); NativeJavaObject creatorObj = (NativeJavaObject) parser.evaluateTestConfig(new StringReader("ci.fixDirFromResource()"), "string"); FixDirFromResourceCreator creator = (FixDirFromResourceCreator) creatorObj.unwrap(); Assert.assertEquals(new File("/stuff"), creator.getPath(testRun)); }
Example #27
Source File: LessCompiler.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
/** * Compiles the LESS input <code>String</code> to CSS. * * @param input The LESS input <code>String</code> to compile. * @return The CSS. */ public String compile(final String input) throws LessException { synchronized(this){ if (scope == null) { init(); } } final long start = System.currentTimeMillis(); try { final Context cx = Context.enter(); final Object result = doIt.call(cx, scope, null, new Object[]{input, compress}); if (log.isDebugEnabled()) { log.debug("Finished compilation of LESS source in " + (System.currentTimeMillis() - start) + " ms."); } return result.toString(); } catch (final Exception e) { if (e instanceof JavaScriptException) { final Scriptable value = (Scriptable)((JavaScriptException)e).getValue(); if (value != null && ScriptableObject.hasProperty(value, "message")) { final String message = ScriptableObject.getProperty(value, "message").toString(); throw new LessException(message, e); } } throw new LessException(e); }finally{ Context.exit(); } }
Example #28
Source File: ScriptableParameters.java From birt with Eclipse Public License 1.0 | 5 votes |
public Object get( String name, Scriptable start ) { Object result = getScriptableParameter( name ); if ( result == null ) { String errorMessage = CoreMessages.getFormattedString( ResourceConstants.JAVASCRIPT_PARAMETER_NOT_EXIST, name ); throw new JavaScriptException( errorMessage, "<unknown>", -1 ); } return result; }
Example #29
Source File: NativeJavaMap.java From birt with Eclipse Public License 1.0 | 5 votes |
public Object get( String name, Scriptable start ) { if ( "length".equals( name ) ) { return Integer.valueOf( ( (Map) javaObject ).size( ) ); } if ( has( name, start ) ) { return ( (Map) javaObject ).get( name ); } String errorMessage = CoreMessages.getFormattedString( ResourceConstants.JAVASCRIPT_NATIVE_NOT_FOUND, name ); throw new JavaScriptException( errorMessage, "<unknown>", -1 ); //$NON-NLS-1$ }
Example #30
Source File: TestConfigurationParserTest.java From celos with Apache License 2.0 | 4 votes |
@Test(expected = JavaScriptException.class) public void testAvroToJsonFails() throws IOException { TestConfigurationParser parser = new TestConfigurationParser(); parser.evaluateTestConfig(new StringReader("ci.avroToJson()"), "string"); }