Exemplo n.º 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...");
    }
  }
Exemplo n.º 2
0
  @Before
  public void setUp() throws Exception {
    mdc =
        new MongoConnector(
            DatabaseConfigurationFactory.getDatabaseConfiguration("junit-QueryTest"));
    mdc.waitForWrites(true);

    test = new MongoDocument();
    test.setAction(Action.ADD);
    test.putContentField("name", "test");
    test.putMetadataField("date", new Date());

    test2 = new MongoDocument();
    test2.setAction(Action.DELETE);
    test2.putContentField("name", "test");
    test2.putContentField("number", 2);
    test2.putMetadataField("date", new Date());

    random = new MongoDocument();

    try {
      mdc.connect();
    } catch (IOException e) {
      fail("IOException when establishing connection");
    }

    DatabaseDocument<MongoType> d;
    while ((d = mdc.getDocumentReader().getDocument(new MongoQuery())) != null) {
      mdc.getDocumentWriter().delete(d);
    }

    mdc.getDocumentWriter().insert(test);
    mdc.getDocumentWriter().insert(test2);
    mdc.getDocumentWriter().insert(random);
  }