1 package org.simantics.district.selection;
3 //import static org.junit.Assert.*;
5 //import org.eclipse.core.runtime.NullProgressMonitor;
6 //import org.junit.AfterClass;
7 //import org.junit.Before;
8 //import org.junit.BeforeClass;
9 //import org.junit.Test;
10 //import org.simantics.Simantics;
11 //import org.simantics.db.Resource;
12 //import org.simantics.db.WriteGraph;
13 //import org.simantics.db.common.request.WriteRequest;
14 //import org.simantics.db.exception.DatabaseException;
15 //import org.simantics.db.testing.common.AcornTests;
16 //import org.simantics.layer0.Layer0;
18 //public class ElementSelectorTest {
20 // Resource selection;
21 // Resource generator;
25 // public void setUp() throws DatabaseException {
26 // Simantics.sync(new WriteRequest() {
28 // public void perform(WriteGraph graph) throws DatabaseException {
29 // Layer0 L0 = Layer0.getInstance(graph);
30 // ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
32 // selection = graph.newResource();
33 // graph.claim(selection, L0.InstanceOf, ES.Selection);
34 // graph.claimLiteral(selection, L0.HasLabel, L0.String, "My Selection");
35 // generator = graph.newResource();
36 // graph.claim(selection, ES.Selection_HasGenerator, generator);
37 // selector = graph.newResource();
38 // graph.claim(selection, ES.Selection_HasSelector, selector);
44 // public static void initialize0() throws Exception {
45 // AcornTests.newSimanticsWorkspace(null, null);
49 // public static void deinitialize0() throws Exception {
50 // Simantics.shutdown(new NullProgressMonitor());
54 // public void testExpressionGeneration1() throws DatabaseException {
56 // Simantics.sync(new WriteRequest() {
58 // public void perform(WriteGraph graph) throws DatabaseException {
59 // Layer0 L0 = Layer0.getInstance(graph);
60 // ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
62 // graph.claim(generator, L0.InstanceOf, ES.Generator_Model);
63 // graph.claim(selector, L0.InstanceOf, ES.Selector_NHighest);
64 // graph.claimLiteral(selector, ES.PropertySelector_HasSelectionPropertyName, L0.String, "myProperty");
65 // graph.claimLiteral(selector, ES.PropertySelector_HasResultCount, L0.Integer, 10);
69 // ElementSelector sel = Simantics.sync(new ElementSelector.ElementSelectorQuery(selection));
70 // assertNotNull(sel);
71 // String expression = sel.expression;
72 // assertEquals("select top 10 of myProperty from model", expression);
73 // System.err.println(expression);
77 // public void testExpressionGeneration2() throws DatabaseException {
79 // Simantics.sync(new WriteRequest() {
81 // public void perform(WriteGraph graph) throws DatabaseException {
82 // Layer0 L0 = Layer0.getInstance(graph);
83 // ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
85 // graph.claim(generator, L0.InstanceOf, ES.Generator_Model);
86 // graph.claim(selector, L0.InstanceOf, ES.Selector_NLowest);
87 // graph.claimLiteral(selector, ES.PropertySelector_HasSelectionPropertyName, L0.String, "criteria1");
88 // graph.claimLiteral(selector, ES.PropertySelector_HasResultCount, L0.Integer, 20);
92 // ElementSelector sel = Simantics.sync(new ElementSelector.ElementSelectorQuery(selection));
93 // assertNotNull(sel);
94 // String expression = sel.expression;
95 // assertEquals("select bottom 20 of criteria1 from model", expression);
96 // System.err.println(expression);
100 // public void testExpressionGeneration3() throws DatabaseException {
102 // Simantics.sync(new WriteRequest() {
104 // public void perform(WriteGraph graph) throws DatabaseException {
105 // Layer0 L0 = Layer0.getInstance(graph);
106 // ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
108 // graph.claim(generator, L0.InstanceOf, ES.Generator_Model);
109 // graph.claim(selector, L0.InstanceOf, ES.Selector_All);
113 // ElementSelector sel = Simantics.sync(new ElementSelector.ElementSelectorQuery(selection));
114 // assertNotNull(sel);
115 // String expression = sel.expression;
116 // assertEquals("select all from model", expression);
117 // System.err.println(expression);
121 // public void testExpressionGeneration4() throws DatabaseException {
123 // Simantics.sync(new WriteRequest() {
125 // public void perform(WriteGraph graph) throws DatabaseException {
126 // Layer0 L0 = Layer0.getInstance(graph);
127 // ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
129 // graph.claim(generator, L0.InstanceOf, ES.Generator_Model);
130 // graph.claim(selector, L0.InstanceOf, ES.Selector_All);
131 // Resource condition = graph.newResource();
132 // graph.claim(condition, L0.InstanceOf, ES.PropertyCondition);
133 // graph.claim(condition, ES.Selection_HasCondition_Inverse, selection);
134 // graph.claimLiteral(condition, ES.PropertyCondition_HasPropertyName, L0.String, "myProperty");
135 // graph.claimLiteral(condition, ES.PropertyCondition_HasLowerLimit, L0.Double, 20.0);
139 // ElementSelector sel = Simantics.sync(new ElementSelector.ElementSelectorQuery(selection));
140 // assertNotNull(sel);
141 // String expression = sel.expression;
142 // assertEquals("select all from model where {20.0 < myProperty}", expression);
143 // System.err.println(expression);
147 // public void testExpressionGeneration5() throws DatabaseException {
149 // Simantics.sync(new WriteRequest() {
151 // public void perform(WriteGraph graph) throws DatabaseException {
152 // Layer0 L0 = Layer0.getInstance(graph);
153 // ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
155 // graph.claim(generator, L0.InstanceOf, ES.Generator_Model);
156 // graph.claim(selector, L0.InstanceOf, ES.Selector_NLowest);
157 // graph.claimLiteral(selector, ES.PropertySelector_HasSelectionPropertyName, L0.String, "criteria1");
158 // graph.claimLiteral(selector, ES.PropertySelector_HasResultCount, L0.Integer, 20);
159 // Resource condition = graph.newResource();
160 // graph.claim(condition, L0.InstanceOf, ES.PropertyCondition);
161 // graph.claim(condition, ES.Selection_HasCondition_Inverse, selection);
162 // graph.claimLiteral(condition, ES.PropertyCondition_HasPropertyName, L0.String, "myProperty");
163 // graph.claimLiteral(condition, ES.PropertyCondition_HasLowerLimit, L0.Double, 20.0);
167 // ElementSelector sel = Simantics.sync(new ElementSelector.ElementSelectorQuery(selection));
168 // assertNotNull(sel);
169 // String expression = sel.expression;
170 // assertEquals("select bottom 20 of criteria1 from model where {20.0 < myProperty}", expression);
171 // System.err.println(expression);
175 // public void testExpressionGeneration6() throws DatabaseException {
177 // Simantics.sync(new WriteRequest() {
179 // public void perform(WriteGraph graph) throws DatabaseException {
180 // Layer0 L0 = Layer0.getInstance(graph);
181 // ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
183 // graph.claim(generator, L0.InstanceOf, ES.Generator_Model);
184 // graph.claim(selector, L0.InstanceOf, ES.Selector_NLowest);
185 // graph.claimLiteral(selector, ES.PropertySelector_HasSelectionPropertyName, L0.String, "criteria1");
186 // graph.claimLiteral(selector, ES.PropertySelector_HasResultCount, L0.Integer, 20);
187 // Resource condition = graph.newResource();
188 // graph.claim(condition, L0.InstanceOf, ES.Disjunction);
189 // graph.claim(condition, ES.Selection_HasCondition_Inverse, selection);
190 // Resource condition1 = graph.newResource();
191 // graph.claim(condition1, L0.InstanceOf, ES.PropertyCondition);
192 // graph.claim(condition1, ES.HasSubcondition_Inverse, condition);
193 // graph.claimLiteral(condition1, ES.PropertyCondition_HasPropertyName, L0.String, "myProperty1");
194 // graph.claimLiteral(condition1, ES.PropertyCondition_HasLowerLimit, L0.Double, 20.0);
195 // Resource condition2 = graph.newResource();
196 // graph.claim(condition2, L0.InstanceOf, ES.PropertyCondition);
197 // graph.claim(condition2, ES.HasSubcondition_Inverse, condition);
198 // graph.claimLiteral(condition2, ES.PropertyCondition_HasPropertyName, L0.String, "myProperty2");
199 // graph.claimLiteral(condition2, ES.PropertyCondition_HasLowerLimit, L0.Double, 0.0);
200 // graph.claimLiteral(condition2, ES.PropertyCondition_HasUpperLimit, L0.Double, 100.0);
204 // ElementSelector sel = Simantics.sync(new ElementSelector.ElementSelectorQuery(selection));
205 // assertNotNull(sel);
206 // String expression = sel.expression;
207 // assertEquals("select bottom 20 of criteria1 from model where {{20.0 < myProperty1} or {0.0 < myProperty2 < 100.0}}", expression);
208 // System.err.println(expression);
212 // public void testExpressionGeneration7() throws DatabaseException {
214 // Simantics.sync(new WriteRequest() {
216 // public void perform(WriteGraph graph) throws DatabaseException {
217 // Layer0 L0 = Layer0.getInstance(graph);
218 // ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
220 // graph.claim(generator, L0.InstanceOf, ES.Generator_Explicit);
221 // for (int i = 0; i < 15; i++) {
222 // graph.claim(generator, ES.Generator_HasSelectedElement, graph.newResource());
224 // graph.claim(selector, L0.InstanceOf, ES.Selector_All);
225 // Resource condition = graph.newResource();
226 // graph.claim(condition, L0.InstanceOf, ES.Disjunction);
227 // graph.claim(condition, ES.Selection_HasCondition_Inverse, selection);
228 // Resource condition1 = graph.newResource();
229 // graph.claim(condition1, L0.InstanceOf, ES.PropertyCondition);
230 // graph.claim(condition1, ES.HasSubcondition_Inverse, condition);
231 // graph.claimLiteral(condition1, ES.PropertyCondition_HasPropertyName, L0.String, "myProperty1");
232 // graph.claimLiteral(condition1, ES.PropertyCondition_HasLowerLimit, L0.Double, 20.0);
233 // Resource condition2 = graph.newResource();
234 // graph.claim(condition2, L0.InstanceOf, ES.PropertyCondition);
235 // graph.claim(condition2, ES.HasSubcondition_Inverse, condition);
236 // graph.claimLiteral(condition2, ES.PropertyCondition_HasPropertyName, L0.String, "myProperty2");
237 // graph.claimLiteral(condition2, ES.PropertyCondition_HasLowerLimit, L0.Double, 0.0);
238 // graph.claimLiteral(condition2, ES.PropertyCondition_HasUpperLimit, L0.Double, 100.0);
242 // ElementSelector sel = Simantics.sync(new ElementSelector.ElementSelectorQuery(selection));
243 // assertNotNull(sel);
244 // String expression = sel.expression;
245 // assertEquals("select all from <list of 15 elements> where {{20.0 < myProperty1} or {0.0 < myProperty2 < 100.0}}", expression);
246 // System.err.println(expression);
250 // public void testExpressionGeneration8() throws DatabaseException {
252 // Simantics.sync(new WriteRequest() {
254 // public void perform(WriteGraph graph) throws DatabaseException {
255 // Layer0 L0 = Layer0.getInstance(graph);
256 // ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
258 // graph.claim(generator, L0.InstanceOf, ES.Generator_Model);
259 // graph.claim(selector, L0.InstanceOf, ES.Selector_All);
260 // Resource condition = graph.newResource();
261 // graph.claim(condition, L0.InstanceOf, ES.Conjunction);
262 // graph.claim(condition, ES.Selection_HasCondition_Inverse, selection);
263 // Resource condition1 = graph.newResource();
264 // graph.claim(condition1, L0.InstanceOf, ES.PropertyCondition);
265 // graph.claim(condition1, ES.HasSubcondition_Inverse, condition);
266 // graph.claimLiteral(condition1, ES.PropertyCondition_HasPropertyName, L0.String, "myProperty1");
267 // Resource condition2 = graph.newResource();
268 // graph.claim(condition2, L0.InstanceOf, ES.RegionCondition);
269 // graph.claim(condition2, ES.HasSubcondition_Inverse, condition);
270 // Resource region = graph.newResource();
271 // graph.claim(condition2, ES.RegionCondition_HasRegion, region);
272 // graph.claim(region, L0.InstanceOf, L0.Entity);
273 // graph.claimLiteral(region, L0.HasLabel, L0.String, "region1");
277 // ElementSelector sel = Simantics.sync(new ElementSelector.ElementSelectorQuery(selection));
278 // assertNotNull(sel);
279 // String expression = sel.expression;
280 // assertEquals("select all from model where {{has property myProperty1} and {in region region1}}", expression);
281 // System.err.println(expression);