*/
@Test
public void test_ReplaceVersion_atTimeBounds() {
Clock origClock = _exgMaster.getClock();
try {
Instant now = Instant.now();
ObjectId baseOid = setupTestData(now);
_exgMaster.setClock(Clock.fixed(now.plus(2, HOURS), ZoneOffset.UTC));
final ExternalIdBundle bundle = ExternalIdBundle.of("B", "B0");
final ExternalIdBundle region = ExternalIdBundle.of("R", "R0");
List<ExchangeDocument> replacement = newArrayList();
for (int i = 0; i <= 2; i++) {
ManageableExchange ex = new ManageableExchange(bundle, "replace_" + i, region, null);
ExchangeDocument doc = new ExchangeDocument(ex);
doc.setVersionFromInstant(now.plus(1, MINUTES).plus(i * 20, SECONDS));
replacement.add(doc);
}
replacement.get(replacement.size() - 1).setVersionToInstant(now.plus(2, MINUTES));
ExchangeHistoryRequest historyRequest = new ExchangeHistoryRequest();
historyRequest.setObjectId(baseOid);
historyRequest.setCorrectionsFromInstant(now.plus(2, HOURS));
ExchangeHistoryResult result = _exgMaster.history(historyRequest);
List<ExchangeDocument> exchanges = result.getDocuments();
ExchangeDocument secondVersionDoc = exchanges.get(exchanges.size() - 2);
_exgMaster.replaceVersion(secondVersionDoc.getUniqueId(), replacement);
historyRequest = new ExchangeHistoryRequest();
historyRequest.setObjectId(baseOid);
historyRequest.setCorrectionsFromInstant(now.plus(2, HOURS));
result = _exgMaster.history(historyRequest);
exchanges = result.getDocuments();
assertEquals(7, exchanges.size());
assertEquals(now, exchanges.get(6).getVersionFromInstant());
assertEquals(now.plus(1, MINUTES), exchanges.get(6).getVersionToInstant());
//
assertEquals(now.plus(1, MINUTES), exchanges.get(5).getVersionFromInstant());
assertEquals(now.plus(1, MINUTES).plus(20, SECONDS), exchanges.get(5).getVersionToInstant());
//
assertEquals(now.plus(1, MINUTES).plus(20, SECONDS), exchanges.get(4).getVersionFromInstant());
assertEquals(now.plus(1, MINUTES).plus(40, SECONDS), exchanges.get(4).getVersionToInstant());
//
assertEquals(now.plus(1, MINUTES).plus(40, SECONDS), exchanges.get(3).getVersionFromInstant());
assertEquals(now.plus(1, MINUTES).plus(60, SECONDS), exchanges.get(3).getVersionToInstant());
//
assertEquals(now.plus(1, MINUTES).plus(60, SECONDS), exchanges.get(2).getVersionFromInstant());
assertEquals(now.plus(1, MINUTES).plus(120, SECONDS), exchanges.get(2).getVersionToInstant());
//
assertEquals(now.plus(1, MINUTES).plus(120, SECONDS), exchanges.get(1).getVersionFromInstant());
assertEquals(now.plus(1, MINUTES).plus(180, SECONDS), exchanges.get(1).getVersionToInstant());
//
assertEquals(now.plus(1, MINUTES).plus(180, SECONDS), exchanges.get(0).getVersionFromInstant());
assertEquals(null, exchanges.get(0).getVersionToInstant());
} finally {
_exgMaster.setClock(origClock);
}
}