Search in sources :

Example 21 with RsHasStatus

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

the class ArtifactHeadResponseTest method notFoundIfDoesnExist.

@Test
void notFoundIfDoesnExist() {
    final Storage storage = new InMemoryStorage();
    MatcherAssert.assertThat(new ArtifactHeadResponse(storage, new Key.From("none")), new RsHasStatus(RsStatus.NOT_FOUND));
}
Also used : InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) Storage(com.artipie.asto.Storage) InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) BlockingStorage(com.artipie.asto.blocking.BlockingStorage) RsHasStatus(com.artipie.http.hm.RsHasStatus) Test(org.junit.jupiter.api.Test)

Example 22 with RsHasStatus

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

the class ContentLengthRestrictionTest method shouldPassRequestsWithinLimit.

@ParameterizedTest
@CsvSource({ "10,0", "10,not number", "10,1", "10,10" })
public void shouldPassRequestsWithinLimit(final int limit, final String value) {
    final Slice slice = new ContentLengthRestriction((line, headers, body) -> new RsWithStatus(RsStatus.OK), limit);
    final Response response = slice.response("", this.headers(value), Flowable.empty());
    MatcherAssert.assertThat(response, new RsHasStatus(RsStatus.OK));
}
Also used : Response(com.artipie.http.Response) RsWithStatus(com.artipie.http.rs.RsWithStatus) RsHasStatus(com.artipie.http.hm.RsHasStatus) Slice(com.artipie.http.Slice) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 23 with RsHasStatus

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

the class ContentLengthRestrictionTest method shouldPassRequestsWithoutContentLength.

@Test
public void shouldPassRequestsWithoutContentLength() {
    final int limit = 10;
    final Slice slice = new ContentLengthRestriction((line, headers, body) -> new RsWithStatus(RsStatus.OK), limit);
    final Response response = slice.response("", Collections.emptySet(), Flowable.empty());
    MatcherAssert.assertThat(response, new RsHasStatus(RsStatus.OK));
}
Also used : Response(com.artipie.http.Response) RsWithStatus(com.artipie.http.rs.RsWithStatus) RsHasStatus(com.artipie.http.hm.RsHasStatus) Slice(com.artipie.http.Slice) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 24 with RsHasStatus

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

the class DockerRoutingSliceTest method emptyDockerRequest.

@Test
void emptyDockerRequest() {
    final String username = "alice";
    final String password = "letmein";
    MatcherAssert.assertThat(new DockerRoutingSlice(new SettingsWithAuth(new Authentication.Single(username, password)), (line, headers, body) -> {
        throw new UnsupportedOperationException();
    }), new SliceHasResponse(new AllOf<>(Arrays.asList(new RsHasStatus(RsStatus.OK), new RsHasHeaders(new Headers.From("Docker-Distribution-API-Version", "registry/2.0")))), new RequestLine(RqMethod.GET, "/v2/"), new Headers.From(new Authorization.Basic(username, password)), Content.EMPTY));
}
Also used : RsHasHeaders(com.artipie.http.hm.RsHasHeaders) RqMethod(com.artipie.http.rq.RqMethod) Settings(com.artipie.Settings) Arrays(java.util.Arrays) RqLineHasUri(com.artipie.http.hm.RqLineHasUri) YamlMapping(com.amihaiemil.eoyaml.YamlMapping) Users(com.artipie.auth.Users) SliceHasResponse(com.artipie.http.hm.SliceHasResponse) RsStatus(com.artipie.http.rs.RsStatus) CompletableFuture(java.util.concurrent.CompletableFuture) Content(com.artipie.asto.Content) RsHasStatus(com.artipie.http.hm.RsHasStatus) Layout(com.artipie.Layout) AllOf(org.hamcrest.core.AllOf) Test(org.junit.jupiter.api.Test) Authorization(com.artipie.http.headers.Authorization) RequestLine(com.artipie.http.rq.RequestLine) CompletionStage(java.util.concurrent.CompletionStage) MatcherAssert(org.hamcrest.MatcherAssert) Flowable(io.reactivex.Flowable) Storage(com.artipie.asto.Storage) AssertSlice(com.artipie.http.hm.AssertSlice) Authentication(com.artipie.http.auth.Authentication) Collections(java.util.Collections) SliceHasResponse(com.artipie.http.hm.SliceHasResponse) RsHasStatus(com.artipie.http.hm.RsHasStatus) RsHasHeaders(com.artipie.http.hm.RsHasHeaders) RsHasHeaders(com.artipie.http.hm.RsHasHeaders) Authorization(com.artipie.http.headers.Authorization) RequestLine(com.artipie.http.rq.RequestLine) Authentication(com.artipie.http.auth.Authentication) AllOf(org.hamcrest.core.AllOf) Test(org.junit.jupiter.api.Test)

Example 25 with RsHasStatus

use of com.artipie.http.hm.RsHasStatus 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)

Aggregations

RsHasStatus (com.artipie.http.hm.RsHasStatus)27 Test (org.junit.jupiter.api.Test)23 RequestLine (com.artipie.http.rq.RequestLine)20 SliceHasResponse (com.artipie.http.hm.SliceHasResponse)15 RsWithStatus (com.artipie.http.rs.RsWithStatus)10 Content (com.artipie.asto.Content)9 Key (com.artipie.asto.Key)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 RsStatus (com.artipie.http.rs.RsStatus)8 SliceSimple (com.artipie.http.slice.SliceSimple)7 Storage (com.artipie.asto.Storage)6 ContentIs (com.artipie.asto.test.ContentIs)6 MetadataXml (com.artipie.maven.MetadataXml)6 InMemoryStorage (com.artipie.asto.memory.InMemoryStorage)5 RsHasBody (com.artipie.http.hm.RsHasBody)5 BlockingStorage (com.artipie.asto.blocking.BlockingStorage)4 Slice (com.artipie.http.Slice)4 BasicAuthSlice (com.artipie.http.auth.BasicAuthSlice)4 Permission (com.artipie.http.auth.Permission)4 Authorization (com.artipie.http.headers.Authorization)4