public ScriptingServiceImpl() { // assertion: Jython should not be registered yet if (!supportsScriptLanguage(ScriptLanguage.Jython)) { // ScriptingUtils.setJVMPropertiesForJython270Support(); engineManager.registerEngineName( ScriptLanguage.Jython.getName(), new PyScriptEngineFactory()); } if (!supportsScriptLanguage(ScriptLanguage.Python)) { engineManager.registerEngineName( ScriptLanguage.Python.getName(), new PythonScriptEngineFactory()); } }
@Test public void execute() throws Exception { final GroovyConfiguration configuration = getComponentManager().getInstance(GroovyConfiguration.class); final CompilationCustomizer customizer = getMockery().mock(CompilationCustomizer.class); getMockery() .checking( new Expectations() { { oneOf(configuration).getCompilationCustomizers(); will(returnValue(Arrays.asList(customizer))); // Simulate a Compilation Customizer that throws an error. This would happend for // example with a Secure // Customizer that would prevent executing some statements for example. oneOf(customizer).getPhase(); will(returnValue(CompilePhase.CANONICALIZATION)); oneOf(customizer).needSortedInput(); will(returnValue(false)); oneOf(customizer) .call( with(any(SourceUnit.class)), with(any(GeneratorContext.class)), with(any(ClassNode.class))); will(throwException(new SecurityException("test exception"))); } }); ScriptEngineManager manager = new ScriptEngineManager(); manager.registerEngineName("groovy", getMockedComponent()); ScriptEngine engine = manager.getEngineByName("groovy"); try { engine.eval("def dummy"); } catch (ScriptException expected) { Assert.assertTrue(expected.getMessage().contains("test exception")); } }