use of org.projectnessie.model.LogResponse in project nessie by projectnessie.
the class AbstractRestCommitLog method filterCommitLogByProperties.
@Test
public void filterCommitLogByProperties() throws BaseNessieClientServerException {
Branch branch = createBranch("filterCommitLogByProperties");
int numAuthors = 5;
int commitsPerAuthor = 10;
String currentHash = branch.getHash();
createCommits(branch, numAuthors, commitsPerAuthor, currentHash);
LogResponse log = getApi().getCommitLog().refName(branch.getName()).get();
assertThat(log).isNotNull();
assertThat(log.getLogEntries()).hasSize(numAuthors * commitsPerAuthor);
log = getApi().getCommitLog().refName(branch.getName()).filter("commit.properties['prop1'] == 'val1'").get();
assertThat(log).isNotNull();
assertThat(log.getLogEntries()).hasSize(numAuthors * commitsPerAuthor);
log.getLogEntries().forEach(commit -> assertThat(commit.getCommitMeta().getProperties().get("prop1")).isEqualTo("val1"));
log = getApi().getCommitLog().refName(branch.getName()).filter("commit.properties['prop1'] == 'val3'").get();
assertThat(log).isNotNull();
assertThat(log.getLogEntries()).isEmpty();
}
use of org.projectnessie.model.LogResponse in project nessie by projectnessie.
the class AbstractRestCommitLog method verifyPaging.
void verifyPaging(String branchName, int commits, int pageSizeHint, List<String> commitMessages, String filterByAuthor) throws NessieNotFoundException {
String pageToken = null;
for (int pos = 0; pos < commits; pos += pageSizeHint) {
String filter = null;
if (null != filterByAuthor) {
filter = String.format("commit.author=='%s'", filterByAuthor);
}
LogResponse response = getApi().getCommitLog().refName(branchName).maxRecords(pageSizeHint).pageToken(pageToken).filter(filter).get();
if (pos + pageSizeHint <= commits) {
assertTrue(response.isHasMore());
assertNotNull(response.getToken());
assertEquals(commitMessages.subList(pos, pos + pageSizeHint), response.getLogEntries().stream().map(LogEntry::getCommitMeta).map(CommitMeta::getMessage).collect(Collectors.toList()));
pageToken = response.getToken();
} else {
assertFalse(response.isHasMore());
assertNull(response.getToken());
assertEquals(commitMessages.subList(pos, commitMessages.size()), response.getLogEntries().stream().map(LogEntry::getCommitMeta).map(CommitMeta::getMessage).collect(Collectors.toList()));
break;
}
}
}
use of org.projectnessie.model.LogResponse in project nessie by projectnessie.
the class AbstractRestInvalidRefs method testValidHashesOnValidNamedRefs.
@Test
public void testValidHashesOnValidNamedRefs() throws BaseNessieClientServerException {
Branch branch = createBranch("testValidHashesOnValidNamedRefs");
int commits = 10;
String currentHash = branch.getHash();
createCommits(branch, 1, commits, currentHash);
LogResponse entireLog = getApi().getCommitLog().refName(branch.getName()).get();
assertThat(entireLog).isNotNull();
assertThat(entireLog.getLogEntries()).hasSize(commits);
EntriesResponse allEntries = getApi().getEntries().refName(branch.getName()).get();
assertThat(allEntries).isNotNull();
assertThat(allEntries.getEntries()).hasSize(commits);
List<ContentKey> keys = new ArrayList<>();
IntStream.range(0, commits).forEach(i -> keys.add(ContentKey.of("table" + i)));
// TODO: check where hashOnRef is set
Map<ContentKey, Content> allContent = getApi().getContent().keys(keys).refName(branch.getName()).get();
for (int i = 0; i < commits; i++) {
String hash = entireLog.getLogEntries().get(i).getCommitMeta().getHash();
LogResponse log = getApi().getCommitLog().refName(branch.getName()).hashOnRef(hash).get();
assertThat(log).isNotNull();
assertThat(log.getLogEntries()).hasSize(commits - i);
assertThat(ImmutableList.copyOf(entireLog.getLogEntries()).subList(i, commits)).containsExactlyElementsOf(log.getLogEntries());
EntriesResponse entries = getApi().getEntries().refName(branch.getName()).hashOnRef(hash).get();
assertThat(entries).isNotNull();
assertThat(entries.getEntries()).hasSize(commits - i);
int idx = commits - 1 - i;
ContentKey key = ContentKey.of("table" + idx);
Content c = getApi().getContent().key(key).refName(branch.getName()).hashOnRef(hash).get().get(key);
assertThat(c).isNotNull().isEqualTo(allContent.get(key));
}
}
use of org.projectnessie.model.LogResponse in project nessie by projectnessie.
the class AbstractResteasyTest method testLogFiltering.
@Test
public void testLogFiltering() {
String branchName = "logFiltering";
makeBranch(branchName);
Branch branch = getBranch(branchName);
int numCommits = 3;
String contentId = "cid-test-log-filtering";
for (int i = 0; i < numCommits; i++) {
String newHash = commit(contentId, branch, "xxx.test", "/the/directory/over/there", "author-" + i, i > 0 ? "/the/directory/over/there" : null).getHash();
assertThat(newHash).isNotEqualTo(branch.getHash());
branch = getBranch(branchName);
}
LogResponse log = rest().get(String.format("trees/tree/%s/log", branchName)).then().statusCode(200).extract().as(LogResponse.class);
assertThat(log.getLogEntries()).hasSize(numCommits);
Instant firstCommitTime = log.getLogEntries().get(log.getLogEntries().size() - 1).getCommitMeta().getCommitTime();
Instant lastCommitTime = log.getLogEntries().get(0).getCommitMeta().getCommitTime();
assertThat(firstCommitTime).isNotNull();
assertThat(lastCommitTime).isNotNull();
String author = "author-1";
log = rest().queryParam("filter", String.format("commit.author=='%s'", author)).get(String.format("trees/tree/%s/log", branchName)).then().statusCode(200).extract().as(LogResponse.class);
assertThat(log.getLogEntries()).hasSize(1);
assertThat(log.getLogEntries().get(0).getCommitMeta().getAuthor()).isEqualTo(author);
log = rest().queryParam("filter", String.format("timestamp(commit.commitTime) > timestamp('%s')", firstCommitTime)).get(String.format("trees/tree/%s/log", branchName)).then().statusCode(200).extract().as(LogResponse.class);
assertThat(log.getLogEntries()).hasSize(numCommits - 1);
log.getLogEntries().forEach(commit -> assertThat(commit.getCommitMeta().getCommitTime()).isAfter(firstCommitTime));
log = rest().queryParam("filter", String.format("timestamp(commit.commitTime) < timestamp('%s')", lastCommitTime)).get(String.format("trees/tree/%s/log", branchName)).then().statusCode(200).extract().as(LogResponse.class);
assertThat(log.getLogEntries()).hasSize(numCommits - 1);
log.getLogEntries().forEach(commit -> assertThat(commit.getCommitMeta().getCommitTime()).isBefore(lastCommitTime));
log = rest().queryParam("filter", String.format("timestamp(commit.commitTime) > timestamp('%s') && timestamp(commit.commitTime) < timestamp('%s')", firstCommitTime, lastCommitTime)).get(String.format("trees/tree/%s/log", branchName)).then().statusCode(200).extract().as(LogResponse.class);
assertThat(log.getLogEntries()).hasSize(1);
assertThat(log.getLogEntries().get(0).getCommitMeta().getCommitTime()).isBefore(lastCommitTime).isAfter(firstCommitTime);
}
use of org.projectnessie.model.LogResponse in project nessie by projectnessie.
the class AbstractRestAssign method testAssignRefToFreshMain.
/**
* Assigning a branch/tag to a fresh main without any commits didn't work in 0.9.2
*/
@ParameterizedTest
@EnumSource(ReferenceMode.class)
public void testAssignRefToFreshMain(ReferenceMode refMode) throws BaseNessieClientServerException {
Reference main = getApi().getReference().refName("main").get();
// make sure main doesn't have any commits
LogResponse log = getApi().getCommitLog().refName(main.getName()).get();
assertThat(log.getLogEntries()).isEmpty();
Branch testBranch = createBranch("testBranch");
getApi().assignBranch().branch(testBranch).assignTo(main).assign();
Reference testBranchRef = getApi().getReference().refName(testBranch.getName()).get();
assertThat(testBranchRef.getHash()).isEqualTo(main.getHash());
String testTag = "testTag";
Reference testTagRef = getApi().createReference().sourceRefName(main.getName()).reference(Tag.of(testTag, main.getHash())).create();
assertThat(testTagRef.getHash()).isNotNull();
getApi().assignTag().hash(testTagRef.getHash()).tagName(testTag).assignTo(refMode.transform(main)).assign();
testTagRef = getApi().getReference().refName(testTag).get();
assertThat(testTagRef.getHash()).isEqualTo(main.getHash());
}
Aggregations