Use temp dir and save value
@@ -30,18 +30,31 @@ import com.artipie.asto.Content;
import com.artipie.asto.Key;
import com.artipie.asto.Storage;
import com.artipie.asto.SubStorage;
+import com.artipie.asto.ext.PublisherAs;
+import com.artipie.asto.fs.FileStorage;
+import java.io.IOException;
+import java.nio.file.Path;
import org.hamcrest.MatcherAssert;
import org.hamcrest.core.IsEqual;
import org.hamcrest.core.IsInstanceOf;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
/**
* Test for {@link StorageYamlConfig}.
* @since 0.14
+ * @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
*/
final class StorageYamlConfigTest {
+ /**
+ * Temporary directory for file storage.
+ * @checkstyle VisibilityModifierCheck (3 lines)
+ */
+ @TempDir
+ Path tmp;
+
@Test
void throwsExceptionForInvalidStorageConfig() {
Assertions.assertThrows(
@@ -55,7 +68,7 @@ final class StorageYamlConfigTest {
}
@Test
- void worksForValidYamlConfig() {
+ void worksForValidYamlConfig() throws IOException {
MatcherAssert.assertThat(
this.config().storage(),
new IsInstanceOf(Storage.class)
@@ -63,7 +76,7 @@ final class StorageYamlConfigTest {
}
@Test
- void worksForYamlConfigWithAlias() {
+ void worksForYamlConfigWithAlias() throws IOException {
final String alias = "default";
MatcherAssert.assertThat(
new StorageYamlConfig(
@@ -82,7 +95,7 @@ final class StorageYamlConfigTest {
}
@Test
- void returnsSubStorage() {
+ void returnsSubStorage() throws IOException {
MatcherAssert.assertThat(
this.config().subStorage(new Key.From()),
new IsInstanceOf(SubStorage.class)
@@ -90,28 +103,36 @@ final class StorageYamlConfigTest {
}
@Test
- void returnsSubStorageWithCorrectPrefix() {
+ void returnsSubStorageWithCorrectPrefix() throws IOException {
final Key prefix = new Key.From("prefix");
- final Storage strg = this.config().subStorage(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(
- strg.list(Key.ROOT)
+ new PublisherAs(
+ new FileStorage(this.tmp)
+ .value(full)
.join()
- .contains(prefix),
- new IsEqual<>(true)
+ ).bytes()
+ .toCompletableFuture().join(),
+ new IsEqual<>(data)
);
}
- private StorageYamlConfig config() {
+ private StorageYamlConfig config() throws IOException {
return new StorageYamlConfig(
this.storageYaml(),
StorageAliases.EMPTY
);
}
- private YamlMapping storageYaml() {
+ private YamlMapping storageYaml() throws IOException {
return Yaml.createYamlMappingBuilder()
.add("type", "fs")
- .add("path", "/some/path")
+ .add("path", this.tmp.toString())
.build();
}
