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