]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/readGraph/common/Ontologies.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / api / readGraph / common / Ontologies.java
1 package org.simantics.db.tests.api.readGraph.common;
2
3 import java.util.UUID;
4
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;
10
11 /* Provides simple ontologies for unit tests of various functionalities of
12  * ReadGraph and WriteGraph methods.
13  */
14 public class Ontologies {
15         // 1
16         public static Resource typeMultipleSupertype(Layer0 L0, WriteGraph graph)
17                         throws DatabaseException {
18
19                 // New type with assertions
20                 Resource type = graph.newResource();
21                 graph.claim(type, L0.Inherits, L0.Entity);
22
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);
27                 return type;
28
29         }
30
31         // 2
32         public static Resource typeInherited(Layer0 L0, WriteGraph graph)
33                         throws DatabaseException {
34
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);
40
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);
45
46                 // second resource inherits from first resource
47                 graph.claim(type2, L0.Inherits, type);
48                 return type;
49         }
50
51         // 3
52         public static Resource typeMultipleFunctional(Layer0 L0, WriteGraph graph)
53                         throws DatabaseException {
54
55                 Resource type = graph.newResource();
56                 graph.claim(type, L0.Inherits, L0.Entity);
57
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());
61
62                 graph.claim(type, L0.HasName, string1);
63                 graph.claim(type, L0.HasName, string2);
64                 graph.claim(type, L0.HasName, string3);
65                 return type;
66         }
67
68         // 4
69         public static Resource typeMultipleInheritance(Layer0 L0, WriteGraph graph)
70                         throws DatabaseException {
71
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();
78
79                 Resource string1 = Writes.string(graph, UUID.randomUUID().toString());
80                 Resource string2 = Writes.string(graph, UUID.randomUUID().toString());
81
82                 graph.claim(type2, L0.InstanceOf, string1);
83                 graph.claim(type3, L0.InstanceOf, string2);
84
85                 graph.claim(type, L0.Inherits, type2);
86                 graph.claim(type, L0.Inherits, type3);
87                 return type;
88         }
89
90         // 5
91         public static Resource typeMultipleInheritanceConsistsOf(Layer0 L0,
92                         WriteGraph graph) throws DatabaseException {
93
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);
101
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());
108
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);
115                 return type;
116         }
117
118         // 6
119         public static Resource typeConsistsOfInheritance(Layer0 L0, WriteGraph graph)
120                         throws DatabaseException {
121
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);
129
130                 Resource named1 = Writes.named(graph, UUID.randomUUID().toString());
131
132                 graph.claim(type, L0.ConsistsOf, named1);
133                 graph.claim(type2, L0.ConsistsOf, named1);
134                 graph.claim(type3, L0.ConsistsOf, named1);
135                 return type;
136
137         }
138
139
140         public static Resource typeX(Layer0 L0, WriteGraph graph)
141                         throws DatabaseException {
142
143                 // New type with assertions
144                 Resource type = graph.newResource();
145                 graph.claim(type, L0.Inherits, L0.Entity);
146
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());
150
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));
156
157                 // Assert a functional object
158                 graph.claim(type, L0.Asserts,
159                                 Writes.assertion(graph, L0.HasName, string1));
160                 return type;
161         }
162
163         // 7
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);
171
172                 // Create second resource and give it a name
173                 Resource type2 = graph.newResource();
174                 graph.claim(type2, L0.Inherits, L0.Entity);
175
176                 Resource string2 = Writes.string(graph, UUID.randomUUID().toString());
177                 graph.claim(type2, L0.HasName, string2);
178
179                 // Create third resource and give it a name
180                 Resource type3 = graph.newResource();
181                 graph.claim(type3, L0.Inherits, L0.Entity);
182
183                 string2 = Writes.string(graph, UUID.randomUUID().toString());
184                 graph.claim(type2, L0.HasName, string2);
185
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);
192                 return type1;
193         }
194
195         // assertion3
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);
200
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());
204
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));
211                 return type;
212         }
213
214         // assertion6
215         public static Resource typeFunctionalAndNonFunctionalAssertions(Layer0 L0,
216                         WriteGraph graph) throws DatabaseException {
217
218                 // New type with assertions
219                 Resource type = graph.newResource();
220                 graph.claim(type, L0.Inherits, L0.Entity);
221
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());
225
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));
231
232                 // Assert a functional object
233                 graph.claim(type, L0.Asserts,
234                                 Writes.assertion(graph, L0.HasName, string1));
235                 return type;
236         }
237
238         //assertion7
239         public static Resource typeCyclicAssertion(Layer0 L0, WriteGraph graph)
240                         throws DatabaseException {
241
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()));
249
250                 // named1 = Writes.named(graph, UUID.randomUUID().toString());
251                 // named2 = Writes.named(graph, UUID.randomUUID().toString());
252
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));
258
259                 return type1;
260         }
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);
265                 return resource;
266         }
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);
274                 return resource;
275         }
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);
283                 return resource;
284         }
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);
294                 return resource2;
295         }
296         /* Type testing 
297         public static Resource value1(Layer0 L0, WriteGraph graph) throws DatabaseException {
298
299                 assertTrue(g.<Boolean>getValue(l0.True));
300                 try {
301                     g.getValue(l0.Entity);
302                 } catch (DoesNotContainValueException e) {
303                     return;
304                 }
305                 fail("GetValue did not throw DoesNotContainValueException.");
306             }
307
308     }
309     public static Resource value2(Layer0 L0, WriteGraph graph) throws DatabaseException {
310         s.syncRequest(new ReadRequest() {
311             @Override
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));
316                 try {
317                     g.getValue(l0.Entity, Bindings.BOOLEAN);
318                 } catch (DoesNotContainValueException e) {
319                     return;
320                 }
321                 fail("GetValue did not throw DoesNotContainValueException.");
322             }
323         });
324     }
325          */
326 }