Search in sources :

Example 26 with ContentKey

use of org.projectnessie.model.ContentKey in project nessie by projectnessie.

the class AbstractRestMergeTransplant method mergeWithNamespaces.

@ParameterizedTest
@EnumSource(value = ReferenceMode.class, mode = Mode.EXCLUDE, // merge requires the hash
names = "NAME_ONLY")
public void mergeWithNamespaces(ReferenceMode refMode) throws BaseNessieClientServerException {
    Branch base = createBranch("merge-base");
    Branch branch = createBranch("merge-branch");
    Namespace ns = Namespace.parse("a.b.c");
    // create the same namespace on both branches
    getApi().createNamespace().namespace(ns).refName(branch.getName()).create();
    getApi().createNamespace().namespace(ns).refName(base.getName()).create();
    IcebergTable table1 = IcebergTable.of("merge-table1", 42, 42, 42, 42);
    IcebergTable table2 = IcebergTable.of("merge-table2", 43, 43, 43, 43);
    ContentKey key1 = ContentKey.of(ns, "key1");
    ContentKey key2 = ContentKey.of(ns, "key2");
    Branch committed1 = getApi().commitMultipleOperations().branchName(branch.getName()).hash(branch.getHash()).commitMeta(CommitMeta.fromMessage("test-merge-branch1")).operation(Put.of(key1, table1)).commit();
    assertThat(committed1.getHash()).isNotNull();
    Branch committed2 = getApi().commitMultipleOperations().branchName(branch.getName()).hash(committed1.getHash()).commitMeta(CommitMeta.fromMessage("test-merge-branch2")).operation(Put.of(key1, table1, table1)).commit();
    assertThat(committed2.getHash()).isNotNull();
    getApi().commitMultipleOperations().branchName(base.getName()).hash(base.getHash()).commitMeta(CommitMeta.fromMessage("test-merge-main")).operation(Put.of(key2, table2)).commit();
    getApi().mergeRefIntoBranch().branch(base).fromRef(refMode.transform(committed2)).merge();
    LogResponse log = getApi().getCommitLog().refName(base.getName()).untilHash(base.getHash()).get();
    assertThat(log.getLogEntries().stream().map(LogEntry::getCommitMeta).map(CommitMeta::getMessage)).containsExactly("test-merge-branch2", "test-merge-branch1", "create namespace a.b.c", "test-merge-main", "create namespace a.b.c");
    assertThat(getApi().getEntries().refName(base.getName()).get().getEntries().stream().map(Entry::getName)).containsExactlyInAnyOrder(key1, key2, ContentKey.of(ns.getElements()));
    assertThat(getApi().getNamespace().refName(base.getName()).namespace(ns).get()).isNotNull();
}
Also used : ContentKey(org.projectnessie.model.ContentKey) LogResponse(org.projectnessie.model.LogResponse) LogEntry(org.projectnessie.model.LogResponse.LogEntry) Entry(org.projectnessie.model.EntriesResponse.Entry) Branch(org.projectnessie.model.Branch) IcebergTable(org.projectnessie.model.IcebergTable) CommitMeta(org.projectnessie.model.CommitMeta) Namespace(org.projectnessie.model.Namespace) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 27 with ContentKey

use of org.projectnessie.model.ContentKey in project nessie by projectnessie.

the class AbstractRestContents method verifyContentAndOperationTypesIndividually.

@ParameterizedTest
@MethodSource("contentAndOperationTypes")
public void verifyContentAndOperationTypesIndividually(ContentAndOperationType contentAndOperationType) throws BaseNessieClientServerException {
    Branch branch = createBranch("contentAndOperation_" + contentAndOperationType);
    CommitMultipleOperationsBuilder commit = getApi().commitMultipleOperations().branch(branch).commitMeta(CommitMeta.fromMessage("commit " + contentAndOperationType)).operation(contentAndOperationType.operation);
    if (contentAndOperationType.globalOperation != null) {
        commit.operation(contentAndOperationType.globalOperation);
    }
    commit.commit();
    List<Entry> entries = getApi().getEntries().refName(branch.getName()).get().getEntries();
    // Oh, yea - this is weird. The property ContentAndOperationType.operation.key.namespace is null
    // (!!!)
    // here, because somehow JUnit @MethodSource implementation re-constructs the objects returned
    // from
    // the source-method contentAndOperationTypes.
    ContentKey fixedContentKey = ContentKey.of(contentAndOperationType.operation.getKey().getElements());
    List<Entry> expect = contentAndOperationType.operation instanceof Put ? singletonList(Entry.builder().name(fixedContentKey).type(contentAndOperationType.type).build()) : emptyList();
    assertThat(entries).containsExactlyInAnyOrderElementsOf(expect);
}
Also used : ContentKey(org.projectnessie.model.ContentKey) Entry(org.projectnessie.model.EntriesResponse.Entry) CommitMultipleOperationsBuilder(org.projectnessie.client.api.CommitMultipleOperationsBuilder) Branch(org.projectnessie.model.Branch) Put(org.projectnessie.model.Operation.Put) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 28 with ContentKey

use of org.projectnessie.model.ContentKey in project nessie by projectnessie.

the class AbstractResteasyTest method testGetRefLog.

@Test
public void testGetRefLog() {
    Branch branch = makeBranch("branch-temp");
    IcebergTable table = IcebergTable.of("content-table", 42, 42, 42, 42);
    ContentKey contentKey = ContentKey.of("key1");
    commit(contentKey, table, branch, "code");
    RefLogResponse refLogResponse = rest().get("reflogs").then().statusCode(200).extract().as(RefLogResponse.class);
    assertThat(refLogResponse.getLogEntries().get(0).getOperation()).isEqualTo("COMMIT");
    assertThat(refLogResponse.getLogEntries().get(0).getRefName()).isEqualTo("branch-temp");
    assertThat(refLogResponse.getLogEntries().get(1).getOperation()).isEqualTo("CREATE_REFERENCE");
    assertThat(refLogResponse.getLogEntries().get(1).getRefName()).isEqualTo("branch-temp");
    RefLogResponse refLogResponse1 = rest().queryParam("endHash", refLogResponse.getLogEntries().get(1).getRefLogId()).get("reflogs").then().statusCode(200).extract().as(RefLogResponse.class);
    assertThat(refLogResponse1.getLogEntries().get(0).getRefLogId()).isEqualTo(refLogResponse.getLogEntries().get(1).getRefLogId());
}
Also used : ContentKey(org.projectnessie.model.ContentKey) ImmutableBranch(org.projectnessie.model.ImmutableBranch) Branch(org.projectnessie.model.Branch) IcebergTable(org.projectnessie.model.IcebergTable) RefLogResponse(org.projectnessie.model.RefLogResponse) Test(org.junit.jupiter.api.Test)

Example 29 with ContentKey

use of org.projectnessie.model.ContentKey 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);
}
Also used : ContentKey(org.projectnessie.model.ContentKey) DiffResponse(org.projectnessie.model.DiffResponse) ImmutableBranch(org.projectnessie.model.ImmutableBranch) Branch(org.projectnessie.model.Branch) IcebergTable(org.projectnessie.model.IcebergTable) DiffEntry(org.projectnessie.model.DiffResponse.DiffEntry) Test(org.junit.jupiter.api.Test)

Example 30 with ContentKey

use of org.projectnessie.model.ContentKey in project nessie by projectnessie.

the class TreeApiImpl method truncate.

private EntriesResponse.Entry truncate(EntriesResponse.Entry entry, Integer depth) {
    if (depth == null || depth < 1) {
        return entry;
    }
    Type type = entry.getName().getElements().size() > depth ? Type.NAMESPACE : entry.getType();
    ContentKey key = ContentKey.of(entry.getName().getElements().subList(0, depth));
    return EntriesResponse.Entry.builder().type(type).name(key).build();
}
Also used : ContentKey(org.projectnessie.model.ContentKey) Type(org.projectnessie.model.Content.Type)

Aggregations

ContentKey (org.projectnessie.model.ContentKey)35 Branch (org.projectnessie.model.Branch)20 Test (org.junit.jupiter.api.Test)15 Content (org.projectnessie.model.Content)15 IcebergTable (org.projectnessie.model.IcebergTable)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 CommitMeta (org.projectnessie.model.CommitMeta)10 Put (org.projectnessie.model.Operation.Put)7 Map (java.util.Map)6 Entry (org.projectnessie.model.EntriesResponse.Entry)6 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 NessieApiV1 (org.projectnessie.client.api.NessieApiV1)5 NessieNotFoundException (org.projectnessie.error.NessieNotFoundException)5 LogResponse (org.projectnessie.model.LogResponse)5 Reference (org.projectnessie.model.Reference)5 HashMap (java.util.HashMap)4 EnumSource (org.junit.jupiter.params.provider.EnumSource)4 NessieReferenceNotFoundException (org.projectnessie.error.NessieReferenceNotFoundException)4 LogEntry (org.projectnessie.model.LogResponse.LogEntry)4