Search in sources :

Example 21 with NessieApiV1

use of org.projectnessie.client.api.NessieApiV1 in project nessie by projectnessie.

the class ReadCommits method execute.

@Override
public void execute() throws NessieNotFoundException {
    try (NessieApiV1 api = createNessieApiInstance()) {
        spec.commandLine().getOut().printf("Reading commits for ref '%s'\n\n", ref);
        FetchOption fetchOption = isVerbose() ? FetchOption.ALL : FetchOption.MINIMAL;
        LogResponse logResponse = api.getCommitLog().refName(ref).fetch(fetchOption).get();
        for (LogResponse.LogEntry logEntry : logResponse.getLogEntries()) {
            CommitMeta commitMeta = logEntry.getCommitMeta();
            spec.commandLine().getOut().printf("%s\t%s\t%s [%s]\n", Objects.requireNonNull(commitMeta.getHash()).substring(0, 8), commitMeta.getAuthorTime(), commitMeta.getMessage(), commitMeta.getAuthor());
            List<Operation> operations = logEntry.getOperations();
            if (operations != null) {
                for (Operation op : operations) {
                    spec.commandLine().getOut().printf("  %s\n", op);
                    if (isVerbose()) {
                        List<String> key = op.getKey().getElements();
                        for (int i = 0; i < key.size(); i++) {
                            spec.commandLine().getOut().printf("    key[%d]: %s\n", i, key.get(i));
                        }
                    }
                }
            }
        }
        spec.commandLine().getOut().printf("\nDone reading commits for ref '%s'\n\n", ref);
    }
}
Also used : LogResponse(org.projectnessie.model.LogResponse) Operation(org.projectnessie.model.Operation) CommitMeta(org.projectnessie.model.CommitMeta) NessieApiV1(org.projectnessie.client.api.NessieApiV1) FetchOption(org.projectnessie.api.params.FetchOption)

Example 22 with NessieApiV1

use of org.projectnessie.client.api.NessieApiV1 in project nessie by projectnessie.

the class ITReadCommits method readCommits.

@Test
void readCommits() throws UnsupportedEncodingException, NessieNotFoundException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream out = new PrintStream(baos);
    System.setOut(out);
    assertThat(NessieContentGenerator.runMain(new String[] { "commits", "--uri", NESSIE_API_URI, "--ref", branch.getName() })).isEqualTo(0);
    out.close();
    String[] output = baos.toString(StandardCharsets.UTF_8.toString()).split("\n");
    assertThat(output).anySatisfy(s -> assertThat(s).contains(COMMIT_MSG));
    assertThat(output).noneSatisfy(s -> assertThat(s).contains(CONTENT_KEY.toString()));
    try (NessieApiV1 api = buildNessieApi()) {
        assertThat(api.getCommitLog().refName(branch.getName()).get().getLogEntries()).hasSize(1);
    }
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) NessieApiV1(org.projectnessie.client.api.NessieApiV1) Test(org.junit.jupiter.api.Test)

Example 23 with NessieApiV1

use of org.projectnessie.client.api.NessieApiV1 in project nessie by projectnessie.

the class TestHttpClientBuilder method testAuthBasic.

@ParameterizedTest
@MethodSource("basicAuthConfigs")
void testAuthBasic(Function<HttpClientBuilder, HttpClientBuilder> config) throws Exception {
    AtomicReference<String> authHeader = new AtomicReference<>();
    try (TestServer server = new TestServer(handlerForHeaderTest("Authorization", authHeader))) {
        NessieApiV1 client = config.apply(HttpClientBuilder.builder().withUri(server.getUri())).build(NessieApiV1.class);
        client.getConfig();
    }
    assertThat(authHeader.get()).isNotNull().isEqualTo("Basic " + new String(Base64.getUrlEncoder().encode("my_username:very_secret".getBytes(UTF_8)), UTF_8));
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) TestServer(org.projectnessie.client.util.TestServer) NessieApiV1(org.projectnessie.client.api.NessieApiV1) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 24 with NessieApiV1

use of org.projectnessie.client.api.NessieApiV1 in project nessie by projectnessie.

the class TestNessieHttpClient method testUnauthorized.

@Test
void testUnauthorized() throws IOException {
    try (TestServer server = errorServer(401)) {
        NessieApiV1 api = HttpClientBuilder.builder().withUri(server.getUri().resolve("/unauthorized")).build(NessieApiV1.class);
        assertThatThrownBy(api::getConfig).isInstanceOf(NessieNotAuthorizedException.class).hasMessageContaining("Unauthorized");
    }
}
Also used : NessieNotAuthorizedException(org.projectnessie.client.rest.NessieNotAuthorizedException) TestServer(org.projectnessie.client.util.TestServer) NessieApiV1(org.projectnessie.client.api.NessieApiV1) Test(org.junit.jupiter.api.Test)

Example 25 with NessieApiV1

use of org.projectnessie.client.api.NessieApiV1 in project nessie by projectnessie.

the class TestNessieHttpClient method testTracingNotEnabled.

@Test
void testTracingNotEnabled() throws Exception {
    AtomicReference<String> traceId = new AtomicReference<>();
    try (TestServer server = new TestServer(handlerForHeaderTest("Uber-trace-id", traceId))) {
        NessieApiV1 api = HttpClientBuilder.builder().withUri(server.getUri()).withTracing(false).build(NessieApiV1.class);
        try (Scope ignore = GlobalTracer.get().activateSpan(GlobalTracer.get().buildSpan("testOpenTracing").start())) {
            api.getConfig();
        }
    }
    assertNull(traceId.get());
}
Also used : Scope(io.opentracing.Scope) AtomicReference(java.util.concurrent.atomic.AtomicReference) TestServer(org.projectnessie.client.util.TestServer) NessieApiV1(org.projectnessie.client.api.NessieApiV1) Test(org.junit.jupiter.api.Test)

Aggregations

NessieApiV1 (org.projectnessie.client.api.NessieApiV1)25 Test (org.junit.jupiter.api.Test)11 TestServer (org.projectnessie.client.util.TestServer)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 Instant (java.time.Instant)3 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 Stream (java.util.stream.Stream)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 MethodSource (org.junit.jupiter.params.provider.MethodSource)3 InstanceOfAssertFactories (org.assertj.core.api.InstanceOfAssertFactories)2 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 Arguments (org.junit.jupiter.params.provider.Arguments)2 ValueSource (org.junit.jupiter.params.provider.ValueSource)2 FetchOption (org.projectnessie.api.params.FetchOption)2 HttpClient (org.projectnessie.client.http.HttpClient)2 HttpApiV1 (org.projectnessie.client.http.v1api.HttpApiV1)2 NessieInternalServerException (org.projectnessie.client.rest.NessieInternalServerException)2