コード例 #1
0
  @Test
  public void testGetStreamRules() {
    BasicDBObject mongoList = this.buildMongoBlacklist();

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

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

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

    mongoList.put("blacklisted_terms", rules);

    Blacklist blacklist = new Blacklist(mongoList);

    assertEquals(2, blacklist.getRules().size());
    assertEquals("^foo.+", blacklist.getRules().get(0).getTerm());
    assertEquals(".+bar", blacklist.getRules().get(1).getTerm());
  }
コード例 #2
0
  @Test
  public void testGetStreamRulesWithBlacklistThatHasNoRules() {
    BasicDBObject mongoList = this.buildMongoBlacklist();

    mongoList.put("blacklisted_terms", null);

    Blacklist blacklist = new Blacklist(mongoList);

    assertEquals(0, blacklist.getRules().size());

    // All is fine if there are no exceptions thrown and we get here.
  }