Search in sources :

Example 1 with MetadataXml

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

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

Example 3 with MetadataXml

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

use of com.artipie.maven.MetadataXml 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 5 with MetadataXml

use of com.artipie.maven.MetadataXml in project maven-adapter by artipie.

the class AstoMavenTest method updatesCorrectlyWhenVersionIsDowngraded.

@Test
void updatesCorrectlyWhenVersionIsDowngraded() {
    final String version = "1.0";
    new MetadataXml("com.test", "logger").addXmlToStorage(this.storage, new Key.From(AstoMavenTest.LGR, "maven-metadata.xml"), new MetadataXml.VersionTags("2.0", "2.0", new ListOf<>("2.0")));
    this.storage.save(new Key.From(AstoMavenTest.LGR, "2.0", "logger-2.0.jar"), Content.EMPTY).join();
    new MetadataXml("com.test", "logger").addXmlToStorage(this.storage, new Key.From(AstoMavenTest.LGR_UPLOAD, version, PutMetadataSlice.SUB_META, "maven-metadata.xml"), new MetadataXml.VersionTags("2.0", "1.0", new ListOf<>("2.0", "1.0")));
    new AstoMaven(this.storage).update(new Key.From(AstoMavenTest.LGR_UPLOAD, version), AstoMavenTest.LGR).toCompletableFuture().join();
    MatcherAssert.assertThat("Maven metadata xml is not correct", new XMLDocument(this.storage.value(new Key.From(AstoMavenTest.LGR, "maven-metadata.xml")).thenCompose(content -> new PublisherAs(content).string(StandardCharsets.UTF_8)).join()), new AllOf<>(new ListOf<Matcher<? super XML>>(XhtmlMatchers.hasXPath("/metadata/groupId[text() = 'com.test']"), XhtmlMatchers.hasXPath("/metadata/artifactId[text() = 'logger']"), XhtmlMatchers.hasXPath("/metadata/versioning/latest[text() = '2.0']"), XhtmlMatchers.hasXPath("/metadata/versioning/release[text() = '2.0']"), XhtmlMatchers.hasXPath("/metadata/versioning/versions/version[text() = '2.0']"), XhtmlMatchers.hasXPath("/metadata/versioning/versions/version[text() = '1.0']"), XhtmlMatchers.hasXPath("/metadata/versioning/versions[count(//version) = 2]"), XhtmlMatchers.hasXPath("/metadata/versioning/lastUpdated"))));
    MatcherAssert.assertThat("Upload directory was not cleaned up", this.storage.list(new Key.From(AstoMavenTest.LGR_UPLOAD, version)).join().size(), new IsEqual<>(0));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) MetadataXml(com.artipie.maven.MetadataXml) XhtmlMatchers(com.jcabi.matchers.XhtmlMatchers) AllOf(org.hamcrest.core.AllOf) Storage(com.artipie.asto.Storage) FileStorage(com.artipie.asto.fs.FileStorage) ListOf(org.cactoos.list.ListOf) IsEqual(org.hamcrest.core.IsEqual) TestResource(com.artipie.asto.test.TestResource) XMLDocument(com.jcabi.xml.XMLDocument) InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) Predicate(java.util.function.Predicate) KeyLastPart(com.artipie.asto.ext.KeyLastPart) Matchers(org.hamcrest.Matchers) PutMetadataSlice(com.artipie.maven.http.PutMetadataSlice) Content(com.artipie.asto.Content) Key(com.artipie.asto.Key) BlockingStorage(com.artipie.asto.blocking.BlockingStorage) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) PublisherAs(com.artipie.asto.ext.PublisherAs) Stream(java.util.stream.Stream) MatcherAssert(org.hamcrest.MatcherAssert) Matcher(org.hamcrest.Matcher) Optional(java.util.Optional) XML(com.jcabi.xml.XML) PublisherAs(com.artipie.asto.ext.PublisherAs) XMLDocument(com.jcabi.xml.XMLDocument) MetadataXml(com.artipie.maven.MetadataXml) ListOf(org.cactoos.list.ListOf) Key(com.artipie.asto.Key) Test(org.junit.jupiter.api.Test)

Aggregations

MetadataXml (com.artipie.maven.MetadataXml)8 Content (com.artipie.asto.Content)7 Key (com.artipie.asto.Key)7 Test (org.junit.jupiter.api.Test)7 RsHasStatus (com.artipie.http.hm.RsHasStatus)6 SliceHasResponse (com.artipie.http.hm.SliceHasResponse)6 RequestLine (com.artipie.http.rq.RequestLine)6 ContentIs (com.artipie.asto.test.ContentIs)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 ContentDigest (com.artipie.asto.ext.ContentDigest)3 ContentLength (com.artipie.http.headers.ContentLength)3 Maven (com.artipie.maven.Maven)3 Storage (com.artipie.asto.Storage)1 BlockingStorage (com.artipie.asto.blocking.BlockingStorage)1 KeyLastPart (com.artipie.asto.ext.KeyLastPart)1 PublisherAs (com.artipie.asto.ext.PublisherAs)1 FileStorage (com.artipie.asto.fs.FileStorage)1 InMemoryStorage (com.artipie.asto.memory.InMemoryStorage)1 TestResource (com.artipie.asto.test.TestResource)1 PutMetadataSlice (com.artipie.maven.http.PutMetadataSlice)1