use of com.yahoo.config.application.api.ApplicationFile in project vespa by vespa-engine.
the class FilesApplicationFileTest method getApplicationFile.
@Override
public ApplicationFile getApplicationFile(Path path) throws Exception {
File tmp = temporaryFolder.newFolder();
writeAppTo(tmp);
return new FilesApplicationFile(path, new File(tmp, path.getRelative()));
}
use of com.yahoo.config.application.api.ApplicationFile in project vespa by vespa-engine.
the class FilesApplicationFile method listFiles.
@Override
public List<ApplicationFile> listFiles(final PathFilter filter) {
List<ApplicationFile> files = new ArrayList<>();
if (!file.isDirectory()) {
return files;
}
FileFilter fileFilter = pathname -> filter.accept(path.append(pathname.getName()));
for (File child : file.listFiles(fileFilter)) {
// Ignore dot-files.
if (!child.getName().startsWith(".")) {
files.add(new FilesApplicationFile(path.append(child.getName()), child));
}
}
return files;
}
use of com.yahoo.config.application.api.ApplicationFile in project vespa by vespa-engine.
the class ApplicationFileTest method testApplicationFileCreateFile.
@Test
public void testApplicationFileCreateFile() throws Exception {
ApplicationFile file = getApplicationFile(Path.fromString("newfile.txt"));
assertFalse(file.exists());
file.writeFile(new StringReader("foobar"));
assertTrue(file.exists());
assertFalse(file.isDirectory());
assertThat(com.yahoo.io.IOUtils.readAll(file.createReader()), is("foobar"));
}
use of com.yahoo.config.application.api.ApplicationFile in project vespa by vespa-engine.
the class ApplicationFileTest method testApplicationFileEquals.
@Test
public void testApplicationFileEquals() throws Exception {
Path p1 = Path.fromString("foo/bar/baz");
Path p2 = Path.fromString("foo/bar");
ApplicationFile f1 = getApplicationFile(p1);
ApplicationFile f2 = getApplicationFile(p2);
assertTrue(f1.equals(f1));
assertFalse(f1.equals(f2));
assertFalse(f2.equals(f1));
assertTrue(f2.equals(f2));
}
use of com.yahoo.config.application.api.ApplicationFile in project vespa by vespa-engine.
the class ApplicationFileTest method getGetMetaContent.
@Test
public void getGetMetaContent() throws Exception {
String testFileName = "file1.txt";
ApplicationFile file = getApplicationFile(Path.fromString(testFileName));
assertThat(file.getMetaPath().toString(), is(".meta/" + testFileName));
String input = "a";
file.writeFile(new StringReader(input));
assertThat(file.getMetaData().getStatus(), is(ApplicationFile.ContentStatusNew));
assertThat(file.getMetaData().getMd5(), is(ConfigUtils.getMd5(input)));
testFileName = "foo";
ApplicationFile fooDir = getApplicationFile(Path.fromString(testFileName));
fooDir.createDirectory();
assertThat(fooDir.getMetaData().getStatus(), is(ApplicationFile.ContentStatusNew));
assertThat(fooDir.getMetaData().getMd5(), is(""));
testFileName = "foo/file2.txt";
file = getApplicationFile(Path.fromString(testFileName));
input = "a";
file.writeFile(new StringReader(input));
assertThat(file.getMetaData().getStatus(), is(ApplicationFile.ContentStatusNew));
assertThat(file.getMetaData().getMd5(), is(ConfigUtils.getMd5(input)));
file.delete();
assertThat(file.getMetaData().getStatus(), is(ApplicationFile.ContentStatusDeleted));
assertThat(file.getMetaData().getMd5(), is(""));
fooDir.delete();
assertThat(fooDir.getMetaData().getStatus(), is(ApplicationFile.ContentStatusDeleted));
assertThat(file.getMetaData().getMd5(), is(""));
// non-existing file
testFileName = "non-existing";
file = getApplicationFile(Path.fromString(testFileName));
assertNull(file.getMetaData());
}
Aggregations