use of org.projectnessie.model.DiffResponse.DiffEntry in project nessie by projectnessie.
the class AbstractRestDiff method testDiff.
@ParameterizedTest
@MethodSource("diffRefModes")
public void testDiff(ReferenceMode refModeFrom, ReferenceMode refModeTo) throws BaseNessieClientServerException {
int commitsPerBranch = 10;
Reference fromRef = getApi().createReference().reference(Branch.of("testDiffFromRef", null)).create();
Reference toRef = getApi().createReference().reference(Branch.of("testDiffToRef", null)).create();
String toRefHash = createCommits(toRef, 1, commitsPerBranch, toRef.getHash());
toRef = Branch.of(toRef.getName(), toRefHash);
List<DiffEntry> diffOnRefHeadResponse = getApi().getDiff().fromRef(refModeFrom.transform(fromRef)).toRef(refModeTo.transform(toRef)).get().getDiffs();
// we only committed to toRef, the "from" diff should be null
assertThat(diffOnRefHeadResponse).hasSize(commitsPerBranch).allSatisfy(diff -> {
assertThat(diff.getKey()).isNotNull();
assertThat(diff.getFrom()).isNull();
assertThat(diff.getTo()).isNotNull();
});
// Some combinations with explicit fromHashOnRef/toHashOnRef
assertThat(getApi().getDiff().fromRefName(fromRef.getName()).fromHashOnRef(fromRef.getHash()).toRefName(toRef.getName()).toHashOnRef(toRef.getHash()).get().getDiffs()).isEqualTo(diffOnRefHeadResponse);
// result
if (refModeTo != ReferenceMode.NAME_ONLY) {
Branch toRefAtFrom = Branch.of(toRef.getName(), fromRef.getHash());
assertThat(getApi().getDiff().fromRef(refModeFrom.transform(fromRef)).toRef(refModeTo.transform(toRefAtFrom)).get().getDiffs()).isEmpty();
}
// after committing to fromRef, "from/to" diffs should both have data
fromRef = Branch.of(fromRef.getName(), createCommits(fromRef, 1, commitsPerBranch, fromRef.getHash()));
assertThat(getApi().getDiff().fromRef(refModeFrom.transform(fromRef)).toRef(refModeTo.transform(toRef)).get().getDiffs()).hasSize(commitsPerBranch).allSatisfy(diff -> {
assertThat(diff.getKey()).isNotNull();
assertThat(diff.getFrom()).isNotNull();
assertThat(diff.getTo()).isNotNull();
// we only have a diff on the ID
assertThat(diff.getFrom().getId()).isNotEqualTo(diff.getTo().getId());
Optional<IcebergTable> fromTable = diff.getFrom().unwrap(IcebergTable.class);
assertThat(fromTable).isPresent();
Optional<IcebergTable> toTable = diff.getTo().unwrap(IcebergTable.class);
assertThat(toTable).isPresent();
assertThat(fromTable.get().getMetadataLocation()).isEqualTo(toTable.get().getMetadataLocation());
assertThat(fromTable.get().getSchemaId()).isEqualTo(toTable.get().getSchemaId());
assertThat(fromTable.get().getSnapshotId()).isEqualTo(toTable.get().getSnapshotId());
assertThat(fromTable.get().getSortOrderId()).isEqualTo(toTable.get().getSortOrderId());
assertThat(fromTable.get().getSpecId()).isEqualTo(toTable.get().getSpecId());
});
List<ContentKey> keys = IntStream.rangeClosed(0, commitsPerBranch).mapToObj(i -> ContentKey.of("table" + i)).collect(Collectors.toList());
// request all keys and delete the tables for them on toRef
Map<ContentKey, Content> map = getApi().getContent().refName(toRef.getName()).keys(keys).get();
for (Map.Entry<ContentKey, Content> entry : map.entrySet()) {
toRef = getApi().commitMultipleOperations().branchName(toRef.getName()).hash(toRefHash).commitMeta(CommitMeta.fromMessage("delete")).operation(Delete.of(entry.getKey())).commit();
}
// now that we deleted all tables on toRef, the diff for "to" should be null
assertThat(getApi().getDiff().fromRef(refModeFrom.transform(fromRef)).toRef(refModeTo.transform(toRef)).get().getDiffs()).hasSize(commitsPerBranch).allSatisfy(diff -> {
assertThat(diff.getKey()).isNotNull();
assertThat(diff.getFrom()).isNotNull();
assertThat(diff.getTo()).isNull();
});
}
use of org.projectnessie.model.DiffResponse.DiffEntry in project nessie by projectnessie.
the class AbstractResteasyTest method testGetDiff.
@Test
public void testGetDiff() {
Branch fromBranch = makeBranch("getdiff-test-from");
Branch toBranch = makeBranch("getdiff-test-to");
IcebergTable fromTable = IcebergTable.of("content-table", 42, 42, 42, 42);
IcebergTable toTable = IcebergTable.of("content-table", 43, 43, 43, 43);
ContentKey contentKey = ContentKey.of("key1");
commit(contentKey, fromTable, fromBranch, "diffAuthor");
commit(contentKey, toTable, toBranch, "diffAuthor2");
DiffResponse diffResponse = rest().get(String.format("diffs/%s...%s", fromBranch.getName(), toBranch.getName())).then().statusCode(200).extract().as(DiffResponse.class);
assertThat(diffResponse).isNotNull();
assertThat(diffResponse.getDiffs()).hasSize(1);
DiffEntry diff = diffResponse.getDiffs().get(0);
assertThat(diff.getKey()).isEqualTo(contentKey);
assertThat(diff.getFrom()).isEqualTo(fromTable);
assertThat(diff.getTo()).isEqualTo(toTable);
}
Aggregations