use of com.developmentontheedge.be5.metadata.model.QuerySettings in project be5 by DevelopmentOnTheEdge.
the class ReadModelFromXmlTest method testWriteReadQuerySettings.
@Test
public void testWriteReadQuerySettings() throws Exception {
final Project project = new Project("TestProject");
project.setRoles(Arrays.asList("Admin", "Guest", "User"));
final Module module = project.getApplication();
DataElementUtils.saveQuiet(module);
final Entity table = new Entity("table", module, EntityType.TABLE);
DataElementUtils.saveQuiet(table);
final Query query = new Query("q", table);
DataElementUtils.saveQuiet(query);
final Query query2 = new Query("q2", table);
DataElementUtils.saveQuiet(query2);
final QuerySettings set1 = new QuerySettings(query);
set1.setColorSchemeID(1L);
set1.getRoles().setValues(project.getRoles());
set1.setBeautifier("my.beautifier");
query.setQuerySettings(new QuerySettings[] { set1 });
final QuerySettings set2 = new QuerySettings(query2);
set2.setColorSchemeID(null);
set2.setAutoRefresh(30);
set2.getRoles().setValues(Arrays.asList("Admin", "Guest"));
final QuerySettings set3 = new QuerySettings(query2);
set3.setColorSchemeID(1L);
set3.getRoles().setValues(Arrays.asList("User"));
query2.setQuerySettings(new QuerySettings[] { set2, set3 });
final Path tempFolder = Files.createTempDirectory("be4-temp");
Serialization.save(project, tempFolder);
final Project readProject = Serialization.load(tempFolder);
final Entity readEntity = readProject.getApplication().getEntity("table");
QuerySettings[] querySettings = readEntity.getQueries().get("q").getQuerySettings();
assertEquals(1, querySettings.length);
assertEquals((Long) 1L, querySettings[0].getColorSchemeID());
assertEquals("my.beautifier", querySettings[0].getBeautifier());
assertEquals(new HashSet<>(project.getRoles()), querySettings[0].getRoles().getFinalRoles());
querySettings = readEntity.getQueries().get("q2").getQuerySettings();
assertEquals(2, querySettings.length);
assertEquals(null, querySettings[0].getColorSchemeID());
// TODO assertEquals(null, querySettings[0].getBeautifier());
assertEquals(30, querySettings[0].getAutoRefresh());
assertEquals(new HashSet<>(Arrays.asList("Admin", "Guest")), querySettings[0].getRoles().getFinalRoles());
assertEquals((Long) 1L, querySettings[1].getColorSchemeID());
// TODO assertEquals(null, querySettings[1].getBeautifier());
assertEquals(0, querySettings[1].getAutoRefresh());
assertEquals(new HashSet<>(Arrays.asList("User")), querySettings[1].getRoles().getFinalRoles());
FileUtils.deleteRecursively(tempFolder);
}
Aggregations