use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.
the class MockStorage method getAsset.
@Override
public StorageAsset getAsset(final String requestedPath) {
String path = requestedPath.startsWith("/") ? requestedPath : "/" + requestedPath;
if (assets.containsKey(path)) {
return assets.get(path);
}
String[] pathArr = splitPath(path);
StorageAsset parent = root;
for (String pathElement : pathArr) {
Optional<? extends StorageAsset> next = parent.list().stream().filter(a -> a.getName().equals(pathElement)).findFirst();
if (next.isPresent()) {
parent = next.get();
} else {
MockAsset asset = new MockAsset((MockAsset) parent, pathElement);
assets.put(asset.getPath(), asset);
parent = asset;
}
}
return parent;
}
use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.
the class MockStorage method addAsset.
@Override
public StorageAsset addAsset(String path, boolean container) {
String[] pathArr = splitPath(path);
StorageAsset parent = root;
for (String pathElement : pathArr) {
Optional<? extends StorageAsset> next = parent.list().stream().filter(a -> a.getName().equals(pathElement)).findFirst();
if (next.isPresent()) {
parent = next.get();
} else {
MockAsset asset = new MockAsset((MockAsset) parent, pathElement);
assets.put(asset.getPath(), asset);
parent = asset;
}
}
status.add(ADD, parent);
return parent;
}
use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.
the class AssetSpliteratorTest method forEachRemaining3.
@Test
void forEachRemaining3() {
StorageAsset root = createTree();
StorageAsset testRoot = root.list().get(1);
AssetSpliterator spliterator = new AssetSpliterator(testRoot);
final ConsumeVisitStatus status = new ConsumeVisitStatus();
spliterator.forEachRemaining(status);
int expected = LEVEL2 * LEVEL3 + LEVEL2 + 1;
assertEquals(expected, status.size());
assertEquals(testRoot, status.getLast());
}
use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.
the class AssetSpliteratorTest method forEachRemaining.
@Test
void forEachRemaining() {
StorageAsset root = createTree();
AssetSpliterator spliterator = new AssetSpliterator(root);
final ConsumeVisitStatus status = new ConsumeVisitStatus();
spliterator.forEachRemaining(status);
// 10 * 15 * 5 + 10 * 15 + 10 + 1
assertEquals(LEVEL1 * LEVEL2 * LEVEL3 + LEVEL1 * LEVEL2 + LEVEL1 + 1, status.size());
assertEquals(root, status.getLast());
}
use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.
the class AssetSpliteratorTest method forEachRemaining2.
@Test
void forEachRemaining2() {
StorageAsset root = createTree();
AssetSpliterator spliterator = new AssetSpliterator(root);
final ConsumeVisitStatus status = new ConsumeVisitStatus();
spliterator.tryAdvance(a -> {
});
spliterator.tryAdvance(a -> {
});
spliterator.tryAdvance(a -> {
});
spliterator.tryAdvance(a -> {
});
spliterator.forEachRemaining(status);
int expected = LEVEL1 * LEVEL2 * LEVEL3 + LEVEL1 * LEVEL2 + LEVEL1 + 1;
expected = expected - 4;
assertEquals(expected, status.size());
assertEquals(root, status.getLast());
}
Aggregations