Search in sources :

Example 71 with Branch

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

the class AbstractResteasyTest method testBasic.

@Test
public void testBasic() {
    int preSize = rest().get("trees").then().statusCode(200).extract().as(ReferencesResponse.class).getReferences().size();
    rest().get("trees/tree/mainx").then().statusCode(404);
    rest().body(Branch.of("mainx", null)).post("trees/tree").then().statusCode(200);
    ReferencesResponse references = rest().get("trees").then().statusCode(200).extract().as(ReferencesResponse.class);
    Assertions.assertEquals(preSize + 1, references.getReferences().size());
    Reference reference = rest().get("trees/tree/mainx").then().statusCode(200).extract().as(Reference.class);
    assertEquals("mainx", reference.getName());
    Branch newReference = ImmutableBranch.builder().hash(reference.getHash()).name("test").build();
    rest().queryParam("expectedHash", reference.getHash()).body(Branch.of("test", null)).post("trees/tree").then().statusCode(200);
    assertEquals(newReference, rest().get("trees/tree/test").then().statusCode(200).extract().as(Branch.class));
    IcebergTable table = IcebergTable.of("/the/directory/over/there", 42, 42, 42, 42);
    Branch commitResponse = rest().body(ImmutableOperations.builder().addOperations(ImmutablePut.builder().key(ContentKey.of("xxx", "test")).content(table).build()).commitMeta(CommitMeta.fromMessage("")).build()).queryParam("expectedHash", newReference.getHash()).post("trees/branch/{branch}/commit", newReference.getName()).then().statusCode(200).extract().as(Branch.class);
    Assertions.assertNotEquals(newReference.getHash(), commitResponse.getHash());
    Put[] updates = new Put[11];
    for (int i = 0; i < 10; i++) {
        updates[i] = ImmutablePut.builder().key(ContentKey.of("item", Integer.toString(i))).content(IcebergTable.of("/the/directory/over/there/" + i, 42, 42, 42, 42)).build();
    }
    updates[10] = ImmutablePut.builder().key(ContentKey.of("xxx", "test")).content(IcebergTable.of("/the/directory/over/there/has/been/moved", 42, 42, 42, 42)).build();
    Reference branch = rest().get("trees/tree/test").as(Reference.class);
    Operations contents = ImmutableOperations.builder().addOperations(updates).commitMeta(CommitMeta.fromMessage("")).build();
    commitResponse = rest().body(contents).queryParam("expectedHash", branch.getHash()).post("trees/branch/{branch}/commit", branch.getName()).then().statusCode(200).extract().as(Branch.class);
    Assertions.assertNotEquals(branch.getHash(), commitResponse.getHash());
    Response res = rest().queryParam("ref", "test").get("contents/xxx.test").then().extract().response();
    Assertions.assertEquals(updates[10].getContent(), res.body().as(Content.class));
    IcebergTable currentTable = table;
    table = IcebergTable.of("/the/directory/over/there/has/been/moved/again", 42, 42, 42, 42, table.getId());
    Branch b2 = rest().get("trees/tree/test").as(Branch.class);
    rest().body(ImmutableOperations.builder().addOperations(ImmutablePut.builder().key(ContentKey.of("xxx", "test")).content(table).expectedContent(currentTable).build()).commitMeta(CommitMeta.fromMessage("")).build()).queryParam("expectedHash", b2.getHash()).post("trees/branch/{branch}/commit", b2.getName()).then().statusCode(200).extract().as(Branch.class);
    Content returned = rest().queryParam("ref", "test").get("contents/xxx.test").then().statusCode(200).extract().as(Content.class);
    Assertions.assertEquals(table, returned);
    Branch b3 = rest().get("trees/tree/test").as(Branch.class);
    rest().body(Tag.of("tagtest", b3.getHash())).queryParam("sourceRefName", b3.getName()).post("trees/tree").then().statusCode(200);
    assertThat(rest().get("trees/tree/tagtest").then().statusCode(200).extract().body().as(Tag.class).getHash()).isEqualTo(b3.getHash());
    rest().queryParam("expectedHash", "0011223344556677889900112233445566778899001122334455667788990011".substring(0, b2.getHash().length())).delete("trees/tag/tagtest").then().statusCode(409);
    rest().queryParam("expectedHash", b3.getHash()).delete("trees/tag/tagtest").then().statusCode(204);
    LogResponse log = rest().get("trees/tree/test/log").then().statusCode(200).extract().as(LogResponse.class);
    Assertions.assertEquals(3, log.getLogEntries().size());
    Branch b1 = rest().get("trees/tree/test").as(Branch.class);
    rest().queryParam("expectedHash", b1.getHash()).delete("trees/branch/test").then().statusCode(204);
    Branch bx = rest().get("trees/tree/mainx").as(Branch.class);
    rest().queryParam("expectedHash", bx.getHash()).delete("trees/branch/mainx").then().statusCode(204);
}
Also used : LogResponse(org.projectnessie.model.LogResponse) RefLogResponse(org.projectnessie.model.RefLogResponse) ReferencesResponse(org.projectnessie.model.ReferencesResponse) Response(io.restassured.response.Response) DiffResponse(org.projectnessie.model.DiffResponse) LogResponse(org.projectnessie.model.LogResponse) RefLogResponse(org.projectnessie.model.RefLogResponse) Reference(org.projectnessie.model.Reference) ImmutableBranch(org.projectnessie.model.ImmutableBranch) Branch(org.projectnessie.model.Branch) Content(org.projectnessie.model.Content) IcebergTable(org.projectnessie.model.IcebergTable) ReferencesResponse(org.projectnessie.model.ReferencesResponse) Tag(org.projectnessie.model.Tag) ImmutableOperations(org.projectnessie.model.ImmutableOperations) Operations(org.projectnessie.model.Operations) Put(org.projectnessie.model.Operation.Put) ImmutablePut(org.projectnessie.model.ImmutablePut) Test(org.junit.jupiter.api.Test)

Example 72 with Branch

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

the class AbstractResteasyTest method testOptimisticLocking.

@Test
public void testOptimisticLocking() {
    makeBranch("test3");
    Branch b1 = getBranch("test3");
    String contentId = "cid-test-opt-lock";
    String newHash = commit(contentId, b1, "xxx.test", "/the/directory/over/there").getHash();
    Assertions.assertNotEquals(b1.getHash(), newHash);
    Branch b2 = getBranch("test3");
    newHash = commit(contentId, b2, "xxx.test", "/the/directory/over/there/has/been/moved", "i", "/the/directory/over/there").getHash();
    Assertions.assertNotEquals(b2.getHash(), newHash);
    Branch b3 = getBranch("test3");
    newHash = commit(contentId, b3, "xxx.test", "/the/directory/over/there/has/been/moved/again", "me", "/the/directory/over/there/has/been/moved").getHash();
    Assertions.assertNotEquals(b3.getHash(), newHash);
}
Also used : ImmutableBranch(org.projectnessie.model.ImmutableBranch) Branch(org.projectnessie.model.Branch) Test(org.junit.jupiter.api.Test)

Example 73 with Branch

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

the class TreeApiImplWithAuthorization method createReference.

@Override
public Reference createReference(@Nullable String sourceRefName, Reference reference) throws NessieNotFoundException, NessieConflictException {
    BatchAccessChecker check = startAccessCheck().canCreateReference(RefUtil.toNamedRef(reference));
    try {
        check.canViewReference(namedRefWithHashOrThrow(sourceRefName, reference.getHash()).getValue());
    } catch (NessieNotFoundException e) {
        // cases, re-throw the exception.
        if (!(reference instanceof Branch && reference.getName().equals(getConfig().getDefaultBranch()) && (null == reference.getHash() || getStore().noAncestorHash().asString().equals(reference.getHash())))) {
            throw e;
        }
    }
    check.checkAndThrow();
    return super.createReference(sourceRefName, reference);
}
Also used : BatchAccessChecker(org.projectnessie.services.authz.BatchAccessChecker) Branch(org.projectnessie.model.Branch) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException)

Example 74 with Branch

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

the class AbstractContentGeneratorTest method makeCommit.

protected Branch makeCommit(NessieApiV1 api, String contentId) throws NessieConflictException, NessieNotFoundException {
    String branchName = "test-" + UUID.randomUUID();
    Branch main = api.getDefaultBranch();
    Reference branch = api.createReference().sourceRefName(main.getName()).reference(Branch.of(branchName, main.getHash())).create();
    return api.commitMultipleOperations().branchName(branch.getName()).hash(branch.getHash()).commitMeta(CommitMeta.fromMessage(COMMIT_MSG)).operation(Operation.Put.of(CONTENT_KEY, IcebergTable.of("testMeta", 123, 456, 789, 321, contentId))).commit();
}
Also used : Branch(org.projectnessie.model.Branch) Reference(org.projectnessie.model.Reference)

Example 75 with Branch

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

the class TestAuthorizationRules method testCanReadTargetBranchDuringMerge.

@Test
@TestSecurity(user = "admin_user")
void testCanReadTargetBranchDuringMerge() throws BaseNessieClientServerException {
    String role = "admin_user";
    String branchName = "adminCanReadWhenMerging";
    String targetBranchName = "targetBranchForMerge";
    createBranch(Branch.of(branchName, null), role, false);
    Branch branch = retrieveBranch(branchName, role, false);
    createBranch(Branch.of(targetBranchName, null), role, false);
    Branch targetBranch = retrieveBranch(targetBranchName, role, false);
    addContent(branch, Put.of(ContentKey.of("allowed", "x"), IcebergTable.of("foo", 42, 42, 42, 42, UUID.randomUUID().toString())), role, false);
    branch = retrieveBranch(branchName, role, false);
    api().mergeRefIntoBranch().fromRef(branch).branch(targetBranch).merge();
    targetBranch = retrieveBranch(targetBranch.getName(), role, false);
    assertThat(api().getCommitLog().reference(targetBranch).get().getLogEntries()).isNotEmpty();
}
Also used : Branch(org.projectnessie.model.Branch) TestSecurity(io.quarkus.test.security.TestSecurity) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Branch (org.projectnessie.model.Branch)81 Test (org.junit.jupiter.api.Test)56 IcebergTable (org.projectnessie.model.IcebergTable)30 ContentKey (org.projectnessie.model.ContentKey)29 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)27 LogResponse (org.projectnessie.model.LogResponse)19 Reference (org.projectnessie.model.Reference)19 CommitMeta (org.projectnessie.model.CommitMeta)18 Instant (java.time.Instant)16 LogEntry (org.projectnessie.model.LogResponse.LogEntry)13 List (java.util.List)12 BaseNessieClientServerException (org.projectnessie.error.BaseNessieClientServerException)12 Tag (org.projectnessie.model.Tag)12 Collectors (java.util.stream.Collectors)11 NessieNotFoundException (org.projectnessie.error.NessieNotFoundException)11 Content (org.projectnessie.model.Content)11 Entry (org.projectnessie.model.EntriesResponse.Entry)10 Put (org.projectnessie.model.Operation.Put)10 IcebergView (org.projectnessie.model.IcebergView)9 Map (java.util.Map)8