Search in sources :

Example 6 with RequestLine

use of com.artipie.http.rq.RequestLine in project artipie by artipie.

the class ResponseMetricsSliceTest method shouldForwardRequestUnmodified.

@Test
void shouldForwardRequestUnmodified() {
    final Header header = new Header("header1", "value1");
    final byte[] body = "some code".getBytes();
    final RsStatus status = RsStatus.CREATED;
    MatcherAssert.assertThat(new ResponseMetricsSlice((rsline, rsheaders, rsbody) -> new RsFull(status, rsheaders, rsbody), this.metrics).response(new RequestLine(RqMethod.POST, "/some_upload.war").toString(), new Headers.From(header), Flowable.just(ByteBuffer.wrap(body))), new ResponseMatcher(status, body, header));
}
Also used : RequestLine(com.artipie.http.rq.RequestLine) ResponseMatcher(com.artipie.http.hm.ResponseMatcher) RsFull(com.artipie.http.rs.RsFull) Header(com.artipie.http.headers.Header) RsStatus(com.artipie.http.rs.RsStatus) Test(org.junit.jupiter.api.Test)

Example 7 with RequestLine

use of com.artipie.http.rq.RequestLine in project artipie by artipie.

the class AuthAndPermissionsTest method adminCanDeploy.

@Test
void adminCanDeploy() throws IOException {
    final RsStatus status = RsStatus.ACCEPTED;
    MatcherAssert.assertThat(new BasicAuthSlice(new SliceSimple(new RsWithStatus(status)), new AuthFromYaml(this.credentials()), new Permission.ByName("deploy", this.permissions())).response(new RequestLine("PUT", "/foo", "HTTP/1.2").toString(), new ListOf<Map.Entry<String, String>>(new Authorization(String.format("Basic %s", new Base64Encoded("admin:abc").asString()))), Flowable.empty()), new RsHasStatus(status));
}
Also used : RsHasStatus(com.artipie.http.hm.RsHasStatus) RsStatus(com.artipie.http.rs.RsStatus) Authorization(com.artipie.http.headers.Authorization) BasicAuthSlice(com.artipie.http.auth.BasicAuthSlice) RequestLine(com.artipie.http.rq.RequestLine) RsWithStatus(com.artipie.http.rs.RsWithStatus) Permission(com.artipie.http.auth.Permission) ListOf(org.cactoos.list.ListOf) Base64Encoded(org.cactoos.text.Base64Encoded) Map(java.util.Map) SliceSimple(com.artipie.http.slice.SliceSimple) Test(org.junit.jupiter.api.Test)

Example 8 with RequestLine

use of com.artipie.http.rq.RequestLine in project artipie by artipie.

the class ResponseMetricsSliceTest method shouldForwardResponseUnmodified.

@Test
void shouldForwardResponseUnmodified() {
    final Header rsheader = new Header("header2", "value2");
    final byte[] body = "piece of code".getBytes();
    final RsStatus rsstatus = RsStatus.CREATED;
    final Response response = new ResponseMetricsSlice((rsline, rsheaders, rsbody) -> new RsFull(rsstatus, new Headers.From(rsheader), Flowable.just(ByteBuffer.wrap(body))), this.metrics).response(new RequestLine(RqMethod.PUT, "/").toString(), Headers.EMPTY, Flowable.empty());
    MatcherAssert.assertThat(response, new ResponseMatcher(rsstatus, body, rsheader));
}
Also used : Response(com.artipie.http.Response) RqMethod(com.artipie.http.rq.RqMethod) BeforeEach(org.junit.jupiter.api.BeforeEach) RsWithStatus(com.artipie.http.rs.RsWithStatus) Headers(com.artipie.http.Headers) Header(com.artipie.http.headers.Header) InMemoryMetrics(com.artipie.metrics.memory.InMemoryMetrics) ResponseMatcher(com.artipie.http.hm.ResponseMatcher) Response(com.artipie.http.Response) RsStatus(com.artipie.http.rs.RsStatus) CompletableFuture(java.util.concurrent.CompletableFuture) ByteBuffer(java.nio.ByteBuffer) RsFull(com.artipie.http.rs.RsFull) Test(org.junit.jupiter.api.Test) Authorization(com.artipie.http.headers.Authorization) RequestLine(com.artipie.http.rq.RequestLine) MatcherAssert(org.hamcrest.MatcherAssert) Flowable(io.reactivex.Flowable) IsEqual(org.hamcrest.core.IsEqual) RequestLine(com.artipie.http.rq.RequestLine) ResponseMatcher(com.artipie.http.hm.ResponseMatcher) RsFull(com.artipie.http.rs.RsFull) Header(com.artipie.http.headers.Header) Headers(com.artipie.http.Headers) RsStatus(com.artipie.http.rs.RsStatus) Test(org.junit.jupiter.api.Test)

Example 9 with RequestLine

use of com.artipie.http.rq.RequestLine in project artipie by artipie.

the class TrafficMetricSliceTest method updatesMetrics.

@Test
void updatesMetrics() throws Exception {
    final Metrics metrics = new InMemoryMetrics();
    final int req = 100;
    final int res = 50;
    new TrafficMetricSlice((line, head, body) -> new RsWithBody(Flowable.fromPublisher(body).ignoreElements().andThen(Flowable.just(ByteBuffer.wrap(new byte[res])))), metrics).response(new RequestLine(RqMethod.GET, "/foo").toString(), Collections.emptyList(), Flowable.just(ByteBuffer.wrap(new byte[req]))).send((status, headers, body) -> Flowable.fromPublisher(body).ignoreElements().to(CompletableInterop.await())).toCompletableFuture().get();
    final TestMetricsOutput out = new TestMetricsOutput();
    metrics.publish(out);
    MatcherAssert.assertThat("request body size wasn't updated", out.counters().get("request.body.size"), Matchers.equalTo((long) req));
    MatcherAssert.assertThat("response body size wasn't updated", out.counters().get("response.body.size"), Matchers.equalTo((long) res));
}
Also used : RequestLine(com.artipie.http.rq.RequestLine) InMemoryMetrics(com.artipie.metrics.memory.InMemoryMetrics) Metrics(com.artipie.metrics.Metrics) InMemoryMetrics(com.artipie.metrics.memory.InMemoryMetrics) TestMetricsOutput(com.artipie.metrics.memory.TestMetricsOutput) RsWithBody(com.artipie.http.rs.RsWithBody) Test(org.junit.jupiter.api.Test)

Example 10 with RequestLine

use of com.artipie.http.rq.RequestLine 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)

Aggregations

RequestLine (com.artipie.http.rq.RequestLine)26 RsHasStatus (com.artipie.http.hm.RsHasStatus)21 Test (org.junit.jupiter.api.Test)21 SliceHasResponse (com.artipie.http.hm.SliceHasResponse)16 RsStatus (com.artipie.http.rs.RsStatus)11 Content (com.artipie.asto.Content)9 Key (com.artipie.asto.Key)8 RsWithStatus (com.artipie.http.rs.RsWithStatus)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 SliceSimple (com.artipie.http.slice.SliceSimple)7 ContentIs (com.artipie.asto.test.ContentIs)6 RsHasBody (com.artipie.http.hm.RsHasBody)6 MetadataXml (com.artipie.maven.MetadataXml)6 BasicAuthSlice (com.artipie.http.auth.BasicAuthSlice)5 Authorization (com.artipie.http.headers.Authorization)5 RqMethod (com.artipie.http.rq.RqMethod)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 MatcherAssert (org.hamcrest.MatcherAssert)5 Permission (com.artipie.http.auth.Permission)4 Header (com.artipie.http.headers.Header)4