}
long now = System.currentTimeMillis();
// get history since 'now'
JSONArray array = parseJSONArray(mk.getRevisionHistory(now, -1, null));
// history should be empty since there was no commit since 'now'
assertEquals(0, array.size());
// get oldest available revision
array = parseJSONArray(mk.getRevisionHistory(0, 1, null));
// there should be exactly 1 revision
assertEquals(1, array.size());
long ts0 = System.currentTimeMillis();
final int NUM_COMMITS = 100;
// perform NUM_COMMITS commits
for (int i = 0; i < NUM_COMMITS; i++) {
mk.commit("/test", "+\"child" + i + "\":{}", null, "commit#" + i);
}
// get oldest available revision
array = parseJSONArray(mk.getRevisionHistory(ts0, -1, null));
// there should be exactly NUM_COMMITS revisions
assertEquals(NUM_COMMITS, array.size());
long previousTS = ts0;
for (int i = 0; i < NUM_COMMITS; i++) {
JSONObject rev = getObjectArrayEntry(array, i);
assertPropertyExists(rev, "id", String.class);
assertPropertyExists(rev, "ts", Long.class);
// verify commit msg
assertPropertyValue(rev, "msg", "commit#" + i);
// verify chronological order
long ts = (Long) resolveValue(rev, "ts");
assertTrue(previousTS <= ts);
previousTS = ts;
}
// last revision should be the current head revision
assertPropertyValue(getObjectArrayEntry(array, array.size() - 1), "id", mk.getHeadRevision());
String fromRev = (String) resolveValue(getObjectArrayEntry(array, 0), "id");
String toRev = (String) resolveValue(getObjectArrayEntry(array, array.size() - 1), "id");
// verify journal
array = parseJSONArray(mk.getJournal(fromRev, toRev, ""));
// there should be exactly NUM_COMMITS entries
assertEquals(NUM_COMMITS, array.size());
// verify that 1st and last rev match fromRev and toRev
assertPropertyValue(getObjectArrayEntry(array, 0), "id", fromRev);
assertPropertyValue(getObjectArrayEntry(array, array.size() - 1), "id", toRev);
previousTS = ts0;
for (int i = 0; i < NUM_COMMITS; i++) {
JSONObject rev = getObjectArrayEntry(array, i);
assertPropertyExists(rev, "id", String.class);
assertPropertyExists(rev, "ts", Long.class);
assertPropertyExists(rev, "changes", String.class);
// TODO verify json diff
// verify commit msg
assertPropertyValue(rev, "msg", "commit#" + i);
// verify chronological order
long ts = (Long) resolveValue(rev, "ts");
assertTrue(previousTS <= ts);
previousTS = ts;
}
// test with 'negative' range (from and to swapped)
array = parseJSONArray(mk.getJournal(toRev, fromRev, ""));
// there should be exactly 0 entries
assertEquals(0, array.size());
}