1 package org.simantics.db.tests.api.readGraph.common;
5 import org.simantics.db.Resource;
6 import org.simantics.db.WriteGraph;
7 import org.simantics.db.exception.DatabaseException;
8 import org.simantics.db.tests.common.Writes;
9 import org.simantics.layer0.Layer0;
11 /* Provides simple ontologies for unit tests of various functionalities of
12 * ReadGraph and WriteGraph methods.
14 public class Ontologies {
16 public static Resource typeMultipleSupertype(Layer0 L0, WriteGraph graph)
17 throws DatabaseException {
19 // New type with assertions
20 Resource type = graph.newResource();
21 graph.claim(type, L0.Inherits, L0.Entity);
23 Resource named1 = Writes.named(graph, UUID.randomUUID().toString());
24 Resource named2 = Writes.named(graph, UUID.randomUUID().toString());
25 graph.claim(type, L0.SupertypeOf, named1);
26 graph.claim(type, L0.SupertypeOf, named2);
32 public static Resource typeInherited(Layer0 L0, WriteGraph graph)
33 throws DatabaseException {
35 // Create first resource and give it a name
36 Resource type = graph.newResource();
37 graph.claim(type, L0.Inherits, L0.Entity);
38 Resource string1 = Writes.string(graph, UUID.randomUUID().toString());
39 graph.claim(type, L0.HasName, string1);
41 // Create second resource and give it a name
42 Resource type2 = graph.newResource();
43 Resource string2 = Writes.string(graph, UUID.randomUUID().toString());
44 graph.claim(type2, L0.HasName, string2);
46 // second resource inherits from first resource
47 graph.claim(type2, L0.Inherits, type);
52 public static Resource typeMultipleFunctional(Layer0 L0, WriteGraph graph)
53 throws DatabaseException {
55 Resource type = graph.newResource();
56 graph.claim(type, L0.Inherits, L0.Entity);
58 Resource string1 = Writes.string(graph, UUID.randomUUID().toString());
59 Resource string2 = Writes.string(graph, UUID.randomUUID().toString());
60 Resource string3 = Writes.string(graph, UUID.randomUUID().toString());
62 graph.claim(type, L0.HasName, string1);
63 graph.claim(type, L0.HasName, string2);
64 graph.claim(type, L0.HasName, string3);
69 public static Resource typeMultipleInheritance(Layer0 L0, WriteGraph graph)
70 throws DatabaseException {
72 // New type with assertions
73 Resource type2 = graph.newResource();
74 graph.claim(type2, L0.Inherits, L0.Entity);
75 Resource type3 = graph.newResource();
76 graph.claim(type3, L0.Inherits, L0.Entity);
77 Resource type = graph.newResource();
79 Resource string1 = Writes.string(graph, UUID.randomUUID().toString());
80 Resource string2 = Writes.string(graph, UUID.randomUUID().toString());
82 graph.claim(type2, L0.InstanceOf, string1);
83 graph.claim(type3, L0.InstanceOf, string2);
85 graph.claim(type, L0.Inherits, type2);
86 graph.claim(type, L0.Inherits, type3);
91 public static Resource typeMultipleInheritanceConsistsOf(Layer0 L0,
92 WriteGraph graph) throws DatabaseException {
94 Resource type2 = graph.newResource();
95 graph.claim(type2, L0.Inherits, L0.Entity);
96 Resource type3 = graph.newResource();
97 graph.claim(type3, L0.Inherits, L0.Entity);
98 Resource type = graph.newResource();
99 graph.claim(type, L0.Inherits, type2);
100 graph.claim(type, L0.Inherits, type3);
102 Resource named1 = Writes.named(graph, UUID.randomUUID().toString());
103 Resource named2 = Writes.named(graph, UUID.randomUUID().toString());
104 Resource named3 = Writes.named(graph, UUID.randomUUID().toString());
105 Resource named4 = Writes.named(graph, UUID.randomUUID().toString());
106 Resource named5 = Writes.named(graph, UUID.randomUUID().toString());
107 Resource named6 = Writes.named(graph, UUID.randomUUID().toString());
109 graph.claim(type, L0.ConsistsOf, named1);
110 graph.claim(type, L0.ConsistsOf, named2);
111 graph.claim(type2, L0.ConsistsOf, named3);
112 graph.claim(type2, L0.ConsistsOf, named4);
113 graph.claim(type3, L0.ConsistsOf, named5);
114 graph.claim(type3, L0.ConsistsOf, named6);
119 public static Resource typeConsistsOfInheritance(Layer0 L0, WriteGraph graph)
120 throws DatabaseException {
122 Resource type2 = graph.newResource();
123 graph.claim(type2, L0.Inherits, L0.Entity);
124 Resource type3 = graph.newResource();
125 graph.claim(type3, L0.Inherits, L0.Entity);
126 Resource type = graph.newResource();
127 graph.claim(type, L0.Inherits, type2);
128 graph.claim(type, L0.Inherits, type3);
130 Resource named1 = Writes.named(graph, UUID.randomUUID().toString());
132 graph.claim(type, L0.ConsistsOf, named1);
133 graph.claim(type2, L0.ConsistsOf, named1);
134 graph.claim(type3, L0.ConsistsOf, named1);
140 public static Resource typeX(Layer0 L0, WriteGraph graph)
141 throws DatabaseException {
143 // New type with assertions
144 Resource type = graph.newResource();
145 graph.claim(type, L0.Inherits, L0.Entity);
147 Resource named1 = Writes.named(graph, UUID.randomUUID().toString());
148 Resource named2 = Writes.named(graph, UUID.randomUUID().toString());
149 Resource string1 = Writes.string(graph, UUID.randomUUID().toString());
151 // Assert some nonfunctional objects
152 graph.claim(type, L0.Asserts,
153 Writes.assertion(graph, L0.ConsistsOf, named1));
154 graph.claim(type, L0.Asserts,
155 Writes.assertion(graph, L0.ConsistsOf, named2));
157 // Assert a functional object
158 graph.claim(type, L0.Asserts,
159 Writes.assertion(graph, L0.HasName, string1));
164 public static Resource typeCyclicInheritance(Layer0 L0, WriteGraph graph)
165 throws DatabaseException {
166 // Create first resource and give it a name
167 Resource type1 = graph.newResource();
168 graph.claim(type1, L0.Inherits, L0.Entity);
169 Resource string1 = Writes.string(graph, UUID.randomUUID().toString());
170 graph.claim(type1, L0.HasName, string1);
172 // Create second resource and give it a name
173 Resource type2 = graph.newResource();
174 graph.claim(type2, L0.Inherits, L0.Entity);
176 Resource string2 = Writes.string(graph, UUID.randomUUID().toString());
177 graph.claim(type2, L0.HasName, string2);
179 // Create third resource and give it a name
180 Resource type3 = graph.newResource();
181 graph.claim(type3, L0.Inherits, L0.Entity);
183 string2 = Writes.string(graph, UUID.randomUUID().toString());
184 graph.claim(type2, L0.HasName, string2);
186 // second resource inherits from first resource
187 graph.claim(type2, L0.Inherits, type1);
188 // third resource inherits from second resource
189 graph.claim(type3, L0.Inherits, type2);
190 // Completing loop: first resource inherits from third resource
191 graph.claim(type1, L0.Inherits, type3);
196 public static Resource typeMultipleFunctionalAssertions(Layer0 L0,
197 WriteGraph graph) throws DatabaseException {
198 Resource type = graph.newResource();
199 graph.claim(type, L0.Inherits, L0.Entity);
201 Resource string1 = Writes.string(graph, UUID.randomUUID().toString());
202 Resource string2 = Writes.string(graph, UUID.randomUUID().toString());
203 Resource string3 = Writes.string(graph, UUID.randomUUID().toString());
205 graph.claim(type, L0.Asserts,
206 Writes.assertion(graph, L0.HasName, string1));
207 graph.claim(type, L0.Asserts,
208 Writes.assertion(graph, L0.HasName, string2));
209 graph.claim(type, L0.Asserts,
210 Writes.assertion(graph, L0.HasName, string3));
215 public static Resource typeFunctionalAndNonFunctionalAssertions(Layer0 L0,
216 WriteGraph graph) throws DatabaseException {
218 // New type with assertions
219 Resource type = graph.newResource();
220 graph.claim(type, L0.Inherits, L0.Entity);
222 Resource named1 = Writes.named(graph, UUID.randomUUID().toString());
223 Resource named2 = Writes.named(graph, UUID.randomUUID().toString());
224 Resource string1 = Writes.string(graph, UUID.randomUUID().toString());
226 // Assert some nonfunctional objects
227 graph.claim(type, L0.Asserts,
228 Writes.assertion(graph, L0.ConsistsOf, named1));
229 graph.claim(type, L0.Asserts,
230 Writes.assertion(graph, L0.ConsistsOf, named2));
232 // Assert a functional object
233 graph.claim(type, L0.Asserts,
234 Writes.assertion(graph, L0.HasName, string1));
239 public static Resource typeCyclicAssertion(Layer0 L0, WriteGraph graph)
240 throws DatabaseException {
242 // New type with assertions
243 Resource type1 = graph.newResource();
244 graph.claim(type1, L0.Inherits, L0.Entity);
245 Resource type2 = graph.newResource();
246 graph.claim(type2, L0.Inherits, L0.Entity);
247 graph.claim(type1, L0.HasName,
248 Writes.string(graph, UUID.randomUUID().toString()));
250 // named1 = Writes.named(graph, UUID.randomUUID().toString());
251 // named2 = Writes.named(graph, UUID.randomUUID().toString());
253 // Assert some nonfunctional objects
254 graph.claim(type1, L0.Asserts,
255 Writes.assertion(graph, L0.ConsistsOf, type2));
256 graph.claim(type2, L0.Asserts,
257 Writes.assertion(graph, L0.ConsistsOf, type1));
261 public static Resource blankInstanceofEntity(Layer0 L0, WriteGraph graph)
262 throws DatabaseException {
263 Resource resource = graph.newResource();
264 graph.claim(resource, L0.InstanceOf, null, L0.Entity);
267 public static Resource relatedTypelessResource(Layer0 L0, WriteGraph graph)
268 throws DatabaseException {
269 Resource resource = graph.newResource();
270 Resource name = graph.newResource();
271 graph.claim(name, L0.InstanceOf, null, L0.String);
272 graph.claimValue(name, "A Typeless Resource");
273 graph.claim(resource, L0.HasName, name);
276 public static Resource relatedConsiststOfString(Layer0 L0, WriteGraph graph)
277 throws DatabaseException {
278 Resource instance = graph.newResource();
279 Resource resource = graph.newResource();
280 graph.claim(instance, L0.InstanceOf, null, L0.String);
281 graph.claimValue(instance, "Test String");
282 graph.claim(resource, L0.ConsistsOf, instance);
285 public static Resource relatedTypelessConsistsOf(Layer0 L0, WriteGraph graph)
286 throws DatabaseException {
287 Resource resource1 = graph.newResource();
288 Resource resource2 = graph.newResource();
289 Resource name = graph.newResource();
290 graph.claim(name, L0.InstanceOf, null, L0.String);
291 graph.claimValue(name, "A Typeless Resource");
292 graph.claim(resource1, L0.HasName, name);
293 graph.claim(resource2, L0.ConsistsOf, resource1);
297 public static Resource value1(Layer0 L0, WriteGraph graph) throws DatabaseException {
299 assertTrue(g.<Boolean>getValue(l0.True));
301 g.getValue(l0.Entity);
302 } catch (DoesNotContainValueException e) {
305 fail("GetValue did not throw DoesNotContainValueException.");
309 public static Resource value2(Layer0 L0, WriteGraph graph) throws DatabaseException {
310 s.syncRequest(new ReadRequest() {
312 public void run(ReadGraph g) throws DatabaseException {
313 Layer0 l0 = Layer0.getInstance(g);
314 // g.getValue(null, null);
315 assertTrue(g.<Boolean>getValue(l0.True, Bindings.BOOLEAN));
317 g.getValue(l0.Entity, Bindings.BOOLEAN);
318 } catch (DoesNotContainValueException e) {
321 fail("GetValue did not throw DoesNotContainValueException.");