AntRunAction extends AbstractTestAction { public String getTarget() { return target; } private  AntRunAction(Builder builder); @Override void doExecute(TestContext context); String getBuildFilePath(); String getTarget(); String getTargets(); Properties getProperties(); String getPropertyFilePath(); BuildListener getBuildListener();  }
@Test public void testRunTarget() { AntRunAction ant = new AntRunAction.Builder() .buildFilePath("classpath:com/consol/citrus/actions/build.xml") .target("sayHello") .listener(new AssertingBuildListener() { @Override public void taskStarted(BuildEvent event) { Assert.assertEquals(event.getTarget().getName(), "sayHello"); } @Override public void messageLogged(BuildEvent event) { if (event.getTask() != null && event.getTask().getTaskName().equals("echo")) { Assert.assertEquals(event.getMessage(), "Welcome to Citrus!"); } } }) .build(); ant.execute(context); }
@Test public void testRunTargets() { final List<String> executedTargets = new ArrayList<String>(); final List<String> echoMessages = new ArrayList<String>(); AntRunAction ant = new AntRunAction.Builder() .buildFilePath("classpath:com/consol/citrus/actions/build.xml") .targets("sayHello,sayGoodbye") .listener(new AssertingBuildListener() { @Override public void taskStarted(BuildEvent event) { executedTargets.add(event.getTarget().getName()); } @Override public void messageLogged(BuildEvent event) { if (event.getTask() != null && event.getTask().getTaskName().equals("echo")) { echoMessages.add(event.getMessage()); } } }) .build(); ant.execute(context); Assert.assertEquals(executedTargets.size(), 2L); Assert.assertEquals(executedTargets.get(0), "sayHello"); Assert.assertEquals(executedTargets.get(1), "sayGoodbye"); Assert.assertEquals(echoMessages.size(), 2L); Assert.assertEquals(echoMessages.get(0), "Welcome to Citrus!"); Assert.assertEquals(echoMessages.get(1), "Goodbye!"); }
@Test public void testWithProperties() { final Properties props = new Properties(); props.put("welcomeText", "Welcome!"); AntRunAction ant = new AntRunAction.Builder() .buildFilePath("classpath:com/consol/citrus/actions/build.xml") .target("sayHello") .properties(props) .listener(new AssertingBuildListener() { @Override public void taskStarted(BuildEvent event) { Assert.assertEquals(event.getTarget().getName(), "sayHello"); } @Override public void messageLogged(BuildEvent event) { if (event.getTask() != null && event.getTask().getTaskName().equals("echo")) { Assert.assertEquals(event.getMessage(), "Welcome!"); } } }) .build(); ant.execute(context); }
@Test public void testWithPropertyFile() { AntRunAction ant = new AntRunAction.Builder() .buildFilePath("classpath:com/consol/citrus/actions/build.xml") .target("sayHello") .propertyFile("classpath:com/consol/citrus/actions/build.properties") .listener(new AssertingBuildListener() { @Override public void taskStarted(BuildEvent event) { Assert.assertEquals(event.getTarget().getName(), "sayHello"); } @Override public void messageLogged(BuildEvent event) { if (event.getTask() != null && event.getTask().getTaskName().equals("echo")) { Assert.assertEquals(event.getMessage(), "Welcome with property file!"); } } }) .build(); ant.execute(context); }
@Test public void testWithPropertyOverwrite() { final Properties props = new Properties(); props.put("welcomeText", "Welcome!"); AntRunAction ant = new AntRunAction.Builder() .buildFilePath("classpath:com/consol/citrus/actions/build.xml") .target("sayHello") .properties(props) .propertyFile("classpath:com/consol/citrus/actions/build.properties") .listener(new AssertingBuildListener() { @Override public void taskStarted(BuildEvent event) { Assert.assertEquals(event.getTarget().getName(), "sayHello"); } @Override public void messageLogged(BuildEvent event) { if (event.getTask() != null && event.getTask().getTaskName().equals("echo")) { Assert.assertEquals(event.getMessage(), "Welcome with property file!"); } } }) .build(); ant.execute(context); }
@Test public void testWithNoPropertyDefault() { final Properties props = new Properties(); props.put("checked", "true"); AntRunAction ant = new AntRunAction.Builder() .buildFilePath("classpath:com/consol/citrus/actions/build.xml") .target("checkMe") .properties(props) .listener(new AssertingBuildListener() { @Override public void taskStarted(BuildEvent event) { Assert.assertEquals(event.getTarget().getName(), "checkMe"); } }) .build(); ant.execute(context); }