Search in sources :

Example 1 with Maven

use of com.artipie.maven.Maven 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 2 with Maven

use of com.artipie.maven.Maven 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 3 with Maven

use of com.artipie.maven.Maven 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 4 with Maven

use of com.artipie.maven.Maven 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)

Aggregations

RsHasStatus (com.artipie.http.hm.RsHasStatus)4 SliceHasResponse (com.artipie.http.hm.SliceHasResponse)4 RequestLine (com.artipie.http.rq.RequestLine)4 Maven (com.artipie.maven.Maven)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 Content (com.artipie.asto.Content)3 ContentDigest (com.artipie.asto.ext.ContentDigest)3 MetadataXml (com.artipie.maven.MetadataXml)3 Test (org.junit.jupiter.api.Test)3 Key (com.artipie.asto.Key)2 ContentIs (com.artipie.asto.test.ContentIs)2 ValueSource (org.junit.jupiter.params.provider.ValueSource)1