Example #1
0
  @Test
  public void testRequireAction() throws JsonException {
    LocalQuery q = new LocalQuery();
    q.requireAction(Action.UPDATE);
    List<DatabaseDocument<MongoType>> ds =
        mdc.getDocumentReader().getDocuments(new MongoQuery(q.toJson()), 3);
    if (ds.size() != 0) {
      fail("Got documents for UPDATE, shouldn't have.");
    }

    q = new LocalQuery();
    q.requireAction(Action.ADD);
    ds = mdc.getDocumentReader().getDocuments(new MongoQuery(q.toJson()), 3);
    if (ds.size() != 1) {
      fail("Should have gotten a document back for ADD...");
    }

    if (ds.get(0).getAction() != Action.ADD
        || !ds.get(0).getContentField("name").equals(test.getContentField("name"))) {
      fail("Didn't get the correct document for ADD...");
    }

    q = new LocalQuery();
    q.requireAction(Action.DELETE);
    ds = mdc.getDocumentReader().getDocuments(new MongoQuery(q.toJson()), 3);
    if (ds.size() != 1) {
      fail("Should have gotten a document back for DELETE...");
    }
  }
Example #2
0
 @Test
 public void testMongoDatabaseQuery() throws JsonException {
   LocalQuery lq = new LocalQuery();
   lq.requireTouchedByStage("test");
   lq.requireNotTouchedByStage("test2");
   lq.requireContentFieldExists("exists");
   MongoQuery q = new MongoQuery(lq.toJson());
   Document d = mdc.getDocumentReader().getDocument(q);
   if (d != null) {
     fail("Expected no document to be returned");
   }
   lq = new LocalQuery();
   if (mdc.getDocumentReader().getDocument(new MongoQuery(lq.toJson())) == null) {
     fail("Expected to find a document");
   }
 }
Example #3
0
 @Test
 public void testRequireContentFieldNotExists() throws JsonException {
   LocalQuery q = new LocalQuery();
   q.requireContentFieldNotExists("number");
   List<DatabaseDocument<MongoType>> ds =
       mdc.getDocumentReader().getDocuments(new MongoQuery(q.toJson()), 3);
   if (ds.size() != 2) {
     fail("Received incorrect number of documents..");
   }
   q = new LocalQuery();
   q.requireContentFieldNotExists("name");
   ds = mdc.getDocumentReader().getDocuments(new MongoQuery(q.toJson()), 3);
   if (ds.size() != 1) {
     fail("Received incorrect number of documents..");
   }
 }
Example #4
0
  @Test
  public void testRequireNotTouchedByStage() throws JsonException {
    LocalQuery q = new LocalQuery();
    q.requireNotTouchedByStage("xyz");
    List<DatabaseDocument<MongoType>> ds =
        mdc.getDocumentReader().getDocuments(new MongoQuery(q.toJson()), 3);
    if (ds.size() != 3) {
      fail("Received incorrect number of documents..");
    }

    Document d = mdc.getDocumentWriter().getAndTag(new MongoQuery(), "xyz");
    if (d == null) {
      fail("Should have gotten a document back...");
    }
    mdc.getDocumentWriter().markTouched(d.getID(), "xyz");

    ds = mdc.getDocumentReader().getDocuments(new MongoQuery(q.toJson()), 3);
    if (ds.size() != 2) {
      fail("Received incorrect number of documents..");
    }
  }
Example #5
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");
      }
    }
  }