Search in sources :

Example 11 with PublisherAs

use of com.artipie.asto.ext.PublisherAs 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)

Example 12 with PublisherAs

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

the class ConfigFileTest method valueFromStorageReturnsContentWhenYamlExist.

@ParameterizedTest
@ValueSource(strings = { ".yaml", ".yml", "" })
void valueFromStorageReturnsContentWhenYamlExist(final String extension) {
    final Storage storage = new InMemoryStorage();
    this.saveByKey(storage, ".yml");
    MatcherAssert.assertThat(new PublisherAs(new ConfigFile(new Key.From(ConfigFileTest.NAME + extension)).valueFrom(storage).toCompletableFuture().join()).bytes().toCompletableFuture().join(), new IsEqual<>(ConfigFileTest.CONTENT));
}
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) 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