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;
}
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");
}
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));
}
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());
}
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"));
}
Aggregations