@Test
  public void testBlacklistedWithPositiveResultAndNewline() {
    BasicDBObject mongoList = new BasicDBObject();
    mongoList.put("_id", new ObjectId());
    mongoList.put("title", "foo");

    BasicDBObject mongoRule1 = new BasicDBObject();
    mongoRule1.put("_id", new ObjectId());
    mongoRule1.put("blacklist_id", mongoList.get("_id"));
    mongoRule1.put("term", "^ohai.+");

    BasicDBObject mongoRule2 = new BasicDBObject();
    mongoRule2.put("_id", new ObjectId());
    mongoRule1.put("blacklist_id", mongoList.get("_id"));
    mongoRule2.put("term", ".+aarrghhhllll");

    BasicDBList rules = new BasicDBList();
    rules.add(mongoRule1);
    rules.add(mongoRule2);

    mongoList.put("blacklisted_terms", rules);

    Blacklist blacklist = new Blacklist(mongoList);

    GELFMessage msg = new GELFMessage();
    msg.setShortMessage("ohai thar\nfoo");

    List<Blacklist> blacklists = new ArrayList<Blacklist>();
    blacklists.add(blacklist);

    assertTrue(msg.blacklisted(blacklists));
  }
  @Test
  public void testToOneliner() {

    GELFMessage gelfMessage = createGELFMessage();

    String oneLiner =
        "host.example.com - short message severity=Emergency,facility=local0,file=test.file,line=42,test=test";
    assertEquals(oneLiner, gelfMessage.toOneLiner());
  }
  private GELFMessage createGELFMessage() {

    GELFMessage gelfMessage = new GELFMessage();

    gelfMessage.setHost("host.example.com");
    gelfMessage.setShortMessage("short message");
    gelfMessage.setFullMessage("full message");
    gelfMessage.setVersion("1");
    gelfMessage.setLevel(0);
    gelfMessage.setFacility("local0");
    gelfMessage.setFile("test.file");
    gelfMessage.setLine(42);
    gelfMessage.addAdditionalData("test", "test");

    return gelfMessage;
  }
  @Test
  public void testToStringWithLongMessage() {

    GELFMessage gelfMessage = createGELFMessage();
    gelfMessage.setFullMessage(
        "Really, really, really, really, really, really, really, really, really, really, "
            + "really, really, really, really, really, really, really, really, really, really, really, really, "
            + "really, really, really, really, really, really, really, really, really, really, really, really, "
            + "really, really long");

    String toString =
        "shortMessage: short message | fullMessage: Really, really, really, really, really, really, "
            + "really, really, really, really, really, really, really, really, really, really, really, really, "
            + "really, really, really, really, really (...)";

    assertEquals(toString, gelfMessage.toString());
  }
  @Test
  public void testToString() {

    String stringDelim = " | ";

    GELFMessage gelfMessage = createGELFMessage();

    String toString = "shortMessage: short message" + stringDelim;
    toString += "fullMessage: full message" + stringDelim;
    toString += "level: 0" + stringDelim;
    toString += "host: host.example.com" + stringDelim;
    toString += "file: test.file" + stringDelim;
    toString += "line: 42" + stringDelim;
    toString += "facility: local0" + stringDelim;
    toString += "version: 1" + stringDelim;
    toString += "additional: 1";

    assertEquals(toString, gelfMessage.toString());
  }
  @Test
  public void testAllRequiredFieldsSet() {

    GELFMessage emptyGelfMessage = new GELFMessage();
    assertFalse(emptyGelfMessage.allRequiredFieldsSet());

    GELFMessage versionMissingGelfMessage = createGELFMessage();
    versionMissingGelfMessage.setVersion("");
    assertFalse(versionMissingGelfMessage.allRequiredFieldsSet());

    GELFMessage gelfMessage = createGELFMessage();
    assertTrue(gelfMessage.allRequiredFieldsSet());
  }
  /** Test parsing of standard GELF message with no additional fields. */
  @Test
  public void testParseWithoutAdditionalData() throws Exception {
    GELFClientHandlerBase instance = new GELFClientHandlerBase();
    instance.clientMessage = this.originalMessage;
    instance.parse();

    GELFMessage message = instance.message;

    // There should be not additional data.
    assertEquals(message.getAdditionalData().size(), 0);

    // Test standard fields.
    assertEquals("something.", message.getShortMessage());
    assertEquals("lol!", message.getFullMessage());
    assertEquals("somehost", message.getHost());
    assertEquals(2, message.getLevel());
    assertEquals("example.php", message.getFile());
    assertEquals(1337, message.getLine());
  }
  /** Test parsing of standard GELF message with additional fields. */
  @Test
  public void testParseWithAdditionalData() throws Exception {
    GELFClientHandlerBase instance = new GELFClientHandlerBase();
    instance.clientMessage = this.originalMessageWithAdditionalData;
    instance.parse();

    GELFMessage message = instance.message;

    // There should be two additional data fields.
    assertEquals(message.getAdditionalData().size(), 2);

    // Test standard fields.
    assertEquals("something.", message.getShortMessage());
    assertEquals("lol!", message.getFullMessage());
    assertEquals("somehost", message.getHost());
    assertEquals(2, message.getLevel());
    assertEquals("example.php", message.getFile());
    assertEquals(1337, message.getLine());

    // Test additional fields.
    Map<String, String> additionalData = message.getAdditionalData();
    assertEquals("yes", additionalData.get("s1"));
    assertEquals("yes, really", additionalData.get("s2"));
  }