Example #1
0
  @Test
  public void testFromJSON() throws JsonException {
    LocalQuery q = new LocalQuery();
    MongoQuery mdq = new MongoQuery();
    mdq.fromJson(q.toJson());
    if (mdq.toDBObject().keySet().size() != 0) {
      fail("Expected query to be empty");
    }

    q.requireContentFieldExists("name");
    mdq.fromJson(q.toJson());
    if (mdq.toDBObject().keySet().size() != 1) {
      fail("Expected query to have one value");
    }
    List<DatabaseDocument<MongoType>> list = mdc.getDocumentReader().getDocuments(mdq, 142);
    if (list.size() != 2) {
      fail("Expected to find two documents");
    }
    for (Document d : list) {
      if (!d.hasContentField("name")) {
        fail("Fetched document is missing content field name");
      }
    }
  }