Search in sources :

Example 21 with RequestLine

use of com.artipie.http.rq.RequestLine in project maven-adapter by artipie.

the class PutMetadataSliceTest method returnsCreatedAndSavesSnapshotMetadataWhenReleaseIsPresent.

@Test
void returnsCreatedAndSavesSnapshotMetadataWhenReleaseIsPresent() {
    final byte[] xml = new MetadataXml("com.example", "any").get(new MetadataXml.VersionTags(Optional.empty(), Optional.of("0.2"), new ListOf<String>("0.1", "0.2", "0.3-SNAPSHOT"))).getBytes(StandardCharsets.UTF_8);
    this.asto.save(new Key.From(UploadSlice.TEMP, "com/example/any/0.3-SNAPSHOT/any.jar"), Content.EMPTY).join();
    MatcherAssert.assertThat("Incorrect response status, CREATED is expected", this.pms, new SliceHasResponse(new RsHasStatus(RsStatus.CREATED), new RequestLine(RqMethod.PUT, "/com/example/any/maven-metadata.xml"), new Headers.From(new ContentLength(xml.length)), new Content.OneTime(new Content.From(xml))));
    MatcherAssert.assertThat("Metadata file was not saved to storage", this.asto.value(new Key.From(".upload/com/example/any/0.3-SNAPSHOT/meta/maven-metadata.xml")).join(), new ContentIs(xml));
}
Also used : SliceHasResponse(com.artipie.http.hm.SliceHasResponse) RsHasStatus(com.artipie.http.hm.RsHasStatus) ContentIs(com.artipie.asto.test.ContentIs) RequestLine(com.artipie.http.rq.RequestLine) MetadataXml(com.artipie.maven.MetadataXml) Content(com.artipie.asto.Content) ContentLength(com.artipie.http.headers.ContentLength) Key(com.artipie.asto.Key) Test(org.junit.jupiter.api.Test)

Example 22 with RequestLine

use of com.artipie.http.rq.RequestLine in project maven-adapter by artipie.

the class UploadSliceTest method savesDataToTempUpload.

@Test
void savesDataToTempUpload() {
    final byte[] data = "jar content".getBytes();
    MatcherAssert.assertThat("Wrong response status, CREATED is expected", this.ums, new SliceHasResponse(new RsHasStatus(RsStatus.CREATED), new RequestLine(RqMethod.PUT, "/com/artipie/asto/0.1/asto-0.1.jar"), new Headers.From(new ContentLength(data.length)), new Content.From(data)));
    MatcherAssert.assertThat("Uploaded data were not saved to storage", this.asto.value(new Key.From(".upload/com/artipie/asto/0.1/asto-0.1.jar")).join(), new ContentIs(data));
}
Also used : RequestLine(com.artipie.http.rq.RequestLine) SliceHasResponse(com.artipie.http.hm.SliceHasResponse) RsHasStatus(com.artipie.http.hm.RsHasStatus) ContentLength(com.artipie.http.headers.ContentLength) ContentIs(com.artipie.asto.test.ContentIs) Key(com.artipie.asto.Key) Test(org.junit.jupiter.api.Test)

Example 23 with RequestLine

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

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

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

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