Search in sources :

Example 21 with FilesystemAsset

use of org.apache.archiva.repository.storage.fs.FilesystemAsset in project archiva by apache.

the class FilesystemAssetTest method storeDataFile.

@Test
public void storeDataFile() throws IOException {
    FilesystemAsset asset = new FilesystemAsset(filesystemStorage, "/test1234", assetPathFile);
    Path dataFile = Files.createTempFile("testdata", "dat");
    try (OutputStream os = Files.newOutputStream(dataFile)) {
        IOUtils.write("testkdkdkd", os, "ASCII");
    }
    asset.replaceDataFromFile(dataFile);
    Assert.assertEquals("testkdkdkd", IOUtils.toString(assetPathFile.toUri().toURL(), "ASCII"));
}
Also used : Path(java.nio.file.Path) OutputStream(java.io.OutputStream) FilesystemAsset(org.apache.archiva.repository.storage.fs.FilesystemAsset) Test(org.junit.Test)

Example 22 with FilesystemAsset

use of org.apache.archiva.repository.storage.fs.FilesystemAsset in project archiva by apache.

the class FilesystemAssetTest method getPath.

@Test
public void getPath() {
    FilesystemAsset asset = new FilesystemAsset(filesystemStorage, assetPathFile.getFileName().toString(), assetPathFile);
    Assert.assertEquals("/" + assetPathFile.getFileName().toString(), asset.getPath());
}
Also used : FilesystemAsset(org.apache.archiva.repository.storage.fs.FilesystemAsset) Test(org.junit.Test)

Example 23 with FilesystemAsset

use of org.apache.archiva.repository.storage.fs.FilesystemAsset in project archiva by apache.

the class FilesystemAssetTest method writeDataAppend.

@Test
public void writeDataAppend() throws IOException {
    FilesystemAsset asset = new FilesystemAsset(filesystemStorage, "/test1234", assetPathFile);
    Files.write(assetPathFile, "abcdef".getBytes("ASCII"));
    try (OutputStream os = asset.getWriteStream(false)) {
        IOUtils.write("test12345", os, "ASCII");
    }
    Assert.assertEquals("abcdeftest12345", IOUtils.toString(assetPathFile.toUri().toURL(), "ASCII"));
}
Also used : OutputStream(java.io.OutputStream) FilesystemAsset(org.apache.archiva.repository.storage.fs.FilesystemAsset) Test(org.junit.Test)

Example 24 with FilesystemAsset

use of org.apache.archiva.repository.storage.fs.FilesystemAsset in project archiva by apache.

the class FilesystemAssetTest method getData.

@Test
public void getData() throws IOException {
    FilesystemAsset asset = new FilesystemAsset(filesystemStorage, "/test1234", assetPathFile);
    Files.write(assetPathFile, "abcdef".getBytes("ASCII"));
    try (InputStream is = asset.getReadStream()) {
        Assert.assertEquals("abcdef", IOUtils.toString(is, "ASCII"));
    }
}
Also used : InputStream(java.io.InputStream) FilesystemAsset(org.apache.archiva.repository.storage.fs.FilesystemAsset) Test(org.junit.Test)

Example 25 with FilesystemAsset

use of org.apache.archiva.repository.storage.fs.FilesystemAsset in project archiva by apache.

the class FilesystemAssetTest method getDataExceptionOnDir.

@Test
public void getDataExceptionOnDir() throws IOException {
    FilesystemAsset asset = new FilesystemAsset(filesystemStorage, "/test1234", assetPathDir);
    Files.write(assetPathFile, "abcdef".getBytes("ASCII"));
    try {
        InputStream is = asset.getReadStream();
        Assert.assertFalse("Exception expected for data on dir", true);
    } catch (IOException e) {
    // fine
    }
}
Also used : InputStream(java.io.InputStream) FilesystemAsset(org.apache.archiva.repository.storage.fs.FilesystemAsset) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

FilesystemAsset (org.apache.archiva.repository.storage.fs.FilesystemAsset)26 Test (org.junit.Test)20 Path (java.nio.file.Path)13 DefaultFileLockManager (org.apache.archiva.common.filelock.DefaultFileLockManager)13 FilesystemStorage (org.apache.archiva.repository.storage.fs.FilesystemStorage)13 ArtifactContentEntry (org.apache.archiva.rest.api.model.ArtifactContentEntry)6 OutputStream (java.io.OutputStream)5 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 URI (java.net.URI)3 IndexCreationFeature (org.apache.archiva.repository.features.IndexCreationFeature)3 Instant (java.time.Instant)2 Before (org.junit.Before)2 Files (java.nio.file.Files)1 Paths (java.nio.file.Paths)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 TimeZone (java.util.TimeZone)1 Configuration (org.apache.archiva.configuration.model.Configuration)1