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;
}
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));
}
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));
}
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));
}
Aggregations