@Test
  public void testCicsParser() {
    OurConfiguration configuration = createConfiguration();

    String cicsParser =
        "<MapTransform>"
            + "  <PatternNode key='CICS.OPCLASS' pattern='OPCLASS= (.*?\\s*\\n(?:\\s{10}[^\\n]*\\n)*)' optional='true' reset='false'>"
            + "     <SplitTransform splitPattern='\\s+'/>"
            + "  </PatternNode>"
            + "  <PatternNode key='CICS.OPIDENT' pattern='OPIDENT= (.*?)\\s*\\n' optional='true' reset='false'/>"
            + "  <PatternNode key='CICS.OPPRTY'  pattern='OPPRTY= (.*?)\\s*\\n' optional='true' reset='false'/>"
            + "  <PatternNode key='CICS.TIMEOUT' pattern='TIMEOUT= (.*?)\\s*\\n' optional='true' reset='false'/>"
            + "  <PatternNode key='CICS.XRFSOFF' pattern='XRFSOFF= (.*?)\\s*\\n' optional='true' reset='false'/>"
            + "</MapTransform>";

    try {
      RW3270Connection connection = createLoggedinConnection(configuration);
      try {
        // Now, display a user's CICS info
        //
        String command = "LISTUSER CICSUSER NORACF CICS";
        String line = executeCommand(connection, command);
        MapTransform transform = fillInPatternNodes(cicsParser);
        @SuppressWarnings("unchecked")
        Map<String, Object> attributes = (Map<String, Object>) transform.transform(line);
        Assert.assertNotNull(attributes.get("CICS.XRFSOFF"));
        Assert.assertTrue(attributes.get("CICS.OPCLASS") instanceof List);
      } finally {
        connection.dispose();
      }
    } catch (Exception e) {
      Assert.fail(e.toString());
    }
  }
 private String executeCommand(RW3270Connection connection, String command) {
   connection.send("[clear]" + command + "[enter]");
   connection.waitFor(CONTINUE, READY, SHORT_WAIT);
   String line = connection.getStandardOutput();
   line = line.substring(0, line.lastIndexOf(" READY"));
   // break into lines
   //
   int index = line.indexOf(command);
   System.out.println("index=" + index);
   if (index > -1) line = line.substring(index + 80);
   line = line.replaceAll("(.{80})", "$1\n");
   return line;
 }
 @Test
 public void testTelnetConnectionViaPool() {
   OurConfiguration configuration = createConfiguration();
   try {
     RW3270Connection connection = createLoggedinConnection(configuration);
     try {
       // Now, display a user
       //
       String command = "LISTUSER IDM03";
       String line = executeCommand(connection, command);
       Assert.assertTrue(line.contains("USER=IDM03"));
       System.out.println(line);
     } finally {
       connection.dispose();
     }
   } catch (Exception e) {
     Assert.fail(e.toString());
   }
 }
  @Test
  public void testTsoParser() {
    OurConfiguration configuration = createConfiguration();

    String tsoParser =
        "<MapTransform>"
            + "  <PatternNode key='TSO.ACCTNUM' pattern='ACCTNUM= (.*?)\\s*\\n' optional='true' reset='false'/>"
            + "  <PatternNode key='TSO.HOLDCLASS' pattern='HOLDCLASS= (.*?)\\s*\\n' optional='true' reset='false'/>"
            + "  <PatternNode key='TSO.JOBCLASS' pattern='JOBCLASS= (.*?)\\s*\\n' optional='true' reset='false'/>"
            + "  <PatternNode key='TSO.MSGCLASS' pattern='MSGCLASS= (.*?)\\s*\\n' optional='true' reset='false'/>"
            + "  <PatternNode key='TSO.PROC' pattern='PROC= (.*?)\\s*\\n' optional='true' reset='false'/>"
            + "  <PatternNode key='TSO.SIZE' pattern='SIZE= (.*?)\\s*\\n' optional='true' reset='false'/>"
            + "  <PatternNode key='TSO.MAXSIZE' pattern='MAXSIZE= (.*?)\\s*\\n' optional='true' reset='false'/>"
            + "  <PatternNode key='TSO.SYSOUTCLASS' pattern='SYSOUTCLASS= (.*?)\\s*\\n' optional='true' reset='false'/>"
            + "  <PatternNode key='TSO.PROC' pattern='PROC= (.*?)\\s*\\n' optional='true' reset='false'/>"
            + "  <PatternNode key='TSO.UNIT' pattern='UNIT= (.*?)\\s*\\n' optional='true' reset='false'/>"
            + "  <PatternNode key='TSO.USERDATA' pattern='USERDATA= (.*?)\\s*\\n' optional='true' reset='false'/>"
            + "  <PatternNode key='TSO.COMMAND' pattern='COMMAND= (.*?)\\s*\\n' optional='true' reset='false'/>"
            + "</MapTransform>";

    try {
      RW3270Connection connection = createLoggedinConnection(configuration);
      try {
        // Now, display a user's TSO info
        //
        connection.resetStandardOutput();
        String command = "LISTUSER " + SYSTEM_USER + " NORACF TSO";
        String line = executeCommand(connection, command);
        System.out.println(line);
        MapTransform transform = fillInPatternNodes(tsoParser);
        @SuppressWarnings("unchecked")
        Map<String, Object> attributes = (Map<String, Object>) transform.transform(line);
        Assert.assertNotNull(attributes.get("TSO.MAXSIZE"));
        Assert.assertNotNull(attributes.get("TSO.USERDATA"));
        Assert.assertNotNull(attributes.get("TSO.JOBCLASS"));
      } finally {
        connection.dispose();
      }
    } catch (Exception e) {
      Assert.fail(e.toString());
    }
  }
  /*
   *  <opt><apMatch><t offset='-1'> UID= </t></apMatch><AttrParse><int name='OMVS.UID' noval='NONE'/></AttrParse></opt>
   *  <opt><apMatch><t offset='-1'> HOME= </t></apMatch><AttrParse><str name='OMVS.HOME' len='73' trim='true'/></AttrParse></opt>
   *  <opt><apMatch><t offset='-1'> PROGRAM= </t></apMatch><AttrParse><str name='OMVS.PROGRAM' len='70' trim='true'/></AttrParse></opt>
   *  <opt><apMatch><t offset='-1'> CPUTIMEMAX= </t></apMatch><AttrParse><int name='OMVS.CPUTIMEMAX' noval='NONE'/></AttrParse></opt>
   *  <opt><apMatch><t offset='-1'> ASSIZEMAX= </t></apMatch><AttrParse><int name='OMVS.ASSIZEMAX' noval='NONE'/></AttrParse></opt>
   *  <opt><apMatch><t offset='-1'> FILEPROCMAX= </t></apMatch><AttrParse><int name='OMVS.FILEPROCMAX' noval='NONE'/></AttrParse></opt>
   *  <opt><apMatch><t offset='-1'> PROCUSERMAX= </t></apMatch><AttrParse><int name='OMVS.PROCUSERMAX' noval='NONE'/></AttrParse></opt>
   *  <opt><apMatch><t offset='-1'> THREADSMAX= </t></apMatch><AttrParse><int name='OMVS.THREADSMAX' noval='NONE'/></AttrParse></opt>
   *  <opt><apMatch><t offset='-1'> MMAPAREAMAX= </t></apMatch><AttrParse><int name='OMVS.MMAPAREAMAX' noval='NONE' /></AttrParse></opt>
   */
  @Test
  public void testOmvsParser() {
    String omvsParser =
        "<MapTransform>"
            + "  <PatternNode key='OMVS.HOME' pattern='HOME= (.*?)\\s*\\n' optional='true' reset='false'/>"
            + "  <PatternNode key='OMVS.PROGRAM' pattern='PROGRAM= (.*?)\\s*\\n' optional='true' reset='false'/>"
            + "  <PatternNode key='OMVS.CPUTIMEMAX' pattern='CPUTIMEMAX= (.*?)\\s*\\n' optional='true' reset='false'/>"
            + "  <PatternNode key='OMVS.ASSIZEMAX' pattern='ASSIZEMAX= (.*?)\\s*\\n' optional='true' reset='false'/>"
            + "  <PatternNode key='OMVS.FILEPROCMAX' pattern='FILEPROCMAX= (.*?)\\s*\\n' optional='true' reset='false'/>"
            + "  <PatternNode key='OMVS.PROCUSERMAX' pattern='PROCUSERMAX= (.*?)\\s*\\n' optional='true' reset='false'/>"
            + "  <PatternNode key='OMVS.THREADSMAX' pattern='THREADSMAX= (.*?)\\s*\\n' optional='true' reset='false'/>"
            + "  <PatternNode key='OMVS.MMAPAREAMAX' pattern='MMAPAREAMAX= (.*?)\\s*\\n' optional='true' reset='false'/>"
            + "</MapTransform>";

    OurConfiguration configuration = createConfiguration();
    try {
      RW3270Connection connection = createLoggedinConnection(configuration);
      try {
        // Now, display a user's OMVS info
        //
        String command = "LISTUSER " + SYSTEM_USER + " NORACF OMVS";
        String line = executeCommand(connection, command);
        if (line.contains("NO OMVS INFO")) {
          // Oh, well
        } else {
          MapTransform transform = fillInPatternNodes(omvsParser);
          @SuppressWarnings("unchecked")
          Map<String, Object> attributes = (Map<String, Object>) transform.transform(line);
          Assert.assertNotNull(attributes.get("TSO.MAXSIZE"));
          Assert.assertNotNull(attributes.get("TSO.USERDATA"));
          Assert.assertNotNull(attributes.get("TSO.JOBCLASS"));
        }
      } finally {
        connection.dispose();
      }
    } catch (Exception e) {
      Assert.fail(e.toString());
    }
  }