@Test
public void testMatching()
{

  ArrayList<HashMap<String, String>> test_cases = new ArrayList<HashMap<String, String>>();
  // class comment example case
  HashMap<String, String> test_case = new HashMap<String, String>();
  test_case.put("string", "12345 \"foo bar\" baz;goober");
  test_case.put("regex", "^(?<id>\\d+) \"(?<username>[^\"]+)\" (?<action>[^;]+);(?<cookie>.+)");
  test_case.put("fields", "id,username,action,cookie");
  test_cases.add(test_case);
  // apache log case
  test_case = new HashMap<String, String>();
  test_case.put("string",
      "127.0.0.1 - - [04/Apr/2013:17:17:21 -0700] \"GET /favicon.ico HTTP/1.1\" 404 498 \"http://www.google.com/\" " +
      "\"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 Safari/537" +
      ".31\"");
  test_case.put("regex",
      "^(?<ip>[\\d\\.]+) (\\S+) (\\S+) \\[(?<date>[\\w:/]+\\s[+\\-]\\d{4})\\] \"[A-Z]+ (?<url>.+?) HTTP/\\S+\" " +
      "(?<status>\\d{3}) (?<bytes>\\d+) \"(?<referer>[^\"]+)\" \"(?<agent>[^\"]+)\"");
  test_case.put("fields", "ip,date,url,status,bytes,referer,agent");
  test_cases.add(test_case);
  // iterate through test cases
  for (HashMap<String, String> curr_case : test_cases) {
    String string = curr_case.get("string");
    String regex = curr_case.get("regex");
    String[] fields = curr_case.get("fields").split(",");
    // set up the operator with the regex
    RegexMatchMapOperator oper = new RegexMatchMapOperator();
    oper.setRegex(regex);
    // stub output port
    CollectorTestSink<Object> sink = new CollectorTestSink<Object>();
    oper.output.setSink(sink);
    // process the string
    oper.beginWindow(0);
    oper.data.process(string);
    oper.endWindow();
    // ensure a successful capture
    Assert.assertEquals("number emitted tuples", 1, sink.collectedTuples.size());
    // fetch the Map that was output
    @SuppressWarnings("unchecked")
    Map<String, Object> output = (Map<String, Object>)sink.collectedTuples.get(0);
    // debugging output
    log.debug(String.format("Line is  : %s", string));
    log.debug(String.format("Regex is : %s", regex));
    log.debug(String.format("Map is   : %s", output.toString()));
    for (String field : fields) {
      // ensure keys are set
      Assert.assertTrue("Map is missing '" + field + "' key", output.containsKey(field));
    }
  }
}