]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.district.selection/src/org/simantics/district/selection/ElementSelectorTest.java
Resolve tie situations in n lowest/highest element selection.
[simantics/district.git] / org.simantics.district.selection / src / org / simantics / district / selection / ElementSelectorTest.java
1 package org.simantics.district.selection;
2
3 //import static org.junit.Assert.*;
4 //
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;
17 //
18 //public class ElementSelectorTest {
19 //
20 //      Resource selection;
21 //      Resource generator;
22 //      Resource selector;
23 //      
24 //      @Before
25 //      public void setUp() throws DatabaseException {
26 //              Simantics.sync(new WriteRequest() {
27 //                      @Override
28 //                      public void perform(WriteGraph graph) throws DatabaseException {
29 //                              Layer0 L0 = Layer0.getInstance(graph);
30 //                              ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
31 //                              
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);
39 //                      }
40 //              });
41 //      }
42 //      
43 //      @BeforeClass
44 //      public static void initialize0() throws Exception {
45 //              AcornTests.newSimanticsWorkspace(null, null);
46 //      }
47 //
48 //      @AfterClass
49 //      public static void deinitialize0() throws Exception {
50 //              Simantics.shutdown(new NullProgressMonitor());
51 //      }
52 //      
53 //      @Test
54 //      public void testExpressionGeneration1() throws DatabaseException {
55 //              
56 //              Simantics.sync(new WriteRequest() {
57 //                      @Override
58 //                      public void perform(WriteGraph graph) throws DatabaseException {
59 //                              Layer0 L0 = Layer0.getInstance(graph);
60 //                              ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
61 //                              
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);
66 //                      }
67 //              });
68 //              
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);
74 //      }
75 //      
76 //      @Test
77 //      public void testExpressionGeneration2() throws DatabaseException {
78 //              
79 //              Simantics.sync(new WriteRequest() {
80 //                      @Override
81 //                      public void perform(WriteGraph graph) throws DatabaseException {
82 //                              Layer0 L0 = Layer0.getInstance(graph);
83 //                              ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
84 //                              
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);
89 //                      }
90 //              });
91 //              
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);
97 //      }
98 //      
99 //      @Test
100 //      public void testExpressionGeneration3() throws DatabaseException {
101 //              
102 //              Simantics.sync(new WriteRequest() {
103 //                      @Override
104 //                      public void perform(WriteGraph graph) throws DatabaseException {
105 //                              Layer0 L0 = Layer0.getInstance(graph);
106 //                              ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
107 //                              
108 //                              graph.claim(generator, L0.InstanceOf, ES.Generator_Model);
109 //                              graph.claim(selector, L0.InstanceOf, ES.Selector_All);
110 //                      }
111 //              });
112 //              
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);
118 //      }
119 //      
120 //      @Test
121 //      public void testExpressionGeneration4() throws DatabaseException {
122 //              
123 //              Simantics.sync(new WriteRequest() {
124 //                      @Override
125 //                      public void perform(WriteGraph graph) throws DatabaseException {
126 //                              Layer0 L0 = Layer0.getInstance(graph);
127 //                              ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
128 //                              
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);
136 //                      }
137 //              });
138 //              
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);
144 //      }
145 //      
146 //      @Test
147 //      public void testExpressionGeneration5() throws DatabaseException {
148 //              
149 //              Simantics.sync(new WriteRequest() {
150 //                      @Override
151 //                      public void perform(WriteGraph graph) throws DatabaseException {
152 //                              Layer0 L0 = Layer0.getInstance(graph);
153 //                              ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
154 //                              
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);
164 //                      }
165 //              });
166 //              
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);
172 //      }
173 //      
174 //      @Test
175 //      public void testExpressionGeneration6() throws DatabaseException {
176 //              
177 //              Simantics.sync(new WriteRequest() {
178 //                      @Override
179 //                      public void perform(WriteGraph graph) throws DatabaseException {
180 //                              Layer0 L0 = Layer0.getInstance(graph);
181 //                              ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
182 //                              
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);
201 //                      }
202 //              });
203 //              
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);
209 //      }
210 //      
211 //      @Test
212 //      public void testExpressionGeneration7() throws DatabaseException {
213 //              
214 //              Simantics.sync(new WriteRequest() {
215 //                      @Override
216 //                      public void perform(WriteGraph graph) throws DatabaseException {
217 //                              Layer0 L0 = Layer0.getInstance(graph);
218 //                              ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
219 //                              
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());
223 //                              }
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);
239 //                      }
240 //              });
241 //              
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);
247 //      }
248 //      
249 //      @Test
250 //      public void testExpressionGeneration8() throws DatabaseException {
251 //              
252 //              Simantics.sync(new WriteRequest() {
253 //                      @Override
254 //                      public void perform(WriteGraph graph) throws DatabaseException {
255 //                              Layer0 L0 = Layer0.getInstance(graph);
256 //                              ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
257 //                              
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");
274 //                      }
275 //              });
276 //              
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);
282 //      }
283 //}