use of org.teiid.metadata.Role in project teiid by teiid.
the class TestDDLStringVisitor method testGrants.
@Test
public void testGrants() throws Exception {
Database db = new Database("foo", "2");
Role role = new Role("admin");
role.setAnyAuthenticated(true);
Role role1 = new Role("uber");
Grant.Permission permission = new Grant.Permission();
permission.setAllowAlter(true);
permission.setAllowSelect(true);
permission.setResourceName("schema.tableName");
permission.setResourceType(ResourceType.TABLE);
Grant.Permission permission2 = new Grant.Permission();
permission2.setAllowDelete(true);
permission2.setResourceName("schema.tableName");
permission2.setResourceType(ResourceType.TABLE);
Grant.Permission permission3 = new Grant.Permission();
permission3.setAllowAllPrivileges(true);
permission3.setAllowTemporyTables(true);
Grant.Permission permission4 = new Grant.Permission();
permission4.setAllowTemporyTables(true);
Grant g = new Grant();
g.setRole(role.getName());
g.addPermission(permission);
g.addPermission(permission4);
Grant g2 = new Grant();
g2.setRole(role.getName());
g2.addPermission(permission2);
Grant g3 = new Grant();
g3.setRole("uber");
g3.addPermission(permission3);
db.addRole(role);
db.addRole(role1);
db.addGrant(g);
db.addGrant(g2);
db.addGrant(g3);
String expected = "\n" + "/*\n" + "###########################################\n" + "# START DATABASE foo\n" + "###########################################\n" + "*/\n" + "CREATE DATABASE foo VERSION '2';\n" + "USE DATABASE foo VERSION '2';\n" + "\n" + "--############ Roles ############\n" + "CREATE ROLE admin WITH ANY AUTHENTICATED;\n\n" + "CREATE ROLE uber;\n\n\n" + "--############ Grants ############\n" + "GRANT SELECT,DELETE,ALTER ON TABLE \"schema.tableName\" TO admin;\n" + "GRANT TEMPORARY TABLE TO admin;\n\n" + "GRANT ALL PRIVILEGES TO uber;\n" + "GRANT TEMPORARY TABLE TO uber;\n" + "\n" + "\n" + "/*\n" + "###########################################\n" + "# END DATABASE foo\n" + "###########################################\n" + "*/\n" + "\n";
String metadataDDL = DDLStringVisitor.getDDLString(db);
assertEquals(expected, metadataDDL);
}