GroovyConditionShell implements ConditionShell { @Override public ConditionScript parse(final String script) throws ConditionParsingException { if (StringUtils.isEmpty(script)) { throw new IllegalArgumentException("Script is null or empty."); } try { Script groovyScript = this.shell.parse(script); return new GroovyConditionScript(groovyScript); } catch (CompilationFailedException e) { throw new ConditionParsingException("Failed to validate the condition script.", script, e); } } GroovyConditionShell(); @Override ConditionScript parse(final String script);  }
@Test public void testValidateScriptWithValidScript() throws ConditionParsingException { String script = "\"a\".equals(\"a\")"; ConditionScript parsedScript = this.shell.parse(script); Assert.assertNotNull(parsedScript); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testValidateEmptyScript() throws ConditionParsingException { String script = ""; this.shell.parse(script); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testValidateNullScript() throws ConditionParsingException { ConditionScript parsedScript = this.shell.parse(null); Assert.assertNotNull(parsedScript); }
@Test public void testValidateScriptWithForLoop() throws ConditionParsingException { String script = "for (int i = 0; i < 5; i++) {}"; this.shell.parse(script); }
@Test(expectedExceptions = ConditionParsingException.class) public void testValidateScriptWithSystemInvocation() throws ConditionParsingException { String script = "System.exit(0)"; this.shell.parse(script); }
@Test(expectedExceptions = ConditionParsingException.class) public void testValidateScriptWithReflection() throws ConditionParsingException { String script = "((System)(Class.forName(\"java.lang.System\")).newInstance()).exit(0);"; this.shell.parse(script); }
@Test(expectedExceptions = ConditionParsingException.class) public void testParseScriptWithThreadInvocation() throws ConditionParsingException { String script = "Thread.currentThread().toString()"; this.shell.parse(script); }
@Test(expectedExceptions = ConditionParsingException.class) public void testParseScriptWithSystemInvocation1() throws ConditionParsingException { String script = "def c = System; c.exit(-1);"; this.shell.parse(script); }
@Test(expectedExceptions = ConditionParsingException.class) public void testParseScriptWithSystemInvocation2() throws ConditionParsingException { String script = "((Object)System).exit(-1);"; this.shell.parse(script); }
@Test(expectedExceptions = ConditionParsingException.class) public void testParseScriptWithSystemInvocation3() throws ConditionParsingException { String script = "Class.forName('java.lang.System').exit(-1);"; this.shell.parse(script); }
@Test(expectedExceptions = ConditionParsingException.class) public void testParseScriptWithSystemInvocation4() throws ConditionParsingException { String script = "('java.lang.System' as Class).exit(-1);"; this.shell.parse(script); }
@Test(expectedExceptions = ConditionParsingException.class) public void testParseScriptWithSystemInvocation5() throws ConditionParsingException { String script = "import static java.lang.System.exit; exit(-1);"; this.shell.parse(script); }
@Test(expectedExceptions = ConditionParsingException.class) public void testParseScriptWithEval() throws ConditionParsingException { String script = "Eval.me(' 2 * 4 + 2');"; this.shell.parse(script); }
@Test(expectedExceptions = ConditionParsingException.class) public void testParseScriptWithStringExecute() throws ConditionParsingException { String script = "'env'.execute();"; this.shell.parse(script); }