Search in sources :

Example 6 with Tag

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

the class AbstractDeltaTest method removeBranches.

@AfterEach
void removeBranches() throws NessieConflictException, NessieNotFoundException {
    for (Reference ref : api.getAllReferences().get().getReferences()) {
        if (ref instanceof Branch) {
            api.deleteBranch().branchName(ref.getName()).hash(ref.getHash()).delete();
        }
        if (ref instanceof Tag) {
            api.deleteTag().tagName(ref.getName()).hash(ref.getHash()).delete();
        }
    }
    api.createReference().reference(Branch.of("main", null)).create();
    api.close();
    api = null;
}
Also used : Reference(org.projectnessie.model.Reference) Branch(org.projectnessie.model.Branch) Tag(org.projectnessie.model.Tag) AfterEach(org.junit.jupiter.api.AfterEach)

Example 7 with Tag

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

the class AbstractSparkSqlTest method removeBranches.

@AfterEach
void removeBranches() throws NessieConflictException, NessieNotFoundException {
    for (Reference ref : api.getAllReferences().get().getReferences()) {
        if (ref instanceof Branch) {
            api.deleteBranch().branchName(ref.getName()).hash(ref.getHash()).delete();
        }
        if (ref instanceof Tag) {
            api.deleteTag().tagName(ref.getName()).hash(ref.getHash()).delete();
        }
    }
    api.createReference().reference(Branch.of("main", null)).create();
    api.close();
    api = null;
}
Also used : Reference(org.projectnessie.model.Reference) Branch(org.projectnessie.model.Branch) Tag(org.projectnessie.model.Tag) AfterEach(org.junit.jupiter.api.AfterEach)

Example 8 with Tag

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

the class AbstractRestInvalidWithHttp method invalidHashes.

@ParameterizedTest
@CsvSource({ "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 invalidHashes(String invalidHashIn, String validHash) {
    // CsvSource maps an empty string as null
    String invalidHash = invalidHashIn != null ? invalidHashIn : "";
    String validBranchName = "hello";
    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(validBranchName).hash(invalidHash).commitMeta(CommitMeta.fromMessage("")).commit()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".hash: " + HASH_MESSAGE).hasMessageContaining(opsCountMsg), () -> assertThatThrownBy(() -> getApi().deleteBranch().branchName(validBranchName).hash(invalidHash).delete()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".hash: " + HASH_MESSAGE), () -> assertThatThrownBy(() -> getApi().assignTag().tagName(validBranchName).hash(invalidHash).assignTo(tag).assign()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".oldHash: " + HASH_MESSAGE), () -> {
        if (null != getHttpClient()) {
            assertThatThrownBy(() -> getHttpClient().newRequest().path("trees/branch/{branchName}/merge").resolveTemplate("branchName", validBranchName).queryParam("expectedHash", invalidHash).post(null)).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining("mergeRefIntoBranch.merge: must not be null").hasMessageContaining(".hash: " + HASH_MESSAGE);
        }
    }, () -> assertThatThrownBy(() -> getApi().mergeRefIntoBranch().branchName(validBranchName).hash(invalidHash).fromRef(getApi().getDefaultBranch()).merge()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".hash: " + HASH_MESSAGE), () -> assertThatThrownBy(() -> getApi().deleteTag().tagName(validBranchName).hash(invalidHash).delete()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".hash: " + HASH_MESSAGE), () -> assertThatThrownBy(() -> getApi().transplantCommitsIntoBranch().branchName(validBranchName).hash(invalidHash).fromRefName("main").hashesToTransplant(singletonList(getApi().getReference().refName("main").get().getHash())).transplant()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".hash: " + HASH_MESSAGE), () -> assertThatThrownBy(() -> getApi().getContent().refName(invalidHash).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".request.requestedKeys: size must be between 1 and 2147483647").hasMessageContaining(REF_NAME_MESSAGE), () -> assertThatThrownBy(() -> getApi().getContent().refName(validBranchName).hashOnRef(invalidHash).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".request.requestedKeys: size must be between 1 and 2147483647").hasMessageContaining(".hashOnRef: " + HASH_MESSAGE), () -> assertThatThrownBy(() -> getApi().getContent().key(key).refName(validBranchName).hashOnRef(invalidHash).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".hashOnRef: " + HASH_MESSAGE), () -> assertThatThrownBy(() -> getApi().getCommitLog().refName(validBranchName).untilHash(invalidHash).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".params.startHash: " + HASH_MESSAGE), () -> assertThatThrownBy(() -> getApi().getCommitLog().refName(validBranchName).hashOnRef(invalidHash).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".params.endHash: " + HASH_MESSAGE), () -> assertThatThrownBy(() -> getApi().getEntries().refName(validBranchName).hashOnRef(invalidHash).get()).isInstanceOf(NessieBadRequestException.class).hasMessageContaining("Bad Request (HTTP/400):").hasMessageContaining(".params.hashOnRef: " + HASH_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 9 with Tag

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

the class AbstractRest method tearDown.

@AfterEach
public void tearDown() throws Exception {
    Branch defaultBranch = api.getDefaultBranch();
    for (Reference ref : api.getAllReferences().get().getReferences()) {
        if (ref.getName().equals(defaultBranch.getName())) {
            continue;
        }
        if (ref instanceof Branch) {
            api.deleteBranch().branch((Branch) ref).delete();
        } else if (ref instanceof Tag) {
            api.deleteTag().tag((Tag) ref).delete();
        }
    }
    api.close();
}
Also used : Branch(org.projectnessie.model.Branch) Reference(org.projectnessie.model.Reference) Tag(org.projectnessie.model.Tag) AfterEach(org.junit.jupiter.api.AfterEach)

Example 10 with Tag

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

the class AbstractRestReferences method referenceNames.

@ParameterizedTest
@ValueSource(strings = { "normal", "with-no_space", "slash/thing" })
public void referenceNames(String refNamePart) throws BaseNessieClientServerException {
    String tagName = "tag" + refNamePart;
    String branchName = "branch" + refNamePart;
    String branchName2 = "branch2" + refNamePart;
    String root = "ref_name_" + refNamePart.replaceAll("[^a-z]", "");
    Branch main = createBranch(root);
    IcebergTable meta = IcebergTable.of("meep", 42, 42, 42, 42);
    main = getApi().commitMultipleOperations().branchName(main.getName()).hash(main.getHash()).commitMeta(CommitMeta.builder().message("common-merge-ancestor").properties(ImmutableMap.of("prop1", "val1", "prop2", "val2")).build()).operation(Operation.Put.of(ContentKey.of("meep"), meta)).commit();
    String someHash = main.getHash();
    Reference createdTag = getApi().createReference().sourceRefName(main.getName()).reference(Tag.of(tagName, someHash)).create();
    assertEquals(Tag.of(tagName, someHash), createdTag);
    Reference createdBranch1 = getApi().createReference().sourceRefName(main.getName()).reference(Branch.of(branchName, someHash)).create();
    assertEquals(Branch.of(branchName, someHash), createdBranch1);
    Reference createdBranch2 = getApi().createReference().sourceRefName(main.getName()).reference(Branch.of(branchName2, someHash)).create();
    assertEquals(Branch.of(branchName2, someHash), createdBranch2);
    Map<String, Reference> references = getApi().getAllReferences().get().getReferences().stream().filter(r -> root.equals(r.getName()) || r.getName().endsWith(refNamePart)).collect(Collectors.toMap(Reference::getName, Function.identity()));
    assertThat(references).containsAllEntriesOf(ImmutableMap.of(main.getName(), main, createdTag.getName(), createdTag, createdBranch1.getName(), createdBranch1, createdBranch2.getName(), createdBranch2));
    assertThat(references.get(main.getName())).isInstanceOf(Branch.class);
    assertThat(references.get(createdTag.getName())).isInstanceOf(Tag.class);
    assertThat(references.get(createdBranch1.getName())).isInstanceOf(Branch.class);
    assertThat(references.get(createdBranch2.getName())).isInstanceOf(Branch.class);
    Reference tagRef = references.get(tagName);
    Reference branchRef = references.get(branchName);
    Reference branchRef2 = references.get(branchName2);
    String tagHash = tagRef.getHash();
    String branchHash = branchRef.getHash();
    String branchHash2 = branchRef2.getHash();
    assertThat(getApi().getReference().refName(tagName).get()).isEqualTo(tagRef);
    assertThat(getApi().getReference().refName(branchName).get()).isEqualTo(branchRef);
    EntriesResponse entries = getApi().getEntries().refName(tagName).get();
    assertThat(entries).isNotNull();
    entries = getApi().getEntries().refName(branchName).get();
    assertThat(entries).isNotNull();
    LogResponse log = getApi().getCommitLog().refName(tagName).get();
    assertThat(log).isNotNull();
    log = getApi().getCommitLog().refName(branchName).get();
    assertThat(log).isNotNull();
    // Need to have at least one op, otherwise all following operations (assignTag/Branch, merge,
    // delete) will fail
    meta = IcebergTable.of("foo", 42, 42, 42, 42);
    getApi().commitMultipleOperations().branchName(branchName).hash(branchHash).operation(Put.of(ContentKey.of("some-key"), meta)).commitMeta(CommitMeta.fromMessage("One dummy op")).commit();
    log = getApi().getCommitLog().refName(branchName).get();
    String newHash = log.getLogEntries().get(0).getCommitMeta().getHash();
    getApi().assignTag().tagName(tagName).hash(tagHash).assignTo(Branch.of(branchName, newHash)).assign();
    getApi().assignBranch().branchName(branchName).hash(newHash).assignTo(Branch.of(branchName, newHash)).assign();
    getApi().mergeRefIntoBranch().branchName(branchName2).hash(branchHash2).fromRefName(branchName).fromHash(newHash).merge();
}
Also used : ReferenceMetadata(org.projectnessie.model.ReferenceMetadata) NessieBadRequestException(org.projectnessie.error.NessieBadRequestException) LogResponse(org.projectnessie.model.LogResponse) Put(org.projectnessie.model.Operation.Put) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) Function(java.util.function.Function) Reference(org.projectnessie.model.Reference) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Map(java.util.Map) Assertions.assertAll(org.junit.jupiter.api.Assertions.assertAll) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CommitMeta(org.projectnessie.model.CommitMeta) ValueSource(org.junit.jupiter.params.provider.ValueSource) Operation(org.projectnessie.model.Operation) ImmutableMap(com.google.common.collect.ImmutableMap) Validation(org.projectnessie.model.Validation) ReferencesResponse(org.projectnessie.model.ReferencesResponse) Branch(org.projectnessie.model.Branch) LogEntry(org.projectnessie.model.LogResponse.LogEntry) EntriesResponse(org.projectnessie.model.EntriesResponse) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) FetchOption(org.projectnessie.api.params.FetchOption) Stream(java.util.stream.Stream) IcebergView(org.projectnessie.model.IcebergView) IcebergTable(org.projectnessie.model.IcebergTable) Optional(java.util.Optional) Tag(org.projectnessie.model.Tag) BaseNessieClientServerException(org.projectnessie.error.BaseNessieClientServerException) ContentKey(org.projectnessie.model.ContentKey) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) EntriesResponse(org.projectnessie.model.EntriesResponse) LogResponse(org.projectnessie.model.LogResponse) Branch(org.projectnessie.model.Branch) Reference(org.projectnessie.model.Reference) IcebergTable(org.projectnessie.model.IcebergTable) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Tag (org.projectnessie.model.Tag)12 Branch (org.projectnessie.model.Branch)10 Reference (org.projectnessie.model.Reference)8 ContentKey (org.projectnessie.model.ContentKey)7 Test (org.junit.jupiter.api.Test)6 IcebergTable (org.projectnessie.model.IcebergTable)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 BaseNessieClientServerException (org.projectnessie.error.BaseNessieClientServerException)4 NessieBadRequestException (org.projectnessie.error.NessieBadRequestException)4 CommitMeta (org.projectnessie.model.CommitMeta)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 Optional (java.util.Optional)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)3 AfterEach (org.junit.jupiter.api.AfterEach)3 NessieReferenceNotFoundException (org.projectnessie.error.NessieReferenceNotFoundException)3 LogResponse (org.projectnessie.model.LogResponse)3 Put (org.projectnessie.model.Operation.Put)3