Search in sources :

Example 11 with ApplicationFile

use of com.yahoo.config.application.api.ApplicationFile in project vespa by vespa-engine.

the class ApplicationFileTest method testApplicationFileCreateDirectory.

@Test
public void testApplicationFileCreateDirectory() throws Exception {
    ApplicationFile file = getApplicationFile(Path.fromString("/notyet/exists/here"));
    assertFalse(file.exists());
    file.createDirectory();
    assertTrue(file.exists());
    assertTrue(file.isDirectory());
    file = getApplicationFile(Path.fromString("myDir")).createDirectory();
    assertTrue(file.isDirectory());
    file = getApplicationFile(Path.fromString("myDir/sub")).createDirectory();
    file = getApplicationFile(Path.fromString("myDir/sub")).createDirectory();
    assertTrue(file.isDirectory());
    file = getApplicationFile(Path.fromString("searchdefinitions/myDir2/")).createDirectory();
    assertTrue(file.isDirectory());
    file = getApplicationFile(Path.fromString("myDir3/myDir4/myDir5")).createDirectory();
    assertTrue(file.exists());
    assertTrue(file.isDirectory());
}
Also used : ApplicationFile(com.yahoo.config.application.api.ApplicationFile) Test(org.junit.Test)

Example 12 with ApplicationFile

use of com.yahoo.config.application.api.ApplicationFile in project vespa by vespa-engine.

the class ApplicationFileTest method assertFileContent.

private void assertFileContent(String expected, String path) throws Exception {
    ApplicationFile file = getApplicationFile(Path.fromString(path));
    String actual = com.yahoo.io.IOUtils.readAll(file.createReader());
    assertThat(actual, is(expected));
}
Also used : ApplicationFile(com.yahoo.config.application.api.ApplicationFile)

Example 13 with ApplicationFile

use of com.yahoo.config.application.api.ApplicationFile in project vespa by vespa-engine.

the class ApplicationFileTest method testApplicationFileListFiles.

@Test
public void testApplicationFileListFiles() throws Exception {
    ApplicationFile file = getApplicationFile(Path.createRoot());
    assertTrue(file.exists());
    assertTrue(file.isDirectory());
    List<ApplicationFile> list = file.listFiles();
    assertThat(list.size(), is(6));
    assertTrue(listContains(list, "vespa-services.xml"));
    assertTrue(listContains(list, "vespa-hosts.xml"));
    assertTrue(listContains(list, "components/"));
    assertTrue(listContains(list, "searchdefinitions/"));
    assertTrue(listContains(list, "templates/"));
    assertTrue(listContains(list, "files/"));
    list = getApplicationFile(Path.fromString("templates")).listFiles(false);
    assertTrue(listContains(list, "templates/basic/"));
    assertTrue(listContains(list, "templates/simple_html/"));
    assertTrue(listContains(list, "templates/text/"));
    list = getApplicationFile(Path.fromString("components")).listFiles(false);
    assertTrue(listContains(list, "components/defs-only.jar"));
    assertTrue(listContains(list, "components/file.txt"));
    list = getApplicationFile(Path.fromString("components")).listFiles(true);
    assertTrue(listContains(list, "components/defs-only.jar"));
    assertTrue(listContains(list, "components/file.txt"));
    list = getApplicationFile(Path.fromString("templates")).listFiles(true);
    assertThat(list.size(), is(14));
    assertTrue(listContains(list, "templates/basic/"));
    assertTrue(listContains(list, "templates/basic/error.templ"));
    assertTrue(listContains(list, "templates/basic/header.templ"));
    assertTrue(listContains(list, "templates/basic/hit.templ"));
    assertTrue(listContains(list, "templates/simple_html/"));
    assertTrue(listContains(list, "templates/simple_html/footer.templ"));
    assertTrue(listContains(list, "templates/simple_html/header.templ"));
    assertTrue(listContains(list, "templates/simple_html/hit.templ"));
    assertTrue(listContains(list, "templates/text/"));
    assertTrue(listContains(list, "templates/text/error.templ"));
    assertTrue(listContains(list, "templates/text/footer.templ"));
    assertTrue(listContains(list, "templates/text/header.templ"));
    assertTrue(listContains(list, "templates/text/hit.templ"));
    assertTrue(listContains(list, "templates/text/nohits.templ"));
    list = getApplicationFile(Path.createRoot()).listFiles(true);
    assertTrue(listContains(list, "components/"));
    assertTrue(listContains(list, "files/"));
    assertTrue(listContains(list, "searchdefinitions/"));
    assertTrue(listContains(list, "templates/"));
    assertTrue(listContains(list, "vespa-hosts.xml"));
    assertTrue(listContains(list, "vespa-services.xml"));
    assertTrue(listContains(list, "templates/text/"));
    assertTrue(listContains(list, "templates/text/error.templ"));
    assertTrue(listContains(list, "templates/text/footer.templ"));
    assertTrue(listContains(list, "templates/text/header.templ"));
    assertTrue(listContains(list, "templates/text/hit.templ"));
    assertTrue(listContains(list, "templates/text/nohits.templ"));
    list = getApplicationFile(Path.createRoot()).listFiles(new ApplicationFile.PathFilter() {

        @Override
        public boolean accept(Path path) {
            return path.getName().endsWith(".xml");
        }
    });
    assertThat(list.size(), is(2));
    assertFalse(listContains(list, "components/"));
    assertFalse(listContains(list, "files/"));
    assertFalse(listContains(list, "searchdefinitions/"));
    assertFalse(listContains(list, "templates/"));
    assertTrue(listContains(list, "vespa-hosts.xml"));
    assertTrue(listContains(list, "vespa-services.xml"));
}
Also used : Path(com.yahoo.path.Path) ApplicationFile(com.yahoo.config.application.api.ApplicationFile) Test(org.junit.Test)

Example 14 with ApplicationFile

use of com.yahoo.config.application.api.ApplicationFile in project vespa by vespa-engine.

the class ApplicationFileTest method testApplicationFileCreateFileWithPath.

@Test
public void testApplicationFileCreateFileWithPath() throws Exception {
    ApplicationFile file = getApplicationFile(Path.fromString("subdir/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 15 with ApplicationFile

use of com.yahoo.config.application.api.ApplicationFile in project vespa by vespa-engine.

the class SessionFactoryTest method require_that_application_name_is_set_in_application_package.

@Test
public void require_that_application_name_is_set_in_application_package() throws IOException, JSONException {
    LocalSession session = getLocalSession("book");
    assertNotNull(session);
    ApplicationFile meta = session.getApplicationFile(Path.createRoot().append(".applicationMetaData"), LocalSession.Mode.READ);
    assertTrue(meta.exists());
    JSONObject json = new JSONObject(IOUtils.readAll(meta.createReader()));
    assertThat(json.getJSONObject("application").getString("name"), is("book"));
}
Also used : JSONObject(org.json.JSONObject) ApplicationFile(com.yahoo.config.application.api.ApplicationFile) Test(org.junit.Test) CompressedApplicationInputStreamTest(com.yahoo.vespa.config.server.http.CompressedApplicationInputStreamTest)

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