Search in sources :

Example 6 with ContentKey

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

the class AbstractRestInvalidWithHttp method invalidBranchNames.

@ParameterizedTest
@CsvSource({ "x/" + COMMA_VALID_HASH_1, "abc'" + COMMA_VALID_HASH_1, ".foo" + COMMA_VALID_HASH_2, "abc'def'..'blah" + COMMA_VALID_HASH_2, "abc'de..blah" + COMMA_VALID_HASH_3, "abc'de@{blah" + COMMA_VALID_HASH_3 })
public void invalidBranchNames(String invalidBranchName, String validHash) {
    ContentKey key = ContentKey.of("x");
    Tag tag = Tag.of("valid", validHash);
    String opsCountMsg = ".operations.operations: size must be between 1 and 2147483647";
    assertAll(() -> assertThatThrownBy(() -> getApi().commitMultipleOperations().branchName(invalidBranchName).hash(validHash).commitMeta(CommitMeta.fromMessage("")).commit()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE).hasMessageContaining(opsCountMsg), () -> assertThatThrownBy(() -> getApi().deleteBranch().branchName(invalidBranchName).hash(validHash).delete()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE), () -> assertThatThrownBy(() -> getApi().getCommitLog().refName(invalidBranchName).untilHash(validHash).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE), () -> assertThatThrownBy(() -> getApi().getEntries().refName(invalidBranchName).hashOnRef(validHash).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE), () -> assertThatThrownBy(() -> getApi().getReference().refName(invalidBranchName).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE), () -> assertThatThrownBy(() -> getApi().assignTag().tagName(invalidBranchName).hash(validHash).assignTo(tag).assign()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE), () -> {
        if (null != getHttpClient()) {
            assertThatThrownBy(() -> getHttpClient().newRequest().path("trees/branch/{branchName}/merge").resolveTemplate("branchName", invalidBranchName).queryParam("expectedHash", validHash).post(null)).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE).hasMessageContaining(".merge: must not be null");
        }
    }, () -> assertThatThrownBy(() -> getApi().mergeRefIntoBranch().branchName(invalidBranchName).hash(validHash).fromRef(getApi().getDefaultBranch()).merge()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE), () -> assertThatThrownBy(() -> getApi().deleteTag().tagName(invalidBranchName).hash(validHash).delete()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE), () -> assertThatThrownBy(() -> getApi().transplantCommitsIntoBranch().branchName(invalidBranchName).hash(validHash).fromRefName("main").hashesToTransplant(singletonList(getApi().getReference().refName("main").get().getHash())).transplant()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE), () -> assertThatThrownBy(() -> getApi().getContent().key(key).refName(invalidBranchName).hashOnRef(validHash).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE), () -> assertThatThrownBy(() -> getApi().getContent().key(key).refName(invalidBranchName).hashOnRef(validHash).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE), () -> assertThatThrownBy(() -> getApi().getDiff().fromRefName(invalidBranchName).toRefName("main").get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(REF_NAME_MESSAGE));
}
Also used : ContentKey(org.projectnessie.model.ContentKey) NessieBadRequestException(org.projectnessie.error.NessieBadRequestException) Tag(org.projectnessie.model.Tag) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with ContentKey

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

the class AbstractRestMisc method checkSpecialCharacterRoundTrip.

@Test
public void checkSpecialCharacterRoundTrip() throws BaseNessieClientServerException {
    Branch branch = createBranch("specialchar");
    // ContentKey k = ContentKey.of("/%国","国.国");
    ContentKey k = ContentKey.of("a.b", "c.txt");
    IcebergTable ta = IcebergTable.of("path1", 42, 42, 42, 42);
    getApi().commitMultipleOperations().branch(branch).operation(Put.of(k, ta)).commitMeta(CommitMeta.fromMessage("commit 1")).commit();
    assertThat(getApi().getContent().key(k).refName(branch.getName()).get()).containsEntry(k, ta);
    assertEquals(ta, getApi().getContent().key(k).refName(branch.getName()).get().get(k));
}
Also used : ContentKey(org.projectnessie.model.ContentKey) Branch(org.projectnessie.model.Branch) IcebergTable(org.projectnessie.model.IcebergTable) Test(org.junit.jupiter.api.Test)

Example 8 with ContentKey

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

the class AbstractRestContents method multiget.

@Test
public void multiget() throws BaseNessieClientServerException {
    Branch branch = createBranch("foo");
    ContentKey a = ContentKey.of("a");
    ContentKey b = ContentKey.of("b");
    IcebergTable ta = IcebergTable.of("path1", 42, 42, 42, 42);
    IcebergTable tb = IcebergTable.of("path2", 42, 42, 42, 42);
    getApi().commitMultipleOperations().branch(branch).operation(Put.of(a, ta)).commitMeta(CommitMeta.fromMessage("commit 1")).commit();
    getApi().commitMultipleOperations().branch(branch).operation(Put.of(b, tb)).commitMeta(CommitMeta.fromMessage("commit 2")).commit();
    Map<ContentKey, Content> response = getApi().getContent().key(a).key(b).key(ContentKey.of("noexist")).refName("foo").get();
    assertThat(response).containsEntry(a, ta).containsEntry(b, tb).doesNotContainKey(ContentKey.of("noexist"));
}
Also used : ContentKey(org.projectnessie.model.ContentKey) Branch(org.projectnessie.model.Branch) Content(org.projectnessie.model.Content) IcebergTable(org.projectnessie.model.IcebergTable) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with ContentKey

use of org.projectnessie.model.ContentKey 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();
    });
}
Also used : IntStream(java.util.stream.IntStream) DiffEntry(org.projectnessie.model.DiffResponse.DiffEntry) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Branch(org.projectnessie.model.Branch) Collectors(java.util.stream.Collectors) Reference(org.projectnessie.model.Reference) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Stream(java.util.stream.Stream) Delete(org.projectnessie.model.Operation.Delete) IcebergTable(org.projectnessie.model.IcebergTable) Map(java.util.Map) Optional(java.util.Optional) BaseNessieClientServerException(org.projectnessie.error.BaseNessieClientServerException) Content(org.projectnessie.model.Content) ContentKey(org.projectnessie.model.ContentKey) CommitMeta(org.projectnessie.model.CommitMeta) MethodSource(org.junit.jupiter.params.provider.MethodSource) Reference(org.projectnessie.model.Reference) ContentKey(org.projectnessie.model.ContentKey) Branch(org.projectnessie.model.Branch) Content(org.projectnessie.model.Content) IcebergTable(org.projectnessie.model.IcebergTable) Map(java.util.Map) DiffEntry(org.projectnessie.model.DiffResponse.DiffEntry) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 10 with ContentKey

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

the class AbstractRestEntries method filterEntriesByNamespace.

@ParameterizedTest
@EnumSource(ReferenceMode.class)
public void filterEntriesByNamespace(ReferenceMode refMode) throws BaseNessieClientServerException {
    Branch branch = createBranch("filterEntriesByNamespace");
    ContentKey first = ContentKey.of("a", "b", "c", "firstTable");
    ContentKey second = ContentKey.of("a", "b", "c", "secondTable");
    ContentKey third = ContentKey.of("a", "thirdTable");
    ContentKey fourth = ContentKey.of("a", "fourthTable");
    getApi().commitMultipleOperations().branch(branch).operation(Put.of(first, IcebergTable.of("path1", 42, 42, 42, 42))).commitMeta(CommitMeta.fromMessage("commit 1")).commit();
    getApi().commitMultipleOperations().branch(branch).operation(Put.of(second, IcebergTable.of("path2", 42, 42, 42, 42))).commitMeta(CommitMeta.fromMessage("commit 2")).commit();
    getApi().commitMultipleOperations().branch(branch).operation(Put.of(third, IcebergTable.of("path3", 42, 42, 42, 42))).commitMeta(CommitMeta.fromMessage("commit 3")).commit();
    branch = getApi().commitMultipleOperations().branch(branch).operation(Put.of(fourth, IcebergTable.of("path4", 42, 42, 42, 42))).commitMeta(CommitMeta.fromMessage("commit 4")).commit();
    List<Entry> entries = getApi().getEntries().reference(refMode.transform(branch)).get().getEntries();
    assertThat(entries).isNotNull().hasSize(4);
    entries = getApi().getEntries().reference(refMode.transform(branch)).get().getEntries();
    assertThat(entries).isNotNull().hasSize(4);
    entries = getApi().getEntries().reference(refMode.transform(branch)).filter("entry.namespace.startsWith('a.b')").get().getEntries();
    assertThat(entries).hasSize(2);
    entries.forEach(e -> assertThat(e.getName().getNamespace().name()).startsWith("a.b"));
    entries = getApi().getEntries().reference(refMode.transform(branch)).filter("entry.namespace.startsWith('a')").get().getEntries();
    assertThat(entries).hasSize(4);
    entries.forEach(e -> assertThat(e.getName().getNamespace().name()).startsWith("a"));
    entries = getApi().getEntries().reference(refMode.transform(branch)).filter("entry.namespace.startsWith('a.b.c.firstTable')").get().getEntries();
    assertThat(entries).isEmpty();
    entries = getApi().getEntries().reference(refMode.transform(branch)).filter("entry.namespace.startsWith('a.fourthTable')").get().getEntries();
    assertThat(entries).isEmpty();
    getApi().deleteBranch().branchName(branch.getName()).hash(getApi().getReference().refName(branch.getName()).get().getHash()).delete();
}
Also used : ContentKey(org.projectnessie.model.ContentKey) Entry(org.projectnessie.model.EntriesResponse.Entry) Branch(org.projectnessie.model.Branch) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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