@Test public void testAutomaticScriptExecutorWrapper() { GroovyAction bean = new GroovyAction(); bean.setScript( "context.setVariable('text', 'Automatic script wrapping works!')\n" + "println context.getVariable('text')"); bean.execute(context); }
@Test public void testCustomScriptTemplate() { GroovyAction bean = new GroovyAction(); bean.setScriptTemplateResource( new ClassPathResource("custom-script-template.groovy", GroovyActionTest.class)); bean.setScript("Assert.assertEquals(context.getVariable('scriptTemplateVar'), 'It works!')"); bean.execute(context); }
@Test public void testNoScriptTemplate() { GroovyAction bean = new GroovyAction(); bean.setUseScriptTemplate(false); String script = "println 'Just executed pure groovy code'"; bean.setScript(script); bean.execute(context); }
@Test public void testCustomClassImplementation() { GroovyAction bean = new GroovyAction(); String script = "public class CustomClass {\n" + "public void run() {\n" + "println 'Just executed custom class implementation'\n" + "}}"; bean.setScript(script); bean.execute(context); }
@Test public void testCustomScriptExecutorImplementation() { GroovyAction bean = new GroovyAction(); String script = "import com.consol.citrus.*\n" + "import com.consol.citrus.variable.*\n" + "import com.consol.citrus.context.TestContext\n" + "import com.consol.citrus.script.GroovyAction.ScriptExecutor\n\n" + "public class GScript implements ScriptExecutor {\n" + "public void execute(TestContext context) {\n" + "context.setVariable('text', 'Script with class definition test successful.')\n" + "println context.getVariable('text')\n" + "}}"; bean.setScript(script); bean.execute(context); }
@Test public void testInvalidScriptTemplate() { GroovyAction bean = new GroovyAction(); bean.setScriptTemplateResource( new ClassPathResource("invalid-script-template.groovy", GroovyActionTest.class)); bean.setScript("println 'This should not work!'"); try { bean.execute(context); } catch (CitrusRuntimeException e) { Assert.assertTrue(e.getMessage().startsWith("Invalid script template")); return; } Assert.fail("Missing exception because of invalid script template"); }
@Test(expectedExceptions = {CitrusRuntimeException.class}) public void testScriptFailure() { GroovyAction bean = new GroovyAction(); bean.setScript("Some wrong script"); bean.execute(context); }
@Test public void testScript() { GroovyAction bean = new GroovyAction(); bean.setScript("println 'Hello TestFramework!'"); bean.execute(context); }