Search in sources :

Example 46 with Project

use of com.developmentontheedge.be5.metadata.model.Project in project be5 by DevelopmentOnTheEdge.

the class ModuleLoader2MergeModulesTest method createModuleWithQueryRoles.

private Project createModuleWithQueryRoles(Project project, Project entityOwner, String moduleName, String queryName, String roleName, Path path) throws Exception {
    Project moduleProject = new Project(moduleName, true);
    Entity entity;
    if (entityOwner == null) {
        entity = ProjectTestUtils.createEntity(moduleProject, "moduleEntity", "ID");
    } else {
        Module appModule = new Module(entityOwner.getName(), moduleProject.getModules());
        DataElementUtils.save(appModule);
        entity = new Entity("moduleEntity", appModule, EntityType.TABLE);
        DataElementUtils.save(entity);
    }
    ProjectTestUtils.createScheme(entity);
    ProjectTestUtils.createQuery(entity, queryName, Collections.singletonList('@' + roleName));
    moduleProject.setRoles(Collections.singletonList(roleName));
    setRoleGroups(moduleProject, roleName);
    Module appModule = new Module(moduleName, project.getModules());
    DataElementUtils.save(appModule);
    Serialization.save(moduleProject, path);
    return moduleProject;
}
Also used : Project(com.developmentontheedge.be5.metadata.model.Project) Entity(com.developmentontheedge.be5.metadata.model.Entity) Module(com.developmentontheedge.be5.metadata.model.Module)

Example 47 with Project

use of com.developmentontheedge.be5.metadata.model.Project in project be5 by DevelopmentOnTheEdge.

the class ModuleLoader2Test method loadAllProjectsTestWithDev.

@Test
public void loadAllProjectsTestWithDev() throws IOException, ProjectSaveException, ProjectLoadException {
    try (PrintWriter out = new PrintWriter(path.resolve("dev.yaml").toFile())) {
        out.println("paths:" + "\n    test: " + path.toAbsolutePath());
    }
    ModuleLoader2.loadAllProjects(Collections.singletonList(path.resolve("project.yaml").toUri().toURL()));
    ModuleLoader2.readDevPathsToSourceProjects(Collections.singletonList(path.resolve("dev.yaml").toUri().toURL()));
    assertTrue(ModuleLoader2.getPathsToProjectsToHotReload().toString().startsWith("{test="));
    assertEquals(1, ModuleLoader2.getPathsToProjectsToHotReload().size());
    Project loadProject = ModuleLoader2.findAndLoadProjectWithModules();
    assertEquals("test", loadProject.getAppName());
    ModuleLoader2.getFileSystem(loadProject, "test");
}
Also used : Project(com.developmentontheedge.be5.metadata.model.Project) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 48 with Project

use of com.developmentontheedge.be5.metadata.model.Project in project be5 by DevelopmentOnTheEdge.

the class ProjectFileSystemTest method testPathsMap.

@Test
public void testPathsMap() throws IOException {
    Project prj = new Project("test");
    Path root = tmp.newFolder().toPath();
    prj.setLocation(root);
    ProjectFileSystem pfs = new ProjectFileSystem(prj);
    Map<Path, Boolean> map = EntryStream.of(pfs.getPaths()).mapKeys(root::relativize).toSortedMap();
    assertTrue(StreamEx.of("", "src", "src/js/extenders", "src/js/forms", "src/js/operations", "src/js/queries", "src/l10n", "src/meta/data", "src/meta/entities").map(Paths::get).noneMatch(map::get));
    assertTrue(StreamEx.of("src/ftl", "src/include", "src/meta/modules", "src/groovy/operations", "src/pages").map(Paths::get).allMatch(map::get));
}
Also used : Path(java.nio.file.Path) Project(com.developmentontheedge.be5.metadata.model.Project) Paths(java.nio.file.Paths) Test(org.junit.Test)

Example 49 with Project

use of com.developmentontheedge.be5.metadata.model.Project in project be5 by DevelopmentOnTheEdge.

the class SerializationTest method testSerializationBasics.

@Test
public void testSerializationBasics() throws IOException, ProjectSaveException, ProjectLoadException {
    Path path = tmp.newFolder().toPath();
    Project project = ProjectTestUtils.getProject("test");
    Entity entity = ProjectTestUtils.createEntity(project, "entity", "ID");
    TableDef scheme = ProjectTestUtils.createScheme(entity);
    // only for test SqlColumnType getType( Collection<ColumnDef> stack )
    ColumnDef column3 = new ColumnDef("column3", scheme.getColumns());
    column3.setTableTo(entity.getName());
    column3.setColumnsTo("ID");
    DataElementUtils.save(column3);
    Query query = ProjectTestUtils.createQuery(entity, "All records", Arrays.asList('@' + SpecialRoleGroup.ALL_ROLES_EXCEPT_GUEST_GROUP, "-User"));
    query.getOperationNames().setValues(Collections.singleton("op"));
    ProjectTestUtils.createOperation(entity);
    Serialization.save(project, path);
    assertEquals(path, project.getLocation());
    LoadContext lc = new LoadContext();
    Project project2 = Serialization.load(path, lc);
    project2.setDatabaseSystem(Rdbms.POSTGRESQL);
    lc.check();
    Entity entity2 = project2.getEntity("entity");
    assertEquals(entity, entity2);
    assertTrue(entity2.isBesql());
    assertEquals("VARCHAR(20)", entity2.findTableDefinition().getColumns().get("name").getTypeString());
    assertEquals(StreamEx.of("Administrator", "Operator").toSet(), entity2.getQueries().get("All records").getRoles().getFinalValues());
    assertEquals("op", entity2.getQueries().get("All records").getOperationNames().getFinalValuesString());
}
Also used : Path(java.nio.file.Path) Project(com.developmentontheedge.be5.metadata.model.Project) Entity(com.developmentontheedge.be5.metadata.model.Entity) Query(com.developmentontheedge.be5.metadata.model.Query) ColumnDef(com.developmentontheedge.be5.metadata.model.ColumnDef) TableDef(com.developmentontheedge.be5.metadata.model.TableDef) Test(org.junit.Test)

Example 50 with Project

use of com.developmentontheedge.be5.metadata.model.Project in project be5 by DevelopmentOnTheEdge.

the class FreemarkerSqlHandlerTest method testHandler.

@Test
public void testHandler() throws UnsupportedEncodingException, IOException, FreemarkerSqlException, ProjectElementException {
    ByteArrayOutputStream log = new ByteArrayOutputStream();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(log, true, "UTF-8");
    PrintStream psOut = new PrintStream(out, true, "UTF-8");
    SqlExecutor executor = new SqlExecutor(new NullConnector(), ps, SqlExecutor.class.getResource("basesql.properties"));
    FreemarkerSqlHandler handler = new FreemarkerSqlHandler(executor, true, new WriterLogger(psOut));
    Project proj = new Project("test");
    proj.setDatabaseSystem(Rdbms.POSTGRESQL);
    FreemarkerScript sql = new FreemarkerScript("sql", proj.getApplication().getFreemarkerScripts());
    DataElementUtils.save(sql);
    FreemarkerScript sql2 = new FreemarkerScript("sql2", proj.getApplication().getFreemarkerScripts());
    DataElementUtils.save(sql2);
    sql2.setSource("UPDATE test SET b = 'c';");
    sql.setSource("delete from test;-- hehehe\nINSERT INTO \"test\" VALUES('a','b','c');\nBEGIN update test SET a='a''b END;';END;\nDELETE FROM test;<#include 'sql2'/>");
    handler.execute(sql);
    String result = new String(log.toByteArray(), StandardCharsets.UTF_8);
    String expected = "\n" + "-- Execute test/application/Scripts/sql\n" + "-- At test/application/Scripts/sql[1,1]-[1,17]\n" + "delete from test;\n" + "-- At test/application/Scripts/sql[2,1]-[2,39]\n" + "INSERT INTO \"test\" VALUES('a','b','c');\n" + "-- At test/application/Scripts/sql[3,1]-[3,40]\n" + "BEGIN update test SET a='a''b END;';END;\n" + "-- At test/application/Scripts/sql[4,1]-[4,17]\n" + "DELETE FROM test;\n" + "-- At test/application/Scripts/sql[4,18]-[4,35]\n" + "-- At test/application/Scripts/sql2[1,1]-[1,24]\n" + "\n" + "-- Start of included test/application/Scripts/sql2\n" + "UPDATE test SET b = 'c';\n" + "-- End of included test/application/Scripts/sql2\n";
    assertEquals(expected, result.replace("\r", ""));
    String outResult = new String(out.toByteArray(), StandardCharsets.UTF_8);
    String outExpected = "xx:xx:xx: [>] test/application/Scripts/sql\n" + "xx:xx:xx: [>]   test/application/Scripts/sql2\n";
    assertEquals(outExpected, outResult.replace("\r", "").replaceAll("\\d\\d", "xx"));
}
Also used : PrintStream(java.io.PrintStream) SqlExecutor(com.developmentontheedge.dbms.SqlExecutor) WriterLogger(com.developmentontheedge.be5.metadata.util.WriterLogger) Project(com.developmentontheedge.be5.metadata.model.Project) FreemarkerScript(com.developmentontheedge.be5.metadata.model.FreemarkerScript) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

Project (com.developmentontheedge.be5.metadata.model.Project)40 Module (com.developmentontheedge.be5.metadata.model.Module)19 Test (org.junit.Test)19 Entity (com.developmentontheedge.be5.metadata.model.Entity)14 Path (java.nio.file.Path)13 Query (com.developmentontheedge.be5.metadata.model.Query)12 LoadContext (com.developmentontheedge.be5.metadata.serialization.LoadContext)7 ArrayList (java.util.ArrayList)7 ProjectLoadException (com.developmentontheedge.be5.metadata.exception.ProjectLoadException)6 FreemarkerScript (com.developmentontheedge.be5.metadata.model.FreemarkerScript)5 URL (java.net.URL)5 Map (java.util.Map)5 ReadException (com.developmentontheedge.be5.metadata.exception.ReadException)4 BeConnectionProfile (com.developmentontheedge.be5.metadata.model.BeConnectionProfile)4 Operation (com.developmentontheedge.be5.metadata.model.Operation)4 IOException (java.io.IOException)4 MojoFailureException (org.apache.maven.plugin.MojoFailureException)4 WriteException (com.developmentontheedge.be5.metadata.exception.WriteException)3 FreemarkerCatalog (com.developmentontheedge.be5.metadata.model.FreemarkerCatalog)3 Localizations (com.developmentontheedge.be5.metadata.model.Localizations)3