Search in sources :

Example 6 with PublisherAs

use of com.artipie.asto.ext.PublisherAs in project maven-adapter by artipie.

the class AstoMavenTest method generatesMetadata.

@Test
void generatesMetadata() {
    final String latest = "0.20.2";
    this.addFilesToStorage(item -> !item.contains("1.0-SNAPSHOT") && !item.contains(latest), AstoMavenTest.ASTO);
    this.addFilesToStorage(item -> item.contains(latest), AstoMavenTest.ASTO_UPLOAD);
    this.metadataAndVersions(latest);
    new AstoMaven(this.storage).update(new Key.From(AstoMavenTest.ASTO_UPLOAD, latest), AstoMavenTest.ASTO).toCompletableFuture().join();
    MatcherAssert.assertThat("Maven metadata xml is not correct", new XMLDocument(this.storage.value(new Key.From(AstoMavenTest.ASTO, "maven-metadata.xml")).thenCompose(content -> new PublisherAs(content).string(StandardCharsets.UTF_8)).join()), new AllOf<>(new ListOf<Matcher<? super XML>>(// @checkstyle LineLengthCheck (20 lines)
    XhtmlMatchers.hasXPath("/metadata/groupId[text() = 'com.artipie']"), XhtmlMatchers.hasXPath("/metadata/artifactId[text() = 'asto']"), XhtmlMatchers.hasXPath("/metadata/versioning/latest[text() = '0.20.2']"), XhtmlMatchers.hasXPath("/metadata/versioning/release[text() = '0.20.2']"), XhtmlMatchers.hasXPath("/metadata/versioning/versions/version[text() = '0.15']"), XhtmlMatchers.hasXPath("/metadata/versioning/versions/version[text() = '0.11.1']"), XhtmlMatchers.hasXPath("/metadata/versioning/versions/version[text() = '0.20.1']"), XhtmlMatchers.hasXPath("/metadata/versioning/versions/version[text() = '0.20.2']"), XhtmlMatchers.hasXPath("/metadata/versioning/versions/version[text() = '0.18']"), XhtmlMatchers.hasXPath("metadata/versioning/versions[count(//version) = 5]"), XhtmlMatchers.hasXPath("/metadata/versioning/lastUpdated"))));
    MatcherAssert.assertThat("Artifacts were not moved to the correct location", this.storage.list(new Key.From(AstoMavenTest.ASTO, latest)).join().size(), new IsEqual<>(3));
    MatcherAssert.assertThat("Upload directory was not cleaned up", this.storage.list(new Key.From(AstoMavenTest.ASTO_UPLOAD, latest)).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) ListOf(org.cactoos.list.ListOf) Key(com.artipie.asto.Key) XMLDocument(com.jcabi.xml.XMLDocument) Test(org.junit.jupiter.api.Test)

Example 7 with PublisherAs

use of com.artipie.asto.ext.PublisherAs in project maven-adapter by artipie.

the class RepositoryChecksumsTest method generatesChecksums.

@Test
void generatesChecksums() {
    final Storage storage = new InMemoryStorage();
    final Key key = new Key.From("my-artifact.jar");
    final byte[] content = "my artifact content".getBytes();
    storage.save(key, new Content.From(content));
    new RepositoryChecksums(storage).generate(key).toCompletableFuture().join();
    MatcherAssert.assertThat("Generates sha1", new PublisherAs(storage.value(new Key.From(String.format("%s.sha1", key.string()))).join()).asciiString().toCompletableFuture().join(), new IsEqual<>(DigestUtils.sha1Hex(content)));
    MatcherAssert.assertThat("Generates sha256", new PublisherAs(storage.value(new Key.From(String.format("%s.sha256", key.string()))).join()).asciiString().toCompletableFuture().join(), new IsEqual<>(DigestUtils.sha256Hex(content)));
    MatcherAssert.assertThat("Generates sha512", new PublisherAs(storage.value(new Key.From(String.format("%s.sha512", key.string()))).join()).asciiString().toCompletableFuture().join(), new IsEqual<>(DigestUtils.sha512Hex(content)));
    MatcherAssert.assertThat("Generates md5", new PublisherAs(storage.value(new Key.From(String.format("%s.md5", key.string()))).join()).asciiString().toCompletableFuture().join(), new IsEqual<>(DigestUtils.md5Hex(content)));
}
Also used : InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) PublisherAs(com.artipie.asto.ext.PublisherAs) Storage(com.artipie.asto.Storage) InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) BlockingStorage(com.artipie.asto.blocking.BlockingStorage) Content(com.artipie.asto.Content) Key(com.artipie.asto.Key) Test(org.junit.jupiter.api.Test)

Example 8 with PublisherAs

use of com.artipie.asto.ext.PublisherAs in project maven-adapter by artipie.

the class HeadProxySliceTest method performsRequestWithEmptyHeaderAndBody.

@Test
void performsRequestWithEmptyHeaderAndBody() {
    new HeadProxySlice(new SliceSimple(StandardRs.EMPTY)).response("HEAD /some/path HTTP/1.1", new Headers.From("some", "value"), new Content.From("000".getBytes())).send((status, headers, body) -> {
        MatcherAssert.assertThat("Headers are empty", headers, new IsEmptyIterable<>());
        MatcherAssert.assertThat("Body is empty", new PublisherAs(body).bytes().toCompletableFuture().join(), new IsEqual<>(new byte[] {}));
        return CompletableFuture.allOf();
    });
}
Also used : PublisherAs(com.artipie.asto.ext.PublisherAs) SliceSimple(com.artipie.http.slice.SliceSimple) Test(org.junit.jupiter.api.Test)

Example 9 with PublisherAs

use of com.artipie.asto.ext.PublisherAs in project maven-adapter by artipie.

the class PutMetadataSlice method response.

@Override
public Response response(final String line, final Iterable<Map.Entry<String, String>> headers, final Publisher<ByteBuffer> body) {
    final Response res;
    final Matcher matcher = PutMetadataSlice.PTN_META.matcher(new RequestLineFrom(line).uri().getPath());
    if (matcher.matches()) {
        final Key pkg = new KeyFromPath(matcher.group("pkg"));
        res = new AsyncResponse(new PublisherAs(body).asciiString().thenCombine(this.asto.list(new Key.From(UploadSlice.TEMP, pkg)), (xml, list) -> {
            final Optional<String> snapshot = new DeployMetadata(xml).snapshots().stream().filter(item -> list.stream().anyMatch(key -> key.string().contains(item))).findFirst();
            final Key key;
            if (snapshot.isPresent()) {
                key = new Key.From(UploadSlice.TEMP, pkg.string(), snapshot.get(), PutMetadataSlice.SUB_META, PutMetadataSlice.MAVEN_METADATA);
            } else {
                key = new Key.From(UploadSlice.TEMP, pkg.string(), new DeployMetadata(xml).release(), PutMetadataSlice.SUB_META, PutMetadataSlice.MAVEN_METADATA);
            }
            return this.asto.save(key, new Content.From(xml.getBytes(StandardCharsets.US_ASCII)));
        }).thenApply(nothing -> new RsWithStatus(RsStatus.CREATED)));
    } else {
        res = new RsWithStatus(RsStatus.BAD_REQUEST);
    }
    return res;
}
Also used : PublisherAs(com.artipie.asto.ext.PublisherAs) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) RsWithStatus(com.artipie.http.rs.RsWithStatus) KeyFromPath(com.artipie.http.slice.KeyFromPath) DeployMetadata(com.artipie.maven.metadata.DeployMetadata) Slice(com.artipie.http.Slice) Publisher(org.reactivestreams.Publisher) Response(com.artipie.http.Response) RsStatus(com.artipie.http.rs.RsStatus) Content(com.artipie.asto.Content) Key(com.artipie.asto.Key) ByteBuffer(java.nio.ByteBuffer) StandardCharsets(java.nio.charset.StandardCharsets) PublisherAs(com.artipie.asto.ext.PublisherAs) Matcher(java.util.regex.Matcher) Storage(com.artipie.asto.Storage) Map(java.util.Map) AsyncResponse(com.artipie.http.async.AsyncResponse) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) Optional(java.util.Optional) Matcher(java.util.regex.Matcher) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) Response(com.artipie.http.Response) AsyncResponse(com.artipie.http.async.AsyncResponse) DeployMetadata(com.artipie.maven.metadata.DeployMetadata) KeyFromPath(com.artipie.http.slice.KeyFromPath) RsWithStatus(com.artipie.http.rs.RsWithStatus) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) AsyncResponse(com.artipie.http.async.AsyncResponse) Key(com.artipie.asto.Key)

Example 10 with PublisherAs

use of com.artipie.asto.ext.PublisherAs in project maven-adapter by artipie.

the class MavenITCase method deploysSnapshot.

@ParameterizedTest
@ValueSource(booleans = { true, false })
void deploysSnapshot(final boolean anonymous) throws Exception {
    this.init(anonymous);
    this.copyHellowordSourceToContainer();
    MatcherAssert.assertThat("Failed to set version 1.0-SNAPSHOT", this.exec("mvn", "-s", "/home/settings.xml", "-f", "/home/helloworld-src/pom.xml", "versions:set", "-DnewVersion=1.0-SNAPSHOT"), new StringContains("BUILD SUCCESS"));
    MatcherAssert.assertThat("Failed to deploy version 1.0-SNAPSHOT", this.exec("mvn", "-s", "/home/settings.xml", "-f", "/home/helloworld-src/pom.xml", "deploy"), new StringContains("BUILD SUCCESS"));
    this.clean();
    this.verifySnapshotAdded("1.0-SNAPSHOT");
    MatcherAssert.assertThat("Maven metadata xml is not correct", new XMLDocument(this.storage.value(new Key.From("com/artipie/helloworld/maven-metadata.xml")).thenCompose(content -> new PublisherAs(content).string(StandardCharsets.UTF_8)).join()), new AllOf<>(new ListOf<Matcher<? super XML>>(XhtmlMatchers.hasXPath("/metadata/versioning/latest[text() = '1.0-SNAPSHOT']"))));
}
Also used : Permissions(com.artipie.http.auth.Permissions) XhtmlMatchers(com.jcabi.matchers.XhtmlMatchers) Testcontainers(org.testcontainers.Testcontainers) AllOf(org.hamcrest.core.AllOf) AfterAll(org.junit.jupiter.api.AfterAll) Vertx(io.vertx.reactivex.core.Vertx) StringContains(org.hamcrest.core.StringContains) Pair(org.apache.commons.lang3.tuple.Pair) Storage(com.artipie.asto.Storage) ListOf(org.cactoos.list.ListOf) VertxSliceServer(com.artipie.vertx.VertxSliceServer) EnabledOnOs(org.junit.jupiter.api.condition.EnabledOnOs) GenericContainer(org.testcontainers.containers.GenericContainer) Authentication(com.artipie.http.auth.Authentication) Path(java.nio.file.Path) TestResource(com.artipie.asto.test.TestResource) ValueSource(org.junit.jupiter.params.provider.ValueSource) XMLDocument(com.jcabi.xml.XMLDocument) InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) Files(java.nio.file.Files) OS(org.junit.jupiter.api.condition.OS) StringContainsInOrder(org.hamcrest.text.StringContainsInOrder) LoggingSlice(com.artipie.http.slice.LoggingSlice) Matchers(org.hamcrest.Matchers) IOException(java.io.IOException) Key(com.artipie.asto.Key) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) PublisherAs(com.artipie.asto.ext.PublisherAs) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MatcherAssert(org.hamcrest.MatcherAssert) MavenSlice(com.artipie.maven.http.MavenSlice) TempDir(org.junit.jupiter.api.io.TempDir) Matcher(org.hamcrest.Matcher) Optional(java.util.Optional) FileUtils(org.testcontainers.shaded.org.apache.commons.io.FileUtils) XML(com.jcabi.xml.XML) PublisherAs(com.artipie.asto.ext.PublisherAs) ListOf(org.cactoos.list.ListOf) XMLDocument(com.jcabi.xml.XMLDocument) Key(com.artipie.asto.Key) StringContains(org.hamcrest.core.StringContains) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

PublisherAs (com.artipie.asto.ext.PublisherAs)12 Key (com.artipie.asto.Key)11 Storage (com.artipie.asto.Storage)10 InMemoryStorage (com.artipie.asto.memory.InMemoryStorage)9 StandardCharsets (java.nio.charset.StandardCharsets)7 Optional (java.util.Optional)7 Test (org.junit.jupiter.api.Test)7 Content (com.artipie.asto.Content)6 TestResource (com.artipie.asto.test.TestResource)6 XhtmlMatchers (com.jcabi.matchers.XhtmlMatchers)6 XML (com.jcabi.xml.XML)6 XMLDocument (com.jcabi.xml.XMLDocument)6 Collectors (java.util.stream.Collectors)6 ListOf (org.cactoos.list.ListOf)6 Matcher (org.hamcrest.Matcher)6 MatcherAssert (org.hamcrest.MatcherAssert)6 Matchers (org.hamcrest.Matchers)6 AllOf (org.hamcrest.core.AllOf)6 BlockingStorage (com.artipie.asto.blocking.BlockingStorage)5 FileStorage (com.artipie.asto.fs.FileStorage)5