Exemplo n.º 1
0
 @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);
 }
Exemplo n.º 2
0
  @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);
  }
Exemplo n.º 3
0
  @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);
  }
Exemplo n.º 4
0
  @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);
  }
Exemplo n.º 5
0
  @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);
  }
Exemplo n.º 6
0
  @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");
  }
Exemplo n.º 7
0
 @Test(expectedExceptions = {CitrusRuntimeException.class})
 public void testScriptFailure() {
   GroovyAction bean = new GroovyAction();
   bean.setScript("Some wrong script");
   bean.execute(context);
 }
Exemplo n.º 8
0
 @Test
 public void testScript() {
   GroovyAction bean = new GroovyAction();
   bean.setScript("println 'Hello TestFramework!'");
   bean.execute(context);
 }