@Test
  public void testJobDeployUndeployFlow() throws InterruptedException {
    logger.info("Create batch job");
    JobParametersHolder.reset();
    final JobParametersHolder jobParametersHolder = new JobParametersHolder();
    String jobName = generateJobName();
    executeJobCreate(jobName, JOB_WITH_PARAMETERS_DESCRIPTOR, false);

    checkForJobInList(jobName, JOB_WITH_PARAMETERS_DESCRIPTOR, false);
    CommandResult cr = deployJob(jobName);
    checkForSuccess(cr);
    checkDeployedJobMessage(cr, jobName);
    triggerJob(jobName);
    assertTrue("Job did not complete within time alotted", jobParametersHolder.isDone());

    checkForJobInList(jobName, JOB_WITH_PARAMETERS_DESCRIPTOR, true);

    cr = undeployJob(jobName);
    checkForSuccess(cr);
    checkUndeployedJobMessage(cr, jobName);

    cr = deployJob(jobName);
    checkForSuccess(cr);
    assertEquals("Deployed job '" + jobName + "'", cr.getResult());

    checkForJobInList(jobName, JOB_WITH_PARAMETERS_DESCRIPTOR, true);
  }
  @Test
  public void testListRuntimeModulesByContainerId() {
    logger.info("Test listing of runtime modules by containerId");
    String streamName = "foo-runtimeModulesByContainerIdTest";
    stream().create(streamName, "time | log");

    Table table = (Table) executeCommand("runtime modules").getResult();
    List<TableRow> runtimeModules = new ArrayList<TableRow>();
    for (TableRow row : table.getRows()) {
      // match by group name
      if (row.getValue(2).equals(streamName)) {
        runtimeModules.add(row);
      }
    }
    // Get containerId for a runtime module
    String containerId = runtimeModules.get(0).getValue(1);
    CommandResult cmdResult = executeCommand("runtime modules --containerId " + containerId);
    Table table1 = (Table) cmdResult.getResult();
    List<TableRow> fooStreamModules = new ArrayList<TableRow>();
    for (TableRow row : table1.getRows()) {
      // Verify all the rows have the same containerId
      assertTrue(row.getValue(1).equals(containerId));
      // match by group name
      if (row.getValue(2).equals(runtimeModules.get(0).getValue(2))) {
        fooStreamModules.add(row);
      }
    }
    // Verify the module is listed for the containerId
    assertTrue(!fooStreamModules.isEmpty());
  }
 public CommandResult executeCommand(String command) {
   CommandResult cr = this.shell.executeCommand(command);
   if (cr.getException() != null) {
     cr.getException().printStackTrace();
   }
   Assert.isTrue(cr.isSuccess(), "Failure.  CommandResult = " + cr.toString());
   return cr;
 }
 @Test
 public void testListRuntimeModulesByInvalidContainerId() {
   logger.info("Test listing of runtime modules by invalid containerId");
   String streamName = "foo-runtimeModulesByInvalidContainerIdTest";
   stream().create(streamName, "time | log");
   CommandResult cmdResult = executeCommand("runtime modules --containerId 10000");
   Table table = (Table) cmdResult.getResult();
   assertEquals(0, table.getRows().size());
 }
  @Test
  public void testSimple() {
    Bootstrap bootstrap = new Bootstrap();

    JLineShellComponent shell = bootstrap.getJLineShellComponent();

    CommandResult cr = shell.executeCommand("hw simple --message hello");
    assertEquals(true, cr.isSuccess());
    assertEquals("Message = [hello] Location = [null]", cr.getResult());
  }
 @Test
 public void testLaunchNotDeployedJob() {
   logger.info("Launch batch job that is not deployed");
   String jobName = generateJobName();
   executeJobCreate(jobName, JOB_WITH_PARAMETERS_DESCRIPTOR, false);
   CommandResult result = executeCommandExpectingFailure("job launch --name " + jobName);
   assertThat(
       result.getException().getMessage(),
       containsString(String.format("The job named '%s' is not currently deployed", jobName)));
 }
 @Test
 public void testListContainers() {
   logger.info("List runtime containers");
   CommandResult cmdResult = executeCommand("runtime containers");
   Table table = (Table) cmdResult.getResult();
   for (TableRow row : table.getRows()) {
     // Verify host name & ip address are not empty
     assertTrue(!StringUtils.isEmpty(row.getValue(2)) && !StringUtils.isEmpty(row.getValue(3)));
   }
   // Verify there should be at least one container in the list.
   assertTrue(table.getRows().size() > 0);
 }
 @Test
 public void testListRuntimeModules() {
   logger.info("List runtime modules");
   String streamName = "foo-runtimeModulesTest";
   stream().create(streamName, "time | log");
   CommandResult cmdResult = executeCommand("runtime modules");
   Table table = (Table) cmdResult.getResult();
   List<TableRow> fooStreamModules = new ArrayList<TableRow>();
   for (TableRow row : table.getRows()) {
     // match by group name
     if (row.getValue(2).equals(streamName)) {
       fooStreamModules.add(row);
     }
   }
   assertEquals(2, fooStreamModules.size());
 }
  @Test
  public void testLaunchJobTwiceWhereMakeUniqueIsFalse() throws Exception {
    logger.info("Launch batch job (makeUnique=false) twice");
    String jobName = generateJobName();
    // Batch 3.0 requires at least one parameter to reject duplicate executions of an instance
    String myJobParams = "{\"-param(long)\":\"12345\"}";
    JobParametersHolder.reset();
    final JobParametersHolder jobParametersHolder = new JobParametersHolder();

    executeJobCreate(jobName, JOB_WITH_PARAMETERS_DESCRIPTOR + " --makeUnique=false");
    checkForJobInList(jobName, JOB_WITH_PARAMETERS_DESCRIPTOR + " --makeUnique=false", true);
    executeJobLaunch(jobName, myJobParams);
    assertTrue("The countdown latch expired and did not count down.", jobParametersHolder.isDone());

    CommandResult result =
        executeCommandExpectingFailure("job launch --name " + jobName + " --params " + myJobParams);
    assertThat(
        result.getException().getMessage(),
        containsString(
            "A job instance already exists and is complete for parameters={param=12345}."
                + "  If you want to run this job again, change the parameters."));
  }