  @Test
  public void testWriteCoordinator() throws Exception {

    ByteArrayOutputStream output = new ByteArrayOutputStream();

    SchedulableJobManager manager = JobManagers.createSchedulable(testSchedule,
        new AppContext(new Configuration()));

    OozieScheduling.writeCoordinator(testSchedule, manager, output);

    Document coord = XMLUtil.toDom(output);

    XPath xpath = XMLUtil.getXPath();

    assertEquals(testSchedule.getFrequency(),
        xpath.evaluate("coord:coordinator-app/@frequency", coord));

    // check for the input and output datasets
    assertEquals(xpath.evaluate("coord:coordinator-app/coord:datasets/" +
            "coord:dataset[@name = \"ds_source_users\"]/coord:uri-template", coord),
        ScheduledInputOutputApp.INPUT_URI_PATTERN);

    assertEquals(xpath.evaluate("coord:coordinator-app/coord:datasets/" +
            "coord:dataset[@name = \"ds_target_users\"]/coord:uri-template", coord),
        ScheduledInputOutputApp.OUTPUT_URI_PATTERN);

    assertEquals("${coord:current(0)}",
        xpath.evaluate("coord:coordinator-app/coord:input-events/coord:data-in/coord:instance",
            coord));

    assertEquals("${coord:current(0)}",
        xpath.evaluate("coord:coordinator-app/coord:output-events/coord:data-out/coord:instance",
            coord));

    assertEquals("${kiteAppRoot}/oozie/workflows/scheduled-input-output",
        xpath.evaluate("coord:coordinator-app/coord:action/coord:workflow/coord:app-path", coord));

    // Check the nominal time is set for the workflow.
    assertEquals("${coord:nominalTime()}",
        xpath.evaluate("coord:coordinator-app/coord:action/coord:workflow/coord:configuration/" +
            "coord:property/coord:value[../coord:name/text() = \"coordNominalTime\"]", coord));

    // Check data input and output properties are set for the workflow.
    assertEquals("${coord:dataIn('datain_source_users')}",
        xpath.evaluate("coord:coordinator-app/coord:action/coord:workflow/coord:configuration/" +
            "coord:property/coord:value[../coord:name/text() = \"coord_source_users\"]", coord));

    assertEquals("${coord:dataOut('dataout_target_users')}",
        xpath.evaluate("coord:coordinator-app/coord:action/coord:workflow/coord:configuration/" +
            "coord:property/coord:value[../coord:name/text() = \"coord_target_users\"]", coord));
  }