--- /dev/null
+package org.simantics.district.selection;
+
+//import static org.junit.Assert.*;
+//
+//import org.eclipse.core.runtime.NullProgressMonitor;
+//import org.junit.AfterClass;
+//import org.junit.Before;
+//import org.junit.BeforeClass;
+//import org.junit.Test;
+//import org.simantics.Simantics;
+//import org.simantics.db.Resource;
+//import org.simantics.db.WriteGraph;
+//import org.simantics.db.common.request.WriteRequest;
+//import org.simantics.db.exception.DatabaseException;
+//import org.simantics.db.testing.common.AcornTests;
+//import org.simantics.layer0.Layer0;
+//
+//public class ElementSelectorTest {
+//
+// Resource selection;
+// Resource generator;
+// Resource selector;
+//
+// @Before
+// public void setUp() throws DatabaseException {
+// Simantics.sync(new WriteRequest() {
+// @Override
+// public void perform(WriteGraph graph) throws DatabaseException {
+// Layer0 L0 = Layer0.getInstance(graph);
+// ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
+//
+// selection = graph.newResource();
+// graph.claim(selection, L0.InstanceOf, ES.Selection);
+// graph.claimLiteral(selection, L0.HasLabel, L0.String, "My Selection");
+// generator = graph.newResource();
+// graph.claim(selection, ES.Selection_HasGenerator, generator);
+// selector = graph.newResource();
+// graph.claim(selection, ES.Selection_HasSelector, selector);
+// }
+// });
+// }
+//
+// @BeforeClass
+// public static void initialize0() throws Exception {
+// AcornTests.newSimanticsWorkspace(null, null);
+// }
+//
+// @AfterClass
+// public static void deinitialize0() throws Exception {
+// Simantics.shutdown(new NullProgressMonitor());
+// }
+//
+// @Test
+// public void testExpressionGeneration1() throws DatabaseException {
+//
+// Simantics.sync(new WriteRequest() {
+// @Override
+// public void perform(WriteGraph graph) throws DatabaseException {
+// Layer0 L0 = Layer0.getInstance(graph);
+// ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
+//
+// graph.claim(generator, L0.InstanceOf, ES.Generator_Model);
+// graph.claim(selector, L0.InstanceOf, ES.Selector_NHighest);
+// graph.claimLiteral(selector, ES.PropertySelector_HasSelectionPropertyName, L0.String, "myProperty");
+// graph.claimLiteral(selector, ES.PropertySelector_HasResultCount, L0.Integer, 10);
+// }
+// });
+//
+// ElementSelector sel = Simantics.sync(new ElementSelector.ElementSelectorQuery(selection));
+// assertNotNull(sel);
+// String expression = sel.expression;
+// assertEquals("select top 10 of myProperty from model", expression);
+// System.err.println(expression);
+// }
+//
+// @Test
+// public void testExpressionGeneration2() throws DatabaseException {
+//
+// Simantics.sync(new WriteRequest() {
+// @Override
+// public void perform(WriteGraph graph) throws DatabaseException {
+// Layer0 L0 = Layer0.getInstance(graph);
+// ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
+//
+// graph.claim(generator, L0.InstanceOf, ES.Generator_Model);
+// graph.claim(selector, L0.InstanceOf, ES.Selector_NLowest);
+// graph.claimLiteral(selector, ES.PropertySelector_HasSelectionPropertyName, L0.String, "criteria1");
+// graph.claimLiteral(selector, ES.PropertySelector_HasResultCount, L0.Integer, 20);
+// }
+// });
+//
+// ElementSelector sel = Simantics.sync(new ElementSelector.ElementSelectorQuery(selection));
+// assertNotNull(sel);
+// String expression = sel.expression;
+// assertEquals("select bottom 20 of criteria1 from model", expression);
+// System.err.println(expression);
+// }
+//
+// @Test
+// public void testExpressionGeneration3() throws DatabaseException {
+//
+// Simantics.sync(new WriteRequest() {
+// @Override
+// public void perform(WriteGraph graph) throws DatabaseException {
+// Layer0 L0 = Layer0.getInstance(graph);
+// ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
+//
+// graph.claim(generator, L0.InstanceOf, ES.Generator_Model);
+// graph.claim(selector, L0.InstanceOf, ES.Selector_All);
+// }
+// });
+//
+// ElementSelector sel = Simantics.sync(new ElementSelector.ElementSelectorQuery(selection));
+// assertNotNull(sel);
+// String expression = sel.expression;
+// assertEquals("select all from model", expression);
+// System.err.println(expression);
+// }
+//
+// @Test
+// public void testExpressionGeneration4() throws DatabaseException {
+//
+// Simantics.sync(new WriteRequest() {
+// @Override
+// public void perform(WriteGraph graph) throws DatabaseException {
+// Layer0 L0 = Layer0.getInstance(graph);
+// ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
+//
+// graph.claim(generator, L0.InstanceOf, ES.Generator_Model);
+// graph.claim(selector, L0.InstanceOf, ES.Selector_All);
+// Resource condition = graph.newResource();
+// graph.claim(condition, L0.InstanceOf, ES.PropertyCondition);
+// graph.claim(condition, ES.Selection_HasCondition_Inverse, selection);
+// graph.claimLiteral(condition, ES.PropertyCondition_HasPropertyName, L0.String, "myProperty");
+// graph.claimLiteral(condition, ES.PropertyCondition_HasLowerLimit, L0.Double, 20.0);
+// }
+// });
+//
+// ElementSelector sel = Simantics.sync(new ElementSelector.ElementSelectorQuery(selection));
+// assertNotNull(sel);
+// String expression = sel.expression;
+// assertEquals("select all from model where {20.0 < myProperty}", expression);
+// System.err.println(expression);
+// }
+//
+// @Test
+// public void testExpressionGeneration5() throws DatabaseException {
+//
+// Simantics.sync(new WriteRequest() {
+// @Override
+// public void perform(WriteGraph graph) throws DatabaseException {
+// Layer0 L0 = Layer0.getInstance(graph);
+// ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
+//
+// graph.claim(generator, L0.InstanceOf, ES.Generator_Model);
+// graph.claim(selector, L0.InstanceOf, ES.Selector_NLowest);
+// graph.claimLiteral(selector, ES.PropertySelector_HasSelectionPropertyName, L0.String, "criteria1");
+// graph.claimLiteral(selector, ES.PropertySelector_HasResultCount, L0.Integer, 20);
+// Resource condition = graph.newResource();
+// graph.claim(condition, L0.InstanceOf, ES.PropertyCondition);
+// graph.claim(condition, ES.Selection_HasCondition_Inverse, selection);
+// graph.claimLiteral(condition, ES.PropertyCondition_HasPropertyName, L0.String, "myProperty");
+// graph.claimLiteral(condition, ES.PropertyCondition_HasLowerLimit, L0.Double, 20.0);
+// }
+// });
+//
+// ElementSelector sel = Simantics.sync(new ElementSelector.ElementSelectorQuery(selection));
+// assertNotNull(sel);
+// String expression = sel.expression;
+// assertEquals("select bottom 20 of criteria1 from model where {20.0 < myProperty}", expression);
+// System.err.println(expression);
+// }
+//
+// @Test
+// public void testExpressionGeneration6() throws DatabaseException {
+//
+// Simantics.sync(new WriteRequest() {
+// @Override
+// public void perform(WriteGraph graph) throws DatabaseException {
+// Layer0 L0 = Layer0.getInstance(graph);
+// ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
+//
+// graph.claim(generator, L0.InstanceOf, ES.Generator_Model);
+// graph.claim(selector, L0.InstanceOf, ES.Selector_NLowest);
+// graph.claimLiteral(selector, ES.PropertySelector_HasSelectionPropertyName, L0.String, "criteria1");
+// graph.claimLiteral(selector, ES.PropertySelector_HasResultCount, L0.Integer, 20);
+// Resource condition = graph.newResource();
+// graph.claim(condition, L0.InstanceOf, ES.Disjunction);
+// graph.claim(condition, ES.Selection_HasCondition_Inverse, selection);
+// Resource condition1 = graph.newResource();
+// graph.claim(condition1, L0.InstanceOf, ES.PropertyCondition);
+// graph.claim(condition1, ES.HasSubcondition_Inverse, condition);
+// graph.claimLiteral(condition1, ES.PropertyCondition_HasPropertyName, L0.String, "myProperty1");
+// graph.claimLiteral(condition1, ES.PropertyCondition_HasLowerLimit, L0.Double, 20.0);
+// Resource condition2 = graph.newResource();
+// graph.claim(condition2, L0.InstanceOf, ES.PropertyCondition);
+// graph.claim(condition2, ES.HasSubcondition_Inverse, condition);
+// graph.claimLiteral(condition2, ES.PropertyCondition_HasPropertyName, L0.String, "myProperty2");
+// graph.claimLiteral(condition2, ES.PropertyCondition_HasLowerLimit, L0.Double, 0.0);
+// graph.claimLiteral(condition2, ES.PropertyCondition_HasUpperLimit, L0.Double, 100.0);
+// }
+// });
+//
+// ElementSelector sel = Simantics.sync(new ElementSelector.ElementSelectorQuery(selection));
+// assertNotNull(sel);
+// String expression = sel.expression;
+// assertEquals("select bottom 20 of criteria1 from model where {{20.0 < myProperty1} or {0.0 < myProperty2 < 100.0}}", expression);
+// System.err.println(expression);
+// }
+//
+// @Test
+// public void testExpressionGeneration7() throws DatabaseException {
+//
+// Simantics.sync(new WriteRequest() {
+// @Override
+// public void perform(WriteGraph graph) throws DatabaseException {
+// Layer0 L0 = Layer0.getInstance(graph);
+// ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
+//
+// graph.claim(generator, L0.InstanceOf, ES.Generator_Explicit);
+// for (int i = 0; i < 15; i++) {
+// graph.claim(generator, ES.Generator_HasSelectedElement, graph.newResource());
+// }
+// graph.claim(selector, L0.InstanceOf, ES.Selector_All);
+// Resource condition = graph.newResource();
+// graph.claim(condition, L0.InstanceOf, ES.Disjunction);
+// graph.claim(condition, ES.Selection_HasCondition_Inverse, selection);
+// Resource condition1 = graph.newResource();
+// graph.claim(condition1, L0.InstanceOf, ES.PropertyCondition);
+// graph.claim(condition1, ES.HasSubcondition_Inverse, condition);
+// graph.claimLiteral(condition1, ES.PropertyCondition_HasPropertyName, L0.String, "myProperty1");
+// graph.claimLiteral(condition1, ES.PropertyCondition_HasLowerLimit, L0.Double, 20.0);
+// Resource condition2 = graph.newResource();
+// graph.claim(condition2, L0.InstanceOf, ES.PropertyCondition);
+// graph.claim(condition2, ES.HasSubcondition_Inverse, condition);
+// graph.claimLiteral(condition2, ES.PropertyCondition_HasPropertyName, L0.String, "myProperty2");
+// graph.claimLiteral(condition2, ES.PropertyCondition_HasLowerLimit, L0.Double, 0.0);
+// graph.claimLiteral(condition2, ES.PropertyCondition_HasUpperLimit, L0.Double, 100.0);
+// }
+// });
+//
+// ElementSelector sel = Simantics.sync(new ElementSelector.ElementSelectorQuery(selection));
+// assertNotNull(sel);
+// String expression = sel.expression;
+// assertEquals("select all from <list of 15 elements> where {{20.0 < myProperty1} or {0.0 < myProperty2 < 100.0}}", expression);
+// System.err.println(expression);
+// }
+//
+// @Test
+// public void testExpressionGeneration8() throws DatabaseException {
+//
+// Simantics.sync(new WriteRequest() {
+// @Override
+// public void perform(WriteGraph graph) throws DatabaseException {
+// Layer0 L0 = Layer0.getInstance(graph);
+// ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
+//
+// graph.claim(generator, L0.InstanceOf, ES.Generator_Model);
+// graph.claim(selector, L0.InstanceOf, ES.Selector_All);
+// Resource condition = graph.newResource();
+// graph.claim(condition, L0.InstanceOf, ES.Conjunction);
+// graph.claim(condition, ES.Selection_HasCondition_Inverse, selection);
+// Resource condition1 = graph.newResource();
+// graph.claim(condition1, L0.InstanceOf, ES.PropertyCondition);
+// graph.claim(condition1, ES.HasSubcondition_Inverse, condition);
+// graph.claimLiteral(condition1, ES.PropertyCondition_HasPropertyName, L0.String, "myProperty1");
+// Resource condition2 = graph.newResource();
+// graph.claim(condition2, L0.InstanceOf, ES.RegionCondition);
+// graph.claim(condition2, ES.HasSubcondition_Inverse, condition);
+// Resource region = graph.newResource();
+// graph.claim(condition2, ES.RegionCondition_HasRegion, region);
+// graph.claim(region, L0.InstanceOf, L0.Entity);
+// graph.claimLiteral(region, L0.HasLabel, L0.String, "region1");
+// }
+// });
+//
+// ElementSelector sel = Simantics.sync(new ElementSelector.ElementSelectorQuery(selection));
+// assertNotNull(sel);
+// String expression = sel.expression;
+// assertEquals("select all from model where {{has property myProperty1} and {in region region1}}", expression);
+// System.err.println(expression);
+// }
+//}