示例#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);
 }
示例#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);
  }
示例#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);
  }
示例#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);
  }
示例#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);
  }
示例#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");
  }
示例#7
0
 @Test(expectedExceptions = {CitrusRuntimeException.class})
 public void testScriptResourceNotFound() {
   GroovyAction bean = new GroovyAction();
   bean.setFileResource(new FileSystemResource("some/wrong/path/test.groovy"));
   bean.execute(context);
 }
示例#8
0
 @Test(expectedExceptions = {CitrusRuntimeException.class})
 public void testScriptFailure() {
   GroovyAction bean = new GroovyAction();
   bean.setScript("Some wrong script");
   bean.execute(context);
 }
示例#9
0
 @Test
 public void testScriptResource() {
   GroovyAction bean = new GroovyAction();
   bean.setFileResource(new ClassPathResource("com/consol/citrus/script/example.groovy"));
   bean.execute(context);
 }
示例#10
0
 @Test
 public void testScript() {
   GroovyAction bean = new GroovyAction();
   bean.setScript("println 'Hello TestFramework!'");
   bean.execute(context);
 }