### Question:
GroovyEngine implements ScriptingEngine { @Override public CompletableFuture<Void> runPrivilegedScript(String script, Wot wot, ExecutorService executorService) { Binding binding = new Binding(); binding.setVariable("wot", wot); CompilerConfiguration config = getPrivilegedCompilerConfiguration(); GroovyShell shell = new GroovyShell(binding, config); Script groovyScript = shell.parse(script); CompletableFuture<Void> completionFuture = new CompletableFuture<>(); executorService.submit(() -> { try { groovyScript.run(); completionFuture.complete(null); } catch (RuntimeException e) { completionFuture.completeExceptionally(new ScriptingEngineException(e)); } }); return completionFuture; }  @Override String getMediaType(); @Override String getFileExtension(); @Override CompletableFuture<Void> runScript(String script,
                                             Wot wot,
                                             ExecutorService executorService); @Override CompletableFuture<Void> runPrivilegedScript(String script,
                                                       Wot wot,
                                                       ExecutorService executorService);  }### Answer:
@Test public void runPrivilegedScriptShouldNotFailOnValidScript() throws WotException, ExecutionException, InterruptedException { String script = "def thing = [\n" + " id : 'KlimabotschafterWetterstation',\n" + " title : 'KlimabotschafterWetterstation',\n" + " '@type' : 'Thing',\n" + " '@context': [\n" + " 'http: " [\n" + " om : 'http: " saref: 'https: " sch : 'http: " sane : 'https: " ]\n" + " ],\n" + "]\n" + "\n" + "def exposedThing = wot.produce(thing)\n" + "\n" + "exposedThing.addProperty(\n" + " 'Temp_2m',\n" + " [\n" + " '@type' : 'saref:Temperature',\n" + " description : 'Temperatur in 2m in Grad Celsisus',\n" + " 'om:unit_of_measure': 'om:degree_Celsius',\n" + " type : 'number',\n" + " readOnly : true,\n" + " observable : true\n" + " ]\n" + ")\n" + "println(exposedThing.toJson(true))"; DefaultWot wot = new DefaultWot(); engine.runPrivilegedScript(script, wot, executorService).get(); assertTrue(true); }
@Test(expected = ScriptingEngineException.class) public void runPrivilegedScriptShouldFailOnInvalidScript() throws Throwable { String script = "wot.dahsjkdhajkdhajkdhasjk()"; DefaultWot wot = new DefaultWot(); try { engine.runPrivilegedScript(script, wot, executorService).get(); } catch (InterruptedException | ExecutionException e) { throw e.getCause(); } }
@Test public void runPrivilegedScriptShouldAutoImportServientClasses() throws WotException, ExecutionException, InterruptedException { String script = "new Thing()"; DefaultWot wot = new DefaultWot(); engine.runPrivilegedScript(script, wot, executorService).get(); assertTrue(true); }