Search in sources :

Example 16 with ApplicationFile

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()));
}
Also used : ApplicationFile(com.yahoo.config.application.api.ApplicationFile) File(java.io.File)

Example 17 with ApplicationFile

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;
}
Also used : Exceptions(com.yahoo.yolean.Exceptions) List(java.util.List) java.io(java.io) Path(com.yahoo.path.Path) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LogLevel(com.yahoo.log.LogLevel) ApplicationFile(com.yahoo.config.application.api.ApplicationFile) IOUtils(com.yahoo.io.IOUtils) Logger(java.util.logging.Logger) ConfigUtils(com.yahoo.vespa.config.util.ConfigUtils) ArrayList(java.util.ArrayList) ApplicationFile(com.yahoo.config.application.api.ApplicationFile) ArrayList(java.util.ArrayList) ApplicationFile(com.yahoo.config.application.api.ApplicationFile)

Example 18 with ApplicationFile

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"));
}
Also used : ApplicationFile(com.yahoo.config.application.api.ApplicationFile) Test(org.junit.Test)

Example 19 with ApplicationFile

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));
}
Also used : Path(com.yahoo.path.Path) ApplicationFile(com.yahoo.config.application.api.ApplicationFile) Test(org.junit.Test)

Example 20 with ApplicationFile

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());
}
Also used : ApplicationFile(com.yahoo.config.application.api.ApplicationFile) Test(org.junit.Test)

Aggregations

ApplicationFile (com.yahoo.config.application.api.ApplicationFile)23 Test (org.junit.Test)11 Path (com.yahoo.path.Path)5 ArrayList (java.util.ArrayList)3 File (java.io.File)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ApplicationPackage (com.yahoo.config.application.api.ApplicationPackage)1 ApplicationId (com.yahoo.config.provision.ApplicationId)1 TenantName (com.yahoo.config.provision.TenantName)1 IOUtils (com.yahoo.io.IOUtils)1 LogLevel (com.yahoo.log.LogLevel)1 CompressedApplicationInputStreamTest (com.yahoo.vespa.config.server.http.CompressedApplicationInputStreamTest)1 ContentHandler (com.yahoo.vespa.config.server.http.ContentHandler)1 Tenant (com.yahoo.vespa.config.server.tenant.Tenant)1 ConfigUtils (com.yahoo.vespa.config.util.ConfigUtils)1 MockCurator (com.yahoo.vespa.curator.mock.MockCurator)1 Exceptions (com.yahoo.yolean.Exceptions)1 java.io (java.io)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1