Search in sources :

Example 6 with NessieApiV1

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

the class ITGenerateContent method basicGenerateContentTest.

@ParameterizedTest
@EnumSource(Content.Type.class)
void basicGenerateContentTest(Content.Type contentType) throws Exception {
    Assumptions.assumeTrue(contentType != Content.Type.UNKNOWN && contentType != Type.NAMESPACE);
    int numCommits = 20;
    try (NessieApiV1 api = buildNessieApi()) {
        String testCaseBranch = "type_" + contentType.name();
        assertThat(NessieContentGenerator.runMain(new String[] { "generate", "-n", Integer.toString(numCommits), "-u", NESSIE_API_URI, "-D", testCaseBranch, "--type=" + contentType.name() })).isEqualTo(0);
        assertThat(api.getCommitLog().refName(testCaseBranch).get().getLogEntries()).hasSize(numCommits);
    }
}
Also used : NessieApiV1(org.projectnessie.client.api.NessieApiV1) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with NessieApiV1

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

the class ITReadCommits method readCommitsVerbose.

@Test
void readCommitsVerbose() throws UnsupportedEncodingException, NessieNotFoundException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try (PrintWriter out = new PrintWriter(new PrintStream(baos), true)) {
        assertThat(NessieContentGenerator.runMain(out, new String[] { "commits", "--uri", NESSIE_API_URI, "--ref", branch.getName(), "--verbose" })).isEqualTo(0);
        String[] output = baos.toString(StandardCharsets.UTF_8.toString()).split("\n");
        assertThat(output).anySatisfy(s -> assertThat(s).contains(COMMIT_MSG));
        assertThat(output).anySatisfy(s -> assertThat(s).contains(CONTENT_KEY.toString()));
        assertThat(output).anySatisfy(s -> assertThat(s).contains("key[0]: " + CONTENT_KEY.getElements().get(0)));
        assertThat(output).anySatisfy(s -> assertThat(s).contains("key[1]: " + CONTENT_KEY.getElements().get(1)));
        assertThat(output).anySatisfy(s -> assertThat(s).contains(contentId));
    }
    try (NessieApiV1 api = buildNessieApi()) {
        List<LogEntry> logEntries = api.getCommitLog().refName(branch.getName()).fetch(FetchOption.ALL).get().getLogEntries();
        assertThat(logEntries).hasSize(1);
        assertThat(logEntries.get(0).getOperations()).isNotEmpty();
        assertThat(logEntries.get(0).getParentCommitHash()).isNotNull();
    }
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) LogEntry(org.projectnessie.model.LogResponse.LogEntry) PrintWriter(java.io.PrintWriter) NessieApiV1(org.projectnessie.client.api.NessieApiV1) Test(org.junit.jupiter.api.Test)

Example 8 with NessieApiV1

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

the class TestNessieHttpClient method testTracing.

@Test
void testTracing() 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(true).build(NessieApiV1.class);
        try (Scope ignore = GlobalTracer.get().activateSpan(GlobalTracer.get().buildSpan("testOpenTracing").start())) {
            api.getConfig();
        }
    }
    // Cannot really assert on the value of the Uber-trace-id header, because the APIs don't
    // give us access to that. Verifying that the Uber-trace-id header is being sent should
    // be good enough though.
    assertNotNull(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)

Example 9 with NessieApiV1

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

the class TestNessieHttpClient method testNotFoundOnBaseUri.

@Test
void testNotFoundOnBaseUri() throws IOException {
    try (TestServer server = errorServer(404)) {
        NessieApiV1 api = HttpClientBuilder.builder().withUri(server.getUri().resolve("/unknownPath")).build(NessieApiV1.class);
        assertThatThrownBy(api::getConfig).isInstanceOf(RuntimeException.class).hasMessageContaining("Not Found");
    }
}
Also used : TestServer(org.projectnessie.client.util.TestServer) NessieApiV1(org.projectnessie.client.api.NessieApiV1) Test(org.junit.jupiter.api.Test)

Example 10 with NessieApiV1

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

the class TestNessieHttpClient method testInternalServerError.

@Test
void testInternalServerError() throws IOException {
    try (TestServer server = errorServer(500)) {
        NessieApiV1 api = HttpClientBuilder.builder().withUri(server.getUri().resolve("/broken")).build(NessieApiV1.class);
        assertThatThrownBy(api::getConfig).isInstanceOf(NessieInternalServerException.class).hasMessageContaining("Internal Server Error");
    }
}
Also used : NessieInternalServerException(org.projectnessie.client.rest.NessieInternalServerException) 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