Search in sources :

Example 1 with QuerySettings

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);
}
Also used : Path(java.nio.file.Path) Project(com.developmentontheedge.be5.metadata.model.Project) Entity(com.developmentontheedge.be5.metadata.model.Entity) QuerySettings(com.developmentontheedge.be5.metadata.model.QuerySettings) Query(com.developmentontheedge.be5.metadata.model.Query) Module(com.developmentontheedge.be5.metadata.model.Module) Test(org.junit.Test)

Aggregations

Entity (com.developmentontheedge.be5.metadata.model.Entity)1 Module (com.developmentontheedge.be5.metadata.model.Module)1 Project (com.developmentontheedge.be5.metadata.model.Project)1 Query (com.developmentontheedge.be5.metadata.model.Query)1 QuerySettings (com.developmentontheedge.be5.metadata.model.QuerySettings)1 Path (java.nio.file.Path)1 Test (org.junit.Test)1