test artifact resolution fixed for Raw Layout
package org.carlspring.strongbox.testing;
import org.carlspring.commons.io.RandomInputStream;
+import org.carlspring.strongbox.providers.io.RepositoryPath;
+import org.carlspring.strongbox.providers.io.RepositoryPathResolver;
+import org.carlspring.strongbox.providers.repository.HostedRepositoryProvider;
import org.carlspring.strongbox.repository.RepositoryManagementStrategyException;
import org.carlspring.strongbox.services.RepositoryManagementService;
import org.carlspring.strongbox.services.StorageManagementService;
@@ -9,9 +12,9 @@ import org.carlspring.strongbox.storage.repository.Repository;
import javax.inject.Inject;
import javax.xml.bind.JAXBException;
-import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.file.Files;
/**
* @author carlspring
@@ -25,6 +28,11 @@ public abstract class TestCaseWithRepositoryManagement extends TestCaseWithRepos
@Inject
protected RepositoryManagementService repositoryManagementService;
+ @Inject
+ protected HostedRepositoryProvider hostedRepositoryProvider;
+
+ @Inject
+ protected RepositoryPathResolver repositoryPathResolver;
public void createStorage(String storageId)
throws IOException
@@ -76,22 +84,22 @@ public abstract class TestCaseWithRepositoryManagement extends TestCaseWithRepos
String path)
throws IOException
{
- File file = new File(repository.getBasedir(), path);
+ String repositoryId = repository.getId();
+ String storageId = repository.getStorage().getId();
- if (!file.getParentFile().exists())
- {
- //noinspection ResultOfMethodCallIgnored
- file.getParentFile().mkdirs();
- }
+ RepositoryPath repositoryPath = repositoryPathResolver.resolve(storageId, repositoryId, path);
+ Files.createDirectories(repositoryPath.getParent());
- createRandomSizeFile(file);
+ createRandomSizeFile(repositoryPath);
}
- private void createRandomSizeFile(File file)
+ private void createRandomSizeFile(RepositoryPath repositoryPath)
throws IOException
{
- FileOutputStream fos = new FileOutputStream(file);
- RandomInputStream ris = new RandomInputStream(true, 1000000);
+ try (OutputStream fos = hostedRepositoryProvider.getOutputStream(repositoryPath))
+ {
+ try (RandomInputStream ris = new RandomInputStream(true, 1000000))
+ {
byte[] buffer = new byte[4096];
int len;
@@ -99,11 +107,8 @@ public abstract class TestCaseWithRepositoryManagement extends TestCaseWithRepos
{
fos.write(buffer, 0, len);
}
-
- ris.close();
-
- fos.flush();
- fos.close();
+ }
+ }
}
}
