Search in sources :

Example 6 with SliceHasResponse

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

the class CachedProxySliceTest method loadsCachedContent.

@Test
void loadsCachedContent() {
    final byte[] data = "cache".getBytes();
    MatcherAssert.assertThat(new CachedProxySlice((line, headers, body) -> new RsWithBody(ByteBuffer.wrap("123".getBytes())), (key, supplier, control) -> CompletableFuture.supplyAsync(() -> Optional.of(new Content.From(data)))), new SliceHasResponse(Matchers.allOf(new RsHasStatus(RsStatus.OK), new RsHasBody(data)), new RequestLine(RqMethod.GET, "/foo")));
}
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 7 with SliceHasResponse

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

the class PutMetadataChecksumSliceTest method returnsBadRequestWhenRepositoryIsNotValid.

@Test
void returnsBadRequestWhenRepositoryIsNotValid() {
    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 String alg = "md5";
    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, BAD_REQUEST is expected", new PutMetadataChecksumSlice(this.asto, new ValidUpload.Dummy(false, true), mvn), new SliceHasResponse(new RsHasStatus(RsStatus.BAD_REQUEST), new RequestLine(RqMethod.PUT, String.format("/com/example/abc/maven-metadata.xml.%s", alg)), Headers.EMPTY, new Content.From(mdfive)));
    MatcherAssert.assertThat("Repository update was started when it does not supposed to", mvn.wasUpdated(), new IsEqual<>(false));
}
Also used : Maven(com.artipie.maven.Maven) SliceHasResponse(com.artipie.http.hm.SliceHasResponse) RsHasStatus(com.artipie.http.hm.RsHasStatus) ContentDigest(com.artipie.asto.ext.ContentDigest) RequestLine(com.artipie.http.rq.RequestLine) MetadataXml(com.artipie.maven.MetadataXml) Content(com.artipie.asto.Content) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with SliceHasResponse

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

the class PutMetadataChecksumSliceTest method returnsCreatedWhenRepositoryIsNotReady.

@Test
void returnsCreatedWhenRepositoryIsNotReady() {
    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 String alg = "sha1";
    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, BAD_REQUEST is expected", new PutMetadataChecksumSlice(this.asto, new ValidUpload.Dummy(false, false), 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 started when it does not supposed to", mvn.wasUpdated(), new IsEqual<>(false));
}
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) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with SliceHasResponse

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

the class PutMetadataChecksumSliceTest method returnsBadRequestIfSuitableMetadataFileNotFound.

@Test
void returnsBadRequestIfSuitableMetadataFileNotFound() {
    this.asto.save(new Key.From(UploadSlice.TEMP, "com/example/xyz/0.1/meta/maven-metadata.xml"), new Content.From("xml".getBytes())).join();
    final Maven.Fake mvn = new Maven.Fake();
    MatcherAssert.assertThat("Incorrect response status, BAD REQUEST is expected", new PutMetadataChecksumSlice(this.asto, new ValidUpload.Dummy(), mvn), new SliceHasResponse(new RsHasStatus(RsStatus.BAD_REQUEST), new RequestLine(RqMethod.PUT, "/com/example/xyz/maven-metadata.xml.sha1"), Headers.EMPTY, new Content.From("any".getBytes())));
    MatcherAssert.assertThat("Repository update was started when it does not supposed to", mvn.wasUpdated(), new IsEqual<>(false));
}
Also used : Maven(com.artipie.maven.Maven) RequestLine(com.artipie.http.rq.RequestLine) SliceHasResponse(com.artipie.http.hm.SliceHasResponse) RsHasStatus(com.artipie.http.hm.RsHasStatus) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with SliceHasResponse

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

the class PutMetadataSliceTest method returnsCreatedAndSavesSnapshotMetadata.

@Test
void returnsCreatedAndSavesSnapshotMetadata() {
    final byte[] xml = new MetadataXml("com.example", "abc").get(new MetadataXml.VersionTags("0.1-SNAPSHOT", "0.2-SNAPSHOT")).getBytes(StandardCharsets.UTF_8);
    this.asto.save(new Key.From(UploadSlice.TEMP, "com/example/abc/0.2-SNAPSHOT/abc.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/abc/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/abc/0.2-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)

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