blob: 1c4ba0293f6cf48fe590e0c35c59caae41ed53c6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server.filedistribution;
import com.yahoo.config.FileReference;
import com.yahoo.config.application.api.FileRegistry;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
/**
* A file registry for config server tests
*
* @author hmusum
*/
public class MockFileRegistry implements FileRegistry {
private final List<Entry> entries = new ArrayList<>();
private final AddFileInterface addFileInterface;
public MockFileRegistry(File applicationDir, Path rootPath) {
FileDirectory fileDirectory = new FileDirectory(rootPath.toFile());
this.addFileInterface = new ApplicationFileManager(applicationDir, fileDirectory);
}
public FileReference addFile(String relativePath) {
if (relativePath.isEmpty())
relativePath = "./";
try {
addFileInterface.addFile(relativePath);
FileReference fileReference = new FileReference(relativePath);
entries.add(new Entry(relativePath, fileReference));
return fileReference;
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
}
public List<Entry> export() { return entries; }
@Override
public FileReference addUri(String uri) {
throw new IllegalArgumentException("FileReference addUri(String uri) is not implemented for " + getClass().getCanonicalName());
}
@Override
public FileReference addBlob(String name, ByteBuffer blob) {
String relativePath = "./" + name;
FileReference fileReference = addFileInterface.addBlob(blob, relativePath);
entries.add(new Entry(relativePath, fileReference));
return fileReference;
}
}
|