Search in sources :

Example 6 with RsHasBody

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

the class PromuSliceTest method producesMetrics.

@ParameterizedTest
@CsvSource({ "http.response.length,500,counter,text/plain", "http.response.length,500,counter,application/openmetrics-text", "app.used.memory,200,gauge,text/plain", "app.used.memory,200,gauge,application/openmetrics-text" })
void producesMetrics(final String name, final long value, final String type, final String mimetype) {
    final Metrics metrics = new InMemoryMetrics();
    collect(metrics, name, value, type);
    MatcherAssert.assertThat(new PromuSlice(metrics), new SliceHasResponse(new AllOf<>(Arrays.asList(new RsHasStatus(RsStatus.OK), new RsHasHeaders(new IsEqual<>(new Header(ContentType.NAME, mimetype)), new IsAnything<>()), new RsHasBody(new MatchesPattern(Pattern.compile(metricFormatted(name, value, type, mimetype))), StandardCharsets.UTF_8))), new RequestLine(RqMethod.GET, "/prometheus/metrics"), new Headers.From(Accept.NAME, mimetype), Content.EMPTY));
}
Also used : SliceHasResponse(com.artipie.http.hm.SliceHasResponse) RsHasStatus(com.artipie.http.hm.RsHasStatus) MatchesPattern(org.hamcrest.text.MatchesPattern) RsHasHeaders(com.artipie.http.hm.RsHasHeaders) RequestLine(com.artipie.http.rq.RequestLine) Metrics(com.artipie.metrics.Metrics) InMemoryMetrics(com.artipie.metrics.memory.InMemoryMetrics) InMemoryMetrics(com.artipie.metrics.memory.InMemoryMetrics) Header(com.artipie.http.headers.Header) RsHasBody(com.artipie.http.hm.RsHasBody) AllOf(org.hamcrest.core.AllOf) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with RsHasBody

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

the class VersionSliceTest method returnVersionOfApplication.

@Test
void returnVersionOfApplication() {
    final ArtipieProperties proprts = new ArtipieProperties();
    MatcherAssert.assertThat(new VersionSlice(proprts), new SliceHasResponse(Matchers.allOf(new RsHasStatus(RsStatus.OK), new RsHasBody(new IsJson(new JsonContains(new JsonHas("version", new JsonValueIs(proprts.version())))))), new RequestLine(RqMethod.GET, "/.version")));
}
Also used : RequestLine(com.artipie.http.rq.RequestLine) SliceHasResponse(com.artipie.http.hm.SliceHasResponse) RsHasStatus(com.artipie.http.hm.RsHasStatus) RsHasBody(com.artipie.http.hm.RsHasBody) ArtipieProperties(com.artipie.misc.ArtipieProperties) JsonContains(wtf.g4s8.hamcrest.json.JsonContains) IsJson(com.artipie.IsJson) JsonHas(wtf.g4s8.hamcrest.json.JsonHas) JsonValueIs(wtf.g4s8.hamcrest.json.JsonValueIs) Test(org.junit.jupiter.api.Test)

Example 8 with RsHasBody

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

the class MetricSliceTest method shouldReturnMetricsInJsonArray.

@Test
void shouldReturnMetricsInJsonArray() {
    final String keyone = "one";
    final String keytwo = "two";
    final String json = "[{\"key\":\"%s\",\"value\":%s},{\"key\":\"%s\",\"value\":%s}]";
    final long valone = 1;
    final long valtwo = 2;
    final String dirorder = String.format(json, keyone, valone, keytwo, valtwo);
    final String revorder = String.format(json, keytwo, valtwo, keyone, valone);
    final Storage storage = new InMemoryStorage();
    storage.save(new Key.From(keyone), this.getContent(valone));
    storage.save(new Key.From(keytwo), this.getContent(valtwo));
    MatcherAssert.assertThat(new MetricSlice(storage), new SliceHasResponse(new AllOf<>(Arrays.asList(new RsHasStatus(RsStatus.OK), new AnyOf<>(Arrays.asList(new RsHasBody(dirorder, StandardCharsets.UTF_8), new RsHasBody(revorder, StandardCharsets.UTF_8))))), new RequestLine(RqMethod.GET, "/api/repositories/")));
}
Also used : SliceHasResponse(com.artipie.http.hm.SliceHasResponse) RsHasStatus(com.artipie.http.hm.RsHasStatus) AnyOf(org.hamcrest.core.AnyOf) InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) RequestLine(com.artipie.http.rq.RequestLine) InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) Storage(com.artipie.asto.Storage) RsHasBody(com.artipie.http.hm.RsHasBody) Key(com.artipie.asto.Key) AllOf(org.hamcrest.core.AllOf) 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