Search in sources :

Example 21 with Storage

use of com.artipie.asto.Storage in project artipie by artipie.

the class ConfigFile method existsIn.

/**
 * Does config file exist in the specified storage?
 * @param storage Storage where the file with different extensions is checked for existence
 * @return True if a file with either of the two extensions exists, false otherwise.
 */
public CompletionStage<Boolean> existsIn(final Storage storage) {
    final CompletionStage<Boolean> res;
    if (this.isYamlOrYml() || this.extension().isEmpty()) {
        final String name = this.name();
        final Key yaml = Extension.YAML.key(name);
        res = storage.exists(yaml).thenCompose(exist -> {
            final CompletionStage<Boolean> result;
            if (exist) {
                result = CompletableFuture.completedFuture(true);
            } else {
                final Key yml = Extension.YML.key(name);
                result = storage.exists(yml);
            }
            return result;
        });
    } else {
        res = CompletableFuture.completedFuture(false);
    }
    return res;
}
Also used : CompletionStage(java.util.concurrent.CompletionStage) Matcher(java.util.regex.Matcher) Storage(com.artipie.asto.Storage) Optional(java.util.Optional) CompletableFuture(java.util.concurrent.CompletableFuture) Pattern(java.util.regex.Pattern) Content(com.artipie.asto.Content) Key(com.artipie.asto.Key) Key(com.artipie.asto.Key) CompletionStage(java.util.concurrent.CompletionStage)

Example 22 with Storage

use of com.artipie.asto.Storage in project artipie by artipie.

the class ConfigFileTest method existInStorageReturnsTrueWhenYamlExist.

@ParameterizedTest
@ValueSource(strings = { ".yaml", ".yml", "" })
void existInStorageReturnsTrueWhenYamlExist(final String extension) {
    final Storage storage = new InMemoryStorage();
    this.saveByKey(storage, ".yaml");
    MatcherAssert.assertThat(new ConfigFile(new Key.From(ConfigFileTest.NAME + extension)).existsIn(storage).toCompletableFuture().join(), new IsEqual<>(true));
}
Also used : InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) 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)

Example 23 with Storage

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

Example 24 with Storage

use of com.artipie.asto.Storage in project artipie by artipie.

the class StorageYamlConfigTest method worksForYamlConfigWithAlias.

@Test
void worksForYamlConfigWithAlias() throws IOException {
    final String alias = "default";
    MatcherAssert.assertThat(new StorageYamlConfig(Yaml.createYamlScalarBuilder().addLine(alias).buildPlainScalar(), new StorageAliases.FromYaml(Yaml.createYamlMappingBuilder().add("storages", Yaml.createYamlMappingBuilder().add(alias, this.storageYaml()).build()).build())).storage(), new IsInstanceOf(Storage.class));
}
Also used : SubStorage(com.artipie.asto.SubStorage) Storage(com.artipie.asto.Storage) FileStorage(com.artipie.asto.fs.FileStorage) IsInstanceOf(org.hamcrest.core.IsInstanceOf) StorageAliases(com.artipie.StorageAliases) Test(org.junit.jupiter.api.Test)

Aggregations

Storage (com.artipie.asto.Storage)24 Key (com.artipie.asto.Key)17 InMemoryStorage (com.artipie.asto.memory.InMemoryStorage)15 Test (org.junit.jupiter.api.Test)15 BlockingStorage (com.artipie.asto.blocking.BlockingStorage)10 RsHasStatus (com.artipie.http.hm.RsHasStatus)6 Content (com.artipie.asto.Content)4 PublisherAs (com.artipie.asto.ext.PublisherAs)4 FileStorage (com.artipie.asto.fs.FileStorage)4 YamlMapping (com.amihaiemil.eoyaml.YamlMapping)3 TestResource (com.artipie.asto.test.TestResource)3 RsHasBody (com.artipie.http.hm.RsHasBody)3 Optional (java.util.Optional)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 CompletionStage (java.util.concurrent.CompletionStage)3 StrictYamlMapping (com.amihaiemil.eoyaml.StrictYamlMapping)2 SubStorage (com.artipie.asto.SubStorage)2 EtcdStorage (com.artipie.asto.etcd.EtcdStorage)2 S3Storage (com.artipie.asto.s3.S3Storage)2 Slice (com.artipie.http.Slice)2