Search in sources :

Example 1 with RsHasBody

use of com.artipie.http.hm.RsHasBody in project artipie by artipie.

the class PromuSliceTest method returnsMetricsThatMatchNames.

@Test
void returnsMetricsThatMatchNames() {
    final Metrics metrics = new InMemoryMetrics();
    metrics.counter("http.response.count").inc();
    metrics.gauge("http.response.content").set(5000L);
    metrics.gauge("app.workload").set(300L);
    MatcherAssert.assertThat(new PromuSlice(metrics), new SliceHasResponse(new RsHasBody(new AnyOf<>(new IsEqual<>(String.join("\n", "# HELP http_response_content Http response content", "# TYPE http_response_content gauge", "http_response_content 5000.0", "# HELP app_workload App workload", "# TYPE app_workload gauge", "app_workload 300.0", "")), new IsEqual<>(String.join("\n", "# HELP app_workload App workload", "# TYPE app_workload gauge", "app_workload 300.0", "# HELP http_response_content Http response content", "# TYPE http_response_content gauge", "http_response_content 5000.0", ""))), StandardCharsets.UTF_8), new RequestLine(RqMethod.GET, "/prometheus/metrics?name=http_response_content&name=app_workload"), new Headers.From(new Header(Accept.NAME, PromuSliceTest.PLAIN_TEXT)), Content.EMPTY));
}
Also used : RequestLine(com.artipie.http.rq.RequestLine) Metrics(com.artipie.metrics.Metrics) InMemoryMetrics(com.artipie.metrics.memory.InMemoryMetrics) InMemoryMetrics(com.artipie.metrics.memory.InMemoryMetrics) SliceHasResponse(com.artipie.http.hm.SliceHasResponse) Header(com.artipie.http.headers.Header) RsHasBody(com.artipie.http.hm.RsHasBody) IsEqual(org.hamcrest.core.IsEqual) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with RsHasBody

use of com.artipie.http.hm.RsHasBody in project maven-adapter by artipie.

the class ArtifactGetResponseTest method hasBodyIfExists.

@Test
void hasBodyIfExists() throws Exception {
    final Storage storage = new InMemoryStorage();
    final Key key = new Key.From("repo/artifact2.jar");
    final byte[] data = "data".getBytes(StandardCharsets.UTF_8);
    new BlockingStorage(storage).save(key, data);
    MatcherAssert.assertThat(new ArtifactGetResponse(storage, key), new RsHasBody(data));
}
Also used : InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) BlockingStorage(com.artipie.asto.blocking.BlockingStorage) Storage(com.artipie.asto.Storage) InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) BlockingStorage(com.artipie.asto.blocking.BlockingStorage) RsHasBody(com.artipie.http.hm.RsHasBody) Key(com.artipie.asto.Key) Test(org.junit.jupiter.api.Test)

Example 3 with RsHasBody

use of com.artipie.http.hm.RsHasBody in project maven-adapter by artipie.

the class CachedProxySliceTest method loadsOriginIfCacheNotFound.

@Test
void loadsOriginIfCacheNotFound() {
    final byte[] data = "remote".getBytes();
    MatcherAssert.assertThat(new CachedProxySlice((line, headers, body) -> new RsWithBody(ByteBuffer.wrap(data)), (key, supplier, control) -> supplier.get()), new SliceHasResponse(Matchers.allOf(new RsHasStatus(RsStatus.OK), new RsHasBody(data)), new RequestLine(RqMethod.GET, "/bar")));
}
Also used : RqMethod(com.artipie.http.rq.RqMethod) RsWithStatus(com.artipie.http.rs.RsWithStatus) SliceHasResponse(com.artipie.http.hm.SliceHasResponse) RsHasBody(com.artipie.http.hm.RsHasBody) RsStatus(com.artipie.http.rs.RsStatus) Matchers(org.hamcrest.Matchers) CompletableFuture(java.util.concurrent.CompletableFuture) Content(com.artipie.asto.Content) RsHasStatus(com.artipie.http.hm.RsHasStatus) RsWithBody(com.artipie.http.rs.RsWithBody) FailedCompletionStage(com.artipie.asto.FailedCompletionStage) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.jupiter.api.Test) RequestLine(com.artipie.http.rq.RequestLine) MatcherAssert(org.hamcrest.MatcherAssert) SliceSimple(com.artipie.http.slice.SliceSimple) Optional(java.util.Optional) RequestLine(com.artipie.http.rq.RequestLine) SliceHasResponse(com.artipie.http.hm.SliceHasResponse) RsHasStatus(com.artipie.http.hm.RsHasStatus) RsHasBody(com.artipie.http.hm.RsHasBody) RsWithBody(com.artipie.http.rs.RsWithBody) Test(org.junit.jupiter.api.Test)

Example 4 with RsHasBody

use of com.artipie.http.hm.RsHasBody in project maven-adapter by artipie.

the class CachedProxySliceTest method loadsCachedContent.

@Test
void loadsCachedContent() {
    final byte[] data = "cache".getBytes();
    MatcherAssert.assertThat(new CachedProxySlice((line, headers, body) -> new RsWithBody(ByteBuffer.wrap("123".getBytes())), (key, supplier, control) -> CompletableFuture.supplyAsync(() -> Optional.of(new Content.From(data)))), new SliceHasResponse(Matchers.allOf(new RsHasStatus(RsStatus.OK), new RsHasBody(data)), new RequestLine(RqMethod.GET, "/foo")));
}
Also used : RqMethod(com.artipie.http.rq.RqMethod) RsWithStatus(com.artipie.http.rs.RsWithStatus) SliceHasResponse(com.artipie.http.hm.SliceHasResponse) RsHasBody(com.artipie.http.hm.RsHasBody) RsStatus(com.artipie.http.rs.RsStatus) Matchers(org.hamcrest.Matchers) CompletableFuture(java.util.concurrent.CompletableFuture) Content(com.artipie.asto.Content) RsHasStatus(com.artipie.http.hm.RsHasStatus) RsWithBody(com.artipie.http.rs.RsWithBody) FailedCompletionStage(com.artipie.asto.FailedCompletionStage) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.jupiter.api.Test) RequestLine(com.artipie.http.rq.RequestLine) MatcherAssert(org.hamcrest.MatcherAssert) SliceSimple(com.artipie.http.slice.SliceSimple) Optional(java.util.Optional) RequestLine(com.artipie.http.rq.RequestLine) SliceHasResponse(com.artipie.http.hm.SliceHasResponse) RsHasStatus(com.artipie.http.hm.RsHasStatus) RsHasBody(com.artipie.http.hm.RsHasBody) RsWithBody(com.artipie.http.rs.RsWithBody) Test(org.junit.jupiter.api.Test)

Example 5 with RsHasBody

use of com.artipie.http.hm.RsHasBody in project maven-adapter by artipie.

the class ArtifactHeadResponseTest method noBodyIfExists.

@Test
void noBodyIfExists() throws Exception {
    final Storage storage = new InMemoryStorage();
    final Key key = new Key.From("repo/artifact2.jar");
    new BlockingStorage(storage).save(key, "data".getBytes(StandardCharsets.UTF_8));
    MatcherAssert.assertThat(new ArtifactHeadResponse(storage, key), new RsHasBody(new byte[0]));
}
Also used : InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) BlockingStorage(com.artipie.asto.blocking.BlockingStorage) Storage(com.artipie.asto.Storage) InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) BlockingStorage(com.artipie.asto.blocking.BlockingStorage) RsHasBody(com.artipie.http.hm.RsHasBody) Key(com.artipie.asto.Key) Test(org.junit.jupiter.api.Test)

Aggregations

RsHasBody (com.artipie.http.hm.RsHasBody)8 Test (org.junit.jupiter.api.Test)7 SliceHasResponse (com.artipie.http.hm.SliceHasResponse)6 RequestLine (com.artipie.http.rq.RequestLine)6 RsHasStatus (com.artipie.http.hm.RsHasStatus)5 Key (com.artipie.asto.Key)3 Storage (com.artipie.asto.Storage)3 InMemoryStorage (com.artipie.asto.memory.InMemoryStorage)3 Content (com.artipie.asto.Content)2 FailedCompletionStage (com.artipie.asto.FailedCompletionStage)2 BlockingStorage (com.artipie.asto.blocking.BlockingStorage)2 Header (com.artipie.http.headers.Header)2 RqMethod (com.artipie.http.rq.RqMethod)2 RsStatus (com.artipie.http.rs.RsStatus)2 RsWithBody (com.artipie.http.rs.RsWithBody)2 RsWithStatus (com.artipie.http.rs.RsWithStatus)2 SliceSimple (com.artipie.http.slice.SliceSimple)2 Metrics (com.artipie.metrics.Metrics)2 InMemoryMetrics (com.artipie.metrics.memory.InMemoryMetrics)2 ByteBuffer (java.nio.ByteBuffer)2