Search in sources :

Example 1 with SliceHasResponse

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

use of com.artipie.http.hm.SliceHasResponse 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 3 with SliceHasResponse

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

the class HeadProxySliceTest method passesStatusAndHeadersFromResponse.

@Test
void passesStatusAndHeadersFromResponse() {
    final RsStatus status = RsStatus.CREATED;
    final Headers.From headers = new Headers.From("abc", "123");
    MatcherAssert.assertThat(new HeadProxySlice(new SliceSimple(new RsWithHeaders(new RsWithStatus(status), headers))), new SliceHasResponse(Matchers.allOf(new RsHasStatus(status), new RsHasHeaders(headers)), new RequestLine(RqMethod.HEAD, "/")));
}
Also used : RequestLine(com.artipie.http.rq.RequestLine) SliceHasResponse(com.artipie.http.hm.SliceHasResponse) RsWithStatus(com.artipie.http.rs.RsWithStatus) RsHasStatus(com.artipie.http.hm.RsHasStatus) RsWithHeaders(com.artipie.http.rs.RsWithHeaders) RsHasHeaders(com.artipie.http.hm.RsHasHeaders) Headers(com.artipie.http.Headers) RsWithHeaders(com.artipie.http.rs.RsWithHeaders) RsStatus(com.artipie.http.rs.RsStatus) RsHasHeaders(com.artipie.http.hm.RsHasHeaders) SliceSimple(com.artipie.http.slice.SliceSimple) Test(org.junit.jupiter.api.Test)

Example 4 with SliceHasResponse

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

the class PutMetadataChecksumSliceTest method foundsCorrespondingMetadataAndSavesChecksum.

@ParameterizedTest
@ValueSource(strings = { "md5", "sha1", "sha256", "sha512" })
void foundsCorrespondingMetadataAndSavesChecksum(final String alg) {
    final byte[] xml = new MetadataXml("com.example", "abc").get(new MetadataXml.VersionTags("0.1")).getBytes(StandardCharsets.UTF_8);
    this.asto.save(new Key.From(UploadSlice.TEMP, "com/example/abc/0.1/meta/maven-metadata.xml"), new Content.From(xml)).join();
    this.asto.save(new Key.From(UploadSlice.TEMP, "com/example/abc/0.2/meta/maven-metadata.xml"), new Content.From("any".getBytes())).join();
    final byte[] mdfive = new ContentDigest(new Content.From(xml), Digests.valueOf(alg.toUpperCase(Locale.US))).hex().toCompletableFuture().join().getBytes(StandardCharsets.US_ASCII);
    final Maven.Fake mvn = new Maven.Fake();
    MatcherAssert.assertThat("Incorrect response status, CREATED is expected", new PutMetadataChecksumSlice(this.asto, new ValidUpload.Dummy(), mvn), new SliceHasResponse(new RsHasStatus(RsStatus.CREATED), new RequestLine(RqMethod.PUT, String.format("/com/example/abc/maven-metadata.xml.%s", alg)), Headers.EMPTY, new Content.From(mdfive)));
    MatcherAssert.assertThat("Incorrect content was saved to storage", this.asto.value(new Key.From(String.format(".upload/com/example/abc/0.1/meta/maven-metadata.xml.%s", alg))).join(), new ContentIs(mdfive));
    MatcherAssert.assertThat("Repository update was not started", mvn.wasUpdated(), new IsEqual<>(true));
}
Also used : Maven(com.artipie.maven.Maven) SliceHasResponse(com.artipie.http.hm.SliceHasResponse) RsHasStatus(com.artipie.http.hm.RsHasStatus) ContentIs(com.artipie.asto.test.ContentIs) ContentDigest(com.artipie.asto.ext.ContentDigest) RequestLine(com.artipie.http.rq.RequestLine) MetadataXml(com.artipie.maven.MetadataXml) Content(com.artipie.asto.Content) Key(com.artipie.asto.Key) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with SliceHasResponse

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

the class PutMetadataSliceTest method returnsCreatedAndSavesMetadata.

@Test
void returnsCreatedAndSavesMetadata() {
    final byte[] xml = new MetadataXml("com.example", "any").get(new MetadataXml.VersionTags("0.1", "0.2", new ListOf<String>("0.1", "0.2"))).getBytes(StandardCharsets.UTF_8);
    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.2/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)

Aggregations

SliceHasResponse (com.artipie.http.hm.SliceHasResponse)16 RequestLine (com.artipie.http.rq.RequestLine)16 RsHasStatus (com.artipie.http.hm.RsHasStatus)15 Test (org.junit.jupiter.api.Test)14 Content (com.artipie.asto.Content)9 Key (com.artipie.asto.Key)7 ContentIs (com.artipie.asto.test.ContentIs)6 RsHasBody (com.artipie.http.hm.RsHasBody)6 MetadataXml (com.artipie.maven.MetadataXml)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 ContentLength (com.artipie.http.headers.ContentLength)4 RsStatus (com.artipie.http.rs.RsStatus)4 Maven (com.artipie.maven.Maven)4 ContentDigest (com.artipie.asto.ext.ContentDigest)3 RsHasHeaders (com.artipie.http.hm.RsHasHeaders)3 RqMethod (com.artipie.http.rq.RqMethod)3 RsWithStatus (com.artipie.http.rs.RsWithStatus)3 SliceSimple (com.artipie.http.slice.SliceSimple)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 MatcherAssert (org.hamcrest.MatcherAssert)3