*/
@Test
public void test_ReplaceVersion_atTimeBounds() {
Clock origClock = _cfgMaster.getClock();
try {
Instant now = Instant.now();
ObjectId baseOid = setupTestData(now);
_cfgMaster.setClock(Clock.fixed(now.plus(2, HOURS), ZoneOffset.UTC));
List<ConfigDocument> replacement = newArrayList();
for (int i = 0; i <= 2; i++) {
String val = "replace_" + i;
ConfigDocument doc = new ConfigDocument(ConfigItem.of(val, "some_name_"+i));
doc.setVersionFromInstant(now.plus(1, MINUTES).plus(i * 20, SECONDS));
replacement.add(doc);
}
replacement.get(replacement.size() - 1).setVersionToInstant(now.plus(2, MINUTES));
ConfigHistoryRequest<String> historyRequest = new ConfigHistoryRequest<String>();
historyRequest.setObjectId(baseOid);
historyRequest.setCorrectionsFromInstant(now.plus(2, HOURS));
ConfigHistoryResult<String> result = _cfgMaster.history(historyRequest);
List<ConfigDocument> confDocs = result.getDocuments();
ConfigDocument secondVersionDoc = confDocs.get(confDocs.size() - 2);
_cfgMaster.replaceVersion(secondVersionDoc.getUniqueId(), replacement);
historyRequest = new ConfigHistoryRequest<String>();
historyRequest.setObjectId(baseOid);
historyRequest.setCorrectionsFromInstant(now.plus(2, HOURS));
result = _cfgMaster.history(historyRequest);
confDocs = result.getDocuments();
assertEquals(7, confDocs.size());
assertEquals(now, confDocs.get(6).getVersionFromInstant());
assertEquals(now.plus(1, MINUTES), confDocs.get(6).getVersionToInstant());
//
assertEquals(now.plus(1, MINUTES), confDocs.get(5).getVersionFromInstant());
assertEquals(now.plus(1, MINUTES).plus(20, SECONDS), confDocs.get(5).getVersionToInstant());
//
assertEquals(now.plus(1, MINUTES).plus(20, SECONDS), confDocs.get(4).getVersionFromInstant());
assertEquals(now.plus(1, MINUTES).plus(40, SECONDS), confDocs.get(4).getVersionToInstant());
//
assertEquals(now.plus(1, MINUTES).plus(40, SECONDS), confDocs.get(3).getVersionFromInstant());
assertEquals(now.plus(1, MINUTES).plus(60, SECONDS), confDocs.get(3).getVersionToInstant());
//
assertEquals(now.plus(1, MINUTES).plus(60, SECONDS), confDocs.get(2).getVersionFromInstant());
assertEquals(now.plus(1, MINUTES).plus(120, SECONDS), confDocs.get(2).getVersionToInstant());
//
assertEquals(now.plus(1, MINUTES).plus(120, SECONDS), confDocs.get(1).getVersionFromInstant());
assertEquals(now.plus(1, MINUTES).plus(180, SECONDS), confDocs.get(1).getVersionToInstant());
//
assertEquals(now.plus(1, MINUTES).plus(180, SECONDS), confDocs.get(0).getVersionFromInstant());
assertEquals(null, confDocs.get(0).getVersionToInstant());
} finally {
_cfgMaster.setClock(origClock);
}
}