Search in sources :

Example 1 with PublisherAs

use of com.artipie.asto.ext.PublisherAs in project artipie by artipie.

the class StorageYamlConfigTest method returnsSubStorageWithCorrectPrefix.

@Test
void returnsSubStorageWithCorrectPrefix() throws IOException {
    final Key prefix = new Key.From("prefix");
    final Key path = new Key.From("some/path");
    final Key full = new Key.From(prefix, path);
    final byte[] data = "content".getBytes();
    this.config().subStorage(prefix).save(path, new Content.From(data)).join();
    MatcherAssert.assertThat(new PublisherAs(new FileStorage(this.tmp).value(full).join()).bytes().toCompletableFuture().join(), new IsEqual<>(data));
}
Also used : PublisherAs(com.artipie.asto.ext.PublisherAs) FileStorage(com.artipie.asto.fs.FileStorage) Key(com.artipie.asto.Key) Test(org.junit.jupiter.api.Test)

Example 2 with PublisherAs

use of com.artipie.asto.ext.PublisherAs in project artipie by artipie.

the class ConfigFileTest method valueFromStorageReturnsYamlWhenBothExist.

@Test
void valueFromStorageReturnsYamlWhenBothExist() {
    final Storage storage = new InMemoryStorage();
    final String yaml = String.join("", Arrays.toString(ConfigFileTest.CONTENT), "some");
    this.saveByKey(storage, ".yml");
    this.saveByKey(storage, ".yaml", yaml.getBytes());
    MatcherAssert.assertThat(new PublisherAs(new ConfigFile(new Key.From(ConfigFileTest.NAME)).valueFrom(storage).toCompletableFuture().join()).asciiString().toCompletableFuture().join(), new IsEqual<>(yaml));
}
Also used : InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) PublisherAs(com.artipie.asto.ext.PublisherAs) InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) Storage(com.artipie.asto.Storage) Key(com.artipie.asto.Key) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with PublisherAs

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

the class MavenITCase method deploysSnapshotAfterRelease.

@ParameterizedTest
@ValueSource(booleans = { true, false })
void deploysSnapshotAfterRelease(final boolean anonymous) throws Exception {
    this.init(anonymous);
    this.copyHellowordSourceToContainer();
    MatcherAssert.assertThat("Failed to deploy version 1.0", this.exec("mvn", "-s", "/home/settings.xml", "-f", "/home/helloworld-src/pom.xml", "deploy"), new StringContains("BUILD SUCCESS"));
    this.clean();
    this.verifyArtifactsAdded("1.0");
    MatcherAssert.assertThat("Failed to set version 2.0-SNAPSHOT", this.exec("mvn", "-s", "/home/settings.xml", "-f", "/home/helloworld-src/pom.xml", "versions:set", "-DnewVersion=2.0-SNAPSHOT"), new StringContains("BUILD SUCCESS"));
    MatcherAssert.assertThat("Failed to deploy version 2.0", this.exec("mvn", "-s", "/home/settings.xml", "-f", "/home/helloworld-src/pom.xml", "deploy"), new StringContains("BUILD SUCCESS"));
    this.clean();
    this.verifySnapshotAdded("2.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() = '2.0-SNAPSHOT']"), XhtmlMatchers.hasXPath("/metadata/versioning/release[text() = '1.0']"))));
}
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)

Example 4 with PublisherAs

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

the class AstoMavenTest method generatesMetadataForFirstArtifact.

@Test
void generatesMetadataForFirstArtifact() {
    final String version = "1.0";
    new TestResource("maven-metadata.xml.example").saveTo(this.storage, new Key.From(AstoMavenTest.LGR_UPLOAD, version, PutMetadataSlice.SUB_META, "maven-metadata.xml"));
    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() = '1.0']"), XhtmlMatchers.hasXPath("/metadata/versioning/release[text() = '1.0']"), XhtmlMatchers.hasXPath("/metadata/versioning/versions/version[text() = '1.0']"), XhtmlMatchers.hasXPath("/metadata/versioning/versions[count(//version) = 1]"), 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) ListOf(org.cactoos.list.ListOf) TestResource(com.artipie.asto.test.TestResource) Key(com.artipie.asto.Key) XMLDocument(com.jcabi.xml.XMLDocument) Test(org.junit.jupiter.api.Test)

Example 5 with PublisherAs

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

the class AstoMavenTest method generatesWithSnapshotMetadata.

@Test
void generatesWithSnapshotMetadata() throws Exception {
    final String snapshot = "1.0-SNAPSHOT";
    final Predicate<String> cond = item -> !item.contains(snapshot);
    this.addFilesToStorage(cond, AstoMavenTest.ASTO);
    this.addFilesToStorage(cond.negate(), AstoMavenTest.ASTO_UPLOAD);
    this.metadataAndVersions(snapshot, "0.20.2");
    new AstoMaven(this.storage).update(new Key.From(AstoMavenTest.ASTO_UPLOAD, snapshot), AstoMavenTest.ASTO).toCompletableFuture().get();
    MatcherAssert.assertThat(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() = '1.0-SNAPSHOT']"), 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/version[text() = '1.0-SNAPSHOT']"), XhtmlMatchers.hasXPath("metadata/versioning/versions[count(//version) = 6]"), XhtmlMatchers.hasXPath("/metadata/versioning/lastUpdated"))));
    MatcherAssert.assertThat("Artifacts were not moved to the correct location", this.storage.list(new Key.From(AstoMavenTest.ASTO, snapshot)).join().size(), new IsEqual<>(12));
    MatcherAssert.assertThat("Upload directory was not cleaned up", this.storage.list(new Key.From(AstoMavenTest.ASTO_UPLOAD, snapshot)).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)

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